Do not insert SPDX line if it is already present (in semantic tests)

This commit is contained in:
Alex Beregszaszi 2020-12-14 13:49:39 +00:00
parent 3a7a0e4256
commit 34cab95446
2 changed files with 7 additions and 3 deletions

View File

@ -51,9 +51,11 @@ AnalysisFramework::parseAnalyseAndReturnError(
) )
{ {
compiler().reset(); compiler().reset();
// Do not insert license if it is already present.
bool insertLicense = _insertLicenseAndVersionPragma && _source.find("// SPDX-License-Identifier:") == string::npos;
compiler().setSources({{"", compiler().setSources({{"",
_insertLicenseAndVersionPragma ? string{_insertLicenseAndVersionPragma ? "pragma solidity >=0.0;\n" : ""} +
"pragma solidity >=0.0;\n// SPDX-License-Identifier: GPL-3.0\n" + _source : string{insertLicense ? "// SPDX-License-Identifier: GPL-3.0\n" : ""} +
_source _source
}}); }});
compiler().setEVMVersion(solidity::test::CommonOptions::get().evmVersion()); compiler().setEVMVersion(solidity::test::CommonOptions::get().evmVersion());

View File

@ -132,7 +132,9 @@ bytes SolidityExecutionFramework::compileContract(
string SolidityExecutionFramework::addPreamble(string const& _sourceCode) string SolidityExecutionFramework::addPreamble(string const& _sourceCode)
{ {
// Silence compiler version warning // Silence compiler version warning
string preamble = "pragma solidity >=0.0;\n// SPDX-License-Identifier: unlicensed\n"; string preamble = "pragma solidity >=0.0;\n";
if (_sourceCode.find("// SPDX-License-Identifier:") == string::npos)
preamble += "// SPDX-License-Identifier: unlicensed\n";
if ( if (
solidity::test::CommonOptions::get().useABIEncoderV2 && solidity::test::CommonOptions::get().useABIEncoderV2 &&
_sourceCode.find("pragma experimental ABIEncoderV2;") == string::npos && _sourceCode.find("pragma experimental ABIEncoderV2;") == string::npos &&