Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2 | |
| 3 | # Prepare the build system within the extensible SDK |
| 4 | |
| 5 | import sys |
| 6 | import os |
| 7 | import subprocess |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 8 | import signal |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 9 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 10 | def reenable_sigint(): |
| 11 | signal.signal(signal.SIGINT, signal.SIG_DFL) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 12 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 13 | def 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 24 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 25 | def 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 37 | |
| 38 | def main(): |
| 39 | if len(sys.argv) < 2: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 40 | print('Please specify output log file') |
| 41 | return 1 |
| 42 | logfile = sys.argv[1] |
| 43 | if len(sys.argv) < 3: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 44 | sdk_targets = [] |
| 45 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 46 | sdk_targets = ' '.join(sys.argv[2:]).split() |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 47 | |
| 48 | prserv = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'conf', 'prserv.inc') |
| 49 | if os.path.isfile(prserv): |
| 50 | with open(logfile, 'a') as logf: |
| 51 | logf.write('Importing PR data...\n') |
| 52 | |
| 53 | ret = run_command_interruptible('bitbake-prserv-tool import %s' % prserv) |
| 54 | |
| 55 | lastlog = get_last_consolelog() |
| 56 | if lastlog: |
| 57 | with open(lastlog, 'r') as f: |
| 58 | for line in f: |
| 59 | logf.write(line) |
| 60 | if ret: |
| 61 | print('ERROR: PR data import failed: error log written to %s' % logfile) |
| 62 | return ret |
| 63 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 64 | if not sdk_targets: |
| 65 | # Just do a parse so the cache is primed |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 66 | ret = run_command_interruptible('bitbake -p --quiet') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 67 | return ret |
| 68 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 69 | with open(logfile, 'a') as logf: |
| 70 | logf.write('Preparing SDK for %s...\n' % ', '.join(sdk_targets)) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 71 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 72 | ret = run_command_interruptible('BB_SETSCENE_ENFORCE=1 bitbake --quiet %s' % ' '.join(sdk_targets)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 73 | if not ret: |
Andrew Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 74 | ret = run_command_interruptible('bitbake --quiet build-sysroots -c build_native_sysroot && bitbake --quiet build-sysroots -c build_target_sysroot') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 75 | lastlog = get_last_consolelog() |
| 76 | if lastlog: |
| 77 | with open(lastlog, 'r') as f: |
| 78 | for line in f: |
| 79 | logf.write(line) |
| 80 | if ret: |
| 81 | print('ERROR: SDK preparation failed: error log written to %s' % logfile) |
| 82 | return ret |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 83 | |
| 84 | if __name__ == "__main__": |
| 85 | try: |
| 86 | ret = main() |
| 87 | except Exception: |
| 88 | ret = 1 |
| 89 | import traceback |
| 90 | traceback.print_exc() |
| 91 | sys.exit(ret) |