diff mbox series

[v2,1/1] classes: Print bitbake branch and revision

Message ID ad2b2df4041f0c721d1a82de0fe759d896c6bfb6.1726059965.git.liezhi.yang@windriver.com
State New
Headers show
Series [v2,1/1] classes: Print bitbake branch and revision | expand

Commit Message

Robert Yang Sept. 11, 2024, 1:10 p.m. UTC
From: Robert Yang <liezhi.yang@windriver.com>

There is no bitbake revision when it is in a separate repo, then we have no way
to know which version of bitbake is used from the log, this patch always prints
it.

* console-latest.log
bitbake              = "master:165368bad152a14b32b5216b938aa4b915d72a70"
meta
meta-poky
meta-yocto-bsp       = "master:165368bad152a14b32b5216b938aa4b915d72a70"

* buildhistory/metadata-revs
bitbake           = master:165368bad152a14b32b5216b938aa4b915d72a70 -- modified
[snip]

* buildhistory/metadata-revs
-----------------------
Build Configuration:  |
-----------------------
DISTRO = poky
DISTRO_VERSION = 5.0+snapshot-165368bad152a14b32b5216b938aa4b915d72a70
-----------------------
Bitbake Revision:      |
-----------------------
bitbake           = master:165368bad152a14b32b5216b938aa4b915d72a70 -- modified
-----------------------
Layer Revisions:      |
-----------------------
[snip]

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 meta/classes-global/base.bbclass     | 10 +++++++---
 meta/classes/buildhistory.bbclass    |  5 +++--
 meta/classes/image-buildinfo.bbclass | 13 +++++++++++--
 meta/lib/oe/buildcfg.py              | 13 +++++++++++++
 4 files changed, 34 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-global/base.bbclass b/meta/classes-global/base.bbclass
index b6940bbb6f..85c7cb8c24 100644
--- a/meta/classes-global/base.bbclass
+++ b/meta/classes-global/base.bbclass
@@ -226,9 +226,13 @@  do_unpack[postfuncs] += "create_source_date_epoch_stamp"
 def get_source_date_epoch_value(d):
     return oe.reproducible.epochfile_read(d.getVar('SDE_FILE'), d)
 
+def get_bitbake_branch_rev(d):
+    revisions = oe.buildcfg.get_bitbake_revision()
+    return oe.buildcfg.get_branch_rev3(revisions)
+
 def get_layers_branch_rev(d):
     revisions = oe.buildcfg.get_layer_revisions(d)
-    layers_branch_rev = ["%-20s = \"%s:%s\"" % (r[1], r[2], r[3]) for r in revisions]
+    layers_branch_rev = oe.buildcfg.get_branch_rev3(revisions)
     i = len(layers_branch_rev)-1
     p1 = layers_branch_rev[i].find("=")
     s1 = layers_branch_rev[i][p1:]
@@ -241,11 +245,11 @@  def get_layers_branch_rev(d):
         else:
             i -= 1
             p1 = layers_branch_rev[i].find("=")
-            s1= layers_branch_rev[i][p1:]
+            s1 = layers_branch_rev[i][p1:]
     return layers_branch_rev
 
 
-BUILDCFG_FUNCS ??= "buildcfg_vars get_layers_branch_rev buildcfg_neededvars"
+BUILDCFG_FUNCS ??= "buildcfg_vars get_bitbake_branch_rev get_layers_branch_rev buildcfg_neededvars"
 BUILDCFG_FUNCS[type] = "list"
 
 def buildcfg_vars(d):
diff --git a/meta/classes/buildhistory.bbclass b/meta/classes/buildhistory.bbclass
index ce3abaa69d..50516e6533 100644
--- a/meta/classes/buildhistory.bbclass
+++ b/meta/classes/buildhistory.bbclass
@@ -764,8 +764,9 @@  def buildhistory_get_build_id(d):
 
 def buildhistory_get_metadata_revs(d):
     # We want an easily machine-readable format here
-    revisions = oe.buildcfg.get_layer_revisions(d)
-    medadata_revs = ["%-17s = %s:%s%s" % (r[1], r[2], r[3], r[4]) for r in revisions]
+    revisions = oe.buildcfg.get_bitbake_revision()
+    revisions.extend(oe.buildcfg.get_layer_revisions(d))
+    medadata_revs = oe.buildcfg.get_branch_rev4(revisions)
     return '\n'.join(medadata_revs)
 
 def outputvars(vars, listvars, d):
diff --git a/meta/classes/image-buildinfo.bbclass b/meta/classes/image-buildinfo.bbclass
index b83ce650ad..7b5f84854c 100644
--- a/meta/classes/image-buildinfo.bbclass
+++ b/meta/classes/image-buildinfo.bbclass
@@ -27,11 +27,14 @@  def image_buildinfo_outputvars(vars, d):
         ret += "%s = %s\n" % (var, value)
     return ret.rstrip('\n')
 
+def get_bitbake_rev(d):
+    revision = oe.buildcfg.get_bitbake_revision()
+    return '\n'.join(oe.buildcfg.get_branch_rev4(revision))
+
 # Returns layer revisions along with their respective status
 def get_layer_revs(d):
     revisions = oe.buildcfg.get_layer_revisions(d)
-    medadata_revs = ["%-17s = %s:%s%s" % (r[1], r[2], r[3], r[4]) for r in revisions]
-    return '\n'.join(medadata_revs)
+    return '\n'.join(oe.buildcfg.get_branch_rev4(revisions))
 
 def buildinfo_target(d):
         # Get context
@@ -55,6 +58,12 @@  Build Configuration:  |
             buildinfo_target(d),
             '''
 -----------------------
+Bitbake Revision:      |
+-----------------------
+''',
+            get_bitbake_rev(d),
+            '''
+-----------------------
 Layer Revisions:      |
 -----------------------
 ''',
diff --git a/meta/lib/oe/buildcfg.py b/meta/lib/oe/buildcfg.py
index 4b22f18f36..dab4aa7831 100644
--- a/meta/lib/oe/buildcfg.py
+++ b/meta/lib/oe/buildcfg.py
@@ -71,6 +71,19 @@  def is_layer_modified(path):
         # output and a 129 return code when a layer isn't a git repo at all.
         return " -- modified"
 
+def get_branch_rev3(revisions):
+    # Return 3 items for each revision
+    return ["%-20s = \"%s:%s\"" % (r[1], r[2], r[3]) for r in revisions]
+
+def get_branch_rev4(revisions):
+    # Return 4 items for each revision
+    return ["%-17s = %s:%s%s" % (r[1], r[2], r[3], r[4]) for r in revisions]
+
+def get_bitbake_revision():
+    bbdir = bb.__file__.rsplit('/', 3)[0]
+    return [(bbdir, os.path.basename(bbdir), get_metadata_git_branch(bbdir).strip(), \
+            get_metadata_git_revision(bbdir), is_layer_modified(bbdir))]
+
 def get_layer_revisions(d):
     layers = (d.getVar("BBLAYERS") or "").split()
     revisions = []