diff options
| author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-06-09 11:27:14 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-06-11 10:30:57 +0100 |
| commit | 5266670b2da48cccc9f042ca7afc7f86d7ff89ae (patch) | |
| tree | 2cda867885b1e605275ff31e73c4197f5c129293 | |
| parent | ba85bb605502a86fa83bd7a0f3d8ed644dc16a8c (diff) | |
| download | poky-5266670b2da48cccc9f042ca7afc7f86d7ff89ae.tar.gz | |
lib/buildcfg: Share common clean/dirty layer function
The comments even say this was copy/paste code. Move to a
shared library function.
(From OE-Core rev: ac3de2f850a418673b87e1c454970cb099e191b0)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/classes/buildhistory.bbclass | 18 | ||||
| -rw-r--r-- | meta/classes/image-buildinfo.bbclass | 18 | ||||
| -rw-r--r-- | meta/lib/oe/buildcfg.py | 15 |
3 files changed, 16 insertions, 35 deletions
diff --git a/meta/classes/buildhistory.bbclass b/meta/classes/buildhistory.bbclass index f2493b3765..6fffd47189 100644 --- a/meta/classes/buildhistory.bbclass +++ b/meta/classes/buildhistory.bbclass | |||
| @@ -741,29 +741,13 @@ def buildhistory_get_build_id(d): | |||
| 741 | statusheader = d.getVar('BUILDCFG_HEADER') | 741 | statusheader = d.getVar('BUILDCFG_HEADER') |
| 742 | return('\n%s\n%s\n' % (statusheader, '\n'.join(statuslines))) | 742 | return('\n%s\n%s\n' % (statusheader, '\n'.join(statuslines))) |
| 743 | 743 | ||
| 744 | def buildhistory_get_modified(path): | ||
| 745 | # copied from get_layer_git_status() in image-buildinfo.bbclass | ||
| 746 | import subprocess | ||
| 747 | try: | ||
| 748 | subprocess.check_output("""cd %s; export PSEUDO_UNLOAD=1; set -e; | ||
| 749 | git diff --quiet --no-ext-diff | ||
| 750 | git diff --quiet --no-ext-diff --cached""" % path, | ||
| 751 | shell=True, | ||
| 752 | stderr=subprocess.STDOUT) | ||
| 753 | return "" | ||
| 754 | except subprocess.CalledProcessError as ex: | ||
| 755 | # Silently treat errors as "modified", without checking for the | ||
| 756 | # (expected) return code 1 in a modified git repo. For example, we get | ||
| 757 | # output and a 129 return code when a layer isn't a git repo at all. | ||
| 758 | return " -- modified" | ||
| 759 | |||
| 760 | def buildhistory_get_metadata_revs(d): | 744 | 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 | 745 | # 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() | 746 | layers = (d.getVar("BBLAYERS") or "").split() |
| 763 | medadata_revs = ["%-17s = %s:%s%s" % (os.path.basename(i), \ | 747 | medadata_revs = ["%-17s = %s:%s%s" % (os.path.basename(i), \ |
| 764 | oe.buildcfg.get_metadata_git_branch(i, None).strip(), \ | 748 | oe.buildcfg.get_metadata_git_branch(i, None).strip(), \ |
| 765 | oe.buildcfg.get_metadata_git_revision(i, None), \ | 749 | oe.buildcfg.get_metadata_git_revision(i, None), \ |
| 766 | buildhistory_get_modified(i)) \ | 750 | oe.buildcfg.is_layer_modified(i)) \ |
| 767 | for i in layers] | 751 | for i in layers] |
| 768 | return '\n'.join(medadata_revs) | 752 | return '\n'.join(medadata_revs) |
| 769 | 753 | ||
diff --git a/meta/classes/image-buildinfo.bbclass b/meta/classes/image-buildinfo.bbclass index 25ca8d8fe6..c149660f31 100644 --- a/meta/classes/image-buildinfo.bbclass +++ b/meta/classes/image-buildinfo.bbclass | |||
| @@ -26,29 +26,13 @@ def image_buildinfo_outputvars(vars, d): | |||
| 26 | ret += "%s = %s\n" % (var, value) | 26 | ret += "%s = %s\n" % (var, value) |
| 27 | return ret.rstrip('\n') | 27 | return ret.rstrip('\n') |
| 28 | 28 | ||
| 29 | # Gets git branch's status (clean or dirty) | ||
| 30 | def get_layer_git_status(path): | ||
| 31 | import subprocess | ||
| 32 | try: | ||
| 33 | subprocess.check_output("""cd %s; export PSEUDO_UNLOAD=1; set -e; | ||
| 34 | git diff --quiet --no-ext-diff | ||
| 35 | git diff --quiet --no-ext-diff --cached""" % path, | ||
| 36 | shell=True, | ||
| 37 | stderr=subprocess.STDOUT) | ||
| 38 | return "" | ||
| 39 | except subprocess.CalledProcessError as ex: | ||
| 40 | # Silently treat errors as "modified", without checking for the | ||
| 41 | # (expected) return code 1 in a modified git repo. For example, we get | ||
| 42 | # output and a 129 return code when a layer isn't a git repo at all. | ||
| 43 | return "-- modified" | ||
| 44 | |||
| 45 | # Returns layer revisions along with their respective status | 29 | # Returns layer revisions along with their respective status |
| 46 | def get_layer_revs(d): | 30 | def get_layer_revs(d): |
| 47 | layers = (d.getVar("BBLAYERS") or "").split() | 31 | layers = (d.getVar("BBLAYERS") or "").split() |
| 48 | medadata_revs = ["%-17s = %s:%s %s" % (os.path.basename(i), \ | 32 | medadata_revs = ["%-17s = %s:%s %s" % (os.path.basename(i), \ |
| 49 | oe.buildcfg.get_metadata_git_branch(i, None).strip(), \ | 33 | oe.buildcfg.get_metadata_git_branch(i, None).strip(), \ |
| 50 | oe.buildcfg.get_metadata_git_revision(i, None), \ | 34 | oe.buildcfg.get_metadata_git_revision(i, None), \ |
| 51 | get_layer_git_status(i)) \ | 35 | oe.buildcfg.is_layer_modified(i)) \ |
| 52 | for i in layers] | 36 | for i in layers] |
| 53 | return '\n'.join(medadata_revs) | 37 | return '\n'.join(medadata_revs) |
| 54 | 38 | ||
diff --git a/meta/lib/oe/buildcfg.py b/meta/lib/oe/buildcfg.py index a749fc5303..a7549f1e22 100644 --- a/meta/lib/oe/buildcfg.py +++ b/meta/lib/oe/buildcfg.py | |||
| @@ -37,4 +37,17 @@ def get_metadata_git_revision(path, d): | |||
| 37 | except bb.process.ExecutionError: | 37 | except bb.process.ExecutionError: |
| 38 | rev = '<unknown>' | 38 | rev = '<unknown>' |
| 39 | return rev.strip() | 39 | return rev.strip() |
| 40 | 40 | ||
| 41 | def is_layer_modified(path): | ||
| 42 | try: | ||
| 43 | subprocess.check_output("""cd %s; export PSEUDO_UNLOAD=1; set -e; | ||
| 44 | git diff --quiet --no-ext-diff | ||
| 45 | git diff --quiet --no-ext-diff --cached""" % path, | ||
| 46 | shell=True, | ||
| 47 | stderr=subprocess.STDOUT) | ||
| 48 | return "" | ||
| 49 | except subprocess.CalledProcessError as ex: | ||
| 50 | # Silently treat errors as "modified", without checking for the | ||
| 51 | # (expected) return code 1 in a modified git repo. For example, we get | ||
| 52 | # output and a 129 return code when a layer isn't a git repo at all. | ||
| 53 | return " -- modified" | ||
