BlockCatIO / solidity-flattener

A python utility to flatten Solidity code with imports into a single file.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node_modules not supported

rstormsf opened this issue · comments

../ico_per_week/crowdsale/contracts/BlockchainLabsCrowdsale.sol:3:1: Error: Source "zeppelin-solidity/contracts/crowdsale/Crowdsale.sol" not found: Unknown exception in read callback.
import 'zeppelin-solidity/contracts/crowdsale/Crowdsale.sol';
commented

You can use a path re-map to fix this issue. Try this (assuming you are in the root directory of your node project, i.e. where node_modules is located):

solidity_flattener --solc-paths=zeppelin-solidity=$(pwd)/node_modules/zeppelin-solidity/ <your_path_to_contract>/BlockchainLabsCrowdsale.sol

I'm not 100% on how that kind of implicit path remapping is handled (I assume) in Truffle, I assume it does a similar thing behind the scenes.

See here for more information on path remaps: http://solidity.readthedocs.io/en/develop/using-the-compiler.html

It does not work :(

lorien@air:/web/token_qwerty$ ls contracts/
Migrations.sol  QwertyTokenCrowdsale.sol  QwertyToken.sol
lorien@air:/web/token_qwerty$ ls node_modules/zeppelin-solidity/contracts/token/
BasicToken.sol     ERC20Basic.sol  LimitedTransferToken.sol  PausableToken.sol  StandardToken.sol  VestedToken.sol
BurnableToken.sol  ERC20.sol       MintableToken.sol         SafeERC20.sol      TokenTimelock.sol
lorien@air:/web/token_qwerty$ solidity_flattener contracts/QwertyToken.sol --solc-paths="zeppelin-solidity=node_modules/zeppelin-solidity"
Warning: This is a pre-release compiler version, please do not use it in production.
contracts/QwertyToken.sol:3:1: Error: Source "node_modules/zeppelin-solidity/contracts/token/StandardToken.sol" not found: File outside of allowed directories.
import 'zeppelin-solidity/contracts/token/StandardToken.sol';
^-----------------------------------------------------------^
contracts/QwertyToken.sol:4:1: Error: Source "node_modules/zeppelin-solidity/contracts/ownership/Ownable.sol" not found: File outside of allowed directories.
import 'zeppelin-solidity/contracts/ownership/Ownable.sol';
^---------------------------------------------------------^
Traceback (most recent call last):
  File "/usr/local/bin/solidity_flattener", line 99, in <module>
    main()
  File "/usr/local/bin/solidity_flattener", line 95, in main
    solc_proc.check_returncode()
  File "/usr/lib/python3.5/subprocess.py", line 349, in check_returncode
    self.stderr)
subprocess.CalledProcessError: Command '['solc', 'zeppelin-solidity=node_modules/zeppelin-solidity', '--ast', 'contracts/QwertyToken.sol']' returned non-zero exit status 1

The error is Error: Source "node_modules/zeppelin-solidity/contracts/token/StandardToken.sol" not found: File outside of allowed directories.

I found the solution. The problem is that solc can't resolve symlinks. You have to specify absolute path in the --solc-paths options

For instance, /web/project is symlinked to /home/lorien/web/project and we run solc from /web/project directory.
Then the only command that works would be:

solc zeppelin-solidity=/home/lorien/web/project/node_modules/zeppelin-solidity --ast contracts/MyToken.sol

solidity_flattener --solc-paths="zeppelin-solidity/=$(pwd)/node_modules/zeppelin-solidity/" works for me, thanks!