blob: 78c1d163047c7d234e9f6e8d60f29a74c055fe36 [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001#!/usr/bin/env python
2
3# Prepare the build system within the extensible SDK
4
5import sys
6import os
7import subprocess
Patrick Williamsc0f7c042017-02-23 20:41:17 -06008import signal
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05009
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010def reenable_sigint():
11 signal.signal(signal.SIGINT, signal.SIG_DFL)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050012
Patrick Williamsc0f7c042017-02-23 20:41:17 -060013def run_command_interruptible(cmd):
14 """
15 Run a command with output displayed on the console, but ensure any Ctrl+C is
16 processed only by the child process.
17 """
18 signal.signal(signal.SIGINT, signal.SIG_IGN)
19 try:
20 ret = subprocess.call(cmd, shell=True, preexec_fn=reenable_sigint)
21 finally:
22 signal.signal(signal.SIGINT, signal.SIG_DFL)
23 return ret
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050024
Patrick Williamsc0f7c042017-02-23 20:41:17 -060025def get_last_consolelog():
26 '''Return the most recent console log file'''
27 logdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'tmp', 'log', 'cooker')
28 if os.path.exists(logdir):
29 mcdir = os.listdir(logdir)
30 if mcdir:
31 logdir = os.path.join(logdir, mcdir[0])
32 logfiles = [os.path.join(logdir, fn) for fn in os.listdir(logdir)]
33 logfiles.sort(key=os.path.getmtime)
34 if logfiles:
35 return os.path.join(logdir, logfiles[-1])
36 return None
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050037
38def main():
39 if len(sys.argv) < 2:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060040 print('Please specify output log file')
41 return 1
42 logfile = sys.argv[1]
43 if len(sys.argv) < 3:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050044 sdk_targets = []
45 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060046 sdk_targets = ' '.join(sys.argv[2:]).split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050047 if not sdk_targets:
48 # Just do a parse so the cache is primed
Patrick Williamsc0f7c042017-02-23 20:41:17 -060049 ret = run_command_interruptible('bitbake -p --quiet')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050050 return ret
51
Patrick Williamsc0f7c042017-02-23 20:41:17 -060052 with open(logfile, 'a') as logf:
53 logf.write('Preparing SDK for %s...\n' % ', '.join(sdk_targets))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050054
Patrick Williamsc0f7c042017-02-23 20:41:17 -060055 ret = run_command_interruptible('BB_SETSCENE_ENFORCE=1 bitbake --quiet %s' % ' '.join(sdk_targets))
56 lastlog = get_last_consolelog()
57 if lastlog:
58 with open(lastlog, 'r') as f:
59 for line in f:
60 logf.write(line)
61 if ret:
62 print('ERROR: SDK preparation failed: error log written to %s' % logfile)
63 return ret
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050064
65if __name__ == "__main__":
66 try:
67 ret = main()
68 except Exception:
69 ret = 1
70 import traceback
71 traceback.print_exc()
72 sys.exit(ret)