M7350/oe-core/meta/classes/metadata_scm.bbclass

83 lines
2.5 KiB
Plaintext
Raw Normal View History

2024-09-09 08:52:07 +00:00
METADATA_BRANCH ?= "${@base_detect_branch(d)}"
METADATA_REVISION ?= "${@base_detect_revision(d)}"
def base_detect_revision(d):
2024-09-09 08:57:42 +00:00
path = base_get_scmbasepath(d)
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
scms = [base_get_metadata_git_revision, \
base_get_metadata_svn_revision]
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
for scm in scms:
rev = scm(path, d)
if rev != "<unknown>":
return rev
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
return "<unknown>"
2024-09-09 08:52:07 +00:00
def base_detect_branch(d):
2024-09-09 08:57:42 +00:00
path = base_get_scmbasepath(d)
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
scms = [base_get_metadata_git_branch]
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
for scm in scms:
rev = scm(path, d)
if rev != "<unknown>":
return rev.strip()
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
return "<unknown>"
2024-09-09 08:52:07 +00:00
def base_get_scmbasepath(d):
2024-09-09 08:57:42 +00:00
return d.getVar( 'COREBASE', True)
2024-09-09 08:52:07 +00:00
def base_get_metadata_monotone_branch(path, d):
2024-09-09 08:57:42 +00:00
monotone_branch = "<unknown>"
try:
with open("%s/_MTN/options" % path) as f:
monotone_branch = f.read().strip()
if monotone_branch.startswith( "database" ):
monotone_branch_words = monotone_branch.split()
monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1]
except:
pass
return monotone_branch
2024-09-09 08:52:07 +00:00
def base_get_metadata_monotone_revision(path, d):
2024-09-09 08:57:42 +00:00
monotone_revision = "<unknown>"
try:
with open("%s/_MTN/revision" % path) as f:
monotone_revision = f.read().strip()
if monotone_revision.startswith( "format_version" ):
monotone_revision_words = monotone_revision.split()
monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1]
except IOError:
pass
return monotone_revision
2024-09-09 08:52:07 +00:00
def base_get_metadata_svn_revision(path, d):
2024-09-09 08:57:42 +00:00
# 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
2024-09-09 08:52:07 +00:00
def base_get_metadata_git_branch(path, d):
2024-09-09 08:57:42 +00:00
branch = os.popen('cd %s; git branch 2>&1 | grep "^* " | tr -d "* "' % path).read()
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
if len(branch) != 0:
return branch
return "<unknown>"
2024-09-09 08:52:07 +00:00
def base_get_metadata_git_revision(path, d):
2024-09-09 08:57:42 +00:00
f = os.popen("cd %s; git log -n 1 --pretty=oneline -- 2>&1" % path)
data = f.read()
if f.close() is None:
rev = data.split(" ")[0]
if len(rev) != 0:
return rev
return "<unknown>"
2024-09-09 08:52:07 +00:00