Skip to contentSkip to conversation

image-buildinfo.bbclass: New class, writes

PATCH Superseded Alejandro Hernandez 2 participants 3 messages Nov 4, 2014 – Nov 5, 2014

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 image-buildinfo.bbclass: New class, writes

build information to target filesystem on /etc/build

such as enabled layers, their current status and commit.

[YOCTO #6770]

---
 meta/classes/image-buildinfo.bbclass | 76 ++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 meta/classes/image-buildinfo.bbclass
meta/classes/image-buildinfo.bbclass new file +76 -0
new file mode 100644
index 0000000..d695d24
@@ -0,0 +1,76 @@
+#
+# Writes build information to target filesystem on /etc/build
+#
+# Copyright (C) 2014 Intel Corporation
+# Author: Alejandro Enedino Hernandez Samaniego <[email protected]>
+#
+# Licensed under the MIT license, see COPYING.MIT for details
+#
+# Usage: add INHERIT += "image-buildinfo" to your conf file
+#
+# Desired variables to display 
+# * If it is a list if values it must be present in both (e.g. IMAGE_FEATURES)
+
+IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION IMAGE_FEATURES IMAGE_INSTALL"
+IMAGE_BUILDINFO_LVARS ?= "IMAGE_FEATURES IMAGE_INSTALL"
+
+# From buildhistory.bbclass
+def squashspaces(string):
+    import re
+    return re.sub("\s+", " ", string).strip()
+
+# From buildhistory.bbclass
+def outputvars(vars, listvars, d): 
+    vars = vars.split()
+    listvars = listvars.split()
+    ret = ""
+    for var in vars:
+        value = d.getVar(var, True) or ""
+        if var in listvars:
+            value = squashspaces(value)
+        ret += "%s = %s\n" % (var, value)
+    return ret.rstrip('\n')
+
+# Gets git branch's status (clean or dirty)
+def get_layer_git_status(path):
+    f = os.popen("cd %s; git diff --stat 2>&1 | tail -n 1" % path)
+    data = f.read()
+    if f.close() is None:
+        if len(data) != 0:
+            return "-- modified"
+    return ""
+
+# Returns layer revisions along with their respective status
+def get_layer_revs(d):
+    layers = (d.getVar("BBLAYERS", True) or "").split()
+    medadata_revs = ["%-17s = %s:%s %s" % (os.path.basename(i), \
+        base_get_metadata_git_branch(i, None).strip(), \
+        base_get_metadata_git_revision(i, None), \
+        get_layer_git_status(i)) \
+            for i in layers]
+    return '\n'.join(medadata_revs)
+
+def buildinfo_target(d):
+        # Get context
+        if d.getVar('BB_WORKERCONTEXT', True) != '1':
+                return ""
+        # Single and list variables to be read
+        vars = (d.getVar("IMAGE_BUILDINFO_VARS", True) or "")
+        listvars = (d.getVar("IMAGE_BUILDINFO_LVARS", True) or "")
+        return outputvars(vars, listvars, d)
+
+# Write build information to target filesystem
+buildinfo () {
+cat > ${IMAGE_ROOTFS}${sysconfdir}/build << END
+-----------------------
+Build Configuration:  |
+-----------------------
+${@buildinfo_target(d)}
+-----------------------
+Layer Revisions:      |   
+-----------------------
+${@get_layer_revs(d)}
+END
+}
+
+IMAGE_PREPROCESS_COMMAND += "buildinfo;"
Signature · 1 line
1.9.1
#1 lore raw

Hi Alejandro,

We're getting there, thanks for your patience - just a few more tweaks:

Quoted 1 line · On Tuesday 04 November 2014 12:09:13 Alejandro Hernandez wrote:

build information to target filesystem on /etc/build

Looks like the shortlog has been split over two lines here...

Quoted 29 lines

such as enabled layers, their current status and commit.

[YOCTO #6770]

---
 meta/classes/image-buildinfo.bbclass | 76
++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+)
 create mode 100644 meta/classes/image-buildinfo.bbclass
(quoted diff) +0 -0

b/meta/classes/image-buildinfo.bbclass new file mode 100644 index 0000000..d695d24

meta/classes/image-buildinfo.bbclass new file +5 -0
@@ -0,0 +1,76 @@
+#
+# Writes build information to target filesystem on /etc/build
+#
+# Copyright (C) 2014 Intel Corporation
+# Author: Alejandro Enedino Hernandez Samaniego

<[email protected]> +#

meta/classes/image-buildinfo.bbclass new file +6 -0
+# Licensed under the MIT license, see COPYING.MIT for details
+#
+# Usage: add INHERIT += "image-buildinfo" to your conf file
+#
+# Desired variables to display
+# * If it is a list if values it must be present in both (e.g.

IMAGE_FEATURES) +

meta/classes/image-buildinfo.bbclass

Quoted 2 lines
meta/classes/image-buildinfo.bbclass new file +2 -0
+IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION IMAGE_FEATURES
+IMAGE_INSTALL" 

I'm not sure we really want IMAGE_FEATURES and IMAGE_INSTALL in the default value; it seems to me at the moment the main usage for this is to help determine the version of the build system & metadata that was used.

