Skip to content

Commit

Permalink
Bug 1047621 - Have link.py import and call expandlibs_exec.py; r=gps …
Browse files Browse the repository at this point in the history
…a=NPOTB
  • Loading branch information
mshal committed Aug 13, 2014
1 parent 141e42c commit 6a7f702
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
13 changes: 8 additions & 5 deletions config/expandlibs_exec.py
Expand Up @@ -313,7 +313,7 @@ def print_command(out, args):
print >>out, "".join([" " + l for l in file.readlines()])
out.flush()

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")
Expand All @@ -328,7 +328,7 @@ def main():
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
Expand All @@ -351,6 +351,8 @@ def main():
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
Expand All @@ -360,9 +362,9 @@ def main():
sys.stderr.write(stdout)
sys.stderr.flush()
if proc.returncode:
exit(proc.returncode)
return proc.returncode
if not options.depend:
return
return 0
ensureParentDir(options.depend)
mk = Makefile()
deps = [dep for dep in deps if os.path.isfile(dep) and dep != options.target
Expand All @@ -374,6 +376,7 @@ def main():

with open(options.depend, 'w') as depfile:
mk.dump(depfile, removal_guard=True)
return 0

if __name__ == '__main__':
main()
exit(main(sys.argv[1:]))
29 changes: 18 additions & 11 deletions config/link.py
Expand Up @@ -2,8 +2,11 @@
# 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):
Expand Down Expand Up @@ -33,14 +36,17 @@ 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__":
Expand All @@ -50,4 +56,5 @@ def measure_link_vsize(output_file, args):
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:]))
4 changes: 3 additions & 1 deletion toolkit/library/build/Makefile.in
Expand Up @@ -4,9 +4,11 @@

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 $(DEPTH)/toolkit/library/linker-vsize $(LD)
EXPAND_LIBS_EXEC := $(PYTHON) $(topsrcdir)/config/link.py $(DEPTH)/toolkit/library/linker-vsize
endif

ifneq (,$(filter WINNT,$(OS_ARCH)))
Expand Down

0 comments on commit 6a7f702

Please sign in to comment.