Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Writes build information to target filesystem on /etc/build |
| 3 | # |
| 4 | # Copyright (C) 2014 Intel Corporation |
| 5 | # Author: Alejandro Enedino Hernandez Samaniego <alejandro.hernandez@intel.com> |
| 6 | # |
| 7 | # Licensed under the MIT license, see COPYING.MIT for details |
| 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 | |
| 15 | # From buildhistory.bbclass |
| 16 | def image_buildinfo_outputvars(vars, listvars, d): |
| 17 | vars = vars.split() |
| 18 | listvars = listvars.split() |
| 19 | ret = "" |
| 20 | for var in vars: |
| 21 | value = d.getVar(var, True) or "" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 22 | if (d.getVarFlag(var, 'type', True) == "list"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | value = oe.utils.squashspaces(value) |
| 24 | ret += "%s = %s\n" % (var, value) |
| 25 | return ret.rstrip('\n') |
| 26 | |
| 27 | # Gets git branch's status (clean or dirty) |
| 28 | def get_layer_git_status(path): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 29 | import subprocess |
| 30 | try: |
| 31 | subprocess.check_output("cd %s; PSEUDO_UNLOAD=1 git diff --quiet --no-ext-diff" % path, |
| 32 | shell=True, |
| 33 | stderr=subprocess.STDOUT) |
| 34 | return "" |
| 35 | except subprocess.CalledProcessError, ex: |
| 36 | # Silently treat errors as "modified", without checking for the |
| 37 | # (expected) return code 1 in a modified git repo. For example, we get |
| 38 | # output and a 129 return code when a layer isn't a git repo at all. |
| 39 | return "-- modified" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | |
| 41 | # Returns layer revisions along with their respective status |
| 42 | def get_layer_revs(d): |
| 43 | layers = (d.getVar("BBLAYERS", True) or "").split() |
| 44 | medadata_revs = ["%-17s = %s:%s %s" % (os.path.basename(i), \ |
| 45 | base_get_metadata_git_branch(i, None).strip(), \ |
| 46 | base_get_metadata_git_revision(i, None), \ |
| 47 | get_layer_git_status(i)) \ |
| 48 | for i in layers] |
| 49 | return '\n'.join(medadata_revs) |
| 50 | |
| 51 | def buildinfo_target(d): |
| 52 | # Get context |
| 53 | if d.getVar('BB_WORKERCONTEXT', True) != '1': |
| 54 | return "" |
| 55 | # Single and list variables to be read |
| 56 | vars = (d.getVar("IMAGE_BUILDINFO_VARS", True) or "") |
| 57 | listvars = (d.getVar("IMAGE_BUILDINFO_LVARS", True) or "") |
| 58 | return image_buildinfo_outputvars(vars, listvars, d) |
| 59 | |
| 60 | # Write build information to target filesystem |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 61 | python buildinfo () { |
| 62 | with open(d.expand('${IMAGE_ROOTFS}${sysconfdir}/build'), 'w') as build: |
| 63 | build.writelines(( |
| 64 | '''----------------------- |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 65 | Build Configuration: | |
| 66 | ----------------------- |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 67 | ''', |
| 68 | buildinfo_target(d), |
| 69 | ''' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | ----------------------- |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 71 | Layer Revisions: | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 72 | ----------------------- |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 73 | ''', |
| 74 | get_layer_revs(d) |
| 75 | )) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | IMAGE_PREPROCESS_COMMAND += "buildinfo;" |