Quoted 1 line

+IMAGE_BUILDINFO_LVARS ?= "IMAGE_FEATURES IMAGE_INSTALL"

I didn't think to use it when I wrote the original implementation, but it turns out that at least for both of these two variables, they have a set type i.e. from meta/classes/image.bbclass:

IMAGE_INSTALL[type] = "list"

So we could use d.getVarFlag(varname, 'type') to determine the type and then we can avoid having to explicitly list them - could you please make this change for this version of the function? (Let's leave fixing the buildhistory version as a separate exercise for now.)

meta/classes/image-buildinfo.bbclass line 20

Quoted 4 lines
meta/classes/image-buildinfo.bbclass new file +4 -0
+# From buildhistory.bbclass
+def squashspaces(string):
+    import re
+    return re.sub("\s+", " ", string).strip()

To be honest I had thought squashspaces() would still be moved to oe.utils since this function is generic.

meta/classes/image-buildinfo.bbclass line 32

Quoted 11 lines
meta/classes/image-buildinfo.bbclass new file +11 -0
+# From buildhistory.bbclass
+def outputvars(vars, listvars, d):
+    vars = vars.split()
+    listvars = listvars.split()
+    ret = ""
+    for var in vars:
+        value = d.getVar(var, True) or ""
+        if var in listvars:
+            value = squashspaces(value)
+        ret += "%s = %s\n" % (var, value)
+    return ret.rstrip('\n')

I've just realised, if we're inheriting both this class and buildhistory globally and these have the same name, that might be a problem. Can we rename this version to something lime image_buildinfo_outputvars?

Thanks,
Paul

Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre
#2 lore raw

Ok, Paul , Imy main reason to list those two was to put an example of "list" variables, but with that fix you mention, it won't be needed anymore, I agree and I'll rename outputvars and I will move squashspaces to oe.utils.

Quoted 80 lines · Paul Eggleton

Hi Alejandro,

We're getting there, thanks for your patience - just a few more tweaks:

Quoted 1 line · On Tuesday 04 November 2014 12:09:13 Alejandro Hernandez wrote:

build information to target filesystem on /etc/build

Looks like the shortlog has been split over two lines here...

Quoted 29 lines

such as enabled layers, their current status and commit.

[YOCTO #6770]

---
  meta/classes/image-buildinfo.bbclass | 76

++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+)
create mode 100644 meta/classes/image-buildinfo.bbclass

(quoted diff) +0 -0

b/meta/classes/image-buildinfo.bbclass new file mode 100644 index 0000000..d695d24

meta/classes/image-buildinfo.bbclass new file +5 -0
@@ -0,0 +1,76 @@
+#
+# Writes build information to target filesystem on /etc/build
+#
+# Copyright (C) 2014 Intel Corporation
+# Author: Alejandro Enedino Hernandez Samaniego

<[email protected]> +#

meta/classes/image-buildinfo.bbclass new file +6 -0
+# Licensed under the MIT license, see COPYING.MIT for details
+#
+# Usage: add INHERIT += "image-buildinfo" to your conf file
+#
+# Desired variables to display
+# * If it is a list if values it must be present in both (e.g.

IMAGE_FEATURES) +

meta/classes/image-buildinfo.bbclass

Quoted 2 lines
meta/classes/image-buildinfo.bbclass new file +2 -0
+IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION IMAGE_FEATURES
+IMAGE_INSTALL"

I'm not sure we really want IMAGE_FEATURES and IMAGE_INSTALL in the default value; it seems to me at the moment the main usage for this is to help determine the version of the build system & metadata that was used.

Quoted 1 line

+IMAGE_BUILDINFO_LVARS ?= "IMAGE_FEATURES IMAGE_INSTALL"

I didn't think to use it when I wrote the original implementation, but it turns out that at least for both of these two variables, they have a set type i.e. from meta/classes/image.bbclass:

IMAGE_INSTALL[type] = "list"

So we could use d.getVarFlag(varname, 'type') to determine the type and then we can avoid having to explicitly list them - could you please make this change for this version of the function? (Let's leave fixing the buildhistory version as a separate exercise for now.)

meta/classes/image-buildinfo.bbclass line 20

Quoted 4 lines
meta/classes/image-buildinfo.bbclass new file +4 -0
+# From buildhistory.bbclass
+def squashspaces(string):
+    import re
+    return re.sub("\s+", " ", string).strip()

To be honest I had thought squashspaces() would still be moved to oe.utils since this function is generic.

meta/classes/image-buildinfo.bbclass line 32

Quoted 11 lines
meta/classes/image-buildinfo.bbclass new file +11 -0
+# From buildhistory.bbclass
+def outputvars(vars, listvars, d):
+    vars = vars.split()
+    listvars = listvars.split()
+    ret = ""
+    for var in vars:
+        value = d.getVar(var, True) or ""
+        if var in listvars:
+            value = squashspaces(value)
+        ret += "%s = %s\n" % (var, value)
+    return ret.rstrip('\n')

I've just realised, if we're inheriting both this class and buildhistory globally and these have the same name, that might be a problem. Can we rename this version to something lime image_buildinfo_outputvars?

Thanks,
Paul