link.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. import expandlibs_exec
  5. import sys
  6. import threading
  7. import time
  8. def periodically_print_status(proc):
  9. """
  10. Print something to the console every 20 minutes to prevent the build job
  11. from getting killed when linking a large binary.
  12. Check status of the linker every 0.5 seconds.
  13. """
  14. idleTime = 0
  15. while proc.returncode is None:
  16. time.sleep(0.5)
  17. idleTime += 0.5
  18. if idleTime > 20 * 60:
  19. print "Still linking, 20 minutes passed..."
  20. sys.stdout.flush()
  21. idleTime = 0
  22. def wrap_linker(args):
  23. """
  24. Execute |args| and pass resulting |proc| object to a second thread that
  25. will track the status of the started |proc|.
  26. """
  27. # This needs to be a list in order for the callback to set the
  28. # variable properly with python-2's scoping rules.
  29. t = [None]
  30. def callback(proc):
  31. t[0] = threading.Thread(target=periodically_print_status,
  32. args=(proc,))
  33. t[0].start()
  34. exitcode = expandlibs_exec.main(args, proc_callback=callback)
  35. # Wait for the background thread to finish.
  36. t[0].join()
  37. return exitcode
  38. if __name__ == "__main__":
  39. if len(sys.argv) < 2:
  40. print >>sys.stderr, "Usage: link.py <commandline>"
  41. sys.exit(1)
  42. sys.exit(wrap_linker(sys.argv[1:]))