summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-06-09 11:23:30 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-06-11 10:29:42 +0100
commit439cdf8a1e52fd2c4dc81dc40ce7e6af282ce7ac (patch)
tree09431c9b687ea7a52d76fbd202199447bf633d64 /meta/lib
parent3464c67cd34acbb1a6705369e34dee8af7e348ac (diff)
downloadopenembedded-core-contrib-439cdf8a1e52fd2c4dc81dc40ce7e6af282ce7ac.tar.gz
classes/buildcfg: Move git/layer revision code into new OE module buildcfg
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>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oe/buildcfg.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/meta/lib/oe/buildcfg.py b/meta/lib/oe/buildcfg.py
new file mode 100644
index 0000000000..a749fc5303
--- /dev/null
+++ b/meta/lib/oe/buildcfg.py
@@ -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()
+