]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
classes/buildcfg: Move git/layer revision code into new OE module buildcfg
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 9 Jun 2022 10:23:30 +0000 (11:23 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 11 Jun 2022 09:29:42 +0000 (10:29 +0100)
There is a load of duplicated git/layer/revision code which makes
most sesne as a python library, not bbclass code. Start to refactor as such.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/base.bbclass
meta/classes/buildhistory.bbclass
meta/classes/image-buildinfo.bbclass
meta/classes/metadata_scm.bbclass
meta/classes/report-error.bbclass
meta/lib/oe/buildcfg.py [new file with mode: 0644]

index bdb3ac33c671930abbc2a3f308f29261939a3ca0..f59e95fef06ac998f4ece4cd99883c6b748c3419 100644 (file)
@@ -7,12 +7,11 @@ inherit staging
 inherit mirrors
 inherit utils
 inherit utility-tasks
-inherit metadata_scm
 inherit logging
 
 OE_EXTRA_IMPORTS ?= ""
 
-OE_IMPORTS += "os sys time oe.path oe.utils oe.types oe.package oe.packagegroup oe.sstatesig oe.lsb oe.cachedpath oe.license oe.qa oe.reproducible oe.rust ${OE_EXTRA_IMPORTS}"
+OE_IMPORTS += "os sys time oe.path oe.utils oe.types oe.package oe.packagegroup oe.sstatesig oe.lsb oe.cachedpath oe.license oe.qa oe.reproducible oe.rust oe.buildcfg ${OE_EXTRA_IMPORTS}"
 OE_IMPORTS[type] = "list"
 
 PACKAGECONFIG_CONFARGS ??= ""
@@ -35,6 +34,8 @@ def oe_import(d):
 # We need the oe module name space early (before INHERITs get added)
 OE_IMPORTED := "${@oe_import(d)}"
 
+inherit metadata_scm
+
 def lsb_distro_identifier(d):
     adjust = d.getVar('LSB_DISTRO_ADJUST')
     adjust_func = None
@@ -219,8 +220,8 @@ def get_source_date_epoch_value(d):
 def get_layers_branch_rev(d):
     layers = (d.getVar("BBLAYERS") or "").split()
     layers_branch_rev = ["%-20s = \"%s:%s\"" % (os.path.basename(i), \
-        base_get_metadata_git_branch(i, None).strip(), \
-        base_get_metadata_git_revision(i, None)) \
+        oe.buildcfg.get_metadata_git_branch(i, None).strip(), \
+        oe.buildcfg.get_metadata_git_revision(i, None)) \
             for i in layers]
     i = len(layers_branch_rev)-1
     p1 = layers_branch_rev[i].find("=")
index 4345ffc6939eb6704945261323abfc5567da1e42..f2493b3765aeacb00b15b17ad7c5bc6cf4ab8e12 100644 (file)
@@ -761,8 +761,8 @@ def buildhistory_get_metadata_revs(d):
     # We want an easily machine-readable format here, so get_layers_branch_rev isn't quite what we want
     layers = (d.getVar("BBLAYERS") 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), \
+        oe.buildcfg.get_metadata_git_branch(i, None).strip(), \
+        oe.buildcfg.get_metadata_git_revision(i, None), \
         buildhistory_get_modified(i)) \
             for i in layers]
     return '\n'.join(medadata_revs)
index 94c585d4cd98d0523fc258b6faf8edb76215b7a2..25ca8d8fe6b526707396be25cba1d0bb965a5427 100644 (file)
@@ -46,8 +46,8 @@ def get_layer_git_status(path):
 def get_layer_revs(d):
     layers = (d.getVar("BBLAYERS") 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), \
+        oe.buildcfg.get_metadata_git_branch(i, None).strip(), \
+        oe.buildcfg.get_metadata_git_revision(i, None), \
         get_layer_git_status(i)) \
             for i in layers]
     return '\n'.join(medadata_revs)
