-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for SPDX license identifiers. #8907
Conversation
libsolidity/parsing/Parser.cpp
Outdated
optional<string> Parser::findLicenseString() | ||
{ | ||
// We circumvent the scanner here, because it skips non-docstring comments. | ||
static regex const licenseRegex("SPDX-License-Identifier:\\s+([^\\n\\r]+)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be the first-ever compliant contract: axic/eth2-deposit-contract@3aaf6f0
(Pushed yesterday)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder what prompted me to start this...
libsolidity/parsing/Parser.cpp
Outdated
{-1, -1, m_scanner->charStream()}, | ||
"SPDX license identifier not provided in source file. " | ||
"Before publishing, consider adding a comment containing " | ||
"\"SPDX-License-Identifier: <SPDX-License>\" to each source file. " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is still unclear what to use for closed source:
a) "Proprietary" perhaps?
b) avoiding the field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide the field with UNLICENSED
or CLOSED-SOURCE
or PROPRIETARY
- do we need to specify that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should provide a recommendation given SPDX does not provide one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm proposes UNLICENSED
: https://docs.npmjs.com/files/package.json#license
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, we should document this and link to npm as well.
Once we merge this, we should maybe start adding the field to common libraries? |
We could also implement a feature for |
@hrkrshnn good idea! |
libsolidity/parsing/Parser.cpp
Outdated
optional<string> Parser::findLicenseString() | ||
{ | ||
// We circumvent the scanner here, because it skips non-docstring comments. | ||
static regex const licenseRegex("SPDX-License-Identifier:\\s+([^\\n\\r]+)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it is now, this can also be found in strings. Do we want to extend this to ^// SPDX...
? Then it would not work for /*
-comments, though.
Taken over by @aarlt. |
There was an error when running
Please check that your changes are working as intended. |
@chriseth I mainly added testing support. Sadly I didn't saw the current errors locally. These errors need to be fixed. |
libsolidity/parsing/Parser.cpp
Outdated
|
||
static regex const licenseRegex("SPDX-License-Identifier:\\s*([^\\n\\r\\s]+)"); | ||
|
||
// Remove all parts of the source that where referenced by different AST node locations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea, but we could also find all places that match the regex and see if we ended up inside one of the nodes.
@@ -46,11 +46,13 @@ AnalysisFramework::parseAnalyseAndReturnError( | |||
bool _reportWarnings, | |||
bool _insertVersionPragma, | |||
bool _allowMultipleErrors, | |||
bool _allowRecoveryErrors | |||
bool _allowRecoveryErrors, | |||
bool _insertLicensePragma |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a situation where we would insert the version but not the license pragma?
578fc47
to
16ad880
Compare
libsolidity/parsing/Parser.cpp
Outdated
); | ||
else | ||
parserError( | ||
0000_error, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ErrorIds... Why are the above two the same errors?
"SPDX license identifier not provided in source file. " | ||
"Before publishing, consider adding a comment containing " | ||
"\"SPDX-License-Identifier: <SPDX-License>\" to each source file. " | ||
"Use \"SPDX-License-Identifier: UNLICENSED\" for non-open-source code. " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Is non-open-source
the best term? Why not just closed-source
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"open source", "source accessible", "proprietary", "closed-source" - all different terms...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also say "free software" as that is even a smaller subset of open source and we advocate for that 😉
@@ -8,6 +8,7 @@ | |||
] | |||
}, | |||
"id": 12, | |||
"license": null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't we had some PR/issue discussing that we shouldn't have null
fields? Maybe it is out of scope here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is an open pr about it.
test/libsolidity/GasTest.cpp
Outdated
@@ -101,6 +101,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 license = "// SPDX-License-Identifier: GPL-3.0\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: why not preamble
as in the other files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add a parser test for MIT OR Apache-2.0
and GPL-2.0 AND GPL-3.0
. I know we do not deal with expression, but as we instruct people to use in a warning, we should make sure they are parsed correctly.
Will the documentation changes be part of a different PR? Can we also have parser tests for different comment styles (if we support them):
|
|
will add a test for |
Added documentation. |
b98a695
to
01df7a1
Compare
it does include the supplied string in the `bytecode metadata <metadata>`_. | ||
|
||
If you do not want to specify a license or if the source code is | ||
not open-source, please use the special value ``UNLICENSED``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we mention this is also the suggested way by npm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw that there is a spdx license identifier UNLICENSE
. I'm wondering whether UNLICENSE
vs UNLICENSED
can create confusions.
{
"reference": "./Unlicense.html",
"isDeprecatedLicenseId": false,
"isFsfLibre": true,
"detailsUrl": "http://spdx.org/licenses/Unlicense.json",
"referenceNumber": "179",
"name": "The Unlicense",
"licenseId": "Unlicense",
"seeAlso": [
"https://unlicense.org/"
],
"isOsiApproved": false
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also recommended by npm, I don't think we should just make an arbitrary new suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
40a5318
to
69fa2f1
Compare
Fingers crossed... |
69fa2f1
to
fdb26c8
Compare
Ah! The joy of external tests! |
The failure seems to be an SMT failure. Re-running... |
dcd35b3
to
fdb26c8
Compare
docs/layout-of-source-files.rst
Outdated
Supplying this comment of course does not free you from other | ||
obligations related to licensing like having to mention | ||
a specific license header in each source file or the | ||
original copyrigh holder. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: copyright
fdb26c8
to
d33b67b
Compare
Closes #7738.