Conversation
solc/CommandLineInterface.cpp
Outdated
| else | ||
| { | ||
| auto infile = boost::filesystem::path(path); | ||
| auto const infile = m_basePath / path; //boost::filesystem::path(path); |
There was a problem hiding this comment.
This changes behaviour: if --base-path is specified, that will be prepended to the filename, e.g. there is no need to use a complete path.
Because of this it may be a breaking change.
There was a problem hiding this comment.
This sounds a bit weird to me - arguments to shell commands should always be files that can be resolved in the usual way.
Shouldn't we rather do something like:
if (absolute_path(m_basePath).isPrefixOf(absolute_path(path)))
path = absolute_path(path).removePrefix(absolute_path(m_basePath))
infile = m_basePath / path;
?
There was a problem hiding this comment.
I guess that can be a convenient feature, however couldn't find similar functions in boost to your pseudocode. Do you have any pointers?
There was a problem hiding this comment.
@chriseth maybe you missed this, but there are no such features in boost/std::fs. Did you mean to implement these and/or was this just pseudo code for logic?
| } | ||
|
|
||
| m_sourceCodes[infile.generic_string()] = readFileAsString(infile.string()); | ||
| m_sourceCodes[path] = readFileAsString(infile.string()); |
There was a problem hiding this comment.
Here we ensure the source mapping in CompilerStack is not tainted with the value of --base-path. This is only a change because above we prepend m_basePath.
solc/CommandLineInterface.cpp
Outdated
| sout() << "allowedpath: " << path << "\n"; | ||
| } | ||
| m_allowedDirectories.push_back(boost::filesystem::path(path).remove_filename()); | ||
| if (!m_basePath.empty()) |
There was a problem hiding this comment.
Here we also include the base path in the allowed directories.
There was a problem hiding this comment.
For some reason it was not working for me without this.
solc/CommandLineInterface.cpp
Outdated
| } | ||
| m_allowedDirectories.push_back(boost::filesystem::path(path).remove_filename()); | ||
| if (!m_basePath.empty()) | ||
| m_allowedDirectories.push_back(boost::filesystem::canonical(m_basePath)); |
There was a problem hiding this comment.
Aren't you saying above we don't need this because line 1155 does it too?
|
Need to check if this could close #9346. |
|
I am still of the opinion, that the commandline arguments to solc should be proper paths that the shell can resolve. Internally, it would be nice to strip the base path if the given file is inside that directory. |
|
Just to state the problem, I expect the following to work: The above output is on (And adding some of those extra paths to I agree that file completion is good, and would be nice to have it. Disregarding that, this messy PR in its current form makes this to work: $ solc/solc --base-path openzeppelin-contracts/contracts/ token/ERC20/SafeERC20.sol
Warning: This is a pre-release compiler version, please do not use it in production.
Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> token/ERC20/SafeERC20.sol
Error: Source file requires different compiler version (current compiler is 0.7.5-develop.2020.11.17+commit.0fe1791f.Darwin.appleclang) - note that nightly builds are considered to be strictly less than the released version
--> math/SafeMath.sol:1:1:
|
1 | pragma solidity ^0.6.0;
| ^^^^^^^^^^^^^^^^^^^^^^^
Error: Source file requires different compiler version (current compiler is 0.7.5-develop.2020.11.17+commit.0fe1791f.Darwin.appleclang) - note that nightly builds are considered to be strictly less than the released version
--> token/ERC20/IERC20.sol:1:1:
|
1 | pragma solidity ^0.6.0;
| ^^^^^^^^^^^^^^^^^^^^^^^
Error: Source file requires different compiler version (current compiler is 0.7.5-develop.2020.11.17+commit.0fe1791f.Darwin.appleclang) - note that nightly builds are considered to be strictly less than the released version
--> utils/Address.sol:1:1:
|
1 | pragma solidity ^0.6.0;
| ^^^^^^^^^^^^^^^^^^^^^^^ |
98d1a9c to
b678720
Compare
|
Draft or ready for review? |
|
For some reason now this translate |
|
Described what this should do on the top. Feel free to take over. |
|
I think essentially |
| { | ||
| auto basePath = boost::filesystem::canonical(m_basePath); | ||
| if (!basePath.empty()) | ||
| m_allowedDirectories.push_back(basePath); |
There was a problem hiding this comment.
Looks like m_allowedDirectories is a vector. I think we should make it a set to avoid duplicates (and the order does not matter, right?).
| if (isPrefix(basePath.string(), boost::filesystem::canonical(infile).string())) | ||
| path = removePrefix(basePath.string(), boost::filesystem::canonical(infile).string()); |
There was a problem hiding this comment.
canonical() raises an exception if the path does not exist. I think this might be a problem here because infile might be a relative path that only works on top of basePath (rather than the current working directory).
| if (m_basePath.empty()) | ||
| infile = path; | ||
| else | ||
| infile = m_basePath / path; |
There was a problem hiding this comment.
I think this needs a check against path being an absolute path.
|
I could take this over. What do you think about first adding a table in the docs that would illustrate how various combinations of We could also extract the path remapping logic out of |
|
Sounds good, but I think a summary of what we want and changing it right away is better than just documenting the status quo. |
The goal of this PR is to make sure that with
solc/solc --base-path openzeppelin-contracts/contracts/ openzeppelin-contracts/contracts/token/ERC20/SafeERC20.solthe following imports will work:openzeppelin-contracts/contracts/token/ERC20/SafeERC20.sol:import "./IERC20.sol";openzeppelin-contracts/contracts/token/ERC20/SafeERC20.sol:import "../../math/SafeMath.sol";