blob: fa791f04c4c090d1f9a3dd77e0b853fa9d4ddae1 [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
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007 scms = [base_get_metadata_git_revision]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008
9 for scm in scms:
10 rev = scm(path, d)
11 if rev != "<unknown>":
12 return rev
13
14 return "<unknown>"
15
16def base_detect_branch(d):
17 path = base_get_scmbasepath(d)
18
19 scms = [base_get_metadata_git_branch]
20
21 for scm in scms:
22 rev = scm(path, d)
23 if rev != "<unknown>":
24 return rev.strip()
25
26 return "<unknown>"
27
28def base_get_scmbasepath(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050029 return os.path.join(d.getVar('COREBASE'), 'meta')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030
31def base_get_metadata_monotone_branch(path, d):
32 monotone_branch = "<unknown>"
33 try:
34 with open("%s/_MTN/options" % path) as f:
35 monotone_branch = f.read().strip()
36 if monotone_branch.startswith( "database" ):
37 monotone_branch_words = monotone_branch.split()
38 monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1]
39 except:
40 pass
41 return monotone_branch
42
43def base_get_metadata_monotone_revision(path, d):
44 monotone_revision = "<unknown>"
45 try:
46 with open("%s/_MTN/revision" % path) as f:
47 monotone_revision = f.read().strip()
48 if monotone_revision.startswith( "format_version" ):
49 monotone_revision_words = monotone_revision.split()
50 monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1]
51 except IOError:
52 pass
53 return monotone_revision
54
55def base_get_metadata_svn_revision(path, d):
56 # This only works with older subversion. For newer versions
57 # this function will need to be fixed by someone interested
58 revision = "<unknown>"
59 try:
60 with open("%s/.svn/entries" % path) as f:
61 revision = f.readlines()[3].strip()
62 except (IOError, IndexError):
63 pass
64 return revision
65
66def base_get_metadata_git_branch(path, d):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050067 import bb.process
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068
Patrick Williamsf1e5d692016-03-30 15:21:19 -050069 try:
70 rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path)
71 except bb.process.ExecutionError:
72 rev = '<unknown>'
73 return rev.strip()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050074
75def base_get_metadata_git_revision(path, d):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050076 import bb.process
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077
Patrick Williamsf1e5d692016-03-30 15:21:19 -050078 try:
79 rev, _ = bb.process.run('git rev-parse HEAD', cwd=path)
80 except bb.process.ExecutionError:
81 rev = '<unknown>'
82 return rev.strip()