diff options
Diffstat (limited to 'meta/classes/metadata_scm.bbclass')
-rw-r--r-- | meta/classes/metadata_scm.bbclass | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/meta/classes/metadata_scm.bbclass b/meta/classes/metadata_scm.bbclass new file mode 100644 index 0000000000..8d3988ace8 --- /dev/null +++ b/meta/classes/metadata_scm.bbclass | |||
@@ -0,0 +1,80 @@ | |||
1 | METADATA_BRANCH ?= "${@base_detect_branch(d)}" | ||
2 | METADATA_REVISION ?= "${@base_detect_revision(d)}" | ||
3 | |||
4 | def base_detect_revision(d): | ||
5 | path = base_get_scmbasepath(d) | ||
6 | |||
7 | scms = [base_get_metadata_git_revision, \ | ||
8 | base_get_metadata_svn_revision] | ||
9 | |||
10 | for scm in scms: | ||
11 | rev = scm(path, d) | ||
12 | if rev != "<unknown>": | ||
13 | return rev | ||
14 | |||
15 | return "<unknown>" | ||
16 | |||
17 | def base_detect_branch(d): | ||
18 | path = base_get_scmbasepath(d) | ||
19 | |||
20 | scms = [base_get_metadata_git_branch] | ||
21 | |||
22 | for scm in scms: | ||
23 | rev = scm(path, d) | ||
24 | if rev != "<unknown>": | ||
25 | return rev.strip() | ||
26 | |||
27 | return "<unknown>" | ||
28 | |||
29 | def base_get_scmbasepath(d): | ||
30 | return d.getVar( 'COREBASE', True) | ||
31 | |||
32 | def base_get_metadata_monotone_branch(path, d): | ||
33 | monotone_branch = "<unknown>" | ||
34 | try: | ||
35 | with open("%s/_MTN/options" % path) as f: | ||
36 | monotone_branch = f.read().strip() | ||
37 | if monotone_branch.startswith( "database" ): | ||
38 | monotone_branch_words = monotone_branch.split() | ||
39 | monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1] | ||
40 | except: | ||
41 | pass | ||
42 | return monotone_branch | ||
43 | |||
44 | def base_get_metadata_monotone_revision(path, d): | ||
45 | monotone_revision = "<unknown>" | ||
46 | try: | ||
47 | with open("%s/_MTN/revision" % path) as f: | ||
48 | monotone_revision = f.read().strip() | ||
49 | if monotone_revision.startswith( "format_version" ): | ||
50 | monotone_revision_words = monotone_revision.split() | ||
51 | monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1] | ||
52 | except IOError: | ||
53 | pass | ||
54 | return monotone_revision | ||
55 | |||
56 | def base_get_metadata_svn_revision(path, d): | ||
57 | revision = "<unknown>" | ||
58 | try: | ||
59 | with open("%s/.svn/entries" % path) as f: | ||
60 | revision = f.readlines()[3].strip() | ||
61 | except IOError: | ||
62 | pass | ||
63 | return revision | ||
64 | |||
65 | def base_get_metadata_git_branch(path, d): | ||
66 | branch = os.popen('cd %s; git branch 2>&1 | grep "^* " | tr -d "* "' % path).read() | ||
67 | |||
68 | if len(branch) != 0: | ||
69 | return branch | ||
70 | return "<unknown>" | ||
71 | |||
72 | def base_get_metadata_git_revision(path, d): | ||
73 | f = os.popen("cd %s; git log -n 1 --pretty=oneline -- 2>&1" % path) | ||
74 | data = f.read() | ||
75 | if f.close() is None: | ||
76 | rev = data.split(" ")[0] | ||
77 | if len(rev) != 0: | ||
78 | return rev | ||
79 | return "<unknown>" | ||
80 | |||