Bug 935881 - Add a FINAL_LIBRARY variable to use in moz.build. r=gps

This will be used to declare in what shared library or intermediate static
library objects are going to be linked into.
This commit is contained in:
Mike Hommey 2013-11-19 11:46:42 +09:00
parent cf857e87f3
commit 015bd905d7
8 changed files with 71 additions and 7 deletions

View File

@ -34,6 +34,7 @@ from ..frontend.data import (
InstallationTarget,
IPDLFile,
JavaJarData,
LibraryDefinition,
LocalInclude,
PreprocessedTestWebIDLFile,
PreprocessedWebIDLFile,
@ -449,6 +450,9 @@ class RecursiveMakeBackend(CommonBackend):
else:
return
elif isinstance(obj, LibraryDefinition):
self._process_library_definition(obj, backend_file)
else:
return
obj.ack()
@ -1063,6 +1067,12 @@ class RecursiveMakeBackend(CommonBackend):
backend_file.write('%s_JAVAC_FLAGS := %s\n' %
(target, ' '.join(jar.javac_flags)))
def _process_library_definition(self, libdef, backend_file):
backend_file.write('LIBRARY_NAME = %s\n' % libdef.basename)
for reldir, basename in libdef.static_libraries:
backend_file.write('SHARED_LIBRARY_LIBS += $(DEPTH)/%s/$(LIB_PREFIX)%s.$(LIB_SUFFIX)\n'
% (reldir, basename))
def _write_manifests(self, dest, manifests):
man_dir = os.path.join(self.environment.topobjdir, '_build_manifests',
dest)

View File

@ -325,6 +325,28 @@ class HostSimpleProgram(BaseProgram):
"""Sandbox container object for each program in HOST_SIMPLE_PROGRAMS"""
class LibraryDefinition(SandboxDerived):
"""Partial definition for a library
The static_libraries member tracks the list of relative directory and
library names of static libraries that are meant to be linked into
the library defined by an instance of this class.
"""
__slots__ = (
'basename',
'static_libraries',
)
def __init__(self, sandbox, basename):
SandboxDerived.__init__(self, sandbox)
self.basename = basename
self.static_libraries = []
def link_static_lib(self, reldir, basename):
self.static_libraries.append((reldir, basename))
class TestManifest(SandboxDerived):
"""Represents a manifest file containing information about tests."""

View File

@ -30,6 +30,7 @@ from .data import (
HostSimpleProgram,
InstallationTarget,
IPDLFile,
LibraryDefinition,
LocalInclude,
PreprocessedTestWebIDLFile,
PreprocessedWebIDLFile,
@ -70,6 +71,9 @@ class TreeMetadataEmitter(LoggingMixin):
else:
self.mozinfo = {}
self._libs = {}
self._final_libs = []
def emit(self, output):
"""Convert the BuildReader output into data structures.
@ -93,6 +97,21 @@ class TreeMetadataEmitter(LoggingMixin):
else:
raise Exception('Unhandled output type: %s' % out)
for reldir, libname, final_lib in self._final_libs:
if final_lib not in self._libs:
raise Exception('FINAL_LIBRARY in %s (%s) does not match any '
'LIBRARY_NAME' % (reldir, final_lib))
libs = self._libs[final_lib]
if len(libs) > 1:
raise Exception('FINAL_LIBRARY in %s (%s) matches a '
'LIBRARY_NAME defined in multiple places (%s)' %
(reldir, final_lib, ', '.join(libs.keys())))
libs.values()[0].link_static_lib(reldir, libname)
for basename, libs in self._libs.items():
for libdef in libs.values():
yield libdef
yield ReaderSummary(file_count, execution_time)
def emit_from_sandbox(self, sandbox):
@ -160,7 +179,6 @@ class TreeMetadataEmitter(LoggingMixin):
HOST_LIBRARY_NAME='HOST_LIBRARY_NAME',
IS_COMPONENT='IS_COMPONENT',
JS_MODULES_PATH='JS_MODULES_PATH',
LIBRARY_NAME='LIBRARY_NAME',
LIBS='LIBS',
LIBXUL_LIBRARY='LIBXUL_LIBRARY',
MODULE='MODULE',
@ -266,6 +284,18 @@ class TreeMetadataEmitter(LoggingMixin):
sandbox.get('DIST_SUBDIR'):
yield InstallationTarget(sandbox)
libname = sandbox.get('LIBRARY_NAME')
if libname:
self._libs.setdefault(libname, {})[sandbox['RELATIVEDIR']] = \
LibraryDefinition(sandbox, libname)
final_lib = sandbox.get('FINAL_LIBRARY')
if final_lib:
if not libname:
# For now, this is true.
raise SandboxValidationError('FINAL_LIBRARY requires LIBRARY_NAME')
self._final_libs.append((sandbox['RELATIVEDIR'], libname, final_lib))
# While there are multiple test manifests, the behavior is very similar
# across them. We enforce this by having common handling of all
# manifests and outputting a single class type with the differences

View File

@ -179,6 +179,14 @@ VARIABLES = {
files will be installed in the ``/components`` directory of the distribution.
""", 'libs'),
'FINAL_LIBRARY': (unicode, unicode, "",
"""Library in which the objects of the current directory will be linked.
This variable contains the name of a library, defined elsewhere with
``LIBRARY_NAME``, in which the objects of the current directory will be
linked.
""", 'binaries'),
'CPP_UNIT_TESTS': (StrictOrderingOnAppendList, list, [],
"""C++ source files for unit tests.

View File

@ -23,7 +23,6 @@ HOST_SOURCES += ['bar.c', 'foo.c']
HOST_LIBRARY_NAME = 'host_bar'
LIBRARY_NAME = 'lib_name'
LIBS = ['bar.lib', 'foo.lib']
OS_LIBS = ['foo.so', '-l123', 'bar.a']

View File

@ -324,9 +324,6 @@ class TestRecursiveMakeBackend(BackendTester):
'HOST_LIBRARY_NAME': [
'HOST_LIBRARY_NAME := host_bar',
],
'LIBRARY_NAME': [
'LIBRARY_NAME := lib_name',
],
'LIBXUL_LIBRARY': [
'LIBXUL_LIBRARY := 1',
],

View File

@ -23,7 +23,6 @@ HOST_SOURCES += ['fans.c', 'tans.c']
HOST_LIBRARY_NAME = 'host_fans'
LIBRARY_NAME = 'lib_name'
LIBS += ['fans.lib', 'tans.lib']
OS_LIBS += ['foo.so', '-l123', 'aaa.a']

View File

@ -156,7 +156,6 @@ class TestEmitterBasic(unittest.TestCase):
HOST_CSRCS=['fans.c', 'tans.c'],
HOST_LIBRARY_NAME='host_fans',
IS_COMPONENT=True,
LIBRARY_NAME='lib_name',
LIBS=['fans.lib', 'tans.lib'],
LIBXUL_LIBRARY=True,
MSVC_ENABLE_PGO=True,