From 754394b646b3859e5325981a985ddbce5ce0ee3b Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 4 Dec 2023 01:37:01 +0000 Subject: [PATCH 1/2] fix: python command exec that is compatible with python 3.6 and updates install recipe tasks --- classes/fossa.bbclass | 9 ++- classes/fossa_upload.bbclass | 16 ++-- recipes-extended/fossa/fossa-cli-native.inc | 79 +++++++++++++++++++ .../fossa/fossa-cli-native_3.6.0.bb | 4 + 4 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 recipes-extended/fossa/fossa-cli-native.inc create mode 100644 recipes-extended/fossa/fossa-cli-native_3.6.0.bb diff --git a/classes/fossa.bbclass b/classes/fossa.bbclass index 740f918..24e6f86 100644 --- a/classes/fossa.bbclass +++ b/classes/fossa.bbclass @@ -82,6 +82,8 @@ python do_fossa_pkg() { # this way it is able to capture the output of `do_fossa_pkg` for every # package that was processed. python do_fossa() { + from oe.rootfs import image_list_installed_packages + if not is_fossa_enabled(d): bb.debug(1, "Since FOSSA_ENABLED is 0, skipping: creating fossa-deps.json") return @@ -93,13 +95,14 @@ python do_fossa() { metadata_dir = d.getVar('FOSSA_METADATA_RECIPES') pkg_metadata = all_pkg_metadata(d, metadata_dir) + pkgs = image_list_installed_packages(d) installed_pkgs = [] - for pkg in pkg_metadata: + for pkg in pkgs: try: installed_pkgs.append(mk_user_dependencies(pkg_metadata[pkg])) - except Exception as err: - bb.error(f'failed to retrieve pkg metadata for {pkg} because: {err}') + except Exception: + pass # Ensure path exists fossa_deps_dir = d.getVar("FOSSA_STAGING_DIR") diff --git a/classes/fossa_upload.bbclass b/classes/fossa_upload.bbclass index b233be4..10a70b5 100644 --- a/classes/fossa_upload.bbclass +++ b/classes/fossa_upload.bbclass @@ -6,14 +6,14 @@ inherit fossa_utils addtask do_fossa_analyze before do_build after do_rootfs do_fossa_analyze[doc] = "Analyze via fossa-cli" do_fossa_analyze[nostamp] = "1" -do_fossa_analyze[depends] = "fossa-cli:do_populate_sysroot" +do_fossa_analyze[depends] = "fossa-cli-native:do_populate_sysroot" addtask do_fossa_test before do_build after do_fossa_analyze do_fossa_test[doc] = "Test via fossa-cli" do_fossa_test[nostamp] = "1" -do_fossa_test[deptask] += "fossa-cli:do_populate_sysroot" +do_fossa_test[deptask] += "fossa-cli-native:do_populate_sysroot" -# This task runs `fossa-cli` against the `fossa-deps` file generated by `fossa:do_fossa`, +# This task runs `fossa-cli-native` against the `fossa-deps` file generated by `fossa:do_fossa`, # analyzing the file and storing its results in the FOSSA backend. # # This task is run after `do_rootfs` is finalized (`fossa:do_fossa` runs as a post-processing @@ -44,6 +44,8 @@ python do_fossa_test() { bb.debug(1, "Since FOSSA_TEST_ENABLED is 0, skipping: fossa test") return + bb.plain("Running fossa test command. It will fail build if FOSSA finds unresolved licensing issues.") + bb.plain("To not fail fatally, fossa test command can be disabled by, setting: FOSSA_TEST_ENABLED to 0.") run_fossa_cli(d, mk_fossa_cmd(d, 'test')) } @@ -54,11 +56,13 @@ def run_fossa_cli(d, cli_args): BINDIR = d.getVar("bindir") WORKDIR = d.getVar("WORKDIR") - cli_path = (f"{WORKDIR}/recipe-sysroot{BINDIR}/fossa") - cmds = [cli_path] + cli_args + # We don't need to specify the whole path here. The sysroot-native + # directory is already in our PATH. + fossa_cli = ("fossa") + cmds = [fossa_cli] + cli_args bb.plain(f"running: {' '.join(cmds)}") - out = subprocess.run(cmds, cwd=d.getVar("FOSSA_STAGING_DIR"), capture_output=True, text=True, shell=False) + out = subprocess.run(cmds, cwd=d.getVar("FOSSA_STAGING_DIR"), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=False) if out.returncode != 0: bb.fatal(out.stderr) else: diff --git a/recipes-extended/fossa/fossa-cli-native.inc b/recipes-extended/fossa/fossa-cli-native.inc new file mode 100644 index 0000000..74d9821 --- /dev/null +++ b/recipes-extended/fossa/fossa-cli-native.inc @@ -0,0 +1,79 @@ + +# These special variables control how BitBake builds the project. +# +# Reference: https://docs.yoctoproject.org/bitbake/2.2/bitbake-user-manual/bitbake-user-manual-ref-variables.html + +SUMMARY = "Flexible, performant dependency analysis" +HOMEPAGE = "https://fossa.com" +LICENSE = "MPL-2.0" +DEPENDS += "unzip-native" +INHIBIT_DEFAULT_DEPS = "1" +LIC_FILES_CHKSUM = "file://LICENSE;md5=815ca599c9df247a0c7f619bab123dad" +S = "${WORKDIR}/fossa-cli-${PV}" + +inherit native + +# Every BitBake recipe implicitly inherits `base.bbclass`: https://docs.yoctoproject.org/ref-manual/classes.html#base-bbclass +# This means that in addition to the tasks defined in this file, implicit tasks are defined. +# Refer to `meta/classes/base.bbclass` in Poky for the implementation of these implicit tasks +# and dependencies. +# +# In Dunfell, the following is the implicit task ordering: +# - addtask fetch +# - addtask unpack after do_fetch +# - addtask configure after do_patch +# - addtask compile after do_configure +# - addtask install after do_compile +# - addtask build after do_populate_sysroot +# - addtask cleansstate after do_clean +# - addtask cleanall after do_cleansstate +# +# An observant reader may have noticed that the `fossa` class is inherited in the quickstart, +# but nothing is explicitly added to depend on this `fossa-cli` recipe. +# +# The connection is in the `fossa_upload` class: +# +# ``` +# do_fossa_analyze[depends] = "fossa-cli:do_populate_sysroot" +# do_fossa_test[deptask] += "fossa-cli:do_populate_sysroot" +# ``` +# +# From the Yocto docs (https://docs.yoctoproject.org/ref-manual/tasks.html#do-populate-sysroot), +# `do_populate_sysroot` depends on the `do_install` task since it populates files from that task +# into the sysroot. +# +# In turn as we can see in the base class, `do_install` depends on `do_configure`, +# which depends on `fetch` which starts things off by pulling the `fossa-cli` bundle +# as part of the configuration step. Note: we delete the do_compile task here as +# there is nothing to compile for this. +# +# While we specify populate_sysroot as the step to perform this, since we are a native +# recipe installing a binary to be run on the build host, the install phase is applied +# to sysroot-native. + +# https://docs.yoctoproject.org/ref-manual/tasks.html#do-compile +# +# Implicitly, before this step is run, the `fetch` and `unpack` tasks are run. +# These ensure that the source at `SRC_URI` is present in `${S}`. +# +# This task downloads `fossa-cli` at the specified version to `${D}`. +# The version provided to the install script should match the version specified by `${PV}`. +do_configure() { + chmod a+x ${S}/install-latest.sh + ${S}/install-latest.sh -b ${S} -d v${PV} +} + +do_compile[noexec] = "1" + +# https://docs.yoctoproject.org/ref-manual/tasks.html#do-install +# +# Implicitly, before this step is run the `compile` task is run. +# +# This task installs the downloaded `fossa` binary to the BitBake binary directory +# for invocation. +do_install() { + install -d ${D}${bindir}/ + install -m 0755 ${S}/fossa ${D}${bindir}/fossa +} + +INSANE_SKIP_${PN} += "already-stripped" diff --git a/recipes-extended/fossa/fossa-cli-native_3.6.0.bb b/recipes-extended/fossa/fossa-cli-native_3.6.0.bb new file mode 100644 index 0000000..93133c4 --- /dev/null +++ b/recipes-extended/fossa/fossa-cli-native_3.6.0.bb @@ -0,0 +1,4 @@ +SRC_URI = "https://github.com/fossas/fossa-cli/archive/refs/tags/v${PV}.tar.gz" +SRC_URI[sha256sum] = "31eac60f057b191734f5b4cc9ffedc25f9a2726828ddad99e6392dc10d638e1c" + +require fossa-cli-native.inc From f0f4b4fed4f4241bebf1610b8c3ad1960b42b3ff Mon Sep 17 00:00:00 2001 From: meghfossa <86321858+meghfossa@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:31:52 -0700 Subject: [PATCH 2/2] Update fossa.bbclass --- classes/fossa.bbclass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/fossa.bbclass b/classes/fossa.bbclass index 24e6f86..7aaeda6 100644 --- a/classes/fossa.bbclass +++ b/classes/fossa.bbclass @@ -102,7 +102,7 @@ python do_fossa() { try: installed_pkgs.append(mk_user_dependencies(pkg_metadata[pkg])) except Exception: - pass + bb.debug(f'failed to retrieve pkg metadata for {pkg} because: {err}') # Ensure path exists fossa_deps_dir = d.getVar("FOSSA_STAGING_DIR")