Bug 1254115 - Move dependentlibs.py invocation to moz.build; r?ted
MozReview-Commit-ID: D8NF03tNuTX
--- a/toolkit/library/Makefile.in
+++ b/toolkit/library/Makefile.in
@@ -8,18 +8,11 @@ include $(topsrcdir)/config/config.mk
ifeq (WINNT_1,$(OS_TARGET)_$(MOZ_PROFILE_USE))
# Wrap linker to measure peak virtual memory usage.
EXPAND_LIBS_EXEC := $(PYTHON) $(topsrcdir)/config/link.py linker-vsize
endif
include $(topsrcdir)/config/rules.mk
-ifdef COMPILE_ENVIRONMENT
-target:: $(FINAL_TARGET)/dependentlibs.list
-endif
-
-$(FINAL_TARGET)/dependentlibs.list: $(topsrcdir)/toolkit/library/dependentlibs.py $(SHARED_LIBRARY) $(wildcard $(if $(wildcard $(FINAL_TARGET)/dependentlibs.list),$(addprefix $(FINAL_TARGET)/,$(shell cat $(FINAL_TARGET)/dependentlibs.list))))
- $(PYTHON) $< $(SHARED_LIBRARY) -L $(FINAL_TARGET) $(if $(TOOLCHAIN_PREFIX),$(addprefix -p ,$(TOOLCHAIN_PREFIX))) > $@
-
.PHONY: gtestxul
gtestxul:
$(MAKE) -C $(DEPTH) toolkit/library/gtest/target LINK_GTEST=1
--- a/toolkit/library/dependentlibs.py
+++ b/toolkit/library/dependentlibs.py
@@ -1,31 +1,28 @@
# 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/.
'''Given a library, dependentlibs.py prints the list of libraries it depends
upon that are in the same directory, followed by the library itself.
'''
-from optparse import OptionParser
import os
import re
-import fnmatch
import subprocess
import sys
+import mozpack.path as mozpath
from mozpack.executables import (
get_type,
ELF,
MACHO,
)
from buildconfig import substs
-TOOLCHAIN_PREFIX = ''
-
def dependentlibs_dumpbin(lib):
'''Returns the list of dependencies declared in the given DLL'''
try:
proc = subprocess.Popen(['dumpbin', '-dependents', lib], stdout = subprocess.PIPE)
except OSError:
# dumpbin is missing, probably mingw compilation. Try using objdump.
return dependentlibs_mingw_objdump(lib)
deps = []
@@ -49,17 +46,17 @@ def dependentlibs_mingw_objdump(lib):
match = re.match('\tDLL Name: (\S+)', line)
if match:
deps.append(match.group(1))
proc.wait()
return deps
def dependentlibs_readelf(lib):
'''Returns the list of dependencies declared in the given ELF .so'''
- proc = subprocess.Popen([TOOLCHAIN_PREFIX + 'readelf', '-d', lib], stdout = subprocess.PIPE)
+ proc = subprocess.Popen([substs.get('TOOLCHAIN_PREFIX', '') + 'readelf', '-d', lib], stdout = subprocess.PIPE)
deps = []
for line in proc.stdout:
# Each line has the following format:
# tag (TYPE) value
# Looking for NEEDED type entries
tmp = line.split(' ', 3)
if len(tmp) > 3 and tmp[2] == '(NEEDED)':
# NEEDED lines look like:
@@ -103,38 +100,36 @@ def dependentlibs(lib, libpaths, func):
for dir in libpaths:
deppath = os.path.join(dir, dep)
if os.path.exists(deppath):
deps.extend([d for d in dependentlibs(deppath, libpaths, func) if not d in deps])
# Black list the ICU data DLL because preloading it at startup
# leads to startup performance problems because of its excessive
# size (around 10MB).
if not dep.startswith("icu"):
- deps.append(dep)
+ deps.append(deppath)
break
return deps
-def main():
- parser = OptionParser()
- parser.add_option("-L", dest="libpaths", action="append", metavar="PATH", help="Add the given path to the library search path")
- parser.add_option("-p", dest="toolchain_prefix", metavar="PREFIX", help="Use the given prefix to readelf")
- (options, args) = parser.parse_args()
- if options.toolchain_prefix:
- global TOOLCHAIN_PREFIX
- TOOLCHAIN_PREFIX = options.toolchain_prefix
- lib = args[0]
+def gen_list(output, lib):
+ libpaths = [os.path.join(substs['DIST'], 'bin')]
binary_type = get_type(lib)
if binary_type == ELF:
func = dependentlibs_readelf
elif binary_type == MACHO:
func = dependentlibs_otool
else:
ext = os.path.splitext(lib)[1]
assert(ext == '.dll')
func = dependentlibs_dumpbin
- if not options.libpaths:
- options.libpaths = [os.path.dirname(lib)]
- print '\n'.join(dependentlibs(lib, options.libpaths, func) + [lib])
+ deps = dependentlibs(lib, libpaths, func)
+ deps.append(mozpath.join(libpaths[0], lib))
+ dependentlibs_output = [mozpath.basename(f) for f in deps]
+ output.write('\n'.join(dependentlibs_output) + '\n')
+ return set(deps)
+
+def main():
+ gen_list(sys.stdout, sys.argv[1])
if __name__ == '__main__':
main()
--- a/toolkit/library/moz.build
+++ b/toolkit/library/moz.build
@@ -358,10 +358,26 @@ if CONFIG['OS_ARCH'] == 'WINNT':
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
OS_LIBS += [
'usp10',
'oleaut32',
]
+if CONFIG['COMPILE_ENVIRONMENT']:
+ if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('cocoa', 'uikit'):
+ full_libname = SHARED_LIBRARY_NAME
+ else:
+ full_libname = '%s%s%s' % (
+ CONFIG['DLL_PREFIX'],
+ LIBRARY_NAME,
+ CONFIG['DLL_SUFFIX']
+ )
+ GENERATED_FILES += ['dependentlibs.list']
+ GENERATED_FILES['dependentlibs.list'].script = 'dependentlibs.py:gen_list'
+ GENERATED_FILES['dependentlibs.list'].inputs = [
+ '!%s' % full_libname,
+ ]
+ FINAL_TARGET_FILES += ['!dependentlibs.list']
+
# This needs to be last
USE_LIBS += ['StaticXULComponentsEnd']