aboutsummaryrefslogtreecommitdiffstats
path: root/solc
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-03-16 01:07:52 +0800
committerGitHub <noreply@github.com>2017-03-16 01:07:52 +0800
commitf0d539ae05739e35336cc9cc8f44bd9798a95c28 (patch)
tree13ef1dea012c7f093122d5e7578dc3c893636e59 /solc
parent364da425d3116a4b85863df39a1864340861d71e (diff)
parent59099908c53129b2f5723bd0d5283c4da089e398 (diff)
downloaddexon-solidity-f0d539ae05739e35336cc9cc8f44bd9798a95c28.tar
dexon-solidity-f0d539ae05739e35336cc9cc8f44bd9798a95c28.tar.gz
dexon-solidity-f0d539ae05739e35336cc9cc8f44bd9798a95c28.tar.bz2
dexon-solidity-f0d539ae05739e35336cc9cc8f44bd9798a95c28.tar.lz
dexon-solidity-f0d539ae05739e35336cc9cc8f44bd9798a95c28.tar.xz
dexon-solidity-f0d539ae05739e35336cc9cc8f44bd9798a95c28.tar.zst
dexon-solidity-f0d539ae05739e35336cc9cc8f44bd9798a95c28.zip
Merge pull request #1782 from ethereum/develop
Solidity 0.4.10
Diffstat (limited to 'solc')
-rw-r--r--solc/CommandLineInterface.cpp40
-rw-r--r--solc/CommandLineInterface.h5
-rw-r--r--solc/jsonCompiler.cpp6
-rw-r--r--solc/main.cpp7
4 files changed, 41 insertions, 17 deletions
diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp
index dd80e189..31f70272 100644
--- a/solc/CommandLineInterface.cpp
+++ b/solc/CommandLineInterface.cpp
@@ -93,6 +93,7 @@ static string const g_strOpcodes = "opcodes";
static string const g_strOptimize = "optimize";
static string const g_strOptimizeRuns = "optimize-runs";
static string const g_strOutputDir = "output-dir";
+static string const g_strOverwrite = "overwrite";
static string const g_strSignatureHashes = "hashes";
static string const g_strSources = "sources";
static string const g_strSourceList = "sourceList";
@@ -200,7 +201,7 @@ void CommandLineInterface::handleBinary(string const& _contract)
if (m_args.count(g_argCloneBinary))
{
if (m_args.count(g_argOutputDir))
- createFile(_contract + ".clone_bin", m_compiler->cloneObject(_contract).toHex());
+ createFile(m_compiler->filesystemFriendlyName(_contract) + ".clone_bin", m_compiler->cloneObject(_contract).toHex());
else
{
cout << "Clone Binary: " << endl;
@@ -210,7 +211,7 @@ void CommandLineInterface::handleBinary(string const& _contract)
if (m_args.count(g_argBinaryRuntime))
{
if (m_args.count(g_argOutputDir))
- createFile(_contract + ".bin-runtime", m_compiler->runtimeObject(_contract).toHex());
+ createFile(m_compiler->filesystemFriendlyName(_contract) + ".bin-runtime", m_compiler->runtimeObject(_contract).toHex());
else
{
cout << "Binary of the runtime part: " << endl;
@@ -222,7 +223,7 @@ void CommandLineInterface::handleBinary(string const& _contract)
void CommandLineInterface::handleOpcode(string const& _contract)
{
if (m_args.count(g_argOutputDir))
- createFile(_contract + ".opcode", solidity::disassemble(m_compiler->object(_contract).bytecode));
+ createFile(m_compiler->filesystemFriendlyName(_contract) + ".opcode", solidity::disassemble(m_compiler->object(_contract).bytecode));
else
{
cout << "Opcodes: " << endl;
@@ -249,7 +250,7 @@ void CommandLineInterface::handleSignatureHashes(string const& _contract)
out += toHex(it.first.ref()) + ": " + it.second->externalSignature() + "\n";
if (m_args.count(g_argOutputDir))
- createFile(_contract + ".signatures", out);
+ createFile(m_compiler->filesystemFriendlyName(_contract) + ".signatures", out);
else
cout << "Function signatures: " << endl << out;
}
@@ -261,7 +262,7 @@ void CommandLineInterface::handleOnChainMetadata(string const& _contract)
string data = m_compiler->onChainMetadata(_contract);
if (m_args.count("output-dir"))
- createFile(_contract + "_meta.json", data);
+ createFile(m_compiler->filesystemFriendlyName(_contract) + "_meta.json", data);
else
cout << "Metadata: " << endl << data << endl;
}
@@ -302,7 +303,7 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co
output = dev::jsonPrettyPrint(m_compiler->metadata(_contract, _type));
if (m_args.count(g_argOutputDir))
- createFile(_contract + suffix, output);
+ createFile(m_compiler->filesystemFriendlyName(_contract) + suffix, output);
else
{
cout << title << endl;
@@ -419,7 +420,16 @@ void CommandLineInterface::readInputFilesAndConfigureRemappings()
bool CommandLineInterface::parseLibraryOption(string const& _input)
{
namespace fs = boost::filesystem;
- string data = fs::is_regular_file(_input) ? contentsString(_input) : _input;
+ string data = _input;
+ try
+ {
+ if (fs::is_regular_file(_input))
+ data = contentsString(_input);
+ }
+ catch (fs::filesystem_error const&)
+ {
+ // Thrown e.g. if path is too long.
+ }
vector<string> libraries;
boost::split(libraries, data, boost::is_space() || boost::is_any_of(","), boost::token_compress_on);
@@ -461,8 +471,16 @@ void CommandLineInterface::createFile(string const& _fileName, string const& _da
namespace fs = boost::filesystem;
// create directory if not existent
fs::path p(m_args.at(g_argOutputDir).as<string>());
- fs::create_directories(p);
+ // Do not try creating the directory if the first item is . or ..
+ if (p.filename() != "." && p.filename() != "..")
+ fs::create_directories(p);
string pathName = (p / _fileName).string();
+ if (fs::exists(pathName) && !m_args.count(g_strOverwrite))
+ {
+ cerr << "Refusing to overwrite existing file \"" << pathName << "\" (use --overwrite to force)." << endl;
+ m_error = true;
+ return;
+ }
ofstream outFile(pathName);
outFile << _data;
if (!outFile)
@@ -508,6 +526,7 @@ Allowed options)",
po::value<string>()->value_name("path"),
"If given, creates one file per component and contract/file at the specified directory."
)
+ (g_strOverwrite.c_str(), "Overwrite existing files (used together with -o).")
(
g_argCombinedJson.c_str(),
po::value<string>()->value_name(boost::join(g_combinedJsonArgs, ",")),
@@ -856,7 +875,7 @@ void CommandLineInterface::handleAst(string const& _argStr)
}
}
-void CommandLineInterface::actOnInput()
+bool CommandLineInterface::actOnInput()
{
if (m_onlyAssemble)
outputAssembly();
@@ -864,6 +883,7 @@ void CommandLineInterface::actOnInput()
writeLinkedFiles();
else
outputCompilationResults();
+ return !m_error;
}
bool CommandLineInterface::link()
@@ -981,7 +1001,7 @@ void CommandLineInterface::outputCompilationResults()
{
stringstream data;
m_compiler->streamAssembly(data, contract, m_sourceCodes, m_args.count(g_argAsmJson));
- createFile(contract + (m_args.count(g_argAsmJson) ? "_evm.json" : ".evm"), data.str());
+ createFile(m_compiler->filesystemFriendlyName(contract) + (m_args.count(g_argAsmJson) ? "_evm.json" : ".evm"), data.str());
}
else
{
diff --git a/solc/CommandLineInterface.h b/solc/CommandLineInterface.h
index bcfc43d7..f52a03c7 100644
--- a/solc/CommandLineInterface.h
+++ b/solc/CommandLineInterface.h
@@ -47,7 +47,8 @@ public:
/// Parse the files and create source code objects
bool processInput();
/// Perform actions on the input depending on provided compiler arguments
- void actOnInput();
+ /// @returns true on success.
+ bool actOnInput();
private:
bool link();
@@ -81,6 +82,8 @@ private:
/// @arg _data to be written
void createFile(std::string const& _fileName, std::string const& _data);
+ bool m_error = false; ///< If true, some error occurred.
+
bool m_onlyAssemble = false;
bool m_onlyLink = false;
diff --git a/solc/jsonCompiler.cpp b/solc/jsonCompiler.cpp
index d761b541..6ebd1a55 100644
--- a/solc/jsonCompiler.cpp
+++ b/solc/jsonCompiler.cpp
@@ -184,15 +184,15 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
}
catch (CompilerError const& exception)
{
- errors.append(formatError(exception, "Compiler error", scannerFromSourceName));
+ errors.append(formatError(exception, "Compiler error (" + exception.lineInfo() + ")", scannerFromSourceName));
}
catch (InternalCompilerError const& exception)
{
- errors.append(formatError(exception, "Internal compiler error", scannerFromSourceName));
+ errors.append(formatError(exception, "Internal compiler error (" + exception.lineInfo() + ")", scannerFromSourceName));
}
catch (UnimplementedFeatureError const& exception)
{
- errors.append(formatError(exception, "Unimplemented feature", scannerFromSourceName));
+ errors.append(formatError(exception, "Unimplemented feature (" + exception.lineInfo() + ")", scannerFromSourceName));
}
catch (Exception const& exception)
{
diff --git a/solc/main.cpp b/solc/main.cpp
index 28726e26..c61da6e9 100644
--- a/solc/main.cpp
+++ b/solc/main.cpp
@@ -58,15 +58,16 @@ int main(int argc, char** argv)
return 1;
if (!cli.processInput())
return 1;
+ bool success = false;
try
{
- cli.actOnInput();
+ success = cli.actOnInput();
}
catch (boost::exception const& _exception)
{
cerr << "Exception during output generation: " << boost::diagnostic_information(_exception) << endl;
- return 1;
+ success = false;
}
- return 0;
+ return success ? 0 : 1;
}