diff options
Diffstat (limited to 'import-layers/yocto-poky/meta/files/ext-sdk-prepare.py')
-rw-r--r-- | import-layers/yocto-poky/meta/files/ext-sdk-prepare.py | 117 |
1 files changed, 43 insertions, 74 deletions
diff --git a/import-layers/yocto-poky/meta/files/ext-sdk-prepare.py b/import-layers/yocto-poky/meta/files/ext-sdk-prepare.py index 605e2ebefa..78c1d16304 100644 --- a/import-layers/yocto-poky/meta/files/ext-sdk-prepare.py +++ b/import-layers/yocto-poky/meta/files/ext-sdk-prepare.py @@ -5,93 +5,62 @@ import sys import os import subprocess +import signal -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 +def reenable_sigint(): + signal.signal(signal.SIGINT, signal.SIG_DFL) - 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 run_command_interruptible(cmd): + """ + Run a command with output displayed on the console, but ensure any Ctrl+C is + processed only by the child process. + """ + signal.signal(signal.SIGINT, signal.SIG_IGN) + try: + ret = subprocess.call(cmd, shell=True, preexec_fn=reenable_sigint) + finally: + signal.signal(signal.SIGINT, signal.SIG_DFL) + return ret -def check_unexpected(lines, recipes): - """Check for unexpected output lines from dry run""" - unexpected = [] - for line in lines.splitlines(): - if 'Running task' in line: - for recipe in recipes: - if recipe in line: - break - else: - line = line.split('Running', 1)[-1] - if 'do_rm_work' not in line: - unexpected.append(line.rstrip()) - elif 'Running setscene' in line: - unexpected.append(line.rstrip()) - return unexpected +def get_last_consolelog(): + '''Return the most recent console log file''' + logdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'tmp', 'log', 'cooker') + if os.path.exists(logdir): + mcdir = os.listdir(logdir) + if mcdir: + logdir = os.path.join(logdir, mcdir[0]) + logfiles = [os.path.join(logdir, fn) for fn in os.listdir(logdir)] + logfiles.sort(key=os.path.getmtime) + if logfiles: + return os.path.join(logdir, logfiles[-1]) + return None def main(): if len(sys.argv) < 2: + print('Please specify output log file') + return 1 + logfile = sys.argv[1] + if len(sys.argv) < 3: sdk_targets = [] else: - sdk_targets = ' '.join(sys.argv[1:]).split() + sdk_targets = ' '.join(sys.argv[2:]).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: + ret = run_command_interruptible('bitbake -p --quiet') 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 = check_unexpected(out, recipes) - except subprocess.CalledProcessError as e: - print('ERROR: Failed to execute dry-run:\n%s' % e.output) - return 1 + with open(logfile, 'a') as logf: + logf.write('Preparing SDK for %s...\n' % ', '.join(sdk_targets)) - if unexpected: - print('ERROR: Unexpected tasks or setscene left over to be executed:') - for line in unexpected: - print(' ' + line) - return 1 + ret = run_command_interruptible('BB_SETSCENE_ENFORCE=1 bitbake --quiet %s' % ' '.join(sdk_targets)) + lastlog = get_last_consolelog() + if lastlog: + with open(lastlog, 'r') as f: + for line in f: + logf.write(line) + if ret: + print('ERROR: SDK preparation failed: error log written to %s' % logfile) + return ret if __name__ == "__main__": try: |