summaryrefslogtreecommitdiffstats
path: root/meta/classes/metadata_scm.bbclass
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@linux.intel.com>2010-03-19 23:12:06 +0000
committerRichard Purdie <rpurdie@linux.intel.com>2010-03-19 23:12:06 +0000
commit9c5386c1fd74d832cf6e2acad3c69b1cc90de6b2 (patch)
treeaa2db23da10e883f0f8627f5993cd2cfade2e705 /meta/classes/metadata_scm.bbclass
parent185cb38f1319856b4bdaaf4d9a73b5056be53d54 (diff)
downloadpoky-9c5386c1fd74d832cf6e2acad3c69b1cc90de6b2.tar.gz
base.bbclass: Split up as per the patch in OE.dev by Chris Larson making code more readable and modularised
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'meta/classes/metadata_scm.bbclass')
-rw-r--r--meta/classes/metadata_scm.bbclass77
1 files changed, 77 insertions, 0 deletions
diff --git a/meta/classes/metadata_scm.bbclass b/meta/classes/metadata_scm.bbclass
new file mode 100644
index 0000000000..4f66011b0d
--- /dev/null
+++ b/meta/classes/metadata_scm.bbclass
@@ -0,0 +1,77 @@
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
29
30
31def base_get_scmbasepath(d):
32 path_to_bbfiles = bb.data.getVar( 'BBFILES', d, 1 ).split()
33 return path_to_bbfiles[0][:path_to_bbfiles[0].rindex( "packages" )]
34
35def base_get_metadata_monotone_branch(path, d):
36 monotone_branch = "<unknown>"
37 try:
38 monotone_branch = file( "%s/_MTN/options" % path ).read().strip()
39 if monotone_branch.startswith( "database" ):
40 monotone_branch_words = monotone_branch.split()
41 monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1]
42 except:
43 pass
44 return monotone_branch
45
46def base_get_metadata_monotone_revision(path, d):
47 monotone_revision = "<unknown>"
48 try:
49 monotone_revision = file( "%s/_MTN/revision" % path ).read().strip()
50 if monotone_revision.startswith( "format_version" ):
51 monotone_revision_words = monotone_revision.split()
52 monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1]
53 except IOError:
54 pass
55 return monotone_revision
56
57def base_get_metadata_svn_revision(path, d):
58 revision = "<unknown>"
59 try:
60 revision = file( "%s/.svn/entries" % path ).readlines()[3].strip()
61 except IOError:
62 pass
63 return revision
64
65def base_get_metadata_git_branch(path, d):
66 branch = os.popen('cd %s; git branch | grep "^* " | tr -d "* "' % path).read()
67
68 if len(branch) != 0:
69 return branch
70 return "<unknown>"
71
72def base_get_metadata_git_revision(path, d):
73 rev = os.popen("cd %s; git log -n 1 --pretty=oneline --" % path).read().split(" ")[0]
74 if len(rev) != 0:
75 return rev
76 return "<unknown>"
77