ext-sdk-prepare.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env python
  2. # Prepare the build system within the extensible SDK
  3. import sys
  4. import os
  5. import subprocess
  6. import signal
  7. def reenable_sigint():
  8. signal.signal(signal.SIGINT, signal.SIG_DFL)
  9. def run_command_interruptible(cmd):
  10. """
  11. Run a command with output displayed on the console, but ensure any Ctrl+C is
  12. processed only by the child process.
  13. """
  14. signal.signal(signal.SIGINT, signal.SIG_IGN)
  15. try:
  16. ret = subprocess.call(cmd, shell=True, preexec_fn=reenable_sigint)
  17. finally:
  18. signal.signal(signal.SIGINT, signal.SIG_DFL)
  19. return ret
  20. def get_last_consolelog():
  21. '''Return the most recent console log file'''
  22. logdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'tmp', 'log', 'cooker')
  23. if os.path.exists(logdir):
  24. mcdir = os.listdir(logdir)
  25. if mcdir:
  26. logdir = os.path.join(logdir, mcdir[0])
  27. logfiles = [os.path.join(logdir, fn) for fn in os.listdir(logdir)]
  28. logfiles.sort(key=os.path.getmtime)
  29. if logfiles:
  30. return os.path.join(logdir, logfiles[-1])
  31. return None
  32. def main():
  33. if len(sys.argv) < 2:
  34. print('Please specify output log file')
  35. return 1
  36. logfile = sys.argv[1]
  37. if len(sys.argv) < 3:
  38. sdk_targets = []
  39. else:
  40. sdk_targets = ' '.join(sys.argv[2:]).split()
  41. if not sdk_targets:
  42. # Just do a parse so the cache is primed
  43. ret = run_command_interruptible('bitbake -p --quiet')
  44. return ret
  45. with open(logfile, 'a') as logf:
  46. logf.write('Preparing SDK for %s...\n' % ', '.join(sdk_targets))
  47. ret = run_command_interruptible('BB_SETSCENE_ENFORCE=1 bitbake --quiet %s' % ' '.join(sdk_targets))
  48. if not ret:
  49. ret = run_command_interruptible('bitbake --quiet build-sysroots')
  50. lastlog = get_last_consolelog()
  51. if lastlog:
  52. with open(lastlog, 'r') as f:
  53. for line in f:
  54. logf.write(line)
  55. if ret:
  56. print('ERROR: SDK preparation failed: error log written to %s' % logfile)
  57. return ret
  58. if __name__ == "__main__":
  59. try:
  60. ret = main()
  61. except Exception:
  62. ret = 1
  63. import traceback
  64. traceback.print_exc()
  65. sys.exit(ret)