index 47cb969b8d8111908093fd328c2c22b30f6719a3..f646b3159a4af42cb4995ed4381da4b7b7437d61 100644 (file)
@@ -1,44 +1,5 @@
-def base_detect_revision(d):
-    path = base_get_scmbasepath(d)
-    return base_get_metadata_git_revision(path, d)
 
-def base_detect_branch(d):
-    path = base_get_scmbasepath(d)
-    return base_get_metadata_git_branch(path, d)
-
-def base_get_scmbasepath(d):
-    return os.path.join(d.getVar('COREBASE'), 'meta')
-
-def base_get_metadata_svn_revision(path, d):
-    # This only works with older subversion. For newer versions 
-    # this function will need to be fixed by someone interested
-    revision = "<unknown>"
-    try:
-        with open("%s/.svn/entries" % path) as f:
-            revision = f.readlines()[3].strip()
-    except (IOError, IndexError):
-        pass
-    return revision
-
-def base_get_metadata_git_branch(path, d):
-    import bb.process
-
-    try:
-        rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path)
-    except bb.process.ExecutionError:
-        rev = '<unknown>'
-    return rev.strip()
-
-def base_get_metadata_git_revision(path, d):
-    import bb.process
-
-    try:
-        rev, _ = bb.process.run('git rev-parse HEAD', cwd=path)
-    except bb.process.ExecutionError:
-        rev = '<unknown>'
-    return rev.strip()
-
-METADATA_BRANCH := "${@base_detect_branch(d)}"
+METADATA_BRANCH := "${@oe.buildcfg.detect_branch(d)}"
 METADATA_BRANCH[vardepvalue] = "${METADATA_BRANCH}"
-METADATA_REVISION := "${@base_detect_revision(d)}"
+METADATA_REVISION := "${@oe.buildcfg.detect_revision(d)}"
 METADATA_REVISION[vardepvalue] = "${METADATA_REVISION}"
index de48e4ff0f529841d79ac5783b744f932693d8c3..6866d47370dafa45d9c2b4f4660679f3971770ad 100644 (file)
@@ -63,7 +63,7 @@ python errorreport_handler () {
             data['target_sys'] = e.data.getVar("TARGET_SYS")
             data['failures'] = []
             data['component'] = " ".join(e.getPkgs())
-            data['branch_commit'] = str(base_detect_branch(e.data)) + ": " + str(base_detect_revision(e.data))
+            data['branch_commit'] = str(oe.buildcfg.detect_branch(e.data)) + ": " + str(oe.buildcfg.detect_revision(e.data))
             data['bitbake_version'] = e.data.getVar("BB_VERSION")
             data['layer_version'] = get_layers_branch_rev(e.data)
             data['local_conf'] = get_conf_data(e, 'local.conf')
diff --git a/meta/lib/oe/buildcfg.py b/meta/lib/oe/buildcfg.py
new file mode 100644 (file)
index 0000000..a749fc5
--- /dev/null
@@ -0,0 +1,40 @@
+
+import subprocess
+import bb.process
+
+def detect_revision(d):
+    path = get_scmbasepath(d)
+    return get_metadata_git_revision(path, d)
+
+def detect_branch(d):
+    path = get_scmbasepath(d)
+    return get_metadata_git_branch(path, d)
+
+def get_scmbasepath(d):
+    return os.path.join(d.getVar('COREBASE'), 'meta')
+
+def get_metadata_svn_revision(path, d):
+    # This only works with older subversion. For newer versions 
+    # this function will need to be fixed by someone interested
+    revision = "<unknown>"
+    try:
+        with open("%s/.svn/entries" % path) as f:
+            revision = f.readlines()[3].strip()
+    except (IOError, IndexError):
+        pass
+    return revision
+
+def get_metadata_git_branch(path, d):
+    try:
+        rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path)
+    except bb.process.ExecutionError:
+        rev = '<unknown>'
+    return rev.strip()
+
+def get_metadata_git_revision(path, d):
+    try:
+        rev, _ = bb.process.run('git rev-parse HEAD', cwd=path)
+    except bb.process.ExecutionError:
+        rev = '<unknown>'
+    return rev.strip()
+