xref: /openbmc/openbmc/poky/meta/classes-recipe/create-spdx-image-3.0.bbclass (revision 8460358c3d24c71d9d38fd126c745854a6301564)
1*8460358cSPatrick Williams#
2*8460358cSPatrick Williams# Copyright OpenEmbedded Contributors
3*8460358cSPatrick Williams#
4*8460358cSPatrick Williams# SPDX-License-Identifier: GPL-2.0-only
5*8460358cSPatrick Williams#
6*8460358cSPatrick Williams# SPDX image tasks
7*8460358cSPatrick Williams
8*8460358cSPatrick WilliamsSPDX_ROOTFS_PACKAGES = "${SPDXDIR}/rootfs-packages.json"
9*8460358cSPatrick WilliamsSPDXIMAGEDEPLOYDIR = "${SPDXDIR}/image-deploy"
10*8460358cSPatrick WilliamsSPDXROOTFSDEPLOY = "${SPDXDIR}/rootfs-deploy"
11*8460358cSPatrick Williams
12*8460358cSPatrick Williamspython spdx_collect_rootfs_packages() {
13*8460358cSPatrick Williams    import json
14*8460358cSPatrick Williams    from pathlib import Path
15*8460358cSPatrick Williams    from oe.rootfs import image_list_installed_packages
16*8460358cSPatrick Williams
17*8460358cSPatrick Williams    root_packages_file = Path(d.getVar("SPDX_ROOTFS_PACKAGES"))
18*8460358cSPatrick Williams
19*8460358cSPatrick Williams    packages = image_list_installed_packages(d)
20*8460358cSPatrick Williams    if not packages:
21*8460358cSPatrick Williams        packages = {}
22*8460358cSPatrick Williams
23*8460358cSPatrick Williams    root_packages_file.parent.mkdir(parents=True, exist_ok=True)
24*8460358cSPatrick Williams    with root_packages_file.open("w") as f:
25*8460358cSPatrick Williams        json.dump(packages, f)
26*8460358cSPatrick Williams}
27*8460358cSPatrick WilliamsROOTFS_POSTUNINSTALL_COMMAND =+ "spdx_collect_rootfs_packages"
28*8460358cSPatrick Williams
29*8460358cSPatrick Williamspython do_create_rootfs_spdx() {
30*8460358cSPatrick Williams    import oe.spdx30_tasks
31*8460358cSPatrick Williams    oe.spdx30_tasks.create_rootfs_spdx(d)
32*8460358cSPatrick Williams}
33*8460358cSPatrick Williamsaddtask do_create_rootfs_spdx after do_rootfs before do_image
34*8460358cSPatrick WilliamsSSTATETASKS += "do_create_rootfs_spdx"
35*8460358cSPatrick Williamsdo_create_rootfs_spdx[sstate-inputdirs] = "${SPDXROOTFSDEPLOY}"
36*8460358cSPatrick Williamsdo_create_rootfs_spdx[sstate-outputdirs] = "${DEPLOY_DIR_SPDX}"
37*8460358cSPatrick Williamsdo_create_rootfs_spdx[recrdeptask] += "do_create_spdx do_create_package_spdx"
38*8460358cSPatrick Williamsdo_create_rootfs_spdx[cleandirs] += "${SPDXROOTFSDEPLOY}"
39*8460358cSPatrick Williamsdo_create_rootfs_spdx[file-checksums] += "${SPDX3_LIB_DEP_FILES}"
40*8460358cSPatrick Williams
41*8460358cSPatrick Williamspython do_create_rootfs_spdx_setscene() {
42*8460358cSPatrick Williams    sstate_setscene(d)
43*8460358cSPatrick Williams}
44*8460358cSPatrick Williamsaddtask do_create_rootfs_spdx_setscene
45*8460358cSPatrick Williams
46*8460358cSPatrick Williamspython do_create_image_spdx() {
47*8460358cSPatrick Williams    import oe.spdx30_tasks
48*8460358cSPatrick Williams    oe.spdx30_tasks.create_image_spdx(d)
49*8460358cSPatrick Williams}
50*8460358cSPatrick Williamsaddtask do_create_image_spdx after do_image_complete do_create_rootfs_spdx before do_build
51*8460358cSPatrick WilliamsSSTATETASKS += "do_create_image_spdx"
52*8460358cSPatrick WilliamsSSTATE_SKIP_CREATION:task-create-image-spdx = "1"
53*8460358cSPatrick Williamsdo_create_image_spdx[sstate-inputdirs] = "${SPDXIMAGEWORK}"
54*8460358cSPatrick Williamsdo_create_image_spdx[sstate-outputdirs] = "${DEPLOY_DIR_SPDX}"
55*8460358cSPatrick Williamsdo_create_image_spdx[cleandirs] = "${SPDXIMAGEWORK}"
56*8460358cSPatrick Williamsdo_create_image_spdx[dirs] = "${SPDXIMAGEWORK}"
57*8460358cSPatrick Williamsdo_create_image_spdx[file-checksums] += "${SPDX3_LIB_DEP_FILES}"
58*8460358cSPatrick Williamsdo_create_image_spdx[vardeps] += "\
59*8460358cSPatrick Williams    SPDX_IMAGE_PURPOSE \
60*8460358cSPatrick Williams    "
61*8460358cSPatrick Williams
62*8460358cSPatrick Williamspython do_create_image_spdx_setscene() {
63*8460358cSPatrick Williams    sstate_setscene(d)
64*8460358cSPatrick Williams}
65*8460358cSPatrick Williamsaddtask do_create_image_spdx_setscene
66*8460358cSPatrick Williams
67*8460358cSPatrick Williams
68*8460358cSPatrick Williamspython do_create_image_sbom_spdx() {
69*8460358cSPatrick Williams    import oe.spdx30_tasks
70*8460358cSPatrick Williams    oe.spdx30_tasks.create_image_sbom_spdx(d)
71*8460358cSPatrick Williams}
72*8460358cSPatrick Williamsaddtask do_create_image_sbom_spdx after do_create_rootfs_spdx do_create_image_spdx before do_build
73*8460358cSPatrick WilliamsSSTATETASKS += "do_create_image_sbom_spdx"
74*8460358cSPatrick WilliamsSSTATE_SKIP_CREATION:task-create-image-sbom = "1"
75*8460358cSPatrick Williamsdo_create_image_sbom_spdx[sstate-inputdirs] = "${SPDXIMAGEDEPLOYDIR}"
76*8460358cSPatrick Williamsdo_create_image_sbom_spdx[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
77*8460358cSPatrick Williamsdo_create_image_sbom_spdx[stamp-extra-info] = "${MACHINE_ARCH}"
78*8460358cSPatrick Williamsdo_create_image_sbom_spdx[cleandirs] = "${SPDXIMAGEDEPLOYDIR}"
79*8460358cSPatrick Williamsdo_create_image_sbom_spdx[recrdeptask] += "do_create_spdx do_create_package_spdx"
80*8460358cSPatrick Williamsdo_create_image_sbom_spdx[file-checksums] += "${SPDX3_LIB_DEP_FILES}"
81*8460358cSPatrick Williams
82*8460358cSPatrick Williamspython do_create_image_sbom_spdx_setscene() {
83*8460358cSPatrick Williams    sstate_setscene(d)
84*8460358cSPatrick Williams}
85*8460358cSPatrick Williamsaddtask do_create_image_sbom_spdx_setscene
86