-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up the mess of basePath in solc #9353
Conversation
solc/CommandLineInterface.cpp
Outdated
@@ -563,7 +563,7 @@ bool CommandLineInterface::readInputFilesAndConfigureRemappings() | |||
addStdin = true; | |||
else | |||
{ | |||
auto infile = boost::filesystem::path(path); | |||
auto const infile = m_basePath / path; //boost::filesystem::path(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was just pseudo code.
@@ -590,10 +590,13 @@ bool CommandLineInterface::readInputFilesAndConfigureRemappings() | |||
continue; | |||
} | |||
|
|||
m_sourceCodes[infile.generic_string()] = readFileAsString(infile.string()); | |||
m_sourceCodes[path] = readFileAsString(infile.string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
} | ||
m_allowedDirectories.push_back(boost::filesystem::path(path).remove_filename()); | ||
if (!m_basePath.empty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we also include the base path in the allowed directories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See line 1115
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weakly canonical?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
bool CommandLineInterface::readInputFilesAndConfigureRemappings() | ||
{ | ||
auto basePath = boost::filesystem::canonical(m_basePath); | ||
if (!basePath.empty()) | ||
m_allowedDirectories.push_back(basePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.sol
the 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";