diff options
author | Joshua Watt <JPEWhacker@gmail.com> | 2022-06-13 21:30:47 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-06-15 12:27:01 +0100 |
commit | ec2f329787224cd72a569cd07bc78939a96f2793 (patch) | |
tree | 3e0096f8ed4c17fac538c597676ac402a4dec5d8 /meta/classes/create-spdx.bbclass | |
parent | ee0d001b8104419798fc129c3ed9769c98b0832c (diff) | |
download | poky-ec2f329787224cd72a569cd07bc78939a96f2793.tar.gz |
classes/create-spdx: Add SPDX_PRETTY option
Adds an option to make the SPDX more human-readable (at the expense of a
larger files)
(From OE-Core rev: 4799594b26f77ed259dc661bf077519b338390c8)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/create-spdx.bbclass')
-rw-r--r-- | meta/classes/create-spdx.bbclass | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/meta/classes/create-spdx.bbclass b/meta/classes/create-spdx.bbclass index 37b6b569a1..15cccac84b 100644 --- a/meta/classes/create-spdx.bbclass +++ b/meta/classes/create-spdx.bbclass | |||
@@ -25,6 +25,7 @@ SPDX_ARCHIVE_PACKAGED ??= "0" | |||
25 | 25 | ||
26 | SPDX_UUID_NAMESPACE ??= "sbom.openembedded.org" | 26 | SPDX_UUID_NAMESPACE ??= "sbom.openembedded.org" |
27 | SPDX_NAMESPACE_PREFIX ??= "http://spdx.org/spdxdoc" | 27 | SPDX_NAMESPACE_PREFIX ??= "http://spdx.org/spdxdoc" |
28 | SPDX_PRETTY ??= "0" | ||
28 | 29 | ||
29 | SPDX_LICENSES ??= "${COREBASE}/meta/files/spdx-licenses.json" | 30 | SPDX_LICENSES ??= "${COREBASE}/meta/files/spdx-licenses.json" |
30 | 31 | ||
@@ -76,6 +77,11 @@ def recipe_spdx_is_native(d, recipe): | |||
76 | def is_work_shared_spdx(d): | 77 | def is_work_shared_spdx(d): |
77 | return bb.data.inherits_class('kernel', d) or ('work-shared' in d.getVar('WORKDIR')) | 78 | return bb.data.inherits_class('kernel', d) or ('work-shared' in d.getVar('WORKDIR')) |
78 | 79 | ||
80 | def get_json_indent(d): | ||
81 | if d.getVar("SPDX_PRETTY") == "1": | ||
82 | return 2 | ||
83 | return None | ||
84 | |||
79 | python() { | 85 | python() { |
80 | import json | 86 | import json |
81 | if d.getVar("SPDX_LICENSE_DATA"): | 87 | if d.getVar("SPDX_LICENSE_DATA"): |
@@ -515,7 +521,7 @@ python do_create_spdx() { | |||
515 | 521 | ||
516 | dep_recipes = collect_dep_recipes(d, doc, recipe) | 522 | dep_recipes = collect_dep_recipes(d, doc, recipe) |
517 | 523 | ||
518 | doc_sha1 = oe.sbom.write_doc(d, doc, "recipes") | 524 | doc_sha1 = oe.sbom.write_doc(d, doc, "recipes", indent=get_json_indent(d)) |
519 | dep_recipes.append(oe.sbom.DepRecipe(doc, doc_sha1, recipe)) | 525 | dep_recipes.append(oe.sbom.DepRecipe(doc, doc_sha1, recipe)) |
520 | 526 | ||
521 | recipe_ref = oe.spdx.SPDXExternalDocumentRef() | 527 | recipe_ref = oe.spdx.SPDXExternalDocumentRef() |
@@ -579,7 +585,7 @@ python do_create_spdx() { | |||
579 | 585 | ||
580 | add_package_sources_from_debug(d, package_doc, spdx_package, package, package_files, sources) | 586 | add_package_sources_from_debug(d, package_doc, spdx_package, package, package_files, sources) |
581 | 587 | ||
582 | oe.sbom.write_doc(d, package_doc, "packages") | 588 | oe.sbom.write_doc(d, package_doc, "packages", indent=get_json_indent(d)) |
583 | } | 589 | } |
584 | # NOTE: depending on do_unpack is a hack that is necessary to get it's dependencies for archive the source | 590 | # NOTE: depending on do_unpack is a hack that is necessary to get it's dependencies for archive the source |
585 | addtask do_create_spdx after do_package do_packagedata do_unpack before do_populate_sdk do_build do_rm_work | 591 | addtask do_create_spdx after do_package do_packagedata do_unpack before do_populate_sdk do_build do_rm_work |
@@ -743,7 +749,7 @@ python do_create_runtime_spdx() { | |||
743 | ) | 749 | ) |
744 | seen_deps.add(dep) | 750 | seen_deps.add(dep) |
745 | 751 | ||
746 | oe.sbom.write_doc(d, runtime_doc, "runtime", spdx_deploy) | 752 | oe.sbom.write_doc(d, runtime_doc, "runtime", spdx_deploy, indent=get_json_indent(d)) |
747 | } | 753 | } |
748 | 754 | ||
749 | addtask do_create_runtime_spdx after do_create_spdx before do_build do_rm_work | 755 | addtask do_create_runtime_spdx after do_create_spdx before do_build do_rm_work |
@@ -938,7 +944,7 @@ def combine_spdx(d, rootfs_name, rootfs_deploydir, rootfs_spdxid, packages): | |||
938 | image_spdx_path = rootfs_deploydir / (rootfs_name + ".spdx.json") | 944 | image_spdx_path = rootfs_deploydir / (rootfs_name + ".spdx.json") |
939 | 945 | ||
940 | with image_spdx_path.open("wb") as f: | 946 | with image_spdx_path.open("wb") as f: |
941 | doc.to_json(f, sort_keys=True) | 947 | doc.to_json(f, sort_keys=True, indent=get_json_indent(d)) |
942 | 948 | ||
943 | num_threads = int(d.getVar("BB_NUMBER_THREADS")) | 949 | num_threads = int(d.getVar("BB_NUMBER_THREADS")) |
944 | 950 | ||
@@ -996,7 +1002,11 @@ def combine_spdx(d, rootfs_name, rootfs_deploydir, rootfs_spdxid, packages): | |||
996 | 1002 | ||
997 | index["documents"].sort(key=lambda x: x["filename"]) | 1003 | index["documents"].sort(key=lambda x: x["filename"]) |
998 | 1004 | ||
999 | index_str = io.BytesIO(json.dumps(index, sort_keys=True).encode("utf-8")) | 1005 | index_str = io.BytesIO(json.dumps( |
1006 | index, | ||
1007 | sort_keys=True, | ||
1008 | indent=get_json_indent(d), | ||
1009 | ).encode("utf-8")) | ||
1000 | 1010 | ||
1001 | info = tarfile.TarInfo() | 1011 | info = tarfile.TarInfo() |
1002 | info.name = "index.json" | 1012 | info.name = "index.json" |
@@ -1010,4 +1020,4 @@ def combine_spdx(d, rootfs_name, rootfs_deploydir, rootfs_spdxid, packages): | |||
1010 | 1020 | ||
1011 | spdx_index_path = rootfs_deploydir / (rootfs_name + ".spdx.index.json") | 1021 | spdx_index_path = rootfs_deploydir / (rootfs_name + ".spdx.index.json") |
1012 | with spdx_index_path.open("w") as f: | 1022 | with spdx_index_path.open("w") as f: |
1013 | json.dump(index, f, sort_keys=True) | 1023 | json.dump(index, f, sort_keys=True, indent=get_json_indent(d)) |