-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
refactor(license): improve license expression normalization #8257
Conversation
Signed-off-by: knqyf263 <[email protected]>
Signed-off-by: knqyf263 <[email protected]>
Signed-off-by: knqyf263 <[email protected]>
@@ -11,7 +11,7 @@ var ( | |||
ErrInvalidExpression = xerrors.New("invalid expression error") | |||
) | |||
|
|||
type NormalizeFunc func(license string) SimpleExpr | |||
type NormalizeFunc func(license Expression) Expression |
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 the main change.
pkg/licensing/normalize_test.go
Outdated
{ | ||
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"}, |
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.
Newly added a test case for compound licenses
Signed-off-by: knqyf263 <[email protected]>
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.
LGTM
Description
This PR modifies
expression.NormalizeFunc
to acceptexpression.Expression
instead ofstring
as its argument. This change allows for more flexible license normalization, particularly for compound licenses containing theWITH
operator.Current Issues
Changes
expression.NormalizeFunc
signature to acceptexpression.Expression
NormalizeLicense
to properly handle composite licenses withWITH
operatorNote
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
hasExtractedLicensingInfos
field for licenses that are not listed in the SPDX #8077Checklist