Skip to content

Commit 04365c0

Browse files
ErniGHmemsharded
authored andcommitted
Fix | Validate if the licenses in the SBOM are SPDX compatible (conan-io#18358)
* validate spdx_licenses in the sbom, test * add deprecated licenses and fixes
1 parent cdda7c4 commit 04365c0

3 files changed

Lines changed: 1406 additions & 18 deletions

File tree

conan/tools/sbom/cyclonedx.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,6 @@ def cyclonedx_1_4(conanfile, name=None, add_build=False, add_tests=False, **kwar
5252
deps["dependsOn"] = depends_on
5353
dependencies.append(deps)
5454

55-
def _calculate_licenses(component):
56-
if isinstance(component.conanfile.license, str): # Just one license
57-
return [{"license": {
58-
"id": component.conanfile.license
59-
}}]
60-
return [{"license": {
61-
"id": l
62-
}} for l in component.conanfile.license]
63-
6455
sbom_cyclonedx_1_4 = {
6556
**({"components": [{
6657
"author": node.conanfile.author or "Unknown",
@@ -152,15 +143,6 @@ def cyclonedx_1_6(conanfile, name=None, add_build=False, add_tests=False, **kwar
152143
deps["dependsOn"] = depends_on
153144
dependencies.append(deps)
154145

155-
def _calculate_licenses(component):
156-
if isinstance(component.conanfile.license, str): # Just one license
157-
return [{"license": {
158-
"id": component.conanfile.license
159-
}}]
160-
return [{"license": {
161-
"id": l
162-
}} for l in component.conanfile.license]
163-
164146
sbom_cyclonedx_1_6 = {
165147
**({"components": [{
166148
**({"authors": [{"name": node.conanfile.author}]} if node.conanfile.author else {}),
@@ -199,3 +181,21 @@ def _calculate_licenses(component):
199181
"version": 1,
200182
}
201183
return sbom_cyclonedx_1_6
184+
185+
186+
def _calculate_licenses(component):
187+
from conan.tools.sbom.spdx_licenses import NORMALIZED_VALID_SPDX_LICENSES
188+
licenses = component.conanfile.license
189+
190+
if isinstance(licenses, str): # Just one license
191+
field = "id" if licenses.lower() in NORMALIZED_VALID_SPDX_LICENSES else "name"
192+
return [{"license":{ field: licenses }}]
193+
194+
return [ # More than one license
195+
{"license": {
196+
"id" if l.lower() in NORMALIZED_VALID_SPDX_LICENSES else "name": l
197+
}}
198+
for l in licenses
199+
]
200+
201+

0 commit comments

Comments
 (0)