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

refactor(license): improve license expression normalization #8257

Merged
merged 5 commits into from
Jan 21, 2025

Conversation

knqyf263
Copy link
Collaborator

@knqyf263 knqyf263 commented Jan 20, 2025

Description

This PR modifies expression.NormalizeFunc to accept expression.Expression instead of string as its argument. This change allows for more flexible license normalization, particularly for compound licenses containing the WITH operator.

Current Issues

  • The current implementation processes the Left and Right parts of WITH-containing licenses separately
  • This separate processing can lead to suboptimal normalization when licenses should be treated as a single unit

Changes

  • Modified expression.NormalizeFunc signature to accept expression.Expression
  • Updated NormalizeLicense to properly handle composite licenses with WITH operator

Note

This change is expected to facilitate the implementation of #8077 by allowing easier replacement of non-SPDX licenses by returning expression.SimpleExpression{License: LicenseRef-xxx} format.

Related PRs

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@knqyf263 knqyf263 self-assigned this Jan 20, 2025
@knqyf263 knqyf263 changed the title refactor(licensing): improve license expression normalization refactor(license): improve license expression normalization Jan 20, 2025
@@ -11,7 +11,7 @@ var (
ErrInvalidExpression = xerrors.New("invalid expression error")
)

type NormalizeFunc func(license string) SimpleExpr
type NormalizeFunc func(license Expression) Expression
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the main change.

Comment on lines 220 to 230
{
licenses: []expression.Expression{
expression.SimpleExpr{License: "GPLv2 WITH EXCEPTIONS"},
expression.NewCompoudExpr( // "GPLv2 WITH EXCEPTIONS"
expression.SimpleExpr{License: "GPLv2"},
expression.TokenWith,
expression.SimpleExpr{License: "EXCEPTIONS"},
),
},
normalized: "UPL-1.0",
normalizedKey: "UPL-1.0",
want: "GPL-2.0-with-classpath-exception",
wantLicense: expression.SimpleExpr{License: "GPL-2.0-with-classpath-exception"},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Newly added a test case for compound licenses

Signed-off-by: knqyf263 <[email protected]>
Copy link
Contributor

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

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

LGTM

@DmitriyLewen DmitriyLewen added this pull request to the merge queue Jan 21, 2025
Merged via the queue into aquasecurity:main with commit 2d30dd7 Jan 21, 2025
12 checks passed
@knqyf263 knqyf263 deleted the refactor/license_normalize branch January 21, 2025 07:47
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.

2 participants