blob: 163d5e9912ef16c90a6b284031304795a1cc4d89 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/usr/bin/env python3
2
3# Prepare the build system within the extensible SDK
4
5import sys
6import os
7import subprocess
8import signal
9
10def reenable_sigint():
11 signal.signal(signal.SIGINT, signal.SIG_DFL)
12
13def 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
24
25def 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
37
38def main():
39 if len(sys.argv) < 2:
40 print('Please specify output log file')
41 return 1
42 logfile = sys.argv[1]
43 if len(sys.argv) < 3:
44 sdk_targets = []
45 else:
46 sdk_targets = ' '.join(sys.argv[2:]).split()
47 if not sdk_targets:
48 # Just do a parse so the cache is primed
49 ret = run_command_interruptible('bitbake -p --quiet')
50 return ret
51
52 with open(logfile, 'a') as logf:
53 logf.write('Preparing SDK for %s...\n' % ', '.join(sdk_targets))
54
55 ret = run_command_interruptible('BB_SETSCENE_ENFORCE=1 bitbake --quiet %s' % ' '.join(sdk_targets))
56 if not ret:
57 ret = run_command_interruptible('bitbake --quiet build-sysroots')
58 lastlog = get_last_consolelog()
59 if lastlog:
60 with open(lastlog, 'r') as f:
61 for line in f:
62 logf.write(line)
63 if ret:
64 print('ERROR: SDK preparation failed: error log written to %s' % logfile)
65 return ret
66
67if __name__ == "__main__":
68 try:
69 ret = main()
70 except Exception:
71 ret = 1
72 import traceback
73 traceback.print_exc()
74 sys.exit(ret)