2012-05-21 15:12:37 +04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2012-05-01 20:09:44 +04:00
|
|
|
|
2014-08-13 22:24:15 +04:00
|
|
|
import expandlibs_exec
|
|
|
|
import sys
|
|
|
|
import threading
|
|
|
|
import time
|
|
|
|
|
2016-09-21 03:58:34 +03:00
|
|
|
def periodically_print_status(proc):
|
2012-05-01 20:09:44 +04:00
|
|
|
"""
|
2016-09-21 03:58:34 +03:00
|
|
|
Print something to the console every 20 minutes to prevent the build job
|
|
|
|
from getting killed when linking a large binary.
|
|
|
|
Check status of the linker every 0.5 seconds.
|
2012-05-01 20:09:44 +04:00
|
|
|
"""
|
2013-09-27 00:54:48 +04:00
|
|
|
idleTime = 0
|
2012-05-01 20:09:44 +04:00
|
|
|
while proc.returncode is None:
|
|
|
|
time.sleep(0.5)
|
2013-09-27 00:54:48 +04:00
|
|
|
idleTime += 0.5
|
2016-09-21 03:58:34 +03:00
|
|
|
if idleTime > 20 * 60:
|
|
|
|
print "Still linking, 20 minutes passed..."
|
2013-09-27 00:54:48 +04:00
|
|
|
sys.stdout.flush()
|
|
|
|
idleTime = 0
|
2012-05-01 20:09:44 +04:00
|
|
|
|
2016-09-21 03:58:34 +03:00
|
|
|
def wrap_linker(args):
|
2012-05-01 20:09:44 +04:00
|
|
|
"""
|
2016-09-21 03:58:34 +03:00
|
|
|
Execute |args| and pass resulting |proc| object to a second thread that
|
|
|
|
will track the status of the started |proc|.
|
2012-05-01 20:09:44 +04:00
|
|
|
"""
|
2014-08-13 22:24:15 +04:00
|
|
|
|
|
|
|
# This needs to be a list in order for the callback to set the
|
|
|
|
# variable properly with python-2's scoping rules.
|
|
|
|
t = [None]
|
|
|
|
def callback(proc):
|
2016-09-21 03:58:34 +03:00
|
|
|
t[0] = threading.Thread(target=periodically_print_status,
|
|
|
|
args=(proc,))
|
2014-08-13 22:24:15 +04:00
|
|
|
t[0].start()
|
|
|
|
exitcode = expandlibs_exec.main(args, proc_callback=callback)
|
|
|
|
# Wait for the background thread to finish.
|
|
|
|
t[0].join()
|
2012-05-01 20:09:44 +04:00
|
|
|
return exitcode
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2016-09-21 03:58:34 +03:00
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print >>sys.stderr, "Usage: link.py <commandline>"
|
2012-05-01 20:09:44 +04:00
|
|
|
sys.exit(1)
|
2016-09-21 03:58:34 +03:00
|
|
|
sys.exit(wrap_linker(sys.argv[1:]))
|