BlockCatIO / solidity-flattener

A python utility to flatten Solidity code with imports into a single file.
MIT License
265 stars 98 forks source link

File outside of allowed directories error. #30

Closed andreafspeziale closed 6 years ago

andreafspeziale commented 6 years ago

Hi, I was trying to flat a very simple contract just to test the library and python requirements:

pragma solidity ^0.4.24;

import "../node_modules/openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "../node_modules/openzeppelin-solidity/contracts/token/ERC20/StandardBurnableToken.sol";

contract myToken is StandardBurnableToken, Ownable {
    string public name = "";
    string public symbol = "";
    uint8 public decimals = 18;
}

and I get this:

solidity_flattener contracts/MyToken.sol
contracts/MyToken.sol:3:1: Error: Source "node_modules/openzeppelin-solidity/contracts/ownership/Ownable.sol" not found: File outside of allowed directories.
import "../node_modules/openzeppelin-solidity/contracts/ownership/Ownable.sol";
^-----------------------------------------------------------------------------^
contracts/MyToken.sol:4:1: Error: Source "node_modules/openzeppelin-solidity/contracts/token/ERC20/StandardBurnableToken.sol" not found: File outside of allowed directories.
import "../node_modules/openzeppelin-solidity/contracts/token/ERC20/StandardBurnableToken.sol";
^---------------------------------------------------------------------------------------------^
Traceback (most recent call last):
  File "/Users/andreaspeziale/Repository/my-token/env/bin/solidity_flattener", line 4, in <module>
    flattener.core.main()
  File "/Users/andreaspeziale/Repository/my-token/env/lib/python3.7/site-packages/flattener/core.py", line 97, in main
    solc_proc.check_returncode()
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 409, in check_returncode
    self.stderr)
subprocess.CalledProcessError: Command '['solc', '--ast', 'contracts/MyToken.sol']' returned non-zero exit status 1.

The $ truffle compile works well.

Thank you for the help.

denisglotov commented 6 years ago

solidity_flattener --solc-path="--allow-paths $PWD/node_modules/zeppelin-solidity/ zeppelin-solidity=$PWD/node_modules/zeppelin-solidity" contracts/MyToken.sol You are welcome.

andreafspeziale commented 6 years ago

I'll try as soon as possible and give u back a feedback thank you so much @denisglotov

andreafspeziale commented 6 years ago

@denisglotov It seems not working:

solidity_flattener --solc-path="--allow-paths $PWD/node_modules/zeppelin-solidity/ zeppelin-solidity=$PWD/node_modules/zeppelin-solidity" contracts/SpaghettiCoin.sol
unrecognised option '--allow-paths /Users/andreaspeziale/Repository/learning/spaghetti-sale/node_modules/zeppelin-solidity/ zeppelin-solidity=/Users/andreaspeziale/Repository/learning/spaghetti-sale/node_modules/zeppelin-solidity'
Traceback (most recent call last):
  File "/Users/andreaspeziale/Repository/learning/spaghetti-sale/env/bin/solidity_flattener", line 4, in <module>
    flattener.core.main()
  File "/Users/andreaspeziale/Repository/learning/spaghetti-sale/env/lib/python3.7/site-packages/flattener/core.py", line 97, in main
    solc_proc.check_returncode()
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 409, in check_returncode
    self.stderr)
subprocess.CalledProcessError: Command '['solc', '--allow-paths /Users/andreaspeziale/Repository/learning/spaghetti-sale/node_modules/zeppelin-solidity/ zeppelin-solidity=/Users/andreaspeziale/Repository/learning/spaghetti-sale/node_modules/zeppelin-solidity', '--ast', 'contracts/SpaghettiCoin.sol']' returned non-zero exit status 1.

This is my sample project :) https://github.com/andreafspeziale/spaghetti-sale

Thanks for the help.

andreafspeziale commented 6 years ago

