aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-09-13 19:21:48 +0800
committerGitHub <noreply@github.com>2017-09-13 19:21:48 +0800
commit72b7e001aa837ab59b3b14bfbabf69bbd102ded1 (patch)
treeb8eff1420200fa78a3d085453fdfe1854a5770ba
parent1eb49fb144dbf472a54d6c64dedf87c6c4280139 (diff)
parent61dabb2f29362728b0b57a73680c23463e0b73f6 (diff)
downloaddexon-solidity-72b7e001aa837ab59b3b14bfbabf69bbd102ded1.tar
dexon-solidity-72b7e001aa837ab59b3b14bfbabf69bbd102ded1.tar.gz
dexon-solidity-72b7e001aa837ab59b3b14bfbabf69bbd102ded1.tar.bz2
dexon-solidity-72b7e001aa837ab59b3b14bfbabf69bbd102ded1.tar.lz
dexon-solidity-72b7e001aa837ab59b3b14bfbabf69bbd102ded1.tar.xz
dexon-solidity-72b7e001aa837ab59b3b14bfbabf69bbd102ded1.tar.zst
dexon-solidity-72b7e001aa837ab59b3b14bfbabf69bbd102ded1.zip
Merge pull request #2290 from ali92hm/develop
Enabling --combined-json to output to file using the -o flag
-rw-r--r--solc/CommandLineInterface.cpp16
-rw-r--r--solc/CommandLineInterface.h5
2 files changed, 20 insertions, 1 deletions
diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp
index e6d8776b..271511d4 100644
--- a/solc/CommandLineInterface.cpp
+++ b/solc/CommandLineInterface.cpp
@@ -112,10 +112,12 @@ static string const g_strSourceList = "sourceList";
static string const g_strSrcMap = "srcmap";
static string const g_strSrcMapRuntime = "srcmap-runtime";
static string const g_strStandardJSON = "standard-json";
+static string const g_strPrettyJson = "pretty-json";
static string const g_strVersion = "version";
static string const g_argAbi = g_strAbi;
static string const g_argAddStandard = g_strAddStandard;
+static string const g_argPrettyJson = g_strPrettyJson;
static string const g_argAllowPaths = g_strAllowPaths;
static string const g_argAsm = g_strAsm;
static string const g_argAsmJson = g_strAsmJson;
@@ -508,6 +510,11 @@ void CommandLineInterface::createFile(string const& _fileName, string const& _da
BOOST_THROW_EXCEPTION(FileError() << errinfo_comment("Could not write to file: " + pathName));
}
+void CommandLineInterface::createJson(string const& _fileName, string const& _json)
+{
+ createFile(boost::filesystem::basename(_fileName) + string(".json"), _json);
+}
+
bool CommandLineInterface::parseArguments(int _argc, char** _argv)
{
// Declare the supported options.
@@ -541,6 +548,7 @@ Allowed options)",
"Estimated number of contract runs for optimizer tuning."
)
(g_argAddStandard.c_str(), "Add standard contracts.")
+ (g_argPrettyJson.c_str(), "Output JSON in pretty format. Currently it only works with the combined JSON output.")
(
g_argLibraries.c_str(),
po::value<vector<string>>()->value_name("libs"),
@@ -905,7 +913,13 @@ void CommandLineInterface::handleCombinedJSON()
output[g_strSources][sourceCode.first]["AST"] = converter.toJson(m_compiler->ast(sourceCode.first));
}
}
- cout << dev::jsonCompactPrint(output) << endl;
+
+ string json = m_args.count(g_argPrettyJson) ? dev::jsonPrettyPrint(output) : dev::jsonCompactPrint(output);
+
+ if (m_args.count(g_argOutputDir))
+ createJson("combined", json);
+ else
+ cout << json << endl;
}
void CommandLineInterface::handleAst(string const& _argStr)
diff --git a/solc/CommandLineInterface.h b/solc/CommandLineInterface.h
index bf9400e4..4768c9d8 100644
--- a/solc/CommandLineInterface.h
+++ b/solc/CommandLineInterface.h
@@ -81,6 +81,11 @@ private:
/// @arg _data to be written
void createFile(std::string const& _fileName, std::string const& _data);
+ /// Create a json file in the given directory
+ /// @arg _fileName the name of the file (the extension will be replaced with .json)
+ /// @arg _json json string to be written
+ void createJson(std::string const& _fileName, std::string const& _json);
+
bool m_error = false; ///< If true, some error occurred.
bool m_onlyAssemble = false;