bug 1198226 - Add HOST_{CFLAGS,CXXFLAGS,DEFINES} support to mozbuild frontend+recursive make backend. r=mshal

--HG--
rename : python/mozbuild/mozbuild/test/backend/data/defines/moz.build => python/mozbuild/mozbuild/test/backend/data/host-defines/moz.build
rename : python/mozbuild/mozbuild/test/frontend/data/defines/moz.build => python/mozbuild/mozbuild/test/frontend/data/host-defines/moz.build
extra : commitid : BqqF9IWK2hy
extra : rebase_source : 4beab63be2ffca5c0a43cd14039ffeb259ea74fe
This commit is contained in:
Ted Mielczarek 2015-09-04 13:33:04 -04:00
Родитель f6da15111c
Коммит 15063c8111
11 изменённых файлов: 122 добавлений и 6 удалений

Просмотреть файл

@ -428,6 +428,9 @@ ifndef CROSS_COMPILE
HOST_CFLAGS += $(RTL_FLAGS)
endif
HOST_CFLAGS += $(HOST_DEFINES) $(MOZBUILD_HOST_CFLAGS)
HOST_CXXFLAGS += $(HOST_DEFINES) $(MOZBUILD_HOST_CXXFLAGS)
#
# Name of the binary code directories
#

Просмотреть файл

