diff options
Diffstat (limited to 'meta/classes/image-buildinfo.bbclass')
-rw-r--r-- | meta/classes/image-buildinfo.bbclass | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/meta/classes/image-buildinfo.bbclass b/meta/classes/image-buildinfo.bbclass index 83d0db37d8..206cc9d57d 100644 --- a/meta/classes/image-buildinfo.bbclass +++ b/meta/classes/image-buildinfo.bbclass @@ -1,10 +1,10 @@ # -# Writes build information to target filesystem on /etc/build +# Writes build information to target filesystem on /etc/buildinfo # # Copyright (C) 2014 Intel Corporation # Author: Alejandro Enedino Hernandez Samaniego <alejandro.hernandez@intel.com> # -# Licensed under the MIT license, see COPYING.MIT for details +# SPDX-License-Identifier: MIT # # Usage: add INHERIT += "image-buildinfo" to your conf file # @@ -12,54 +12,41 @@ # Desired variables to display IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION" +# Desired location of the output file in the image. +IMAGE_BUILDINFO_FILE ??= "${sysconfdir}/buildinfo" +SDK_BUILDINFO_FILE ??= "/buildinfo" + # From buildhistory.bbclass -def image_buildinfo_outputvars(vars, listvars, d): +def image_buildinfo_outputvars(vars, d): vars = vars.split() - listvars = listvars.split() ret = "" for var in vars: - value = d.getVar(var, True) or "" - if (d.getVarFlag(var, 'type', True) == "list"): + value = d.getVar(var) or "" + if (d.getVarFlag(var, 'type') == "list"): value = oe.utils.squashspaces(value) ret += "%s = %s\n" % (var, value) return ret.rstrip('\n') -# Gets git branch's status (clean or dirty) -def get_layer_git_status(path): - import subprocess - try: - subprocess.check_output("cd %s; PSEUDO_UNLOAD=1 git diff --quiet --no-ext-diff" % path, - shell=True, - stderr=subprocess.STDOUT) - return "" - except subprocess.CalledProcessError as ex: - # Silently treat errors as "modified", without checking for the - # (expected) return code 1 in a modified git repo. For example, we get - # output and a 129 return code when a layer isn't a git repo at all. - return "-- modified" - # Returns layer revisions along with their respective status def get_layer_revs(d): - layers = (d.getVar("BBLAYERS", True) or "").split() - medadata_revs = ["%-17s = %s:%s %s" % (os.path.basename(i), \ - base_get_metadata_git_branch(i, None).strip(), \ - base_get_metadata_git_revision(i, None), \ - get_layer_git_status(i)) \ - for i in layers] + revisions = oe.buildcfg.get_layer_revisions(d) + medadata_revs = ["%-17s = %s:%s%s" % (r[1], r[2], r[3], r[4]) for r in revisions] return '\n'.join(medadata_revs) def buildinfo_target(d): # Get context - if d.getVar('BB_WORKERCONTEXT', True) != '1': + if d.getVar('BB_WORKERCONTEXT') != '1': return "" # Single and list variables to be read - vars = (d.getVar("IMAGE_BUILDINFO_VARS", True) or "") - listvars = (d.getVar("IMAGE_BUILDINFO_LVARS", True) or "") - return image_buildinfo_outputvars(vars, listvars, d) + vars = (d.getVar("IMAGE_BUILDINFO_VARS") or "") + return image_buildinfo_outputvars(vars, d) -# Write build information to target filesystem -python buildinfo () { - with open(d.expand('${IMAGE_ROOTFS}${sysconfdir}/build'), 'w') as build: +python buildinfo() { + if not d.getVar('IMAGE_BUILDINFO_FILE'): + return + destfile = d.expand('${BUILDINFODEST}${IMAGE_BUILDINFO_FILE}') + bb.utils.mkdirhier(os.path.dirname(destfile)) + with open(destfile, 'w') as build: build.writelines(( '''----------------------- Build Configuration: | @@ -71,8 +58,24 @@ Build Configuration: | Layer Revisions: | ----------------------- ''', - get_layer_revs(d) + get_layer_revs(d), + ''' +''' )) } -IMAGE_PREPROCESS_COMMAND += "buildinfo;" +# Write build information to target filesystem +python buildinfo_image () { + d.setVar("BUILDINFODEST", "${IMAGE_ROOTFS}") + bb.build.exec_func("buildinfo", d) +} + +python buildinfo_sdk () { + d.setVar("BUILDINFODEST", "${SDK_OUTPUT}/${SDKPATH}") + d.setVar("IMAGE_BUILDINFO_FILE", d.getVar("SDK_BUILDINFO_FILE")) + bb.build.exec_func("buildinfo", d) +} + +IMAGE_PREPROCESS_COMMAND += "buildinfo_image;" +POPULATE_SDK_PRE_TARGET_COMMAND += "buildinfo_sdk;" + |