mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #8927 from ethereum/solc-base-path
Adds ``--base-path` to solc when compiling in `--standard-json` mode for resolving relative paths.
This commit is contained in:
commit
bf4ef7483c
@ -8,6 +8,7 @@ Language Features:
|
||||
Compiler Features:
|
||||
* Code Generator: Do not introduce new source references for small internal routines.
|
||||
* Build system: Update the soljson.js build to emscripten 1.39.15 and boost 1.73.0 and include Z3 for integrated SMTChecker support without the callback mechanism.
|
||||
* Commandline Interface: Adds new option ``--base-path PATH`` to use the given path as the root of the source tree instead of the root of the filesystem.
|
||||
* SMTChecker: Support array ``length``.
|
||||
* SMTChecker: Support array ``push`` and ``pop``.
|
||||
* SMTChecker: General support to BitVectors and the bitwise ``and`` operator.
|
||||
|
@ -44,8 +44,15 @@ An empty remapping prefix is not allowed.
|
||||
|
||||
If there are multiple matches due to remappings, the one with the longest common prefix is selected.
|
||||
|
||||
When accessing the filesystem to search for imports, all paths are treated as if they were fully qualified paths.
|
||||
This behaviour can be customized by adding the command line option ``--base-path`` with a path to be prepended
|
||||
before each filesystem access for imports is performed. Furthermore, the part added via ``--base-path``
|
||||
will not appear in the contract metadata.
|
||||
|
||||
For security reasons the compiler has restrictions what directories it can access. Paths (and their subdirectories) of source files specified on the commandline and paths defined by remappings are allowed for import statements, but everything else is rejected. Additional paths (and their subdirectories) can be allowed via the ``--allow-paths /sample/path,/another/sample/path`` switch.
|
||||
|
||||
Everything inside the path specified via ``--base-path`` is always allowed.
|
||||
|
||||
If your contracts use :ref:`libraries <libraries>`, you will notice that the bytecode contains substrings of the form ``__$53aea86b7d70b31448b230b20ae141a537$__``. These are placeholders for the actual library addresses.
|
||||
The placeholder is a 34 character prefix of the hex encoding of the keccak256 hash of the fully qualified library name.
|
||||
The bytecode file will also contain lines of the form ``// <placeholder> -> <fq library name>`` at the end to help
|
||||
@ -58,6 +65,7 @@ Either add ``--libraries "file.sol:Math:0x12345678901234567890123456789012345678
|
||||
If ``solc`` is called with the option ``--link``, all input files are interpreted to be unlinked binaries (hex-encoded) in the ``__$53aea86b7d70b31448b230b20ae141a537$__``-format given above and are linked in-place (if the input is read from stdin, it is written to stdout). All options except ``--libraries`` are ignored (including ``-o``) in this case.
|
||||
|
||||
If ``solc`` is called with the option ``--standard-json``, it will expect a JSON input (as explained below) on the standard input, and return a JSON output on the standard output. This is the recommended interface for more complex and especially automated uses. The process will always terminate in a "success" state and report any errors via the JSON output.
|
||||
The option ``--base-path`` is also processed in standard-json mode.
|
||||
|
||||
.. note::
|
||||
The library placeholder used to be the fully qualified name of the library itself
|
||||
|
@ -107,6 +107,7 @@ std::ostream& serr(bool _used = true)
|
||||
static string const g_stdinFileNameStr = "<stdin>";
|
||||
static string const g_strAbi = "abi";
|
||||
static string const g_strAllowPaths = "allow-paths";
|
||||
static string const g_strBasePath = "base-path";
|
||||
static string const g_strAsm = "asm";
|
||||
static string const g_strAsmJson = "asm-json";
|
||||
static string const g_strAssemble = "assemble";
|
||||
@ -181,6 +182,7 @@ static string const g_strOldReporter = "old-reporter";
|
||||
static string const g_argAbi = g_strAbi;
|
||||
static string const g_argPrettyJson = g_strPrettyJson;
|
||||
static string const g_argAllowPaths = g_strAllowPaths;
|
||||
static string const g_argBasePath = g_strBasePath;
|
||||
static string const g_argAsm = g_strAsm;
|
||||
static string const g_argAsmJson = g_strAsmJson;
|
||||
static string const g_argAssemble = g_strAssemble;
|
||||
@ -830,6 +832,11 @@ Allowed options)").c_str(),
|
||||
po::value<string>()->value_name("path(s)"),
|
||||
"Allow a given path for imports. A list of paths can be supplied by separating them with a comma."
|
||||
)
|
||||
(
|
||||
g_argBasePath.c_str(),
|
||||
po::value<string>()->value_name("path"),
|
||||
"Use the given path as the root of the source tree instead of the root of the filesystem."
|
||||
)
|
||||
(g_argColor.c_str(), "Force colored output.")
|
||||
(g_argNoColor.c_str(), "Explicitly disable colored output, disabling terminal auto-detection.")
|
||||
(g_argOldReporter.c_str(), "Enables old diagnostics reporter.")
|
||||
@ -965,7 +972,8 @@ bool CommandLineInterface::processInput()
|
||||
string validPath = _path;
|
||||
if (validPath.find("file://") == 0)
|
||||
validPath.erase(0, 7);
|
||||
auto path = boost::filesystem::path(validPath);
|
||||
|
||||
auto const path = m_basePath / validPath;
|
||||
auto canonicalPath = boost::filesystem::weakly_canonical(path);
|
||||
bool isAllowed = false;
|
||||
for (auto const& allowedDir: m_allowedDirectories)
|
||||
@ -1003,6 +1011,19 @@ bool CommandLineInterface::processInput()
|
||||
}
|
||||
};
|
||||
|
||||
if (m_args.count(g_argBasePath))
|
||||
{
|
||||
boost::filesystem::path const fspath{m_args[g_argBasePath].as<string>()};
|
||||
if (!boost::filesystem::is_directory(fspath))
|
||||
{
|
||||
serr() << "Base path must be a directory: \"" << fspath << "\"\n";
|
||||
return false;
|
||||
}
|
||||
m_basePath = fspath;
|
||||
if (!contains(m_allowedDirectories, fspath))
|
||||
m_allowedDirectories.push_back(fspath);
|
||||
}
|
||||
|
||||
if (m_args.count(g_argAllowPaths))
|
||||
{
|
||||
vector<string> paths;
|
||||
|
@ -117,6 +117,8 @@ private:
|
||||
std::vector<frontend::CompilerStack::Remapping> m_remappings;
|
||||
/// list of allowed directories to read files from
|
||||
std::vector<boost::filesystem::path> m_allowedDirectories;
|
||||
/// Base path, used for resolving relative paths in imports.
|
||||
boost::filesystem::path m_basePath;
|
||||
/// map of library names to addresses
|
||||
std::map<std::string, util::h160> m_libraries;
|
||||
/// Solidity compiler stack
|
||||
|
Loading…
Reference in New Issue
Block a user