summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
authorJoshua Watt <JPEWhacker@gmail.com>2022-06-13 21:30:47 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-01-06 17:33:23 +0000
commit99483cff5c358d847ceb077349321eb57d5143e4 (patch)
tree8d67d4af1694f49acc84a0e2c9d01bfa074de4cc /meta/classes
parent4f3a35407172d79e4dec4f8ba703b1d102347fe3 (diff)
downloadpoky-99483cff5c358d847ceb077349321eb57d5143e4.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: e680a7402edec2803b03c56590c9d08d07497c73) 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> (cherry picked from commit 4799594b26f77ed259dc661bf077519b338390c8) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-rw-r--r--meta/classes/create-spdx.bbclass22
1 files changed, 16 insertions, 6 deletions
diff --git a/meta/classes/create-spdx.bbclass b/meta/classes/create-spdx.bbclass
index 212dfe0aa3..349ecfe6ab 100644
--- a/meta/classes/create-spdx.bbclass
+++ b/meta/classes/create-spdx.bbclass
@@ -24,6 +24,7 @@ SPDX_ARCHIVE_PACKAGED ??= "0"
24 24
25SPDX_UUID_NAMESPACE ??= "sbom.openembedded.org" 25SPDX_UUID_NAMESPACE ??= "sbom.openembedded.org"
26SPDX_NAMESPACE_PREFIX ??= "http://spdx.org/spdxdoc" 26SPDX_NAMESPACE_PREFIX ??= "http://spdx.org/spdxdoc"
27SPDX_PRETTY ??= "0"
27 28
28SPDX_LICENSES ??= "${COREBASE}/meta/files/spdx-licenses.json" 29SPDX_LICENSES ??= "${COREBASE}/meta/files/spdx-licenses.json"
29 30
@@ -75,6 +76,11 @@ def recipe_spdx_is_native(d, recipe):
75def is_work_shared_spdx(d): 76def is_work_shared_spdx(d):
76 return bb.data.inherits_class('kernel', d) or ('work-shared' in d.getVar('WORKDIR')) 77 return bb.data.inherits_class('kernel', d) or ('work-shared' in d.getVar('WORKDIR'))
77 78
79def get_json_indent(d):
80 if d.getVar("SPDX_PRETTY") == "1":
81 return 2
82 return None
83
78python() { 84python() {
79 import json 85 import json
80 if d.getVar("SPDX_LICENSE_DATA"): 86 if d.getVar("SPDX_LICENSE_DATA"):
@@ -514,7 +520,7 @@ python do_create_spdx() {
514 520
515 dep_recipes = collect_dep_recipes(d, doc, recipe) 521 dep_recipes = collect_dep_recipes(d, doc, recipe)
516 522
517 doc_sha1 = oe.sbom.write_doc(d, doc, "recipes") 523 doc_sha1 = oe.sbom.write_doc(d, doc, "recipes", indent=get_json_indent(d))
518 dep_recipes.append(oe.sbom.DepRecipe(doc, doc_sha1, recipe)) 524 dep_recipes.append(oe.sbom.DepRecipe(doc, doc_sha1, recipe))
519 525
520 recipe_ref = oe.spdx.SPDXExternalDocumentRef() 526 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
585addtask do_create_spdx after do_package do_packagedata do_unpack before do_populate_sdk do_build do_rm_work 591addtask 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
749addtask do_create_runtime_spdx after do_create_spdx before do_build do_rm_work 755addtask do_create_runtime_spdx after do_create_spdx before do_build do_rm_work
@@ -939,7 +945,7 @@ def combine_spdx(d, rootfs_name, rootfs_deploydir, rootfs_spdxid, packages):
939 image_spdx_path = rootfs_deploydir / (rootfs_name + ".spdx.json") 945 image_spdx_path = rootfs_deploydir / (rootfs_name + ".spdx.json")
940 946
941 with image_spdx_path.open("wb") as f: 947 with image_spdx_path.open("wb") as f:
942 doc.to_json(f, sort_keys=True) 948 doc.to_json(f, sort_keys=True, indent=get_json_indent(d))
943 949
944 num_threads = int(d.getVar("BB_NUMBER_THREADS")) 950 num_threads = int(d.getVar("BB_NUMBER_THREADS"))
945 951
@@ -997,7 +1003,11 @@ def combine_spdx(d, rootfs_name, rootfs_deploydir, rootfs_spdxid, packages):
997 1003
998 index["documents"].sort(key=lambda x: x["filename"]) 1004 index["documents"].sort(key=lambda x: x["filename"])
999 1005
1000 index_str = io.BytesIO(json.dumps(index, sort_keys=True).encode("utf-8")) 1006 index_str = io.BytesIO(json.dumps(
1007 index,
1008 sort_keys=True,
1009 indent=get_json_indent(d),
1010 ).encode("utf-8"))
1001 1011
1002 info = tarfile.TarInfo() 1012 info = tarfile.TarInfo()
1003 info.name = "index.json" 1013 info.name = "index.json"
@@ -1011,4 +1021,4 @@ def combine_spdx(d, rootfs_name, rootfs_deploydir, rootfs_spdxid, packages):
1011 1021
1012 spdx_index_path = rootfs_deploydir / (rootfs_name + ".spdx.index.json") 1022 spdx_index_path = rootfs_deploydir / (rootfs_name + ".spdx.index.json")
1013 with spdx_index_path.open("w") as f: 1023 with spdx_index_path.open("w") as f:
1014 json.dump(index, f, sort_keys=True) 1024 json.dump(index, f, sort_keys=True, indent=get_json_indent(d))