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

Update _joinExpressions to preserve precedence #1087

Merged
merged 3 commits into from
Jun 5, 2024

Conversation

lumaxis
Copy link
Contributor

@lumaxis lumaxis commented Apr 4, 2024

Fixes #1084

@lumaxis lumaxis requested review from qtomlinson and elrayle April 4, 2024 15:31
@lumaxis lumaxis marked this pull request as ready for review April 4, 2024 15:31
Copy link
Collaborator

@qtomlinson qtomlinson left a comment

Choose a reason for hiding this comment

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

Yes. This would be my first thought of fixing this as well. But looking at the test cases of stringify in service/test/lib/spdx.js, I have 2nd thought: the license expressions joined this way may not be the simplified form. stringify in the SPDX module has the ability to add and omit () based on precedence (e.g, MIT AND BSD-3-Clause WITH GCC-exception-3.1 OR CC-BY-4.0 AND Apache-2.0). Options to leverage this may include:

  1. avoid calling stringify the expression nodes in _createExpressionFromLicense, construct an AND expression node when joining all expression nodes, and finally use SPDX.stringify to serialize the AND expression node. This however means that the internals of expression node need to be used to construct AND node, which is not ideal
  2. Alternatively, in _joinExpressions, can add () to each license expression unconditionally, use AND to join them, and then return SPDX.normalize(joinedExpressionString). SPDX.normalize calls stringify internally, so the expression after normalization is the simplified form without unnecessary (). This approach is less efficient in that normalize parses the expression string again before stringify. But the advantage is that it is simple and delegates the knowledge of operators, precedence, and simplifying () to @clearlydefined/spdx.

Any thoughts?

@lumaxis lumaxis self-assigned this Apr 23, 2024
@lumaxis
Copy link
Contributor Author

lumaxis commented Apr 23, 2024

As we discussed last week, I agree and would definitely prefer to let the library handle this logic. Actually, my preference would be to either figure out if @clearlydefined/spdx can already do this through merge/flatten/expand somehow or alternatively, make changes to the library so that it can handle joining expressions for us.

@lumaxis
Copy link
Contributor Author

lumaxis commented May 30, 2024

@qtomlinson Do you think you might have time to carry this forward while I'm on vacation? I think that would be tremendously helpful! 🙏🏼

@qtomlinson
Copy link
Collaborator

qtomlinson commented May 30, 2024

@lumaxis sounds good. The merge/flatten/expand methods in @clearlydefined/spdx do not help us here. I have updated the PR based on what we discussed during the dev sync meeting. Please review and provide feedback. I can also rebase this PR after the ScanCode upgrade PRs are merged.

Copy link
Collaborator

@elrayle elrayle left a comment

Choose a reason for hiding this comment

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

LGTM... are there any outstanding questions from previous discussions? If not, let's ship it. 🚢

@elrayle elrayle merged commit a7f58d3 into master Jun 5, 2024
3 checks passed
@elrayle elrayle deleted the fix-license-expression-precedence branch June 5, 2024 14:51
qtomlinson added a commit to qtomlinson/service that referenced this pull request Jun 21, 2024
Update definition schema due to recent fixes:
clearlydefined#1087
clearlydefined#1108
qtomlinson added a commit to qtomlinson/service that referenced this pull request Jun 26, 2024
Update definition schema due to recent fixes:
clearlydefined#1087
clearlydefined#1108
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.

Precedence is not preserved when joining Scancode license expressions
3 participants