mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
CommandLineParser: Validate compiler output selection
This commit is contained in:
parent
aed218fd75
commit
b9b2c69d24
@ -10,6 +10,7 @@ Compiler Features:
|
||||
|
||||
Bugfixes:
|
||||
* Commandline Interface: Fix extra newline character being appended to sources passed through standard input, affecting their hashes.
|
||||
* Commandline Interface: Report output selection options unsupported by the selected input mode instead of ignoring them.
|
||||
* SMTChecker: Fix internal error in magic type access (``block``, ``msg``, ``tx``).
|
||||
* TypeChecker: Fix internal error when using user defined value types in public library functions.
|
||||
|
||||
|
@ -137,6 +137,14 @@ static set<string> const g_metadataHashArgs
|
||||
g_strNone
|
||||
};
|
||||
|
||||
static map<InputMode, string> const g_inputModeName = {
|
||||
{InputMode::Compiler, "compiler"},
|
||||
{InputMode::CompilerWithASTImport, "compiler (AST import)"},
|
||||
{InputMode::Assembler, "assembler"},
|
||||
{InputMode::StandardJson, "standard JSON"},
|
||||
{InputMode::Linker, "linker"},
|
||||
};
|
||||
|
||||
void CommandLineParser::printVersionAndExit()
|
||||
{
|
||||
sout() <<
|
||||
@ -460,6 +468,47 @@ bool CommandLineParser::parseLibraryOption(string const& _input)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandLineParser::parseOutputSelection()
|
||||
{
|
||||
static auto outputSupported = [](InputMode _mode, string_view _outputName)
|
||||
{
|
||||
static set<string> const compilerModeOutputs =
|
||||
CompilerOutputs::componentMap() |
|
||||
ranges::views::keys |
|
||||
ranges::to<set>();
|
||||
|
||||
switch (_mode)
|
||||
{
|
||||
case InputMode::Compiler:
|
||||
case InputMode::CompilerWithASTImport:
|
||||
return contains(compilerModeOutputs, _outputName);
|
||||
case InputMode::Assembler:
|
||||
case InputMode::StandardJson:
|
||||
case InputMode::Linker:
|
||||
return false;
|
||||
}
|
||||
|
||||
solAssert(false, "");
|
||||
};
|
||||
|
||||
for (auto&& [optionName, outputComponent]: CompilerOutputs::componentMap())
|
||||
m_options.compiler.outputs.*outputComponent = (m_args.count(optionName) > 0);
|
||||
|
||||
vector<string> unsupportedOutputs;
|
||||
for (auto&& [optionName, outputComponent]: CompilerOutputs::componentMap())
|
||||
if (m_options.compiler.outputs.*outputComponent && !outputSupported(m_options.input.mode, optionName))
|
||||
unsupportedOutputs.push_back(optionName);
|
||||
|
||||
if (!unsupportedOutputs.empty())
|
||||
{
|
||||
serr() << "The following outputs are not supported in " << g_inputModeName.at(m_options.input.mode) << " mode: ";
|
||||
serr() << joinOptionNames(unsupportedOutputs) << ".";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
po::options_description CommandLineParser::optionsDescription()
|
||||
{
|
||||
// Declare the supported options.
|
||||
@ -930,8 +979,8 @@ bool CommandLineParser::processArgs()
|
||||
m_options.formatting.json.indent = m_args[g_strJsonIndent].as<uint32_t>();
|
||||
}
|
||||
|
||||
for (auto&& [optionName, outputComponent]: CompilerOutputs::componentMap())
|
||||
m_options.compiler.outputs.*outputComponent = (m_args.count(optionName) > 0);
|
||||
if (!parseOutputSelection())
|
||||
return false;
|
||||
|
||||
m_options.compiler.estimateGas = (m_args.count(g_strGas) > 0);
|
||||
|
||||
|
@ -286,6 +286,8 @@ private:
|
||||
/// @return false if there are any validation errors, true otherwise.
|
||||
bool parseLibraryOption(std::string const& _input);
|
||||
|
||||
bool parseOutputSelection();
|
||||
|
||||
bool checkMutuallyExclusive(std::vector<std::string> const& _optionNames);
|
||||
[[noreturn]] void printVersionAndExit();
|
||||
[[noreturn]] void printLicenseAndExit();
|
||||
|
@ -0,0 +1 @@
|
||||
--link --asm --asm-json --opcodes --bin --bin-runtime --abi --ir --ir-optimized --ewasm --hashes --userdoc --devdoc --metadata --storage-layout
|
@ -0,0 +1 @@
|
||||
The following outputs are not supported in linker mode: --abi, --asm, --asm-json, --bin, --bin-runtime, --devdoc, --ewasm, --hashes, --ir, --ir-optimized, --metadata, --opcodes, --storage-layout, --userdoc.
|
@ -0,0 +1 @@
|
||||
1
|
@ -0,0 +1 @@
|
||||
--ast-compact-json --asm --asm-json --opcodes --bin --bin-runtime --abi --ir --ir-optimized --ewasm --hashes --userdoc --devdoc --metadata --storage-layout
|
@ -0,0 +1 @@
|
||||
The following outputs are not supported in standard JSON mode: --abi, --asm, --asm-json, --ast-compact-json, --bin, --bin-runtime, --devdoc, --ewasm, --hashes, --ir, --ir-optimized, --metadata, --opcodes, --storage-layout, --userdoc.
|
@ -0,0 +1 @@
|
||||
1
|
@ -0,0 +1 @@
|
||||
--strict-assembly --asm --asm-json --opcodes --bin --bin-runtime --abi --ir --ir-optimized --ewasm --hashes --userdoc --devdoc --metadata --storage-layout
|
@ -0,0 +1 @@
|
||||
The following outputs are not supported in assembler mode: --abi, --asm, --asm-json, --bin, --bin-runtime, --devdoc, --ewasm, --hashes, --ir, --ir-optimized, --metadata, --opcodes, --storage-layout, --userdoc.
|
@ -0,0 +1 @@
|
||||
1
|
@ -1 +1 @@
|
||||
--yul --yul-dialect evm --optimize --ir-optimized --optimize-runs 10000
|
||||
--yul --yul-dialect evm --optimize --optimize-runs 10000
|
||||
|
@ -289,10 +289,6 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
|
||||
"underflow,"
|
||||
"divByZero",
|
||||
"--model-checker-timeout=5", // Ignored in assembly mode
|
||||
|
||||
// Accepted but has no effect in assembly mode
|
||||
"--ast-compact-json", "--asm", "--asm-json", "--opcodes", "--bin", "--bin-runtime", "--abi",
|
||||
"--ir", "--ir-optimized", "--ewasm", "--hashes", "--userdoc", "--devdoc", "--metadata", "--storage-layout",
|
||||
};
|
||||
commandLine += assemblyOptions;
|
||||
if (expectedLanguage == AssemblyStack::Language::StrictAssembly || expectedLanguage == AssemblyStack::Language::Ewasm)
|
||||
@ -328,11 +324,6 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
|
||||
};
|
||||
expectedOptions.formatting.coloredOutput = false;
|
||||
expectedOptions.formatting.withErrorIds = true;
|
||||
expectedOptions.compiler.outputs = {
|
||||
true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
};
|
||||
if (expectedLanguage == AssemblyStack::Language::StrictAssembly || expectedLanguage == AssemblyStack::Language::Ewasm)
|
||||
{
|
||||
expectedOptions.optimizer.enabled = true;
|
||||
@ -388,10 +379,6 @@ BOOST_AUTO_TEST_CASE(standard_json_mode_options)
|
||||
"underflow,"
|
||||
"divByZero",
|
||||
"--model-checker-timeout=5", // Ignored in Standard JSON mode
|
||||
|
||||
// Accepted but has no effect in Standard JSON mode
|
||||
"--ast-compact-json", "--asm", "--asm-json", "--opcodes", "--bin", "--bin-runtime", "--abi",
|
||||
"--ir", "--ir-optimized", "--ewasm", "--hashes", "--userdoc", "--devdoc", "--metadata", "--storage-layout",
|
||||
};
|
||||
|
||||
CommandLineOptions expectedOptions;
|
||||
@ -408,11 +395,6 @@ BOOST_AUTO_TEST_CASE(standard_json_mode_options)
|
||||
expectedOptions.formatting.json = JsonFormat {JsonFormat::Pretty, 1};
|
||||
expectedOptions.formatting.coloredOutput = false;
|
||||
expectedOptions.formatting.withErrorIds = true;
|
||||
expectedOptions.compiler.outputs = {
|
||||
true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
};
|
||||
expectedOptions.compiler.estimateGas = true;
|
||||
expectedOptions.compiler.combinedJsonRequests = CombinedJsonRequests{};
|
||||
expectedOptions.compiler.combinedJsonRequests->abi = true;
|
||||
|
Loading…
Reference in New Issue
Block a user