Adds `--base-path to solc when compiling in --standard-json mode for resolving relative paths.

This commit is contained in:
Christian Parpart
2020-05-27 16:23:03 +02:00
parent b488627c79
commit 09485058d8
4 changed files with 33 additions and 1 deletions
+22 -1
View File
@@ -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;
+2
View File
@@ -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