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:30:56 +0100
commitba85bb605502a86fa83bd7a0f3d8ed644dc16a8c (patch)
treee30bf6f81aa714fad3b9f94c0814339410b0973f /meta/lib
parent5ed5a3cc8a4d819a0af8ee59f0c960bc4de07b61 (diff)
downloadpoky-ba85bb605502a86fa83bd7a0f3d8ed644dc16a8c.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. (From OE-Core rev: 439cdf8a1e52fd2c4dc81dc40ce7e6af282ce7ac) 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 @@
1
2import subprocess
3import bb.process
4
5def detect_revision(d):
6 path = get_scmbasepath(d)
7 return get_metadata_git_revision(path, d)
8
9def detect_branch(d):
10 path = get_scmbasepath(d)
11 return get_metadata_git_branch(path, d)
12
13def get_scmbasepath(d):
14 return os.path.join(d.getVar('COREBASE'), 'meta')
15
16def get_metadata_svn_revision(path, d):
17 # This only works with older subversion. For newer versions
18 # this function will need to be fixed by someone interested
19 revision = "<unknown>"
20 try:
21 with open("%s/.svn/entries" % path) as f:
22 revision = f.readlines()[3].strip()
23 except (IOError, IndexError):
24 pass
25 return revision
26
27def get_metadata_git_branch(path, d):
28 try:
29 rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path)
30 except bb.process.ExecutionError:
31 rev = '<unknown>'
32 return rev.strip()
33
34def get_metadata_git_revision(path, d):
35 try:
36 rev, _ = bb.process.run('git rev-parse HEAD', cwd=path)
37 except bb.process.ExecutionError:
38 rev = '<unknown>'
39 return rev.strip()
40