Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 2 | # Writes build information to target filesystem on /etc/buildinfo |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3 | # |
| 4 | # Copyright (C) 2014 Intel Corporation |
| 5 | # Author: Alejandro Enedino Hernandez Samaniego <alejandro.hernandez@intel.com> |
| 6 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 7 | # SPDX-License-Identifier: MIT |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8 | # |
| 9 | # Usage: add INHERIT += "image-buildinfo" to your conf file |
| 10 | # |
| 11 | |
| 12 | # Desired variables to display |
| 13 | IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION" |
| 14 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 15 | # Desired location of the output file in the image. |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 16 | IMAGE_BUILDINFO_FILE ??= "${sysconfdir}/buildinfo" |
| 17 | SDK_BUILDINFO_FILE ??= "/buildinfo" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 18 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 19 | # From buildhistory.bbclass |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 20 | def image_buildinfo_outputvars(vars, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 21 | vars = vars.split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 22 | ret = "" |
| 23 | for var in vars: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 24 | value = d.getVar(var) or "" |
| 25 | if (d.getVarFlag(var, 'type') == "list"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | value = oe.utils.squashspaces(value) |
| 27 | ret += "%s = %s\n" % (var, value) |
| 28 | return ret.rstrip('\n') |
| 29 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | # Returns layer revisions along with their respective status |
| 31 | def get_layer_revs(d): |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 32 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 34 | return '\n'.join(medadata_revs) |
| 35 | |
| 36 | def buildinfo_target(d): |
| 37 | # Get context |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 38 | if d.getVar('BB_WORKERCONTEXT') != '1': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | return "" |
| 40 | # Single and list variables to be read |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 41 | vars = (d.getVar("IMAGE_BUILDINFO_VARS") or "") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 42 | return image_buildinfo_outputvars(vars, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 43 | |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 44 | python buildinfo() { |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 45 | if not d.getVar('IMAGE_BUILDINFO_FILE'): |
| 46 | return |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 47 | destfile = d.expand('${BUILDINFODEST}${IMAGE_BUILDINFO_FILE}') |
| 48 | bb.utils.mkdirhier(os.path.dirname(destfile)) |
| 49 | with open(destfile, 'w') as build: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 50 | build.writelines(( |
| 51 | '''----------------------- |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 52 | Build Configuration: | |
| 53 | ----------------------- |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 54 | ''', |
| 55 | buildinfo_target(d), |
| 56 | ''' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | ----------------------- |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 58 | Layer Revisions: | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | ----------------------- |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 60 | ''', |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 61 | get_layer_revs(d), |
| 62 | ''' |
| 63 | ''' |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 64 | )) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 65 | } |
| 66 | |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 67 | # Write build information to target filesystem |
| 68 | python buildinfo_image () { |
| 69 | d.setVar("BUILDINFODEST", "${IMAGE_ROOTFS}") |
| 70 | bb.build.exec_func("buildinfo", d) |
| 71 | } |
| 72 | |
| 73 | python 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 Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame^] | 79 | IMAGE_PREPROCESS_COMMAND += "buildinfo_image" |
| 80 | POPULATE_SDK_PRE_TARGET_COMMAND += "buildinfo_sdk" |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 81 | |