blob: 3003f5d2564d509808d94a7cd5f98d991f4ae7fb [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
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
13IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION"
14
15# From buildhistory.bbclass
16def 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 Williamsd8c66bc2016-06-20 12:57:21 -050022 if (d.getVarFlag(var, 'type', True) == "list"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023 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)
28def get_layer_git_status(path):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050029 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 ""
Patrick Williamsc0f7c042017-02-23 20:41:17 -060035 except subprocess.CalledProcessError as ex:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050036 # 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 Williamsc124f4f2015-09-15 14:41:29 -050040
41# Returns layer revisions along with their respective status
42def 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
51def 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 Williamsd8c66bc2016-06-20 12:57:21 -050061python buildinfo () {
62 with open(d.expand('${IMAGE_ROOTFS}${sysconfdir}/build'), 'w') as build:
63 build.writelines((
64 '''-----------------------
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065Build Configuration: |
66-----------------------
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050067''',
68 buildinfo_target(d),
69 '''
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070-----------------------
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050071Layer Revisions: |
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072-----------------------
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050073''',
Patrick Williamsc0f7c042017-02-23 20:41:17 -060074 get_layer_revs(d),
75 '''
76'''
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050077 ))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078}
79
80IMAGE_PREPROCESS_COMMAND += "buildinfo;"