Ensure logger is passed into runcmd function or use sys.stderr.write

Otherwise it might not be defined when an error.needs to be printed.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2013-07-28 18:19:02 +01:00
parent 1eebd6e525
commit 93ce26f21c
4 changed files with 23 additions and 18 deletions

View File

@ -43,11 +43,11 @@ def _parse_layer_conf(layerdir, data):
data.expandVarref('LAYERDIR')
def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout=False, classic=False):
def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout=False, classic=False, logger=None):
if not (nocheckout or classic):
# Check out the branch of BitBake appropriate for this branch and clean out any stale files (e.g. *.pyc)
out = utils.runcmd("git checkout origin/%s" % branch.bitbake_branch, bitbakepath)
out = utils.runcmd("git clean -f -x", bitbakepath)
out = utils.runcmd("git checkout origin/%s" % branch.bitbake_branch, bitbakepath, logger=logger)
out = utils.runcmd("git clean -f -x", bitbakepath, logger=logger)
# Skip sanity checks
os.environ['BB_ENV_EXTRAWHITE'] = 'DISABLE_SANITY_CHECKS'
@ -72,8 +72,8 @@ def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout
core_repodir = os.path.join(fetchdir, core_urldir)
core_layerdir = os.path.join(core_repodir, core_subdir)
if not nocheckout:
out = utils.runcmd("git checkout origin/%s" % core_branchname, core_repodir)
out = utils.runcmd("git clean -f -x", core_repodir)
out = utils.runcmd("git checkout origin/%s" % core_branchname, core_repodir, logger=logger)
out = utils.runcmd("git clean -f -x", core_repodir, logger=logger)
# The directory above where this script exists should contain our conf/layer.conf,
# so add it to BBPATH along with the core layer directory
confparentdir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
@ -94,13 +94,13 @@ def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout
return (tinfoil, tempdir)
def checkout_layer_branch(layerbranch, repodir):
def checkout_layer_branch(layerbranch, repodir, logger=None):
if layerbranch.actual_branch:
branchname = layerbranch.actual_branch
else:
branchname = layerbranch.branch.name
out = utils.runcmd("git checkout origin/%s" % branchname, repodir)
out = utils.runcmd("git clean -f -x", repodir)
out = utils.runcmd("git checkout origin/%s" % branchname, repodir, logger=logger)
out = utils.runcmd("git clean -f -x", repodir, logger=logger)
def setup_layer(config_data, fetchdir, layerdir, layer, layerbranch):
# Parse layer.conf files for this layer and its dependencies

View File

@ -139,7 +139,7 @@ def main():
confparentdir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../oe-classic'))
os.environ['BBPATH'] = str("%s:%s" % (confparentdir, oeclassicpath))
try:
(tinfoil, tempdir) = recipeparse.init_parser(settings, branch, bitbakepath, nocheckout=True, classic=True)
(tinfoil, tempdir) = recipeparse.init_parser(settings, branch, bitbakepath, nocheckout=True, classic=True, logger=logger)
except recipeparse.RecipeParseError as e:
logger.error(str(e))
sys.exit(1)

View File

@ -193,9 +193,9 @@ def main():
out = None
try:
if not os.path.exists(repodir):
out = utils.runcmd("git clone %s %s" % (layer.vcs_url, urldir), fetchdir)
out = utils.runcmd("git clone %s %s" % (layer.vcs_url, urldir), fetchdir, logger=logger)
else:
out = utils.runcmd("git fetch", repodir)
out = utils.runcmd("git fetch", repodir, logger=logger)
except Exception as e:
logger.error("Fetch of layer %s failed: %s" % (layer.name, str(e)))
failedrepos.append(layer.vcs_url)
@ -208,12 +208,12 @@ def main():
logger.info("Fetching bitbake from remote repository %s" % settings.BITBAKE_REPO_URL)
if not os.path.exists(bitbakepath):
out = utils.runcmd("git clone %s %s" % (settings.BITBAKE_REPO_URL, 'bitbake'), fetchdir)
out = utils.runcmd("git clone %s %s" % (settings.BITBAKE_REPO_URL, 'bitbake'), fetchdir, logger=logger)
else:
out = utils.runcmd("git fetch", bitbakepath)
out = utils.runcmd("git fetch", bitbakepath, logger=logger)
try:
(tinfoil, tempdir) = recipeparse.init_parser(settings, branch, bitbakepath, nocheckout=options.nocheckout)
(tinfoil, tempdir) = recipeparse.init_parser(settings, branch, bitbakepath, nocheckout=options.nocheckout, logger=logger)
except recipeparse.RecipeParseError as e:
logger.error(str(e))
sys.exit(1)
@ -299,8 +299,8 @@ def main():
if layerbranch.vcs_last_rev != topcommit.hexsha or options.reload:
# Check out appropriate branch
if not options.nocheckout:
out = utils.runcmd("git checkout origin/%s" % branchname, repodir)
out = utils.runcmd("git clean -f -x", repodir)
out = utils.runcmd("git checkout origin/%s" % branchname, repodir, logger=logger)
out = utils.runcmd("git clean -f -x", repodir, logger=logger)
if not os.path.exists(layerdir):
if options.branch == 'master':

View File

@ -26,7 +26,7 @@ def get_layer(layername):
return res[0]
return None
def runcmd(cmd, destdir=None, printerr=True):
def runcmd(cmd, destdir=None, printerr=True, logger=None):
"""
execute command, raise CalledProcessError if fail
return output if succeed
@ -38,7 +38,12 @@ def runcmd(cmd, destdir=None, printerr=True):
except subprocess.CalledProcessError,e:
out.seek(0)
if printerr:
logger.error("%s" % out.read())
output = out.read()
if logger:
logger.error("%s" % output)
else:
sys.stderr.write("%s\n" % output)
e.output = output
raise e
out.seek(0)