Skip to content

Commit 754394b

Browse files
author
Ubuntu
committed
fix: python command exec that is compatible with python 3.6 and updates install recipe tasks
1 parent 0713907 commit 754394b

File tree

4 files changed

+99
-9
lines changed

4 files changed

+99
-9
lines changed

classes/fossa.bbclass

+6-3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ python do_fossa_pkg() {
8282
# this way it is able to capture the output of `do_fossa_pkg` for every
8383
# package that was processed.
8484
python do_fossa() {
85+
from oe.rootfs import image_list_installed_packages
86+
8587
if not is_fossa_enabled(d):
8688
bb.debug(1, "Since FOSSA_ENABLED is 0, skipping: creating fossa-deps.json")
8789
return
@@ -93,13 +95,14 @@ python do_fossa() {
9395

9496
metadata_dir = d.getVar('FOSSA_METADATA_RECIPES')
9597
pkg_metadata = all_pkg_metadata(d, metadata_dir)
98+
pkgs = image_list_installed_packages(d)
9699

97100
installed_pkgs = []
98-
for pkg in pkg_metadata:
101+
for pkg in pkgs:
99102
try:
100103
installed_pkgs.append(mk_user_dependencies(pkg_metadata[pkg]))
101-
except Exception as err:
102-
bb.error(f'failed to retrieve pkg metadata for {pkg} because: {err}')
104+
except Exception:
105+
pass
103106

104107
# Ensure path exists
105108
fossa_deps_dir = d.getVar("FOSSA_STAGING_DIR")

classes/fossa_upload.bbclass

+10-6
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ inherit fossa_utils
66
addtask do_fossa_analyze before do_build after do_rootfs
77
do_fossa_analyze[doc] = "Analyze via fossa-cli"
88
do_fossa_analyze[nostamp] = "1"
9-
do_fossa_analyze[depends] = "fossa-cli:do_populate_sysroot"
9+
do_fossa_analyze[depends] = "fossa-cli-native:do_populate_sysroot"
1010

1111
addtask do_fossa_test before do_build after do_fossa_analyze
1212
do_fossa_test[doc] = "Test via fossa-cli"
1313
do_fossa_test[nostamp] = "1"
14-
do_fossa_test[deptask] += "fossa-cli:do_populate_sysroot"
14+
do_fossa_test[deptask] += "fossa-cli-native:do_populate_sysroot"
1515

16-
# This task runs `fossa-cli` against the `fossa-deps` file generated by `fossa:do_fossa`,
16+
# This task runs `fossa-cli-native` against the `fossa-deps` file generated by `fossa:do_fossa`,
1717
# analyzing the file and storing its results in the FOSSA backend.
1818
#
1919
# 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() {
4444
bb.debug(1, "Since FOSSA_TEST_ENABLED is 0, skipping: fossa test")
4545
return
4646

47+
bb.plain("Running fossa test command. It will fail build if FOSSA finds unresolved licensing issues.")
48+
bb.plain("To not fail fatally, fossa test command can be disabled by, setting: FOSSA_TEST_ENABLED to 0.")
4749
run_fossa_cli(d, mk_fossa_cmd(d, 'test'))
4850
}
4951

@@ -54,11 +56,13 @@ def run_fossa_cli(d, cli_args):
5456
BINDIR = d.getVar("bindir")
5557
WORKDIR = d.getVar("WORKDIR")
5658

57-
cli_path = (f"{WORKDIR}/recipe-sysroot{BINDIR}/fossa")
58-
cmds = [cli_path] + cli_args
59+
# We don't need to specify the whole path here. The sysroot-native
60+
# directory is already in our PATH.
61+
fossa_cli = ("fossa")
62+
cmds = [fossa_cli] + cli_args
5963
bb.plain(f"running: {' '.join(cmds)}")
6064

61-
out = subprocess.run(cmds, cwd=d.getVar("FOSSA_STAGING_DIR"), capture_output=True, text=True, shell=False)
65+
out = subprocess.run(cmds, cwd=d.getVar("FOSSA_STAGING_DIR"), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=False)
6266
if out.returncode != 0:
6367
bb.fatal(out.stderr)
6468
else:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
# These special variables control how BitBake builds the project.
3+
#
4+
# Reference: https://docs.yoctoproject.org/bitbake/2.2/bitbake-user-manual/bitbake-user-manual-ref-variables.html
5+
6+
SUMMARY = "Flexible, performant dependency analysis"
7+
HOMEPAGE = "https://fossa.com"
8+
LICENSE = "MPL-2.0"
9+
DEPENDS += "unzip-native"
10+
INHIBIT_DEFAULT_DEPS = "1"
11+
LIC_FILES_CHKSUM = "file://LICENSE;md5=815ca599c9df247a0c7f619bab123dad"
12+
S = "${WORKDIR}/fossa-cli-${PV}"
13+
14+
inherit native
15+
16+
# Every BitBake recipe implicitly inherits `base.bbclass`: https://docs.yoctoproject.org/ref-manual/classes.html#base-bbclass
17+
# This means that in addition to the tasks defined in this file, implicit tasks are defined.
18+
# Refer to `meta/classes/base.bbclass` in Poky for the implementation of these implicit tasks
19+
# and dependencies.
20+
#
21+
# In Dunfell, the following is the implicit task ordering:
22+
# - addtask fetch
23+
# - addtask unpack after do_fetch
24+
# - addtask configure after do_patch
25+
# - addtask compile after do_configure
26+
# - addtask install after do_compile
27+
# - addtask build after do_populate_sysroot
28+
# - addtask cleansstate after do_clean
29+
# - addtask cleanall after do_cleansstate
30+
#
31+
# An observant reader may have noticed that the `fossa` class is inherited in the quickstart,
32+
# but nothing is explicitly added to depend on this `fossa-cli` recipe.
33+
#
34+
# The connection is in the `fossa_upload` class:
35+
#
36+
# ```
37+
# do_fossa_analyze[depends] = "fossa-cli:do_populate_sysroot"
38+
# do_fossa_test[deptask] += "fossa-cli:do_populate_sysroot"
39+
# ```
40+
#
41+
# From the Yocto docs (https://docs.yoctoproject.org/ref-manual/tasks.html#do-populate-sysroot),
42+
# `do_populate_sysroot` depends on the `do_install` task since it populates files from that task
43+
# into the sysroot.
44+
#
45+
# In turn as we can see in the base class, `do_install` depends on `do_configure`,
46+
# which depends on `fetch` which starts things off by pulling the `fossa-cli` bundle
47+
# as part of the configuration step. Note: we delete the do_compile task here as
48+
# there is nothing to compile for this.
49+
#
50+
# While we specify populate_sysroot as the step to perform this, since we are a native
51+
# recipe installing a binary to be run on the build host, the install phase is applied
52+
# to sysroot-native.
53+
54+
# https://docs.yoctoproject.org/ref-manual/tasks.html#do-compile
55+
#
56+
# Implicitly, before this step is run, the `fetch` and `unpack` tasks are run.
57+
# These ensure that the source at `SRC_URI` is present in `${S}`.
58+
#
59+
# This task downloads `fossa-cli` at the specified version to `${D}`.
60+
# The version provided to the install script should match the version specified by `${PV}`.
61+
do_configure() {
62+
chmod a+x ${S}/install-latest.sh
63+
${S}/install-latest.sh -b ${S} -d v${PV}
64+
}
65+
66+
do_compile[noexec] = "1"
67+
68+
# https://docs.yoctoproject.org/ref-manual/tasks.html#do-install
69+
#
70+
# Implicitly, before this step is run the `compile` task is run.
71+
#
72+
# This task installs the downloaded `fossa` binary to the BitBake binary directory
73+
# for invocation.
74+
do_install() {
75+
install -d ${D}${bindir}/
76+
install -m 0755 ${S}/fossa ${D}${bindir}/fossa
77+
}
78+
79+
INSANE_SKIP_${PN} += "already-stripped"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SRC_URI = "https://github.com/fossas/fossa-cli/archive/refs/tags/v${PV}.tar.gz"
2+
SRC_URI[sha256sum] = "31eac60f057b191734f5b4cc9ffedc25f9a2726828ddad99e6392dc10d638e1c"
3+
4+
require fossa-cli-native.inc

0 commit comments

Comments
 (0)