blob: 0f7f4235a34b31fc86449dbb9097b0b26bfa3342 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001METADATA_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):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050068 import bb.process
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069
Patrick Williamsf1e5d692016-03-30 15:21:19 -050070 try:
71 rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path)
72 except bb.process.ExecutionError:
73 rev = '<unknown>'
74 return rev.strip()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075
76def base_get_metadata_git_revision(path, d):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050077 import bb.process
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078
Patrick Williamsf1e5d692016-03-30 15:21:19 -050079 try:
80 rev, _ = bb.process.run('git rev-parse HEAD', cwd=path)
81 except bb.process.ExecutionError:
82 rev = '<unknown>'
83 return rev.strip()