Skip to content
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

Merged
merged 6 commits into from
May 13, 2020
Merged

Check for SPDX license identifiers. #8907

merged 6 commits into from
May 13, 2020

Conversation

chriseth
Copy link
Contributor

@chriseth chriseth commented May 12, 2020

Closes #7738.

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]+)");
Copy link
Member

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)

Copy link
Contributor Author

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...

{-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. "
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

@chriseth
Copy link
Contributor Author

Once we merge this, we should maybe start adding the field to common libraries?

@hrkrshnn
Copy link
Member

We could also implement a feature for solidity-upgrade to do add a license.

@chriseth
Copy link
Contributor Author

@hrkrshnn good idea!

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]+)");
Copy link
Contributor Author

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.

@chriseth
Copy link
Contributor Author

Taken over by @aarlt.
We would like to get this finished quickly, so please report your progress so that others can take over because of timezones.

@stackenbotten
Copy link

There was an error when running chk_coding_style for commit 021444e697d84e928661cadb443ac0b0ae77068b:

Coding style error:
 libsolidity/parsing/Parser.cpp:1997: for (auto& node : _nodes)
 libsolidity/parsing/Parser.cpp:1999: for (auto& remove : toBeRemoved)

Please check that your changes are working as intended.

@aarlt
Copy link
Member

aarlt commented May 13, 2020

@chriseth I mainly added testing support. Sadly I didn't saw the current errors locally. These errors need to be fixed.


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.
Copy link
Contributor Author

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
Copy link
Contributor Author

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?

@chriseth chriseth force-pushed the licenseIdentifier branch 4 times, most recently from 578fc47 to 16ad880 Compare May 13, 2020 10:49
@chriseth chriseth marked this pull request as ready for review May 13, 2020 10:49
);
else
parserError(
0000_error,
Copy link
Member

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. "
Copy link
Member

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?

Copy link
Contributor Author

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...

Copy link
Member

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,
Copy link
Member

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.

Copy link
Contributor Author

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.

@@ -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";
Copy link
Member

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?

Copy link
Member

@axic axic left a 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.

@axic
Copy link
Member

axic commented May 13, 2020

Will the documentation changes be part of a different PR?

Can we also have parser tests for different comment styles (if we support them):

//SPDX-License-Identifier:
///SPDX-License-Identifier:
// SPDX-License-Identifier:
/// SPDX-License-Identifier:
/* SPDX-License-Identifier:
 * SPDX-License-Identifier:

@chriseth
Copy link
Contributor Author

/// will not work, it is a doxygen comment.

@chriseth
Copy link
Contributor Author

will add a test for /// and also multpile licenses.

@chriseth
Copy link
Contributor Author

Added documentation.

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``.
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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
    }

Copy link
Contributor Author

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.

axic
axic previously approved these changes May 13, 2020
Copy link
Member

@axic axic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@chriseth chriseth force-pushed the licenseIdentifier branch 3 times, most recently from 40a5318 to 69fa2f1 Compare May 13, 2020 16:09
@chriseth
Copy link
Contributor Author

Fingers crossed...

@chriseth chriseth requested a review from axic May 13, 2020 16:12
@chriseth
Copy link
Contributor Author

Ah! The joy of external tests!

@chriseth
Copy link
Contributor Author

The failure seems to be an SMT failure. Re-running...

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: copyright

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add pragma about open or closed source / license
5 participants