Files
poky/meta/files/ext-sdk-prepare.py
Richard Purdie c37d5426b1 scripts, lib: Don't limit traceback lengths to arbitrary values
There appears to have been a lot of copy and pasting of the code
which prints tracebacks upon failure and limits the stack trace to
5 entries. This obscures the real error and is very confusing to the user
it look me an age to work out why some tracebacks weren't useful.

This patch removes the limit, making tracebacks much more useful for
debugging.

[YOCTO #9230]

(From OE-Core rev: 6069175e9bb97ace100bb5e99b6104d33163a3a2)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2016-03-31 23:01:36 +01:00

99 lines
2.9 KiB
Python

#!/usr/bin/env python
# Prepare the build system within the extensible SDK
import sys
import os
import subprocess
def exec_watch(cmd, **options):
"""Run program with stdout shown on sys.stdout"""
if isinstance(cmd, basestring) and not "shell" in options:
options["shell"] = True
process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **options
)
buf = ''
while True:
out = process.stdout.read(1)
if out:
sys.stdout.write(out)
sys.stdout.flush()
buf += out
elif out == '' and process.poll() != None:
break
return process.returncode, buf
def main():
if len(sys.argv) < 2:
sdk_targets = []
else:
sdk_targets = ' '.join(sys.argv[1:]).split()
if not sdk_targets:
# Just do a parse so the cache is primed
ret, _ = exec_watch('bitbake -p')
return ret
print('Preparing SDK for %s...' % ', '.join(sdk_targets))
ret, out = exec_watch('bitbake %s --setscene-only' % ' '.join(sdk_targets))
if ret:
return ret
targetlist = []
for target in sdk_targets:
if ':' in target:
target = target.split(':')[0]
if not target in targetlist:
targetlist.append(target)
recipes = []
for target in targetlist:
try:
out = subprocess.check_output(('bitbake -e %s' % target).split(), stderr=subprocess.STDOUT)
for line in out.splitlines():
if line.startswith('FILE='):
splitval = line.rstrip().split('=')
if len(splitval) > 1:
recipes.append(splitval[1].strip('"'))
break
except subprocess.CalledProcessError as e:
print('ERROR: Failed to get recipe for target %s:\n%s' % (target, e.output))
return 1
try:
out = subprocess.check_output('bitbake %s -n' % ' '.join(sdk_targets), stderr=subprocess.STDOUT, shell=True)
unexpected = []
for line in out.splitlines():
if 'Running task' in line:
for recipe in recipes:
if recipe in line:
break
else:
line = line.split('Running', 1)[-1]
unexpected.append(line.rstrip())
elif 'Running setscene' in line:
unexpected.append(line.rstrip())
except subprocess.CalledProcessError as e:
print('ERROR: Failed to execute dry-run:\n%s' % e.output)
return 1
if unexpected:
print('ERROR: Unexpected tasks or setscene left over to be executed:')
for line in unexpected:
print(' ' + line)
return 1
if __name__ == "__main__":
try:
ret = main()
except Exception:
ret = 1
import traceback
traceback.print_exc()
sys.exit(ret)