diff options
Diffstat (limited to 'meta/classes/image-buildinfo.bbclass')
-rw-r--r-- | meta/classes/image-buildinfo.bbclass | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/meta/classes/image-buildinfo.bbclass b/meta/classes/image-buildinfo.bbclass index 94c585d4cd..b83ce650ad 100644 --- a/meta/classes/image-buildinfo.bbclass +++ b/meta/classes/image-buildinfo.bbclass | |||
@@ -1,10 +1,10 @@ | |||
1 | # | 1 | # |
2 | # Writes build information to target filesystem on /etc/build | 2 | # Writes build information to target filesystem on /etc/buildinfo |
3 | # | 3 | # |
4 | # Copyright (C) 2014 Intel Corporation | 4 | # Copyright (C) 2014 Intel Corporation |
5 | # Author: Alejandro Enedino Hernandez Samaniego <alejandro.hernandez@intel.com> | 5 | # Author: Alejandro Enedino Hernandez Samaniego <alejandro.hernandez@intel.com> |
6 | # | 6 | # |
7 | # Licensed under the MIT license, see COPYING.MIT for details | 7 | # SPDX-License-Identifier: MIT |
8 | # | 8 | # |
9 | # Usage: add INHERIT += "image-buildinfo" to your conf file | 9 | # Usage: add INHERIT += "image-buildinfo" to your conf file |
10 | # | 10 | # |
@@ -13,7 +13,8 @@ | |||
13 | IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION" | 13 | IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION" |
14 | 14 | ||
15 | # Desired location of the output file in the image. | 15 | # Desired location of the output file in the image. |
16 | IMAGE_BUILDINFO_FILE ??= "${sysconfdir}/build" | 16 | IMAGE_BUILDINFO_FILE ??= "${sysconfdir}/buildinfo" |
17 | SDK_BUILDINFO_FILE ??= "/buildinfo" | ||
17 | 18 | ||
18 | # From buildhistory.bbclass | 19 | # From buildhistory.bbclass |
19 | def image_buildinfo_outputvars(vars, d): | 20 | def image_buildinfo_outputvars(vars, d): |
@@ -26,30 +27,10 @@ def image_buildinfo_outputvars(vars, d): | |||
26 | ret += "%s = %s\n" % (var, value) | 27 | ret += "%s = %s\n" % (var, value) |
27 | return ret.rstrip('\n') | 28 | return ret.rstrip('\n') |
28 | 29 | ||
29 | # Gets git branch's status (clean or dirty) | ||
30 | def get_layer_git_status(path): | ||
31 | import subprocess | ||
32 | try: | ||
33 | subprocess.check_output("""cd %s; export PSEUDO_UNLOAD=1; set -e; | ||
34 | git diff --quiet --no-ext-diff | ||
35 | git diff --quiet --no-ext-diff --cached""" % path, | ||
36 | shell=True, | ||
37 | stderr=subprocess.STDOUT) | ||
38 | return "" | ||
39 | except subprocess.CalledProcessError as ex: | ||
40 | # Silently treat errors as "modified", without checking for the | ||
41 | # (expected) return code 1 in a modified git repo. For example, we get | ||
42 | # output and a 129 return code when a layer isn't a git repo at all. | ||
43 | return "-- modified" | ||
44 | |||
45 | # Returns layer revisions along with their respective status | 30 | # Returns layer revisions along with their respective status |
46 | def get_layer_revs(d): | 31 | def get_layer_revs(d): |
47 | layers = (d.getVar("BBLAYERS") or "").split() | 32 | revisions = oe.buildcfg.get_layer_revisions(d) |
48 | medadata_revs = ["%-17s = %s:%s %s" % (os.path.basename(i), \ | 33 | medadata_revs = ["%-17s = %s:%s%s" % (r[1], r[2], r[3], r[4]) for r in revisions] |
49 | base_get_metadata_git_branch(i, None).strip(), \ | ||
50 | base_get_metadata_git_revision(i, None), \ | ||
51 | get_layer_git_status(i)) \ | ||
52 | for i in layers] | ||
53 | return '\n'.join(medadata_revs) | 34 | return '\n'.join(medadata_revs) |
54 | 35 | ||
55 | def buildinfo_target(d): | 36 | def buildinfo_target(d): |
@@ -60,11 +41,12 @@ def buildinfo_target(d): | |||
60 | vars = (d.getVar("IMAGE_BUILDINFO_VARS") or "") | 41 | vars = (d.getVar("IMAGE_BUILDINFO_VARS") or "") |
61 | return image_buildinfo_outputvars(vars, d) | 42 | return image_buildinfo_outputvars(vars, d) |
62 | 43 | ||
63 | # Write build information to target filesystem | 44 | python buildinfo() { |
64 | python buildinfo () { | ||
65 | if not d.getVar('IMAGE_BUILDINFO_FILE'): | 45 | if not d.getVar('IMAGE_BUILDINFO_FILE'): |
66 | return | 46 | return |
67 | with open(d.expand('${IMAGE_ROOTFS}${IMAGE_BUILDINFO_FILE}'), 'w') as build: | 47 | destfile = d.expand('${BUILDINFODEST}${IMAGE_BUILDINFO_FILE}') |
48 | bb.utils.mkdirhier(os.path.dirname(destfile)) | ||
49 | with open(destfile, 'w') as build: | ||
68 | build.writelines(( | 50 | build.writelines(( |
69 | '''----------------------- | 51 | '''----------------------- |
70 | Build Configuration: | | 52 | Build Configuration: | |
@@ -82,4 +64,18 @@ Layer Revisions: | | |||
82 | )) | 64 | )) |
83 | } | 65 | } |
84 | 66 | ||
85 | IMAGE_PREPROCESS_COMMAND += "buildinfo;" | 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 | |||
79 | IMAGE_PREPROCESS_COMMAND += "buildinfo_image" | ||
80 | POPULATE_SDK_PRE_TARGET_COMMAND += "buildinfo_sdk" | ||
81 | |||