@ -44,6 +44,7 @@ from ..frontend.data import (
GeneratedFile,
GeneratedInclude,
GeneratedSources,
HostDefines,
HostLibrary,
HostProgram,
HostSimpleProgram,
@ -504,7 +505,8 @@ class RecursiveMakeBackend(CommonBackend):
backend_file.write('%s := 1\n' % k)
else:
backend_file.write('%s := %s\n' % (k, v))
elif isinstance(obj, HostDefines):
self._process_defines(obj, backend_file, which='HOST_DEFINES')
elif isinstance(obj, Defines):
self._process_defines(obj, backend_file)
@ -945,11 +947,11 @@ class RecursiveMakeBackend(CommonBackend):
dest = mozpath.join(namespace, path, mozpath.basename(s))
yield source, dest, strings.flags_for(s)
def _process_defines(self, obj, backend_file):
def _process_defines(self, obj, backend_file, which='DEFINES'):
"""Output the DEFINES rules to the given backend file."""
defines = list(obj.get_defines())
if defines:
backend_file.write('DEFINES +=')
backend_file.write(which + ' +=')
for define in defines:
backend_file.write(' %s' % define)
backend_file.write('\n')

Просмотреть файл

@ -1519,6 +1519,11 @@ VARIABLES = {
appear in the moz.build file.
""", None),
'HOST_DEFINES': (OrderedDict, dict,
"""Dictionary of compiler defines to declare for host compilation.
See ``DEFINES`` for specifics.
""", None),
'CMFLAGS': (List, list,
"""Flags passed to the Objective-C compiler for all of the Objective-C
source files declared in this directory.
@ -1546,6 +1551,24 @@ VARIABLES = {
appear in the moz.build file.
""", None),
'HOST_CFLAGS': (List, list,
"""Flags passed to the host C compiler for all of the C source files
declared in this directory.
Note that the ordering of flags matters here, these flags will be
added to the compiler's command line in the same order as they
appear in the moz.build file.
""", None),
'HOST_CXXFLAGS': (List, list,
"""Flags passed to the host C++ compiler for all of the C++ source files
declared in this directory.
Note that the ordering of flags matters here; these flags will be
added to the compiler's command line in the same order as they
appear in the moz.build file.
""", None),
'LDFLAGS': (List, list,
"""Flags passed to the linker when linking all of the libraries and
executables declared in this directory.

Просмотреть файл

@ -173,8 +173,9 @@ class XPIDLFile(ContextDerived):
self.install_target = context['FINAL_TARGET']
class Defines(ContextDerived):
"""Context derived container object for DEFINES, which is an OrderedDict.
class BaseDefines(ContextDerived):
"""Context derived container object for DEFINES/HOST_DEFINES,
which are OrderedDicts.
"""
__slots__ = ('defines')
@ -197,6 +198,12 @@ class Defines(ContextDerived):
else:
self.defines.update(more_defines)
class Defines(BaseDefines):
pass
class HostDefines(BaseDefines):
pass
class Exports(ContextDerived):
"""Context derived container object for EXPORTS, which is a
HierarchicalStringList.

Просмотреть файл

@ -45,6 +45,7 @@ from .data import (
ExternalStaticLibrary,
ExternalSharedLibrary,
HeaderFileSubstitution,
HostDefines,
HostLibrary,
HostProgram,
HostSimpleProgram,
@ -588,7 +589,7 @@ class TreeMetadataEmitter(LoggingMixin):
context['OS_LIBS'].append('delayimp')
for v in ['CFLAGS', 'CXXFLAGS', 'CMFLAGS', 'CMMFLAGS', 'ASFLAGS',
'LDFLAGS']:
'LDFLAGS', 'HOST_CFLAGS', 'HOST_CXXFLAGS']:
if v in context and context[v]:
passthru.variables['MOZBUILD_' + v] = context[v]
@ -623,6 +624,10 @@ class TreeMetadataEmitter(LoggingMixin):
if defines:
yield Defines(context, defines)
host_defines = context.get('HOST_DEFINES')
if host_defines:
yield HostDefines(context, host_defines)
resources = context.get('RESOURCE_FILES')
if resources:
yield Resources(context, resources, defines)

Просмотреть файл

@ -0,0 +1,14 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
value = 'xyz'
HOST_DEFINES = {
'FOO': True,
}
HOST_DEFINES['BAZ'] = '"ab\'cd"'
HOST_DEFINES.update({
'BAR': 7,
'VALUE': value,
'QUX': False,
})

Просмотреть файл

@ -19,6 +19,8 @@ USE_STATIC_LIBS = True
CFLAGS += ['-fno-exceptions', '-w']
CXXFLAGS += ['-fcxx-exceptions', '-include foo.h']
LDFLAGS += ['-framework Foo', '-x']
HOST_CFLAGS += ['-funroll-loops', '-wall']
HOST_CXXFLAGS += ['-funroll-loops-harder', '-wall-day-everyday']
WIN32_EXE_LDFLAGS += ['-subsystem:console']
DISABLE_STL_WRAPPING = True

Просмотреть файл

@ -307,6 +307,14 @@ class TestRecursiveMakeBackend(BackendTester):
'MOZBUILD_LDFLAGS += -DELAYLOAD:foo.dll',
'MOZBUILD_LDFLAGS += -DELAYLOAD:bar.dll',
],
'MOZBUILD_HOST_CFLAGS': [
'MOZBUILD_HOST_CFLAGS += -funroll-loops',
'MOZBUILD_HOST_CFLAGS += -wall',
],
'MOZBUILD_HOST_CXXFLAGS': [
'MOZBUILD_HOST_CXXFLAGS += -funroll-loops-harder',
'MOZBUILD_HOST_CXXFLAGS += -wall-day-everyday',
],
'WIN32_EXE_LDFLAGS': [
'WIN32_EXE_LDFLAGS += -subsystem:console',
],
@ -578,6 +586,19 @@ class TestRecursiveMakeBackend(BackendTester):
expected = ['DEFINES += -DFOO -DBAZ=\'"ab\'\\\'\'cd"\' -UQUX -DBAR=7 -DVALUE=\'xyz\'']
self.assertEqual(defines, expected)
def test_host_defines(self):
"""Test that HOST_DEFINES are written to backend.mk correctly."""
env = self._consume('host-defines', RecursiveMakeBackend)
backend_path = mozpath.join(env.topobjdir, 'backend.mk')
lines = [l.strip() for l in open(backend_path, 'rt').readlines()[2:]]
var = 'HOST_DEFINES'
defines = [val for val in lines if val.startswith(var)]
expected = ['HOST_DEFINES += -DFOO -DBAZ=\'"ab\'\\\'\'cd"\' -UQUX -DBAR=7 -DVALUE=\'xyz\'']
self.assertEqual(defines, expected)
def test_local_includes(self):
"""Test that LOCAL_INCLUDES are written to backend.mk correctly."""
env = self._consume('local_includes', RecursiveMakeBackend)

Просмотреть файл

@ -0,0 +1,14 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
value = 'xyz'
HOST_DEFINES = {
'FOO': True,
}
HOST_DEFINES['BAZ'] = '"abcd"'
HOST_DEFINES.update({
'BAR': 7,
'VALUE': value,
'QUX': False,
})

Просмотреть файл

@ -21,6 +21,8 @@ USE_STATIC_LIBS = True
CFLAGS += ['-fno-exceptions', '-w']
CXXFLAGS += ['-fcxx-exceptions', '-include foo.h']
LDFLAGS += ['-framework Foo', '-x']
HOST_CFLAGS += ['-funroll-loops', '-wall']
HOST_CXXFLAGS += ['-funroll-loops-harder', '-wall-day-everyday']
WIN32_EXE_LDFLAGS += ['-subsystem:console']
DISABLE_STL_WRAPPING = True

Просмотреть файл

@ -20,6 +20,7 @@ from mozbuild.frontend.data import (
GeneratedFile,
GeneratedInclude,
GeneratedSources,
HostDefines,
HostSources,
IPDLFile,
JARManifest,
@ -176,6 +177,9 @@ class TestEmitterBasic(unittest.TestCase):
'MOZBUILD_CXXFLAGS': ['-fcxx-exceptions', '-include foo.h'],
'MOZBUILD_LDFLAGS': ['-framework Foo', '-x', '-DELAYLOAD:foo.dll',
'-DELAYLOAD:bar.dll'],
'MOZBUILD_HOST_CFLAGS': ['-funroll-loops', '-wall'],
'MOZBUILD_HOST_CXXFLAGS': ['-funroll-loops-harder',
'-wall-day-everyday'],
'WIN32_EXE_LDFLAGS': ['-subsystem:console'],
}
@ -685,6 +689,25 @@ class TestEmitterBasic(unittest.TestCase):
self.assertEqual(defines, expected)
def test_host_defines(self):
reader = self.reader('host-defines')
objs = self.read_topsrcdir(reader)
defines = {}
for o in objs:
if isinstance(o, HostDefines):
defines = o.defines
expected = {
'BAR': 7,
'BAZ': '"abcd"',
'FOO': True,
'VALUE': 'xyz',
'QUX': False,
}
self.assertEqual(defines, expected)
def test_jar_manifests(self):
reader = self.reader('jar-manifests')
objs = self.read_topsrcdir(reader)