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