mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add support for SPDX license identifiers.
This commit is contained in:
@@ -45,7 +45,10 @@ TestCase::TestResult ABIJsonTest::run(ostream& _stream, string const& _linePrefi
|
||||
{
|
||||
CompilerStack compiler;
|
||||
|
||||
compiler.setSources({{"", "pragma solidity >=0.0;\n" + m_source}});
|
||||
compiler.setSources({{
|
||||
"",
|
||||
"pragma solidity >=0.0;\n// SPDX-License-Identifier: GPL-3.0\n" + m_source
|
||||
}});
|
||||
compiler.setEVMVersion(solidity::test::CommonOptions::get().evmVersion());
|
||||
compiler.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
||||
if (!compiler.parseAndAnalyze())
|
||||
|
||||
@@ -44,13 +44,17 @@ pair<SourceUnit const*, ErrorList>
|
||||
AnalysisFramework::parseAnalyseAndReturnError(
|
||||
string const& _source,
|
||||
bool _reportWarnings,
|
||||
bool _insertVersionPragma,
|
||||
bool _insertLicenseAndVersionPragma,
|
||||
bool _allowMultipleErrors,
|
||||
bool _allowRecoveryErrors
|
||||
)
|
||||
{
|
||||
compiler().reset();
|
||||
compiler().setSources({{"", _insertVersionPragma ? "pragma solidity >=0.0;\n" + _source : _source}});
|
||||
compiler().setSources({{"",
|
||||
_insertLicenseAndVersionPragma ?
|
||||
"pragma solidity >=0.0;\n// SPDX-License-Identifier: GPL-3.0\n" + _source :
|
||||
_source
|
||||
}});
|
||||
compiler().setEVMVersion(solidity::test::CommonOptions::get().evmVersion());
|
||||
compiler().setParserErrorRecovery(_allowRecoveryErrors);
|
||||
_allowMultipleErrors = _allowMultipleErrors || _allowRecoveryErrors;
|
||||
|
||||
@@ -47,7 +47,7 @@ protected:
|
||||
parseAnalyseAndReturnError(
|
||||
std::string const& _source,
|
||||
bool _reportWarnings = false,
|
||||
bool _insertVersionPragma = true,
|
||||
bool _insertLicenseAndVersionPragma = true,
|
||||
bool _allowMultipleErrors = false,
|
||||
bool _allowRecoveryErrors = false
|
||||
);
|
||||
|
||||
@@ -43,7 +43,8 @@ public:
|
||||
void compile(string const& _sourceCode)
|
||||
{
|
||||
m_compiler.reset();
|
||||
m_compiler.setSources({{"", "pragma solidity >=0.0;\n" + _sourceCode}});
|
||||
m_compiler.setSources({{"", "pragma solidity >=0.0;\n"
|
||||
"// SPDX-License-Identifier: GPL-3.0\n" + _sourceCode}});
|
||||
m_compiler.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
||||
m_compiler.setEVMVersion(m_evmVersion);
|
||||
BOOST_REQUIRE_MESSAGE(m_compiler.compile(), "Compiling contract failed");
|
||||
|
||||
@@ -100,7 +100,7 @@ void GasTest::printUpdatedExpectations(ostream& _stream, string const& _linePref
|
||||
|
||||
TestCase::TestResult GasTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||
{
|
||||
string const versionPragma = "pragma solidity >=0.0;\n";
|
||||
string const preamble = "pragma solidity >=0.0;\n// SPDX-License-Identifier: GPL-3.0\n";
|
||||
compiler().reset();
|
||||
// Prerelease CBOR metadata varies in size due to changing version numbers and build dates.
|
||||
// This leads to volatile creation cost estimates. Therefore we force the compiler to
|
||||
@@ -114,7 +114,7 @@ TestCase::TestResult GasTest::run(ostream& _stream, string const& _linePrefix, b
|
||||
}
|
||||
settings.expectedExecutionsPerDeployment = m_optimiseRuns;
|
||||
compiler().setOptimiserSettings(settings);
|
||||
compiler().setSources({{"", versionPragma + m_source}});
|
||||
compiler().setSources({{"", preamble + m_source}});
|
||||
|
||||
if (!compiler().parseAndAnalyze() || !compiler().compile())
|
||||
{
|
||||
|
||||
@@ -38,7 +38,7 @@ protected:
|
||||
parseAnalyseAndReturnError(
|
||||
std::string const& _source,
|
||||
bool _reportWarnings = false,
|
||||
bool _insertVersionPragma = true,
|
||||
bool _insertLicenseAndVersionPragma = true,
|
||||
bool _allowMultipleErrors = false,
|
||||
bool _allowRecoveryErrors = false
|
||||
) override
|
||||
@@ -46,7 +46,7 @@ protected:
|
||||
return AnalysisFramework::parseAnalyseAndReturnError(
|
||||
"pragma experimental SMTChecker;\n" + _source,
|
||||
_reportWarnings,
|
||||
_insertVersionPragma,
|
||||
_insertLicenseAndVersionPragma,
|
||||
_allowMultipleErrors,
|
||||
_allowRecoveryErrors
|
||||
);
|
||||
|
||||
@@ -64,8 +64,8 @@ TestCase::TestResult SMTCheckerJSONTest::run(ostream& _stream, string const& _li
|
||||
StandardCompiler compiler;
|
||||
|
||||
// Run the compiler and retrieve the smtlib2queries (1st run)
|
||||
string versionPragma = "pragma solidity >=0.0;\n";
|
||||
Json::Value input = buildJson(versionPragma);
|
||||
string preamble = "pragma solidity >=0.0;\n// SPDX-License-Identifier: GPL-3.0\n";
|
||||
Json::Value input = buildJson(preamble);
|
||||
Json::Value result = compiler.compile(input);
|
||||
|
||||
// This is the list of query hashes requested by the 1st run
|
||||
@@ -121,10 +121,10 @@ TestCase::TestResult SMTCheckerJSONTest::run(ostream& _stream, string const& _li
|
||||
std::string sourceName;
|
||||
if (location.isMember("source") && location["source"].isString())
|
||||
sourceName = location["source"].asString();
|
||||
if (start >= static_cast<int>(versionPragma.size()))
|
||||
start -= versionPragma.size();
|
||||
if (end >= static_cast<int>(versionPragma.size()))
|
||||
end -= versionPragma.size();
|
||||
if (start >= static_cast<int>(preamble.size()))
|
||||
start -= preamble.size();
|
||||
if (end >= static_cast<int>(preamble.size()))
|
||||
end -= preamble.size();
|
||||
m_errorList.emplace_back(SyntaxTestError{
|
||||
error["type"].asString(),
|
||||
error["message"].asString(),
|
||||
|
||||
@@ -370,6 +370,7 @@ BOOST_AUTO_TEST_CASE(dynamic_return_types_not_possible)
|
||||
BOOST_AUTO_TEST_CASE(warn_nonpresent_pragma)
|
||||
{
|
||||
char const* text = R"(
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
contract C {}
|
||||
)";
|
||||
auto sourceAndError = parseAnalyseAndReturnError(text, true, false);
|
||||
|
||||
@@ -209,7 +209,7 @@ BOOST_AUTO_TEST_CASE(type_identifiers)
|
||||
ModifierDefinition mod(++id, SourceLocation{}, make_shared<string>("modif"), {}, emptyParams, {}, {}, {});
|
||||
BOOST_CHECK_EQUAL(ModifierType(mod).identifier(), "t_modifier$__$");
|
||||
|
||||
SourceUnit su(++id, {}, {});
|
||||
SourceUnit su(++id, {}, {}, {});
|
||||
BOOST_CHECK_EQUAL(ModuleType(su).identifier(), "t_module_7");
|
||||
BOOST_CHECK_EQUAL(MagicType(MagicType::Kind::Block).identifier(), "t_magic_block");
|
||||
BOOST_CHECK_EQUAL(MagicType(MagicType::Kind::Message).identifier(), "t_magic_message");
|
||||
|
||||
@@ -427,7 +427,7 @@ BOOST_AUTO_TEST_CASE(basic_compilation)
|
||||
BOOST_CHECK(result["sources"]["fileA"]["legacyAST"].isObject());
|
||||
BOOST_CHECK_EQUAL(
|
||||
util::jsonCompactPrint(result["sources"]["fileA"]["legacyAST"]),
|
||||
"{\"attributes\":{\"absolutePath\":\"fileA\",\"exportedSymbols\":{\"A\":[1]}},\"children\":"
|
||||
"{\"attributes\":{\"absolutePath\":\"fileA\",\"exportedSymbols\":{\"A\":[1]},\"license\":null},\"children\":"
|
||||
"[{\"attributes\":{\"abstract\":false,\"baseContracts\":[null],\"contractDependencies\":[null],\"contractKind\":\"contract\","
|
||||
"\"documentation\":null,\"fullyImplemented\":true,\"linearizedBaseContracts\":[1],\"name\":\"A\",\"nodes\":[null],\"scope\":2},"
|
||||
"\"id\":1,\"name\":\"ContractDefinition\",\"src\":\"0:14:0\"}],\"id\":2,\"name\":\"SourceUnit\",\"src\":\"0:14:0\"}"
|
||||
|
||||
@@ -52,11 +52,11 @@ TestCase::TestResult SyntaxTest::run(ostream& _stream, string const& _linePrefix
|
||||
|
||||
void SyntaxTest::setupCompiler()
|
||||
{
|
||||
string const versionPragma = "pragma solidity >=0.0;\n";
|
||||
string const preamble = "pragma solidity >=0.0;\n// SPDX-License-Identifier: GPL-3.0\n";
|
||||
compiler().reset();
|
||||
auto sourcesWithPragma = m_sources;
|
||||
for (auto& source: sourcesWithPragma)
|
||||
source.second = versionPragma + source.second;
|
||||
source.second = preamble + source.second;
|
||||
compiler().setSources(sourcesWithPragma);
|
||||
compiler().setEVMVersion(m_evmVersion);
|
||||
compiler().setParserErrorRecovery(m_parserErrorRecovery);
|
||||
@@ -89,18 +89,18 @@ void SyntaxTest::parseAndAnalyze()
|
||||
|
||||
void SyntaxTest::filterObtainedErrors()
|
||||
{
|
||||
string const versionPragma = "pragma solidity >=0.0;\n";
|
||||
string const preamble = "pragma solidity >=0.0;\n// SPDX-License-Identifier: GPL-3.0\n";
|
||||
for (auto const& currentError: filterErrors(compiler().errors(), true))
|
||||
{
|
||||
int locationStart = -1, locationEnd = -1;
|
||||
string sourceName;
|
||||
if (auto location = boost::get_error_info<errinfo_sourceLocation>(*currentError))
|
||||
{
|
||||
// ignore the version pragma inserted by the testing tool when calculating locations.
|
||||
if (location->start >= static_cast<int>(versionPragma.size()))
|
||||
locationStart = location->start - versionPragma.size();
|
||||
if (location->end >= static_cast<int>(versionPragma.size()))
|
||||
locationEnd = location->end - versionPragma.size();
|
||||
// ignore the version & license pragma inserted by the testing tool when calculating locations.
|
||||
if (location->start >= static_cast<int>(preamble.size()))
|
||||
locationStart = location->start - (preamble.size());
|
||||
if (location->end >= static_cast<int>(preamble.size()))
|
||||
locationEnd = location->end - (preamble.size());
|
||||
if (location->source)
|
||||
sourceName = location->source->name();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user