poky/meta/classes/metadata_scm.bbclass
Peter Kjellerstedt cfd897e213 metadata_scm.bbclass: Use immediate expansion for the METADATA_* variables
Define METADATA_BRANCH and METADATA_REVISION using immediate expansion.
This avoids running `git rev-parse HEAD` multiple times during recipe
parsing.

(From OE-Core rev: 34e1841ec14c545c73fbe03a9f946d43d65ab326)

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2021-03-14 16:33:59 +00:00

45 lines
1.3 KiB
Plaintext

def base_detect_revision(d):
path = base_get_scmbasepath(d)
return base_get_metadata_git_revision(path, d)
def base_detect_branch(d):
path = base_get_scmbasepath(d)
return base_get_metadata_git_branch(path, d)
def base_get_scmbasepath(d):
return os.path.join(d.getVar('COREBASE'), 'meta')
def base_get_metadata_svn_revision(path, d):
# This only works with older subversion. For newer versions
# this function will need to be fixed by someone interested
revision = "<unknown>"
try:
with open("%s/.svn/entries" % path) as f:
revision = f.readlines()[3].strip()
except (IOError, IndexError):
pass
return revision
def base_get_metadata_git_branch(path, d):
import bb.process
try:
rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path)
except bb.process.ExecutionError:
rev = '<unknown>'
return rev.strip()
def base_get_metadata_git_revision(path, d):
import bb.process
try:
rev, _ = bb.process.run('git rev-parse HEAD', cwd=path)
except bb.process.ExecutionError:
rev = '<unknown>'
return rev.strip()
METADATA_BRANCH := "${@base_detect_branch(d)}"
METADATA_BRANCH[vardepvalue] = "${METADATA_BRANCH}"
METADATA_REVISION := "${@base_detect_revision(d)}"
METADATA_REVISION[vardepvalue] = "${METADATA_REVISION}"