Bug 1047621 - Have link.py import and call expandlibs_exec.py; r=gps a=NPOTB
authorMike Shal <mshal@mozilla.com>
Wed, 13 Aug 2014 14:24:15 -0400
changeset 217543 0313315936fea1154fa5a3912a23a9a5bfe03827
parent 217542 0569cf7f29cd66d151fb671838936f23df70f4f1
child 217544 71a901b41f4c85d63f8d8fbf314d2e2cce4da39e
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps, NPOTB
Bug 1047621 - Have link.py import and call expandlibs_exec.py; r=gps a=NPOTB
--- a/config/expandlibs_exec.py
+++ b/config/expandlibs_exec.py
@@ -308,32 +308,32 @@ 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()])
-def main():
+def main(args, proc_callback=None):
     parser = OptionParser()
     parser.add_option("--depend", dest="depend", metavar="FILE",
         help="generate dependencies for the given execution and store it in the given file")
     parser.add_option("--target", dest="target", metavar="FILE",
         help="designate the target for dependencies")
     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)
     if not options.target:
         options.depend = False
     if options.depend:
         deps = ExpandLibsDeps(args)
         # Filter out common command wrappers
         while os.path.basename(deps[0]) in ['ccache', 'distcc']:
@@ -346,34 +346,37 @@ def main():
         if options.uselist:
         if options.verbose:
             print_command(sys.stderr, args)
             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)
         if proc.returncode:
-            exit(proc.returncode)
+            return proc.returncode
     if not options.depend:
-        return
+        return 0
     mk = Makefile()
     deps = [dep for dep in deps if os.path.isfile(dep) and dep != options.target
             and os.path.abspath(dep) != os.path.abspath(options.depend)]
     no_dynamic_lib = [dep for dep in deps if not isDynamicLib(dep)]
     if len(deps) != len(no_dynamic_lib):
         mk.create_rule(['%s_order_only' % options.target]).add_dependencies(dep for dep in deps if isDynamicLib(dep))
     with open(options.depend, 'w') as depfile:
         mk.dump(depfile, removal_guard=True)
+    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!"
     if len(sys.argv) < 3:
         print >>sys.stderr, "Usage: link.py <output filename> <commandline>"
-    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/build/Makefile.in
+++ b/toolkit/library/build/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
 # Wrap linker to measure peak virtual memory usage.
-LD := $(PYTHON) $(topsrcdir)/config/link.py $(DEPTH)/toolkit/library/linker-vsize $(LD)
+EXPAND_LIBS_EXEC := $(PYTHON) $(topsrcdir)/config/link.py $(DEPTH)/toolkit/library/linker-vsize
 ifneq (,$(filter WINNT,$(OS_ARCH)))