Skip to contentSkip to conversation

spdx: Add do_deploy_build_sbom_spdx

PATCH In review Joshua Watt 2 participants 2 messages Nov 22, 2024 – Nov 23, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spdx: Add do_deploy_build_sbom_spdx

Adds a task that can be used to generate a stand alone SBoM for a given build of a recipe. This SBoM includes the inputs and output for the build, as well as the build and runtime dependencies. The dependencies however will be added as unresolved imports to the OE SPDX alias, so as to avoid pulling in the entire dependency tree (that is, the generated SBoM is focused on just the specific recipe, not the entire build dependency tree).

---
 meta/classes/create-spdx-3.0.bbclass | 25 ++++++++++++
 meta/lib/oe/sbom30.py                | 55 ++++++++++++++++----------
 meta/lib/oe/spdx30_tasks.py          | 59 ++++++++++++++++++++++++++--
 meta/lib/oeqa/selftest/cases/spdx.py | 20 +++++++++-
 4 files changed, 133 insertions(+), 26 deletions(-)
meta/classes/create-spdx-3.0.bbclass +25 -0
index 640f5490bda..3b421bfda67 100644
@@ -117,6 +117,8 @@ SPDX_PACKAGE_SUPPLIER[doc] = "The base variable name to describe the Agent who \
 IMAGE_CLASSES:append = " create-spdx-image-3.0"
 SDK_CLASSES += "create-spdx-sdk-3.0"
 
+SPDXRECIPEBUILDDEPLOYDIR = "${SPDXDIR}/recipe-build-deploy"
+
 oe.spdx30_tasks.set_timestamp_now[vardepsexclude] = "SPDX_INCLUDE_TIMESTAMPS"
 oe.spdx30_tasks.get_package_sources_from_debug[vardepsexclude] += "STAGING_KERNEL_DIR"
 oe.spdx30_tasks.collect_dep_objsets[vardepsexclude] = "SPDX_MULTILIB_SSTATE_ARCHS"
@@ -179,6 +181,29 @@ do_create_package_spdx[dirs] = "${SPDXRUNTIMEDEPLOY}"
 do_create_package_spdx[cleandirs] = "${SPDXRUNTIMEDEPLOY}"
 do_create_package_spdx[rdeptask] = "do_create_spdx"
 
+python do_deploy_build_sbom_spdx() {
+    import oe.spdx30_tasks
+    from pathlib import Path
+
+    deploydir = Path(d.getVar("SPDXRECIPEBUILDDEPLOYDIR"))
+    spdx_path = deploydir / (d.getVar("PN") + "-build.spdx.json")
+
+    oe.spdx30_tasks.create_build_sbom(d, spdx_path)
+}
+addtask do_deploy_build_sbom_spdx after do_create_spdx do_create_package_spdx
+SSTATETASKS += "do_deploy_build_sbom_spdx"
+SSTATE_SKIP_CREATION:task-create-recipe-sbom = "1"
+do_deploy_build_sbom_spdx[sstate-inputdirs] = "${SPDXRECIPEBUILDDEPLOYDIR}"
+do_deploy_build_sbom_spdx[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
+do_deploy_build_sbom_spdx[stamp-extra-info] = "${MACHINE_ARCH}"
+do_deploy_build_sbom_spdx[cleandirs] = "${SPDXRECIPEBUILDDEPLOYDIR}"
+do_deploy_build_sbom_spdx[file-checksums] += "${SPDX3_LIB_DEP_FILES}"
+
+python do_deploy_build_sbom_spdx_setscene() {
+    sstate_setscene(d)
+}
+addtask do_deploy_build_sbom_spdx_setscene
+
 python spdx30_build_started_handler () {
     import oe.spdx30_tasks
     d = e.data.createCopy()
meta/lib/oe/sbom30.py +34 -21

96 lines not on this page · raw message

meta/lib/oe/spdx30_tasks.py +56 -3

78 lines not on this page · raw message

meta/lib/oeqa/selftest/cases/spdx.py +18 -2
index 83840702199..5e104b0c668 100644
@@ -120,7 +120,15 @@ class SPDX3CheckBase(object):
         return self.check_spdx_file(filename)
 
     def check_objset_missing_ids(self, objset):
-        if objset.missing_ids:
+        import oe.spdx30
+
+        missing = objset.missing_ids
+
+        for doc in objset.foreach_type(oe.spdx30.SpdxDocument):
+            for i in doc.import_:
+                missing.discard(i.externalSpdxId)
+
+        if missing:
             self.assertTrue(
                 False,
                 "The following SPDXIDs are unresolved:\n  "
@@ -137,7 +145,6 @@ class SPDX30Check(SPDX3CheckBase, OESelftestTestCase):
             "{DEPLOY_DIR_SPDX}/{MACHINE_ARCH}/packages/base-files.spdx.json",
         )
 
-
     def test_gcc_include_source(self):
         import oe.spdx30
 
@@ -197,3 +204,12 @@ class SPDX30Check(SPDX3CheckBase, OESelftestTestCase):
 
         # Document should be fully linked
         self.check_objset_missing_ids(objset)
+
+    def test_deploy_build_sbom_spdx_bash(self):
+        objset = self.check_recipe_spdx(
+            "bash",
+            "{DEPLOY_DIR_IMAGE}/bash-build.spdx.json",
+            task="deploy_build_sbom_spdx",
+        )
+
+        self.check_objset_missing_ids(objset)
Signature · 1 line
2.47.0
#1 lore raw
Quoted 8 lines · Joshua Watt via lists.openembedded.org

Adds a task that can be used to generate a stand alone SBoM for a given build of a recipe. This SBoM includes the inputs and output for the build, as well as the build and runtime dependencies. The dependencies however will be added as unresolved imports to the OE SPDX alias, so as to avoid pulling in the entire dependency tree (that is, the generated SBoM is focused on just the specific recipe, not the entire build dependency tree).

Quoted 7 lines

---
 meta/classes/create-spdx-3.0.bbclass | 25 ++++++++++++ meta/lib/oe/sbom30.py                | 55 ++++++++++++++++---------- meta/lib/oe/spdx30_tasks.py          | 59 ++++++++++++++++++++++++++-- meta/lib/oeqa/selftest/cases/spdx.py | 20 +++++++++-

 4 files changed, 133 insertions(+), 26 deletions(-)

One of the other selftests may need a tweak after this:

https://valkyrie.yoctoproject.org/#/builders/76/builds/477/steps/14/logs/stdio

Cheers,

Richard