diff options
Diffstat (limited to 'meta/lib/oe/buildcfg.py')
-rw-r--r-- | meta/lib/oe/buildcfg.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/meta/lib/oe/buildcfg.py b/meta/lib/oe/buildcfg.py new file mode 100644 index 0000000000..27b059b834 --- /dev/null +++ b/meta/lib/oe/buildcfg.py | |||
@@ -0,0 +1,79 @@ | |||
1 | |||
2 | import os | ||
3 | import subprocess | ||
4 | import bb.process | ||
5 | |||
6 | def detect_revision(d): | ||
7 | path = get_scmbasepath(d) | ||
8 | return get_metadata_git_revision(path) | ||
9 | |||
10 | def detect_branch(d): | ||
11 | path = get_scmbasepath(d) | ||
12 | return get_metadata_git_branch(path) | ||
13 | |||
14 | def get_scmbasepath(d): | ||
15 | return os.path.join(d.getVar('COREBASE'), 'meta') | ||
16 | |||
17 | def get_metadata_git_branch(path): | ||
18 | try: | ||
19 | rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path) | ||
20 | except bb.process.ExecutionError: | ||
21 | rev = '<unknown>' | ||
22 | return rev.strip() | ||
23 | |||
24 | def get_metadata_git_revision(path): | ||
25 | try: | ||
26 | rev, _ = bb.process.run('git rev-parse HEAD', cwd=path) | ||
27 | except bb.process.ExecutionError: | ||
28 | rev = '<unknown>' | ||
29 | return rev.strip() | ||
30 | |||
31 | def get_metadata_git_toplevel(path): | ||
32 | try: | ||
33 | toplevel, _ = bb.process.run('git rev-parse --show-toplevel', cwd=path) | ||
34 | except bb.process.ExecutionError: | ||
35 | return "" | ||
36 | return toplevel.strip() | ||
37 | |||
38 | def get_metadata_git_remotes(path): | ||
39 | try: | ||
40 | remotes_list, _ = bb.process.run('git remote', cwd=path) | ||
41 | remotes = remotes_list.split() | ||
42 | except bb.process.ExecutionError: | ||
43 | remotes = [] | ||
44 | return remotes | ||
45 | |||
46 | def get_metadata_git_remote_url(path, remote): | ||
47 | try: | ||
48 | uri, _ = bb.process.run('git remote get-url {remote}'.format(remote=remote), cwd=path) | ||
49 | except bb.process.ExecutionError: | ||
50 | return "" | ||
51 | return uri.strip() | ||
52 | |||
53 | def get_metadata_git_describe(path): | ||
54 | try: | ||
55 | describe, _ = bb.process.run('git describe --tags', cwd=path) | ||
56 | except bb.process.ExecutionError: | ||
57 | return "" | ||
58 | return describe.strip() | ||
59 | |||
60 | def is_layer_modified(path): | ||
61 | try: | ||
62 | subprocess.check_output("""cd %s; export PSEUDO_UNLOAD=1; set -e; | ||
63 | git diff --quiet --no-ext-diff | ||
64 | git diff --quiet --no-ext-diff --cached""" % path, | ||
65 | shell=True, | ||
66 | stderr=subprocess.STDOUT) | ||
67 | return "" | ||
68 | except subprocess.CalledProcessError as ex: | ||
69 | # Silently treat errors as "modified", without checking for the | ||
70 | # (expected) return code 1 in a modified git repo. For example, we get | ||
71 | # output and a 129 return code when a layer isn't a git repo at all. | ||
72 | return " -- modified" | ||
73 | |||
74 | def get_layer_revisions(d): | ||
75 | layers = (d.getVar("BBLAYERS") or "").split() | ||
76 | revisions = [] | ||
77 | for i in layers: | ||
78 | revisions.append((i, os.path.basename(i), get_metadata_git_branch(i).strip(), get_metadata_git_revision(i), is_layer_modified(i))) | ||
79 | return revisions | ||