blob: 2608a7ef7b8d8bf4b7aa644290d5e72424ff5316 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001METADATA_BRANCH ?= "${@base_detect_branch(d)}"
Andrew Geissler09209ee2020-12-13 08:44:15 -06002METADATA_BRANCH[vardepvalue] = "${METADATA_BRANCH}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003METADATA_REVISION ?= "${@base_detect_revision(d)}"
Andrew Geissler09209ee2020-12-13 08:44:15 -06004METADATA_REVISION[vardepvalue] = "${METADATA_REVISION}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005
6def base_detect_revision(d):
7 path = base_get_scmbasepath(d)
Brad Bishop19323692019-04-05 15:28:33 -04008 return base_get_metadata_git_revision(path, d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009
10def base_detect_branch(d):
11 path = base_get_scmbasepath(d)
Brad Bishop19323692019-04-05 15:28:33 -040012 return base_get_metadata_git_branch(path, d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013
14def base_get_scmbasepath(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050015 return os.path.join(d.getVar('COREBASE'), 'meta')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017def base_get_metadata_svn_revision(path, d):
18 # This only works with older subversion. For newer versions
19 # this function will need to be fixed by someone interested
20 revision = "<unknown>"
21 try:
22 with open("%s/.svn/entries" % path) as f:
23 revision = f.readlines()[3].strip()
24 except (IOError, IndexError):
25 pass
26 return revision
27
28def base_get_metadata_git_branch(path, d):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050029 import bb.process
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030
Patrick Williamsf1e5d692016-03-30 15:21:19 -050031 try:
32 rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path)
33 except bb.process.ExecutionError:
34 rev = '<unknown>'
35 return rev.strip()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050036
37def base_get_metadata_git_revision(path, d):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050038 import bb.process
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039
Patrick Williamsf1e5d692016-03-30 15:21:19 -050040 try:
41 rev, _ = bb.process.run('git rev-parse HEAD', cwd=path)
42 except bb.process.ExecutionError:
43 rev = '<unknown>'
44 return rev.strip()