diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-06-09 11:23:30 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-06-11 10:30:56 +0100 |
commit | ba85bb605502a86fa83bd7a0f3d8ed644dc16a8c (patch) | |
tree | e30bf6f81aa714fad3b9f94c0814339410b0973f /meta | |
parent | 5ed5a3cc8a4d819a0af8ee59f0c960bc4de07b61 (diff) | |
download | poky-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')
-rw-r--r-- | meta/classes/base.bbclass | 9 | ||||
-rw-r--r-- | meta/classes/buildhistory.bbclass | 4 | ||||
-rw-r--r-- | meta/classes/image-buildinfo.bbclass | 4 | ||||
-rw-r--r-- | meta/classes/metadata_scm.bbclass | 43 | ||||
-rw-r--r-- | meta/classes/report-error.bbclass | 2 | ||||
-rw-r--r-- | meta/lib/oe/buildcfg.py | 40 |
6 files changed, 52 insertions, 50 deletions
diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass index bdb3ac33c6..f59e95fef0 100644 --- a/meta/classes/base.bbclass +++ b/meta/classes/base.bbclass | |||
@@ -7,12 +7,11 @@ inherit staging | |||
7 | inherit mirrors | 7 | inherit mirrors |
8 | inherit utils | 8 | inherit utils |
9 | inherit utility-tasks | 9 | inherit utility-tasks |
10 | inherit metadata_scm | ||
11 | inherit logging | 10 | inherit logging |
12 | 11 | ||
13 | OE_EXTRA_IMPORTS ?= "" | 12 | OE_EXTRA_IMPORTS ?= "" |
14 | 13 | ||
15 | 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}" | 14 | 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}" |
16 | OE_IMPORTS[type] = "list" | 15 | OE_IMPORTS[type] = "list" |
17 | 16 | ||
18 | PACKAGECONFIG_CONFARGS ??= "" | 17 | PACKAGECONFIG_CONFARGS ??= "" |
@@ -35,6 +34,8 @@ def oe_import(d): | |||
35 | # We need the oe module name space early (before INHERITs get added) | 34 | # We need the oe module name space early (before INHERITs get added) |
36 | OE_IMPORTED := "${@oe_import(d)}" | 35 | OE_IMPORTED := "${@oe_import(d)}" |
37 | 36 | ||
37 | inherit metadata_scm | ||
38 | |||
38 | def lsb_distro_identifier(d): | 39 | def lsb_distro_identifier(d): |
39 | adjust = d.getVar('LSB_DISTRO_ADJUST') | 40 | adjust = d.getVar('LSB_DISTRO_ADJUST') |
40 | adjust_func = None | 41 | adjust_func = None |
@@ -219,8 +220,8 @@ def get_source_date_epoch_value(d): | |||
219 | def get_layers_branch_rev(d): | 220 | def get_layers_branch_rev(d): |
220 | layers = (d.getVar("BBLAYERS") or "").split() | 221 | layers = (d.getVar("BBLAYERS") or "").split() |
221 | layers_branch_rev = ["%-20s = \"%s:%s\"" % (os.path.basename(i), \ | 222 | layers_branch_rev = ["%-20s = \"%s:%s\"" % (os.path.basename(i), \ |
222 | base_get_metadata_git_branch(i, None).strip(), \ | 223 | oe.buildcfg.get_metadata_git_branch(i, None).strip(), \ |
223 | base_get_metadata_git_revision(i, None)) \ | 224 | oe.buildcfg.get_metadata_git_revision(i, None)) \ |
224 | for i in layers] | 225 | for i in layers] |
225 | i = len(layers_branch_rev)-1 | 226 | i = len(layers_branch_rev)-1 |
226 | p1 = layers_branch_rev[i].find("=") | 227 | p1 = layers_branch_rev[i].find("=") |
diff --git a/meta/classes/buildhistory.bbclass b/meta/classes/buildhistory.bbclass index 4345ffc693..f2493b3765 100644 --- a/meta/classes/buildhistory.bbclass +++ b/meta/classes/buildhistory.bbclass | |||
@@ -761,8 +761,8 @@ def buildhistory_get_metadata_revs(d): | |||
761 | # We want an easily machine-readable format here, so get_layers_branch_rev isn't quite what we want | 761 | # We want an easily machine-readable format here, so get_layers_branch_rev isn't quite what we want |
762 | layers = (d.getVar("BBLAYERS") or "").split() | 762 | layers = (d.getVar("BBLAYERS") or "").split() |
763 | medadata_revs = ["%-17s = %s:%s%s" % (os.path.basename(i), \ | 763 | medadata_revs = ["%-17s = %s:%s%s" % (os.path.basename(i), \ |
764 | base_get_metadata_git_branch(i, None).strip(), \ | 764 | oe.buildcfg.get_metadata_git_branch(i, None).strip(), \ |
765 | base_get_metadata_git_revision(i, None), \ | 765 | oe.buildcfg.get_metadata_git_revision(i, None), \ |
766 | buildhistory_get_modified(i)) \ | 766 | buildhistory_get_modified(i)) \ |
767 | for i in layers] | 767 | for i in layers] |
768 | return '\n'.join(medadata_revs) | 768 | return '\n'.join(medadata_revs) |
diff --git a/meta/classes/image-buildinfo.bbclass b/meta/classes/image-buildinfo.bbclass index 94c585d4cd..25ca8d8fe6 100644 --- a/meta/classes/image-buildinfo.bbclass +++ b/meta/classes/image-buildinfo.bbclass | |||
@@ -46,8 +46,8 @@ def get_layer_git_status(path): | |||
46 | def get_layer_revs(d): | 46 | def get_layer_revs(d): |
47 | layers = (d.getVar("BBLAYERS") or "").split() | 47 | layers = (d.getVar("BBLAYERS") or "").split() |
48 | medadata_revs = ["%-17s = %s:%s %s" % (os.path.basename(i), \ | 48 | medadata_revs = ["%-17s = %s:%s %s" % (os.path.basename(i), \ |
49 | base_get_metadata_git_branch(i, None).strip(), \ | 49 | oe.buildcfg.get_metadata_git_branch(i, None).strip(), \ |
50 | base_get_metadata_git_revision(i, None), \ | 50 | oe.buildcfg.get_metadata_git_revision(i, None), \ |
51 | get_layer_git_status(i)) \ | 51 | get_layer_git_status(i)) \ |
52 | for i in layers] | 52 | for i in layers] |
53 | return '\n'.join(medadata_revs) | 53 | return '\n'.join(medadata_revs) |
diff --git a/meta/classes/metadata_scm.bbclass b/meta/classes/metadata_scm.bbclass index 47cb969b8d..f646b3159a 100644 --- a/meta/classes/metadata_scm.bbclass +++ b/meta/classes/metadata_scm.bbclass | |||
@@ -1,44 +1,5 @@ | |||
1 | def base_detect_revision(d): | ||
2 | path = base_get_scmbasepath(d) | ||
3 | return base_get_metadata_git_revision(path, d) | ||
4 | 1 | ||
5 | def base_detect_branch(d): | 2 | METADATA_BRANCH := "${@oe.buildcfg.detect_branch(d)}" |
6 | path = base_get_scmbasepath(d) | ||
7 | return base_get_metadata_git_branch(path, d) | ||
8 | |||
9 | def base_get_scmbasepath(d): | ||
10 | return os.path.join(d.getVar('COREBASE'), 'meta') | ||
11 | |||
12 | def base_get_metadata_svn_revision(path, d): | ||
13 | # This only works with older subversion. For newer versions | ||
14 | # this function will need to be fixed by someone interested | ||
15 | revision = "<unknown>" | ||
16 | try: | ||
17 | with open("%s/.svn/entries" % path) as f: | ||
18 | revision = f.readlines()[3].strip() | ||
19 | except (IOError, IndexError): | ||
20 | pass | ||
21 | return revision | ||
22 | |||
23 | def base_get_metadata_git_branch(path, d): | ||
24 | import bb.process | ||
25 | |||
26 | try: | ||
27 | rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path) | ||
28 | except bb.process.ExecutionError: | ||
29 | rev = '<unknown>' | ||
30 | return rev.strip() | ||
31 | |||
32 | def base_get_metadata_git_revision(path, d): | ||
33 | import bb.process | ||
34 | |||
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 | |||
41 | METADATA_BRANCH := "${@base_detect_branch(d)}" | ||
42 | METADATA_BRANCH[vardepvalue] = "${METADATA_BRANCH}" | 3 | METADATA_BRANCH[vardepvalue] = "${METADATA_BRANCH}" |
43 | METADATA_REVISION := "${@base_detect_revision(d)}" | 4 | METADATA_REVISION := "${@oe.buildcfg.detect_revision(d)}" |
44 | METADATA_REVISION[vardepvalue] = "${METADATA_REVISION}" | 5 | METADATA_REVISION[vardepvalue] = "${METADATA_REVISION}" |
diff --git a/meta/classes/report-error.bbclass b/meta/classes/report-error.bbclass index de48e4ff0f..6866d47370 100644 --- a/meta/classes/report-error.bbclass +++ b/meta/classes/report-error.bbclass | |||
@@ -63,7 +63,7 @@ python errorreport_handler () { | |||
63 | data['target_sys'] = e.data.getVar("TARGET_SYS") | 63 | data['target_sys'] = e.data.getVar("TARGET_SYS") |
64 | data['failures'] = [] | 64 | data['failures'] = [] |
65 | data['component'] = " ".join(e.getPkgs()) | 65 | data['component'] = " ".join(e.getPkgs()) |
66 | data['branch_commit'] = str(base_detect_branch(e.data)) + ": " + str(base_detect_revision(e.data)) | 66 | data['branch_commit'] = str(oe.buildcfg.detect_branch(e.data)) + ": " + str(oe.buildcfg.detect_revision(e.data)) |
67 | data['bitbake_version'] = e.data.getVar("BB_VERSION") | 67 | data['bitbake_version'] = e.data.getVar("BB_VERSION") |
68 | data['layer_version'] = get_layers_branch_rev(e.data) | 68 | data['layer_version'] = get_layers_branch_rev(e.data) |
69 | data['local_conf'] = get_conf_data(e, 'local.conf') | 69 | 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 index 0000000000..a749fc5303 --- /dev/null +++ b/meta/lib/oe/buildcfg.py | |||
@@ -0,0 +1,40 @@ | |||
1 | |||
2 | import subprocess | ||
3 | import bb.process | ||
4 | |||
5 | def detect_revision(d): | ||
6 | path = get_scmbasepath(d) | ||
7 | return get_metadata_git_revision(path, d) | ||
8 | |||
9 | def detect_branch(d): | ||
10 | path = get_scmbasepath(d) | ||
11 | return get_metadata_git_branch(path, d) | ||
12 | |||
13 | def get_scmbasepath(d): | ||
14 | return os.path.join(d.getVar('COREBASE'), 'meta') | ||
15 | |||
16 | def 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 | |||
27 | def 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 | |||
34 | def 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 | |||