summaryrefslogtreecommitdiffstats
path: root/meta/classes/metadata_scm.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/metadata_scm.bbclass')
-rw-r--r--meta/classes/metadata_scm.bbclass82
1 files changed, 82 insertions, 0 deletions
diff --git a/meta/classes/metadata_scm.bbclass b/meta/classes/metadata_scm.bbclass
new file mode 100644
index 0000000..ba0edf9
--- /dev/null
+++ b/meta/classes/metadata_scm.bbclass
@@ -0,0 +1,82 @@
1METADATA_BRANCH ?= "${@base_detect_branch(d)}"
2METADATA_REVISION ?= "${@base_detect_revision(d)}"
3
4def 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
17def 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
29def base_get_scmbasepath(d):
30 return d.getVar( 'COREBASE', True)
31
32def 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
44def 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
56def base_get_metadata_svn_revision(path, d):
57 # This only works with older subversion. For newer versions
58 # this function will need to be fixed by someone interested
59 revision = "<unknown>"
60 try:
61 with open("%s/.svn/entries" % path) as f:
62 revision = f.readlines()[3].strip()
63 except IOError, IndexError:
64 pass
65 return revision
66
67def base_get_metadata_git_branch(path, d):
68 branch = os.popen('cd %s; git branch 2>&1 | grep "^* " | tr -d "* "' % path).read()
69
70 if len(branch) != 0:
71 return branch
72 return "<unknown>"
73
74def base_get_metadata_git_revision(path, d):
75 f = os.popen("cd %s; git log -n 1 --pretty=oneline -- 2>&1" % path)
76 data = f.read()
77 if f.close() is None:
78 rev = data.split(" ")[0]
79 if len(rev) != 0:
80 return rev
81 return "<unknown>"
82