1METADATA_BRANCH ?= "${@base_detect_branch(d)}"
2METADATA_REVISION ?= "${@base_detect_revision(d)}"
3
4def base_detect_revision(d):
5    path = base_get_scmbasepath(d)
6    return base_get_metadata_git_revision(path, d)
7
8def base_detect_branch(d):
9    path = base_get_scmbasepath(d)
10    return base_get_metadata_git_branch(path, d)
11
12def base_get_scmbasepath(d):
13    return os.path.join(d.getVar('COREBASE'), 'meta')
14
15def 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):
27    import bb.process
28
29    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()
34
35def base_get_metadata_git_revision(path, d):
36    import bb.process
37
38    try:
39        rev, _ = bb.process.run('git rev-parse HEAD', cwd=path)
40    except bb.process.ExecutionError:
41        rev = '<unknown>'
42    return rev.strip()
43