blob: b83ce650ad45c6a0ea49180994ee6572374fb08d [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
Andrew Geissler78b72792022-06-14 06:47:25 -05002# Writes build information to target filesystem on /etc/buildinfo
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003#
4# Copyright (C) 2014 Intel Corporation
5# Author: Alejandro Enedino Hernandez Samaniego <alejandro.hernandez@intel.com>
6#
Patrick Williams92b42cb2022-09-03 06:53:57 -05007# SPDX-License-Identifier: MIT
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008#
9# Usage: add INHERIT += "image-buildinfo" to your conf file
10#
11
12# Desired variables to display
13IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION"
14
Brad Bishop6e60e8b2018-02-01 10:27:11 -050015# Desired location of the output file in the image.
Andrew Geissler78b72792022-06-14 06:47:25 -050016IMAGE_BUILDINFO_FILE ??= "${sysconfdir}/buildinfo"
17SDK_BUILDINFO_FILE ??= "/buildinfo"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050018
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019# From buildhistory.bbclass
Brad Bishop19323692019-04-05 15:28:33 -040020def image_buildinfo_outputvars(vars, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021 vars = vars.split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022 ret = ""
23 for var in vars:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024 value = d.getVar(var) or ""
25 if (d.getVarFlag(var, 'type') == "list"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026 value = oe.utils.squashspaces(value)
27 ret += "%s = %s\n" % (var, value)
28 return ret.rstrip('\n')
29
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030# Returns layer revisions along with their respective status
31def get_layer_revs(d):
Andrew Geissler78b72792022-06-14 06:47:25 -050032 revisions = oe.buildcfg.get_layer_revisions(d)
33 medadata_revs = ["%-17s = %s:%s%s" % (r[1], r[2], r[3], r[4]) for r in revisions]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034 return '\n'.join(medadata_revs)
35
36def buildinfo_target(d):
37 # Get context
Brad Bishop6e60e8b2018-02-01 10:27:11 -050038 if d.getVar('BB_WORKERCONTEXT') != '1':
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039 return ""
40 # Single and list variables to be read
Brad Bishop6e60e8b2018-02-01 10:27:11 -050041 vars = (d.getVar("IMAGE_BUILDINFO_VARS") or "")
Brad Bishop19323692019-04-05 15:28:33 -040042 return image_buildinfo_outputvars(vars, d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043
Andrew Geissler78b72792022-06-14 06:47:25 -050044python buildinfo() {
Brad Bishopf86d0552018-12-04 14:18:15 -080045 if not d.getVar('IMAGE_BUILDINFO_FILE'):
46 return
Andrew Geissler78b72792022-06-14 06:47:25 -050047 destfile = d.expand('${BUILDINFODEST}${IMAGE_BUILDINFO_FILE}')
48 bb.utils.mkdirhier(os.path.dirname(destfile))
49 with open(destfile, 'w') as build:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050050 build.writelines((
51 '''-----------------------
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052Build Configuration: |
53-----------------------
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050054''',
55 buildinfo_target(d),
56 '''
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057-----------------------
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050058Layer Revisions: |
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059-----------------------
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050060''',
Patrick Williamsc0f7c042017-02-23 20:41:17 -060061 get_layer_revs(d),
62 '''
63'''
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050064 ))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065}
66
Andrew Geissler78b72792022-06-14 06:47:25 -050067# Write build information to target filesystem
68python buildinfo_image () {
69 d.setVar("BUILDINFODEST", "${IMAGE_ROOTFS}")
70 bb.build.exec_func("buildinfo", d)
71}
72
73python buildinfo_sdk () {
74 d.setVar("BUILDINFODEST", "${SDK_OUTPUT}/${SDKPATH}")
75 d.setVar("IMAGE_BUILDINFO_FILE", d.getVar("SDK_BUILDINFO_FILE"))
76 bb.build.exec_func("buildinfo", d)
77}
78
Andrew Geissler5082cc72023-09-11 08:41:39 -040079IMAGE_PREPROCESS_COMMAND += "buildinfo_image"
80POPULATE_SDK_PRE_TARGET_COMMAND += "buildinfo_sdk"
Andrew Geissler78b72792022-06-14 06:47:25 -050081