blob: 58bb4c555a22469f20a7abcf4c9c38f08afe2442 [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)
Brad Bishop19323692019-04-05 15:28:33 -04006 return base_get_metadata_git_revision(path, d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007
8def base_detect_branch(d):
9 path = base_get_scmbasepath(d)
Brad Bishop19323692019-04-05 15:28:33 -040010 return base_get_metadata_git_branch(path, d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011
12def base_get_scmbasepath(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013 return os.path.join(d.getVar('COREBASE'), 'meta')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015def base_get_metadata_svn_revision(path, d):
16 # This only works with older subversion. For newer versions
17 # this function will need to be fixed by someone interested
18 revision = "<unknown>"
19 try:
20 with open("%s/.svn/entries" % path) as f:
21 revision = f.readlines()[3].strip()
22 except (IOError, IndexError):
23 pass
24 return revision
25
26def base_get_metadata_git_branch(path, d):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050027 import bb.process
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028
Patrick Williamsf1e5d692016-03-30 15:21:19 -050029 try:
30 rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path)
31 except bb.process.ExecutionError:
32 rev = '<unknown>'
33 return rev.strip()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034
35def base_get_metadata_git_revision(path, d):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050036 import bb.process
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037
Patrick Williamsf1e5d692016-03-30 15:21:19 -050038 try:
39 rev, _ = bb.process.run('git rev-parse HEAD', cwd=path)
40 except bb.process.ExecutionError:
41 rev = '<unknown>'
42 return rev.strip()