diff options
Diffstat (limited to 'meta/classes/image-buildinfo.bbclass')
-rw-r--r-- | meta/classes/image-buildinfo.bbclass | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/meta/classes/image-buildinfo.bbclass b/meta/classes/image-buildinfo.bbclass new file mode 100644 index 0000000000..aa17cc8f9e --- /dev/null +++ b/meta/classes/image-buildinfo.bbclass | |||
@@ -0,0 +1,69 @@ | |||
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 "" | ||
22 | if (d.getVarFlag(var, 'type') == "list"): | ||
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): | ||
29 | f = os.popen("cd %s; git diff --stat 2>&1 | tail -n 1" % path) | ||
30 | data = f.read() | ||
31 | if f.close() is None: | ||
32 | if len(data) != 0: | ||
33 | return "-- modified" | ||
34 | return "" | ||
35 | |||
36 | # Returns layer revisions along with their respective status | ||
37 | def get_layer_revs(d): | ||
38 | layers = (d.getVar("BBLAYERS", True) or "").split() | ||
39 | medadata_revs = ["%-17s = %s:%s %s" % (os.path.basename(i), \ | ||
40 | base_get_metadata_git_branch(i, None).strip(), \ | ||
41 | base_get_metadata_git_revision(i, None), \ | ||
42 | get_layer_git_status(i)) \ | ||
43 | for i in layers] | ||
44 | return '\n'.join(medadata_revs) | ||
45 | |||
46 | def buildinfo_target(d): | ||
47 | # Get context | ||
48 | if d.getVar('BB_WORKERCONTEXT', True) != '1': | ||
49 | return "" | ||
50 | # Single and list variables to be read | ||
51 | vars = (d.getVar("IMAGE_BUILDINFO_VARS", True) or "") | ||
52 | listvars = (d.getVar("IMAGE_BUILDINFO_LVARS", True) or "") | ||
53 | return image_buildinfo_outputvars(vars, listvars, d) | ||
54 | |||
55 | # Write build information to target filesystem | ||
56 | buildinfo () { | ||
57 | cat > ${IMAGE_ROOTFS}${sysconfdir}/build << END | ||
58 | ----------------------- | ||
59 | Build Configuration: | | ||
60 | ----------------------- | ||
61 | ${@buildinfo_target(d)} | ||
62 | ----------------------- | ||
63 | Layer Revisions: | | ||
64 | ----------------------- | ||
65 | ${@get_layer_revs(d)} | ||
66 | END | ||
67 | } | ||
68 | |||
69 | IMAGE_PREPROCESS_COMMAND += "buildinfo;" | ||