Skip to content

Conversation

@asmitbanik
Copy link

Summary
Fixes invalid SPDX license expressions by using the WITH operator instead of AND when combining base licenses with license exceptions.

Problem
ScanCode was producing invalid SPDX expressions when detecting licenses with exceptions:
❌ Before: "GPL-3.0-only AND GCC-exception-3.1"
✅ After: "GPL-3.0-only WITH GCC-exception-3.1"
According to the SPDX specification, exceptions must always appear on the right side of a WITH expression. Using AND to combine a license with an exception produces an invalid SPDX expression.

Solution
Added a new function combine_expressions_with_exceptions() in detection.py that:
Checks if a license key has is_exception=True in the license database
Combines exceptions with their preceding base license using WITH instead of AND
Falls back to AND for regular license combinations

Changes
Modified: src/licensedcode/detection.py
Added combine_expressions_with_exceptions() function
Updated get_detected_license_expression() to use the new function

Testing
Test: ['gpl-3.0', 'gcc-exception-3.1']Result: gpl-3.0 WITH gcc-exception-3.1 ✓Test: ['gpl-3.0', 'gcc-exception-3.1', 'mit']Result: gpl-3.0 WITH gcc-exception-3.1 AND mit ✓Test: ['gpl-2.0', 'classpath-exception-2.0']Result: gpl-2.0 WITH classpath-exception-2.0 ✓

Impact
This fix applies to all 281 license exceptions in ScanCode's database, ensuring valid SPDX expressions for any license+exception combination.
Related Issues
Fixes #[issue_number] - Invalid SPDX expressions with license exceptions

Checklist:
[✓] Code follows project conventions
[✓] Self-reviewed the code changes
[✓] Tested with multiple exception types (GCC, Classpath, etc.)
[✓] No breaking changes to public API

…andle license exceptions using the WITH operator for valid SPDX expressions. Update get_detected_license_expression to utilize this new function.

Signed-off-by: asmitbanik <[email protected]>
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.

1 participant