utils: add common function to check out a specific git revision

Checking out a revision in the bitbake/layer repositories is something
we are doing in a few places, so add a checkout_repo() function that
does this, ensuring that we don't get tripped up by any junk files,
and avoids checking out if the repository is already at the desired
revision (thus avoiding the clean operation and e.g. preserving any
.pyc files that aren't stale and would speed things up a little). Note
that we do the clean before checking out in case there are untracked
files that are tracked in the commit we are checking out.

In addition to adding this function, change the existing code that we
use in the update script to check out a layer use the new function.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2018-04-06 23:27:00 +12:00
parent 009adcb8df
commit 7343484695
2 changed files with 26 additions and 8 deletions

View File

@ -31,8 +31,7 @@ def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout
else: else:
# Branch name # Branch name
bitbake_ref = 'origin/%s' % branch.bitbake_branch bitbake_ref = 'origin/%s' % branch.bitbake_branch
out = utils.runcmd("git checkout %s" % bitbake_ref, bitbakepath, logger=logger) utils.checkout_repo(bitbakepath, bitbake_ref, logger=logger)
out = utils.runcmd("git clean -f -x", bitbakepath, logger=logger)
# Skip sanity checks # Skip sanity checks
os.environ['BB_ENV_EXTRAWHITE'] = 'DISABLE_SANITY_CHECKS' os.environ['BB_ENV_EXTRAWHITE'] = 'DISABLE_SANITY_CHECKS'
@ -57,8 +56,7 @@ def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout
core_repodir = os.path.join(fetchdir, core_urldir) core_repodir = os.path.join(fetchdir, core_urldir)
core_layerdir = os.path.join(core_repodir, core_subdir) core_layerdir = os.path.join(core_repodir, core_subdir)
if not nocheckout: if not nocheckout:
out = utils.runcmd("git checkout origin/%s" % core_branchname, core_repodir, logger=logger) utils.checkout_repo(core_repodir, "origin/%s" % core_branchname, logger=logger)
out = utils.runcmd("git clean -f -x", core_repodir, logger=logger)
if not os.path.exists(os.path.join(core_layerdir, 'conf/bitbake.conf')): if not os.path.exists(os.path.join(core_layerdir, 'conf/bitbake.conf')):
raise RecipeParseError("conf/bitbake.conf not found in core layer %s - is subdirectory set correctly?" % core_layer.name) raise RecipeParseError("conf/bitbake.conf not found in core layer %s - is subdirectory set correctly?" % core_layer.name)
# The directory above where this script exists should contain our conf/layer.conf, # The directory above where this script exists should contain our conf/layer.conf,

View File

@ -206,14 +206,34 @@ def explode_dep_versions2(bitbakepath, deps):
import bb.utils import bb.utils
return bb.utils.explode_dep_versions2(deps) return bb.utils.explode_dep_versions2(deps)
def checkout_layer_branch(layerbranch, repodir, logger=None): def checkout_repo(repodir, commit, logger, force=False):
"""
Check out a revision in a repository, ensuring that untracked/uncommitted
files don't get in the way.
WARNING: this will throw away any untracked/uncommitted files in the repo,
so it is only suitable for use with repos where you don't care about such
things (which we don't for the layer repos that we use)
"""
if force:
currentref = ''
else:
currentref = runcmd("git rev-parse HEAD", repodir, logger=logger).strip()
if currentref != commit:
# Reset in case there are added but uncommitted changes
runcmd("git reset --hard HEAD", repodir, logger=logger)
# Drop any untracked files in case these cause problems (either because
# they will exist in the revision we're checking out, or will otherwise
# interfere with operation, e.g. stale pyc files)
runcmd("git clean -qdfx", repodir, logger=logger)
# Now check out the revision
runcmd("git checkout %s" % commit,
repodir, logger=logger)
def checkout_layer_branch(layerbranch, repodir, logger=None):
branchname = layerbranch.branch.name branchname = layerbranch.branch.name
if layerbranch.actual_branch: if layerbranch.actual_branch:
branchname = layerbranch.actual_branch branchname = layerbranch.actual_branch
checkout_repo(repodir, 'origin/%s' % branchname, logger)
out = runcmd("git checkout origin/%s" % branchname, repodir, logger=logger)
out = runcmd("git clean -f -x", repodir, logger=logger)
def is_layer_valid(layerdir): def is_layer_valid(layerdir):
conf_file = os.path.join(layerdir, "conf", "layer.conf") conf_file = os.path.join(layerdir, "conf", "layer.conf")