blob: 47cb969b8d8111908093fd328c2c22b30f6719a3 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001def base_detect_revision(d):
2 path = base_get_scmbasepath(d)
Brad Bishop19323692019-04-05 15:28:33 -04003 return base_get_metadata_git_revision(path, d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004
5def base_detect_branch(d):
6 path = base_get_scmbasepath(d)
Brad Bishop19323692019-04-05 15:28:33 -04007 return base_get_metadata_git_branch(path, d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008
9def base_get_scmbasepath(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010 return os.path.join(d.getVar('COREBASE'), 'meta')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012def base_get_metadata_svn_revision(path, d):
13 # This only works with older subversion. For newer versions
14 # this function will need to be fixed by someone interested
15 revision = "<unknown>"
16 try:
17 with open("%s/.svn/entries" % path) as f:
18 revision = f.readlines()[3].strip()
19 except (IOError, IndexError):
20 pass
21 return revision
22
23def base_get_metadata_git_branch(path, d):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050024 import bb.process
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025
Patrick Williamsf1e5d692016-03-30 15:21:19 -050026 try:
27 rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path)
28 except bb.process.ExecutionError:
29 rev = '<unknown>'
30 return rev.strip()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031
32def base_get_metadata_git_revision(path, d):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050033 import bb.process
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034
Patrick Williamsf1e5d692016-03-30 15:21:19 -050035 try:
36 rev, _ = bb.process.run('git rev-parse HEAD', cwd=path)
37 except bb.process.ExecutionError:
38 rev = '<unknown>'
39 return rev.strip()
Andrew Geissler95ac1b82021-03-31 14:34:31 -050040
41METADATA_BRANCH := "${@base_detect_branch(d)}"
42METADATA_BRANCH[vardepvalue] = "${METADATA_BRANCH}"
43METADATA_REVISION := "${@base_detect_revision(d)}"
44METADATA_REVISION[vardepvalue] = "${METADATA_REVISION}"