diff options
Diffstat (limited to 'meta/classes')
-rw-r--r-- | meta/classes/buildhistory.bbclass | 74 | ||||
-rw-r--r-- | meta/classes/create-spdx-2.2.bbclass | 17 | ||||
-rw-r--r-- | meta/classes/devtool-source.bbclass | 4 | ||||
-rw-r--r-- | meta/classes/spdx-common.bbclass | 3 |
4 files changed, 25 insertions, 73 deletions
diff --git a/meta/classes/buildhistory.bbclass b/meta/classes/buildhistory.bbclass index e970182620..4a380c10c6 100644 --- a/meta/classes/buildhistory.bbclass +++ b/meta/classes/buildhistory.bbclass | |||
@@ -16,28 +16,6 @@ BUILDHISTORY_DIR ?= "${TOPDIR}/buildhistory" | |||
16 | BUILDHISTORY_DIR_IMAGE = "${BUILDHISTORY_DIR}/images/${MACHINE_ARCH}/${TCLIBC}/${IMAGE_BASENAME}" | 16 | BUILDHISTORY_DIR_IMAGE = "${BUILDHISTORY_DIR}/images/${MACHINE_ARCH}/${TCLIBC}/${IMAGE_BASENAME}" |
17 | BUILDHISTORY_DIR_PACKAGE = "${BUILDHISTORY_DIR}/packages/${MULTIMACH_TARGET_SYS}/${PN}" | 17 | BUILDHISTORY_DIR_PACKAGE = "${BUILDHISTORY_DIR}/packages/${MULTIMACH_TARGET_SYS}/${PN}" |
18 | 18 | ||
19 | # Setting this to non-empty will remove the old content of the buildhistory as part of | ||
20 | # the current bitbake invocation and replace it with information about what was built | ||
21 | # during the build. | ||
22 | # | ||
23 | # This is meant to be used in continuous integration (CI) systems when invoking bitbake | ||
24 | # for full world builds. The effect in that case is that information about packages | ||
25 | # that no longer get build also gets removed from the buildhistory, which is not | ||
26 | # the case otherwise. | ||
27 | # | ||
28 | # The advantage over manually cleaning the buildhistory outside of bitbake is that | ||
29 | # the "version-going-backwards" check still works. When relying on that, be careful | ||
30 | # about failed world builds: they will lead to incomplete information in the | ||
31 | # buildhistory because information about packages that could not be built will | ||
32 | # also get removed. A CI system should handle that by discarding the buildhistory | ||
33 | # of failed builds. | ||
34 | # | ||
35 | # The expected usage is via auto.conf, but passing via the command line also works | ||
36 | # with: BB_ENV_PASSTHROUGH_ADDITIONS=BUILDHISTORY_RESET BUILDHISTORY_RESET=1 | ||
37 | BUILDHISTORY_RESET ?= "" | ||
38 | |||
39 | BUILDHISTORY_OLD_DIR = "${BUILDHISTORY_DIR}/${@ "old" if "${BUILDHISTORY_RESET}" else ""}" | ||
40 | BUILDHISTORY_OLD_DIR_PACKAGE = "${BUILDHISTORY_OLD_DIR}/packages/${MULTIMACH_TARGET_SYS}/${PN}" | ||
41 | BUILDHISTORY_DIR_SDK = "${BUILDHISTORY_DIR}/sdk/${SDK_NAME}${SDK_EXT}/${IMAGE_BASENAME}" | 19 | BUILDHISTORY_DIR_SDK = "${BUILDHISTORY_DIR}/sdk/${SDK_NAME}${SDK_EXT}/${IMAGE_BASENAME}" |
42 | BUILDHISTORY_IMAGE_FILES ?= "/etc/passwd /etc/group" | 20 | BUILDHISTORY_IMAGE_FILES ?= "/etc/passwd /etc/group" |
43 | BUILDHISTORY_SDK_FILES ?= "conf/local.conf conf/bblayers.conf conf/auto.conf conf/locked-sigs.inc conf/devtool.conf" | 21 | BUILDHISTORY_SDK_FILES ?= "conf/local.conf conf/bblayers.conf conf/auto.conf conf/locked-sigs.inc conf/devtool.conf" |
@@ -70,9 +48,10 @@ SSTATEPOSTUNPACKFUNCS[vardepvalueexclude] .= "| buildhistory_emit_outputsigs" | |||
70 | # necessary because some of these items (package directories, files that | 48 | # necessary because some of these items (package directories, files that |
71 | # we no longer emit) might be obsolete. | 49 | # we no longer emit) might be obsolete. |
72 | # | 50 | # |
73 | # When extending build history, derive your class from buildhistory.bbclass | 51 | # The files listed here are either written by tasks that aren't do_package (e.g. |
74 | # and extend this list here with the additional files created by the derived | 52 | # latest_srcrev from do_fetch) so do_package must not remove them, or, they're |
75 | # class. | 53 | # used to read values in do_package before always being overwritten, e.g. latest, |
54 | # for version backwards checks. | ||
76 | BUILDHISTORY_PRESERVE = "latest latest_srcrev sysroot" | 55 | BUILDHISTORY_PRESERVE = "latest latest_srcrev sysroot" |
77 | 56 | ||
78 | PATCH_GIT_USER_EMAIL ?= "buildhistory@oe" | 57 | PATCH_GIT_USER_EMAIL ?= "buildhistory@oe" |
@@ -108,7 +87,6 @@ python buildhistory_emit_pkghistory() { | |||
108 | return 0 | 87 | return 0 |
109 | 88 | ||
110 | pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE') | 89 | pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE') |
111 | oldpkghistdir = d.getVar('BUILDHISTORY_OLD_DIR_PACKAGE') | ||
112 | 90 | ||
113 | class RecipeInfo: | 91 | class RecipeInfo: |
114 | def __init__(self, name): | 92 | def __init__(self, name): |
@@ -203,7 +181,7 @@ python buildhistory_emit_pkghistory() { | |||
203 | 181 | ||
204 | def getlastpkgversion(pkg): | 182 | def getlastpkgversion(pkg): |
205 | try: | 183 | try: |
206 | histfile = os.path.join(oldpkghistdir, pkg, "latest") | 184 | histfile = os.path.join(pkghistdir, pkg, "latest") |
207 | return readPackageInfo(pkg, histfile) | 185 | return readPackageInfo(pkg, histfile) |
208 | except EnvironmentError: | 186 | except EnvironmentError: |
209 | return None | 187 | return None |
@@ -219,20 +197,6 @@ python buildhistory_emit_pkghistory() { | |||
219 | items.sort() | 197 | items.sort() |
220 | return ' '.join(items) | 198 | return ' '.join(items) |
221 | 199 | ||
222 | def preservebuildhistoryfiles(pkg, preserve): | ||
223 | if os.path.exists(os.path.join(oldpkghistdir, pkg)): | ||
224 | listofobjs = os.listdir(os.path.join(oldpkghistdir, pkg)) | ||
225 | for obj in listofobjs: | ||
226 | if obj not in preserve: | ||
227 | continue | ||
228 | try: | ||
229 | bb.utils.mkdirhier(os.path.join(pkghistdir, pkg)) | ||
230 | shutil.copyfile(os.path.join(oldpkghistdir, pkg, obj), os.path.join(pkghistdir, pkg, obj)) | ||
231 | except IOError as e: | ||
232 | bb.note("Unable to copy file. %s" % e) | ||
233 | except EnvironmentError as e: | ||
234 | bb.note("Unable to copy file. %s" % e) | ||
235 | |||
236 | pn = d.getVar('PN') | 200 | pn = d.getVar('PN') |
237 | pe = d.getVar('PE') or "0" | 201 | pe = d.getVar('PE') or "0" |
238 | pv = d.getVar('PV') | 202 | pv = d.getVar('PV') |
@@ -260,14 +224,6 @@ python buildhistory_emit_pkghistory() { | |||
260 | if not os.path.exists(pkghistdir): | 224 | if not os.path.exists(pkghistdir): |
261 | bb.utils.mkdirhier(pkghistdir) | 225 | bb.utils.mkdirhier(pkghistdir) |
262 | else: | 226 | else: |
263 | # We need to make sure that all files kept in | ||
264 | # buildhistory/old are restored successfully | ||
265 | # otherwise next block of code wont have files to | ||
266 | # check and purge | ||
267 | if d.getVar("BUILDHISTORY_RESET"): | ||
268 | for pkg in packagelist: | ||
269 | preservebuildhistoryfiles(pkg, preserve) | ||
270 | |||
271 | # Remove files for packages that no longer exist | 227 | # Remove files for packages that no longer exist |
272 | for item in os.listdir(pkghistdir): | 228 | for item in os.listdir(pkghistdir): |
273 | if item not in preserve: | 229 | if item not in preserve: |
@@ -887,25 +843,7 @@ END | |||
887 | 843 | ||
888 | python buildhistory_eventhandler() { | 844 | python buildhistory_eventhandler() { |
889 | if (e.data.getVar('BUILDHISTORY_FEATURES') or "").strip(): | 845 | if (e.data.getVar('BUILDHISTORY_FEATURES') or "").strip(): |
890 | reset = e.data.getVar("BUILDHISTORY_RESET") | 846 | if isinstance(e, bb.event.BuildCompleted): |
891 | olddir = e.data.getVar("BUILDHISTORY_OLD_DIR") | ||
892 | if isinstance(e, bb.event.BuildStarted): | ||
893 | if reset: | ||
894 | import shutil | ||
895 | # Clean up after potentially interrupted build. | ||
896 | if os.path.isdir(olddir): | ||
897 | shutil.rmtree(olddir) | ||
898 | rootdir = e.data.getVar("BUILDHISTORY_DIR") | ||
899 | bb.utils.mkdirhier(rootdir) | ||
900 | entries = [ x for x in os.listdir(rootdir) if not x.startswith('.') ] | ||
901 | bb.utils.mkdirhier(olddir) | ||
902 | for entry in entries: | ||
903 | bb.utils.rename(os.path.join(rootdir, entry), | ||
904 | os.path.join(olddir, entry)) | ||
905 | elif isinstance(e, bb.event.BuildCompleted): | ||
906 | if reset: | ||
907 | import shutil | ||
908 | shutil.rmtree(olddir) | ||
909 | if e.data.getVar("BUILDHISTORY_COMMIT") == "1": | 847 | if e.data.getVar("BUILDHISTORY_COMMIT") == "1": |
910 | bb.note("Writing buildhistory") | 848 | bb.note("Writing buildhistory") |
911 | bb.build.exec_func("buildhistory_write_sigs", d) | 849 | bb.build.exec_func("buildhistory_write_sigs", d) |
diff --git a/meta/classes/create-spdx-2.2.bbclass b/meta/classes/create-spdx-2.2.bbclass index 7e8f8b9ff5..94e0108815 100644 --- a/meta/classes/create-spdx-2.2.bbclass +++ b/meta/classes/create-spdx-2.2.bbclass | |||
@@ -23,6 +23,8 @@ def get_namespace(d, name): | |||
23 | namespace_uuid = uuid.uuid5(uuid.NAMESPACE_DNS, d.getVar("SPDX_UUID_NAMESPACE")) | 23 | namespace_uuid = uuid.uuid5(uuid.NAMESPACE_DNS, d.getVar("SPDX_UUID_NAMESPACE")) |
24 | return "%s/%s-%s" % (d.getVar("SPDX_NAMESPACE_PREFIX"), name, str(uuid.uuid5(namespace_uuid, name))) | 24 | return "%s/%s-%s" % (d.getVar("SPDX_NAMESPACE_PREFIX"), name, str(uuid.uuid5(namespace_uuid, name))) |
25 | 25 | ||
26 | SPDX_PACKAGE_VERSION ??= "${PV}" | ||
27 | SPDX_PACKAGE_VERSION[doc] = "The version of a package, versionInfo in recipe, package and image" | ||
26 | 28 | ||
27 | def create_annotation(d, comment): | 29 | def create_annotation(d, comment): |
28 | from datetime import datetime, timezone | 30 | from datetime import datetime, timezone |
@@ -137,6 +139,11 @@ def add_package_files(d, doc, spdx_pkg, topdir, get_spdxid, get_types, *, archiv | |||
137 | spdx_files = [] | 139 | spdx_files = [] |
138 | 140 | ||
139 | file_counter = 1 | 141 | file_counter = 1 |
142 | |||
143 | check_compiled_sources = d.getVar("SPDX_INCLUDE_COMPILED_SOURCES") == "1" | ||
144 | if check_compiled_sources: | ||
145 | compiled_sources, types = oe.spdx_common.get_compiled_sources(d) | ||
146 | bb.debug(1, f"Total compiled files: {len(compiled_sources)}") | ||
140 | for subdir, dirs, files in os.walk(topdir): | 147 | for subdir, dirs, files in os.walk(topdir): |
141 | dirs[:] = [d for d in dirs if d not in ignore_dirs] | 148 | dirs[:] = [d for d in dirs if d not in ignore_dirs] |
142 | if subdir == str(topdir): | 149 | if subdir == str(topdir): |
@@ -147,6 +154,10 @@ def add_package_files(d, doc, spdx_pkg, topdir, get_spdxid, get_types, *, archiv | |||
147 | filename = str(filepath.relative_to(topdir)) | 154 | filename = str(filepath.relative_to(topdir)) |
148 | 155 | ||
149 | if not filepath.is_symlink() and filepath.is_file(): | 156 | if not filepath.is_symlink() and filepath.is_file(): |
157 | # Check if file is compiled | ||
158 | if check_compiled_sources: | ||
159 | if not oe.spdx_common.is_compiled_source(filename, compiled_sources, types): | ||
160 | continue | ||
150 | spdx_file = oe.spdx.SPDXFile() | 161 | spdx_file = oe.spdx.SPDXFile() |
151 | spdx_file.SPDXID = get_spdxid(file_counter) | 162 | spdx_file.SPDXID = get_spdxid(file_counter) |
152 | for t in get_types(filepath): | 163 | for t in get_types(filepath): |
@@ -438,7 +449,7 @@ python do_create_spdx() { | |||
438 | 449 | ||
439 | recipe = oe.spdx.SPDXPackage() | 450 | recipe = oe.spdx.SPDXPackage() |
440 | recipe.name = d.getVar("PN") | 451 | recipe.name = d.getVar("PN") |
441 | recipe.versionInfo = d.getVar("PV") | 452 | recipe.versionInfo = d.getVar("SPDX_PACKAGE_VERSION") |
442 | recipe.SPDXID = oe.sbom.get_recipe_spdxid(d) | 453 | recipe.SPDXID = oe.sbom.get_recipe_spdxid(d) |
443 | recipe.supplier = d.getVar("SPDX_SUPPLIER") | 454 | recipe.supplier = d.getVar("SPDX_SUPPLIER") |
444 | if bb.data.inherits_class("native", d) or bb.data.inherits_class("cross", d): | 455 | if bb.data.inherits_class("native", d) or bb.data.inherits_class("cross", d): |
@@ -547,7 +558,7 @@ python do_create_spdx() { | |||
547 | 558 | ||
548 | spdx_package.SPDXID = oe.sbom.get_package_spdxid(pkg_name) | 559 | spdx_package.SPDXID = oe.sbom.get_package_spdxid(pkg_name) |
549 | spdx_package.name = pkg_name | 560 | spdx_package.name = pkg_name |
550 | spdx_package.versionInfo = d.getVar("PV") | 561 | spdx_package.versionInfo = d.getVar("SPDX_PACKAGE_VERSION") |
551 | spdx_package.licenseDeclared = convert_license_to_spdx(package_license, license_data, package_doc, d, found_licenses) | 562 | spdx_package.licenseDeclared = convert_license_to_spdx(package_license, license_data, package_doc, d, found_licenses) |
552 | spdx_package.supplier = d.getVar("SPDX_SUPPLIER") | 563 | spdx_package.supplier = d.getVar("SPDX_SUPPLIER") |
553 | 564 | ||
@@ -823,7 +834,7 @@ def combine_spdx(d, rootfs_name, rootfs_deploydir, rootfs_spdxid, packages, spdx | |||
823 | 834 | ||
824 | image = oe.spdx.SPDXPackage() | 835 | image = oe.spdx.SPDXPackage() |
825 | image.name = d.getVar("PN") | 836 | image.name = d.getVar("PN") |
826 | image.versionInfo = d.getVar("PV") | 837 | image.versionInfo = d.getVar("SPDX_PACKAGE_VERSION") |
827 | image.SPDXID = rootfs_spdxid | 838 | image.SPDXID = rootfs_spdxid |
828 | image.supplier = d.getVar("SPDX_SUPPLIER") | 839 | image.supplier = d.getVar("SPDX_SUPPLIER") |
829 | 840 | ||
diff --git a/meta/classes/devtool-source.bbclass b/meta/classes/devtool-source.bbclass index 9762003ba7..2e0070486b 100644 --- a/meta/classes/devtool-source.bbclass +++ b/meta/classes/devtool-source.bbclass | |||
@@ -92,9 +92,9 @@ python devtool_post_unpack() { | |||
92 | for fname in local_files: | 92 | for fname in local_files: |
93 | f.write('%s\n' % fname) | 93 | f.write('%s\n' % fname) |
94 | 94 | ||
95 | if os.path.dirname(srcsubdir) != workdir: | 95 | if srcsubdir.startswith(unpackdir) and os.path.dirname(srcsubdir) != unpackdir: |
96 | # Handle if S is set to a subdirectory of the source | 96 | # Handle if S is set to a subdirectory of the source |
97 | srcsubdir = os.path.join(workdir, os.path.relpath(srcsubdir, workdir).split(os.sep)[0]) | 97 | srcsubdir = os.path.normpath(os.path.join(unpackdir, os.path.relpath(srcsubdir, unpackdir).split(os.sep)[0])) |
98 | 98 | ||
99 | scriptutils.git_convert_standalone_clone(srcsubdir) | 99 | scriptutils.git_convert_standalone_clone(srcsubdir) |
100 | 100 | ||
diff --git a/meta/classes/spdx-common.bbclass b/meta/classes/spdx-common.bbclass index 713a7fc651..ca0416d1c7 100644 --- a/meta/classes/spdx-common.bbclass +++ b/meta/classes/spdx-common.bbclass | |||
@@ -26,6 +26,7 @@ SPDX_TOOL_VERSION ??= "1.0" | |||
26 | SPDXRUNTIMEDEPLOY = "${SPDXDIR}/runtime-deploy" | 26 | SPDXRUNTIMEDEPLOY = "${SPDXDIR}/runtime-deploy" |
27 | 27 | ||
28 | SPDX_INCLUDE_SOURCES ??= "0" | 28 | SPDX_INCLUDE_SOURCES ??= "0" |
29 | SPDX_INCLUDE_COMPILED_SOURCES ??= "0" | ||
29 | 30 | ||
30 | SPDX_UUID_NAMESPACE ??= "sbom.openembedded.org" | 31 | SPDX_UUID_NAMESPACE ??= "sbom.openembedded.org" |
31 | SPDX_NAMESPACE_PREFIX ??= "http://spdx.org/spdxdocs" | 32 | SPDX_NAMESPACE_PREFIX ??= "http://spdx.org/spdxdocs" |
@@ -40,6 +41,8 @@ SPDX_MULTILIB_SSTATE_ARCHS ??= "${SSTATE_ARCHS}" | |||
40 | python () { | 41 | python () { |
41 | from oe.cve_check import extend_cve_status | 42 | from oe.cve_check import extend_cve_status |
42 | extend_cve_status(d) | 43 | extend_cve_status(d) |
44 | if d.getVar("SPDX_INCLUDE_COMPILED_SOURCES") == "1": | ||
45 | d.setVar("SPDX_INCLUDE_SOURCES", "1") | ||
43 | } | 46 | } |
44 | 47 | ||
45 | def create_spdx_source_deps(d): | 48 | def create_spdx_source_deps(d): |