If file_licenses is empty, the hasDeclaredLicense relationship from sourcefile
to NoneElement which makes no sense. Such as

    {
      "type": "Relationship",
      ...
      "from": 
"http://spdx.org/spdxdocs/gettext-minimal-native-1fa0d5cb/sourcefile/3323";,
      "relationshipType": "hasDeclaredLicense",
      "to": [
        "NoneElement"
      ]
    },

Create hasDeclaredLicense relationship only if file_licenses is not empty

Signed-off-by: Hongxu Jia <[email protected]>
---
 meta/lib/oe/sbom30.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/meta/lib/oe/sbom30.py b/meta/lib/oe/sbom30.py
index f4cc1f49dd..6df5759596 100644
--- a/meta/lib/oe/sbom30.py
+++ b/meta/lib/oe/sbom30.py
@@ -620,11 +620,12 @@ class ObjectSet(oe.spdx30.SHACLObjectSet):
         for extracted_lic in oe.spdx_common.extract_licenses(filepath):
             file_licenses.add(self.new_license_expression(extracted_lic, 
license_data))
 
-        self.new_relationship(
-            [spdx_file],
-            oe.spdx30.RelationshipType.hasDeclaredLicense,
-            file_licenses,
-        )
+        if file_licenses:
+            self.new_relationship(
+                [spdx_file],
+                oe.spdx30.RelationshipType.hasDeclaredLicense,
+                file_licenses,
+            )
         spdx_file.extension.append(OELicenseScannedExtension())
 
     def new_file(self, _id, name, path, *, purposes=[]):
-- 
2.25.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#206381): 
https://lists.openembedded.org/g/openembedded-core/message/206381
Mute This Topic: https://lists.openembedded.org/mt/109220134/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to