aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/interface/StandardCompiler.cpp
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-04-19 23:45:36 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-04-21 23:44:15 +0800
commit8de02c777856daffc2d48cc68a15b6b6f16ce134 (patch)
tree93bbcff2ccd502f42872a66c8265ad57cd42cea3 /libsolidity/interface/StandardCompiler.cpp
parentc5f182df01b25c1c4b3dd7db6fa884e9beb7c6c4 (diff)
downloaddexon-solidity-8de02c777856daffc2d48cc68a15b6b6f16ce134.tar.gz
dexon-solidity-8de02c777856daffc2d48cc68a15b6b6f16ce134.tar.zst
dexon-solidity-8de02c777856daffc2d48cc68a15b6b6f16ce134.zip
Support URL sources in StandardCompiler
Diffstat (limited to 'libsolidity/interface/StandardCompiler.cpp')
-rw-r--r--libsolidity/interface/StandardCompiler.cpp35
1 files changed, 33 insertions, 2 deletions
diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp
index db89e16c..4a8787b3 100644
--- a/libsolidity/interface/StandardCompiler.cpp
+++ b/libsolidity/interface/StandardCompiler.cpp
@@ -162,11 +162,43 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
if (!sources)
return formatFatalError("JSONError", "No input sources specified.");
+ Json::Value errors = Json::arrayValue;
+
for (auto const& sourceName: sources.getMemberNames())
if (sources[sourceName]["content"].isString())
m_compilerStack.addSource(sourceName, sources[sourceName]["content"].asString());
else if (sources[sourceName]["urls"].isArray())
- return formatFatalError("UnimplementedFeatureError", "Input URLs not supported yet.");
+ {
+ if (!m_readFile)
+ return formatFatalError("JSONError", "No import callback supplied, but URL is requested.");
+
+ bool found = false;
+ vector<string> failures;
+
+ for (auto const& url: sources[sourceName]["urls"])
+ {
+ ReadFile::Result result = m_readFile(url.asString());
+ if (result.success)
+ {
+ m_compilerStack.addSource(sourceName, result.contentsOrErrorMessage);
+ found = true;
+ break;
+ }
+ else
+ failures.push_back("Cannot import url (\"" + url.asString() + "\"): " + result.contentsOrErrorMessage);
+ }
+
+ for (auto const& failure: failures)
+ {
+ /// If the import succeeded, let mark all the others as warnings, otherwise all of them are errors.
+ errors.append(formatError(
+ found ? true : false,
+ "IOError",
+ "general",
+ failure
+ ));
+ }
+ }
else
return formatFatalError("JSONError", "Invalid input source specified.");
@@ -196,7 +228,6 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compilerStack.scanner(_sourceName); };
- Json::Value errors = Json::arrayValue;
bool success = false;
try