Bug 1047621 - Have link.py import and call expandlibs_exec.py; r=gps
authorMike Shal <mshal@mozilla.com>
Wed, 13 Aug 2014 14:24:15 -0400
changeset 199704 ff64d9bbc03cd14dcd05d94f54a0e9c14f57b787
parent 199703 552170c05e9f1a06d0ac8b6ea3485611d1ffc84b
child 199705 220144707b01344488bbf8b003bab481b667b231
push id47713
push usermshal@mozilla.com
push dateFri, 15 Aug 2014 12:41:26 +0000
treeherdermozilla-inbound@ff64d9bbc03c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1047621
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1047621 - Have link.py import and call expandlibs_exec.py; r=gps
config/expandlibs_exec.py
config/link.py
toolkit/library/Makefile.in
--- a/config/expandlibs_exec.py
+++ b/config/expandlibs_exec.py
@@ -306,46 +306,49 @@ class SectionFinder(object):
 def print_command(out, args):
     print >>out, "Executing: " + " ".join(args)
     for tmp in [f for f in args.tmp if os.path.isfile(f)]:
         print >>out, tmp + ":"
         with open(tmp) as file:
             print >>out, "".join(["    " + l for l in file.readlines()])
     out.flush()
 
-def main():
+def main(args, proc_callback=None):
     parser = OptionParser()
     parser.add_option("--extract", action="store_true", dest="extract",
         help="when a library has no descriptor file, extract it first, when possible")
     parser.add_option("--uselist", action="store_true", dest="uselist",
         help="use a list file for objects when executing a command")
     parser.add_option("--verbose", action="store_true", dest="verbose",
         help="display executed command and temporary files content")
     parser.add_option("--symbol-order", dest="symbol_order", metavar="FILE",
         help="use the given list of symbols to order symbols in the resulting binary when using with a linker")
 
-    (options, args) = parser.parse_args()
+    (options, args) = parser.parse_args(args)
 
     with ExpandArgsMore(args) as args:
         if options.extract:
             args.extract()
         if options.symbol_order:
             args.orderSymbols(options.symbol_order)
         if options.uselist:
             args.makelist()
 
         if options.verbose:
             print_command(sys.stderr, args)
         try:
             proc = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
+            if proc_callback:
+                proc_callback(proc)
         except Exception, e:
             print >>sys.stderr, 'error: Launching', args, ':', e
             raise e
         (stdout, stderr) = proc.communicate()
         if proc.returncode and not options.verbose:
             print_command(sys.stderr, args)
         sys.stderr.write(stdout)
         sys.stderr.flush()
         if proc.returncode:
-            exit(proc.returncode)
+            return proc.returncode
+        return 0
 
 if __name__ == '__main__':
-    main()
+    exit(main(sys.argv[1:]))
--- a/config/link.py
+++ b/config/link.py
@@ -1,14 +1,17 @@
 # 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/.
 
-from __future__ import with_statement
-import os, subprocess, sys, threading, time
+import expandlibs_exec
+import sys
+import threading
+import time
+
 from win32 import procmem
 
 def measure_vsize_threadfunc(proc, output_file):
     """
     Measure the virtual memory usage of |proc| at regular intervals
     until it exits, then print the maximum value and write it to
     |output_file|.  Also, print something to the console every
     half an hour to prevent the build job from getting killed when
@@ -28,26 +31,30 @@ def measure_vsize_threadfunc(proc, outpu
     with open(output_file, "w") as f:
         f.write("%d\n" % maxvsize)
 
 def measure_link_vsize(output_file, args):
     """
     Execute |args|, and measure the maximum virtual memory usage of the process,
     printing it to stdout when finished.
     """
-    proc = subprocess.Popen(args)
-    t = threading.Thread(target=measure_vsize_threadfunc,
-                         args=(proc, output_file))
-    t.start()
-    # Wait for the linker to finish.
-    exitcode = proc.wait()
-    # ...and then wait for the background thread to finish.
-    t.join()
+
+    # 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):
+        t[0] = threading.Thread(target=measure_vsize_threadfunc,
+                             args=(proc, output_file))
+        t[0].start()
+    exitcode = expandlibs_exec.main(args, proc_callback=callback)
+    # Wait for the background thread to finish.
+    t[0].join()
     return exitcode
 
 if __name__ == "__main__":
     if sys.platform != "win32":
         print >>sys.stderr, "link.py is only for use on Windows!"
         sys.exit(1)
     if len(sys.argv) < 3:
         print >>sys.stderr, "Usage: link.py <output filename> <commandline>"
         sys.exit(1)
-    sys.exit(measure_link_vsize(sys.argv[1], sys.argv[2:]))
+    output_file = sys.argv.pop(1)
+    sys.exit(measure_link_vsize(output_file, sys.argv[1:]))
--- a/toolkit/library/Makefile.in
+++ b/toolkit/library/Makefile.in
@@ -1,17 +1,19 @@
 # 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/.
 
 include $(topsrcdir)/toolkit/library/libxul.mk
 
+include $(topsrcdir)/config/config.mk
+
 ifeq (WINNT_1,$(OS_TARGET)_$(MOZ_PROFILE_USE))
 # Wrap linker to measure peak virtual memory usage.
-LD := $(PYTHON) $(topsrcdir)/config/link.py linker-vsize $(LD)
+EXPAND_LIBS_EXEC := $(PYTHON) $(topsrcdir)/config/link.py linker-vsize
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef COMPILE_ENVIRONMENT
 libs:: $(FINAL_TARGET)/dependentlibs.list
 endif