From ba85bb605502a86fa83bd7a0f3d8ed644dc16a8c Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Thu, 9 Jun 2022 11:23:30 +0100 Subject: classes/buildcfg: Move git/layer revision code into new OE module buildcfg There is a load of duplicated git/layer/revision code which makes most sesne as a python library, not bbclass code. Start to refactor as such. (From OE-Core rev: 439cdf8a1e52fd2c4dc81dc40ce7e6af282ce7ac) Signed-off-by: Richard Purdie --- meta/lib/oe/buildcfg.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 meta/lib/oe/buildcfg.py (limited to 'meta/lib/oe') diff --git a/meta/lib/oe/buildcfg.py b/meta/lib/oe/buildcfg.py new file mode 100644 index 0000000000..a749fc5303 --- /dev/null +++ b/meta/lib/oe/buildcfg.py @@ -0,0 +1,40 @@ + +import subprocess +import bb.process + +def detect_revision(d): + path = get_scmbasepath(d) + return get_metadata_git_revision(path, d) + +def detect_branch(d): + path = get_scmbasepath(d) + return get_metadata_git_branch(path, d) + +def get_scmbasepath(d): + return os.path.join(d.getVar('COREBASE'), 'meta') + +def 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 = "" + try: + with open("%s/.svn/entries" % path) as f: + revision = f.readlines()[3].strip() + except (IOError, IndexError): + pass + return revision + +def get_metadata_git_branch(path, d): + try: + rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path) + except bb.process.ExecutionError: + rev = '' + return rev.strip() + +def get_metadata_git_revision(path, d): + try: + rev, _ = bb.process.run('git rev-parse HEAD', cwd=path) + except bb.process.ExecutionError: + rev = '' + return rev.strip() + -- cgit v1.2.3-54-g00ecf