diff options
Diffstat (limited to 'meta/classes/create-spdx-2.2.bbclass')
-rw-r--r-- | meta/classes/create-spdx-2.2.bbclass | 71 |
1 files changed, 54 insertions, 17 deletions
diff --git a/meta/classes/create-spdx-2.2.bbclass b/meta/classes/create-spdx-2.2.bbclass index f12e155f6b..c461c77744 100644 --- a/meta/classes/create-spdx-2.2.bbclass +++ b/meta/classes/create-spdx-2.2.bbclass | |||
@@ -16,6 +16,7 @@ SPDXDEPLOY = "${SPDXDIR}/deploy" | |||
16 | SPDXWORK = "${SPDXDIR}/work" | 16 | SPDXWORK = "${SPDXDIR}/work" |
17 | SPDXIMAGEWORK = "${SPDXDIR}/image-work" | 17 | SPDXIMAGEWORK = "${SPDXDIR}/image-work" |
18 | SPDXSDKWORK = "${SPDXDIR}/sdk-work" | 18 | SPDXSDKWORK = "${SPDXDIR}/sdk-work" |
19 | SPDXDEPS = "${SPDXDIR}/deps.json" | ||
19 | 20 | ||
20 | SPDX_TOOL_NAME ??= "oe-spdx-creator" | 21 | SPDX_TOOL_NAME ??= "oe-spdx-creator" |
21 | SPDX_TOOL_VERSION ??= "1.0" | 22 | SPDX_TOOL_VERSION ??= "1.0" |
@@ -337,30 +338,21 @@ def add_package_sources_from_debug(d, package_doc, spdx_package, package, packag | |||
337 | 338 | ||
338 | package_doc.add_relationship(pkg_file, "GENERATED_FROM", ref_id, comment=debugsrc) | 339 | package_doc.add_relationship(pkg_file, "GENERATED_FROM", ref_id, comment=debugsrc) |
339 | 340 | ||
340 | def collect_deps(d): | ||
341 | current_task = "do_" + d.getVar("BB_CURRENTTASK") | ||
342 | |||
343 | taskdepdata = d.getVar("BB_TASKDEPDATA", False) | ||
344 | deps = sorted(set( | ||
345 | (dep[0], dep[7]) for dep in taskdepdata.values() if | ||
346 | dep[1] == current_task and dep[0] != d.getVar("PN") | ||
347 | )) | ||
348 | |||
349 | return deps | ||
350 | |||
351 | collect_deps[vardepsexclude] += "BB_TASKDEPDATA" | ||
352 | collect_deps[vardeps] += "DEPENDS" | ||
353 | |||
354 | def collect_dep_recipes(d, doc, spdx_recipe): | 341 | def collect_dep_recipes(d, doc, spdx_recipe): |
342 | import json | ||
355 | from pathlib import Path | 343 | from pathlib import Path |
356 | import oe.sbom | 344 | import oe.sbom |
357 | import oe.spdx | 345 | import oe.spdx |
358 | 346 | ||
359 | deploy_dir_spdx = Path(d.getVar("DEPLOY_DIR_SPDX")) | 347 | deploy_dir_spdx = Path(d.getVar("DEPLOY_DIR_SPDX")) |
348 | spdx_deps_file = Path(d.getVar("SPDXDEPS")) | ||
360 | 349 | ||
361 | dep_recipes = [] | 350 | dep_recipes = [] |
362 | 351 | ||
363 | for dep_pn, dep_hashfn in collect_deps(d): | 352 | with spdx_deps_file.open("r") as f: |
353 | deps = json.load(f) | ||
354 | |||
355 | for dep_pn, dep_hashfn in deps: | ||
364 | dep_recipe_path = oe.sbom.doc_path_by_hashfn(deploy_dir_spdx, "recipe-" + dep_pn, dep_hashfn) | 356 | dep_recipe_path = oe.sbom.doc_path_by_hashfn(deploy_dir_spdx, "recipe-" + dep_pn, dep_hashfn) |
365 | 357 | ||
366 | spdx_dep_doc, spdx_dep_sha1 = oe.sbom.read_doc(dep_recipe_path) | 358 | spdx_dep_doc, spdx_dep_sha1 = oe.sbom.read_doc(dep_recipe_path) |
@@ -462,6 +454,52 @@ def add_download_packages(d, doc, recipe): | |||
462 | # but this should be sufficient for now | 454 | # but this should be sufficient for now |
463 | doc.add_relationship(package, "BUILD_DEPENDENCY_OF", recipe) | 455 | doc.add_relationship(package, "BUILD_DEPENDENCY_OF", recipe) |
464 | 456 | ||
457 | def collect_deps(d, dep_task): | ||
458 | current_task = "do_" + d.getVar("BB_CURRENTTASK") | ||
459 | pn = d.getVar("PN") | ||
460 | |||
461 | taskdepdata = d.getVar("BB_TASKDEPDATA", False) | ||
462 | |||
463 | for this_dep in taskdepdata.values(): | ||
464 | if this_dep[0] == pn and this_dep[1] == current_task: | ||
465 | break | ||
466 | else: | ||
467 | bb.fatal(f"Unable to find this {pn}:{current_task} in taskdepdata") | ||
468 | |||
469 | deps = set() | ||
470 | for dep_name in this_dep[3]: | ||
471 | dep_data = taskdepdata[dep_name] | ||
472 | if dep_data[1] == dep_task and dep_data[0] != pn: | ||
473 | deps.add((dep_data[0], dep_data[7])) | ||
474 | |||
475 | return sorted(deps) | ||
476 | |||
477 | collect_deps[vardepsexclude] += "BB_TASKDEPDATA" | ||
478 | collect_deps[vardeps] += "DEPENDS" | ||
479 | |||
480 | python do_collect_spdx_deps() { | ||
481 | # This task calculates the build time dependencies of the recipe, and is | ||
482 | # required because while a task can deptask on itself, those dependencies | ||
483 | # do not show up in BB_TASKDEPDATA. To work around that, this task does the | ||
484 | # deptask on do_create_spdx and writes out the dependencies it finds, then | ||
485 | # do_create_spdx reads in the found dependencies when writing the actual | ||
486 | # SPDX document | ||
487 | import json | ||
488 | from pathlib import Path | ||
489 | |||
490 | spdx_deps_file = Path(d.getVar("SPDXDEPS")) | ||
491 | |||
492 | deps = collect_deps(d, "do_create_spdx") | ||
493 | |||
494 | with spdx_deps_file.open("w") as f: | ||
495 | json.dump(deps, f) | ||
496 | } | ||
497 | # NOTE: depending on do_unpack is a hack that is necessary to get it's dependencies for archive the source | ||
498 | addtask do_collect_spdx_deps after do_unpack | ||
499 | do_collect_spdx_deps[depends] += "${PATCHDEPENDENCY}" | ||
500 | do_collect_spdx_deps[deptask] = "do_create_spdx" | ||
501 | do_collect_spdx_deps[dirs] = "${SPDXDIR}" | ||
502 | |||
465 | python do_create_spdx() { | 503 | python do_create_spdx() { |
466 | from datetime import datetime, timezone | 504 | from datetime import datetime, timezone |
467 | import oe.sbom | 505 | import oe.sbom |
@@ -647,7 +685,7 @@ python do_create_spdx() { | |||
647 | oe.sbom.write_doc(d, package_doc, d.getVar("SSTATE_PKGARCH"), "packages", indent=get_json_indent(d)) | 685 | oe.sbom.write_doc(d, package_doc, d.getVar("SSTATE_PKGARCH"), "packages", indent=get_json_indent(d)) |
648 | } | 686 | } |
649 | # NOTE: depending on do_unpack is a hack that is necessary to get it's dependencies for archive the source | 687 | # NOTE: depending on do_unpack is a hack that is necessary to get it's dependencies for archive the source |
650 | addtask do_create_spdx after do_package do_packagedata do_unpack before do_populate_sdk do_build do_rm_work | 688 | addtask do_create_spdx after do_package do_packagedata do_unpack do_collect_spdx_deps before do_populate_sdk do_build do_rm_work |
651 | 689 | ||
652 | SSTATETASKS += "do_create_spdx" | 690 | SSTATETASKS += "do_create_spdx" |
653 | do_create_spdx[sstate-inputdirs] = "${SPDXDEPLOY}" | 691 | do_create_spdx[sstate-inputdirs] = "${SPDXDEPLOY}" |
@@ -661,7 +699,6 @@ addtask do_create_spdx_setscene | |||
661 | do_create_spdx[dirs] = "${SPDXWORK}" | 699 | do_create_spdx[dirs] = "${SPDXWORK}" |
662 | do_create_spdx[cleandirs] = "${SPDXDEPLOY} ${SPDXWORK}" | 700 | do_create_spdx[cleandirs] = "${SPDXDEPLOY} ${SPDXWORK}" |
663 | do_create_spdx[depends] += "${PATCHDEPENDENCY}" | 701 | do_create_spdx[depends] += "${PATCHDEPENDENCY}" |
664 | do_create_spdx[deptask] = "do_create_spdx" | ||
665 | 702 | ||
666 | def collect_package_providers(d): | 703 | def collect_package_providers(d): |
667 | from pathlib import Path | 704 | from pathlib import Path |