Any chance to have some help? This repository is siggested by etherscan and I’m wondering why am I having all of this trouble :(. Thanks so much!

XertroV commented 6 years ago

@andreafspeziale --allow-paths takes a comma separated list, not space separated

e.g. solc --allow-paths ./lib,./ens, (this is what i use - also author of patch to introudce --solc-paths to this repo, not sure why but the --allow-paths used to be autoinjected but fell off during somewhere)

also note the trailing , - not sure why but solc seems to not like it if this is omitted

andreafspeziale commented 6 years ago

Thanks for the help @XertroV. I've been able to flat my contract as follow:

solidity_flattener --solc-path="solc --allow-paths $PWD/node_modules/zeppelin-solidity/ zeppelin-solidity=$PWD/node_modules/zeppelin-solidity" contracts/Contract.sol --output $PWD/flattened/SpaghettiCoin.sol

It seems I was just missing the solc keyword before --allow-....... --solc-path="solc --allow-paths

Thanks again!

XertroV commented 6 years ago

@andreafspeziale glad you got it working.

It's weird that adding solc to the start worked.. I wouldn't expect it to given this line: https://github.com/BlockCatIO/solidity-flattener/blob/53b01d1db12a5ef4dfe35adf4bd6e4f73d90d0f8/flattener/core.py#L93

In any case 👍

andreafspeziale commented 6 years ago

@XertroV Yes i noticed it. Actually I don't know maybe I'm missing something else but it worked. Give a look to those two tracebacks. The first one worked the second one nope and the diff is only the solc prefix.

(env) ➜  spaghetti-sale git:(master) solidity_flattener --solc-path="solc --allow-paths $PWD/node_modules/zeppelin-solidity/ zeppelin-solidity=$PWD/node_modules/zeppelin-solidity" contracts/SpaghettiCoin.sol --output $PWD/flattened/SpaghettiCoin.sol

(env) ➜  spaghetti-sale git:(master) solidity_flattener --solc-path="--allow-paths $PWD/node_modules/zeppelin-solidity/ zeppelin-solidity=$PWD/node_modules/zeppelin-solidity" contracts/SpaghettiCoin.sol --output $PWD/flattened/SpaghettiCoin.sol
unrecognised option '--allow-paths /Users/andreaspeziale/Repository/learning/spaghetti-sale/node_modules/zeppelin-solidity/ zeppelin-solidity=/Users/andreaspeziale/Repository/learning/spaghetti-sale/node_modules/zeppelin-solidity'
Traceback (most recent call last):
  File "/Users/andreaspeziale/Repository/learning/spaghetti-sale/env/bin/solidity_flattener", line 4, in <module>
    flattener.core.main()
  File "/Users/andreaspeziale/Repository/learning/spaghetti-sale/env/lib/python3.7/site-packages/flattener/core.py", line 97, in main
    solc_proc.check_returncode()
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 409, in check_returncode
    self.stderr)
subprocess.CalledProcessError: Command '['solc', '--allow-paths /Users/andreaspeziale/Repository/learning/spaghetti-sale/node_modules/zeppelin-solidity/ zeppelin-solidity=/Users/andreaspeziale/Repository/learning/spaghetti-sale/node_modules/zeppelin-solidity', '--ast', 'contracts/SpaghettiCoin.sol']' returned non-zero exit status 1.
(env) ➜  spaghetti-sale git:(master)
Traceback (most recent call last):
  File "/Users/andreaspeziale/Repository/learning/spaghetti-sale/env/bin/solidity_flattener", line 4, in <module>
    flattener.core.main()
  File "/Users/andreaspeziale/Repository/learning/spaghetti-sale/env/lib/python3.7/site-packages/flattener/core.py", line 97, in main
    solc_proc.check_returncode()
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 409, in check_returncode
    self.stderr)
subprocess.CalledProcessError: Command '['solc', '--allow-paths /Users/andreaspeziale/Repository/learning/spaghetti-sale/node_modules/zeppelin-solidity/ zeppelin-solidity=/Users/andreaspeziale/Repository/learning/spaghetti-sale/node_modules/zeppelin-solidity', '--ast', 'contracts/SpaghettiSale.sol']' returned non-zero exit status 1.

(env) ➜  spaghetti-sale git:(master)

unrecognised option '--allow-paths...

Have a nice day!