From 15063c81118b9a726ccb9bab5957425aa2a532d8 Mon Sep 17 00:00:00 2001 From: Ted Mielczarek Date: Fri, 4 Sep 2015 13:33:04 -0400 Subject: [PATCH] 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 --- config/config.mk | 3 +++ .../mozbuild/backend/recursivemake.py | 8 ++++--- python/mozbuild/mozbuild/frontend/context.py | 23 +++++++++++++++++++ python/mozbuild/mozbuild/frontend/data.py | 11 +++++++-- python/mozbuild/mozbuild/frontend/emitter.py | 7 +++++- .../test/backend/data/host-defines/moz.build | 14 +++++++++++ .../backend/data/variable_passthru/moz.build | 2 ++ .../test/backend/test_recursivemake.py | 21 +++++++++++++++++ .../test/frontend/data/host-defines/moz.build | 14 +++++++++++ .../frontend/data/variable-passthru/moz.build | 2 ++ .../mozbuild/test/frontend/test_emitter.py | 23 +++++++++++++++++++ 11 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 python/mozbuild/mozbuild/test/backend/data/host-defines/moz.build create mode 100644 python/mozbuild/mozbuild/test/frontend/data/host-defines/moz.build diff --git a/config/config.mk b/config/config.mk index 82cc3af4e77f..21a75feb1a60 100644 --- a/config/config.mk +++ b/config/config.mk @@ -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 # diff --git a/python/mozbuild/mozbuild/backend/recursivemake.py b/python/mozbuild/mozbuild/backend/recursivemake.py index cd761040d678..645d959989f2 100644 --- a/python/mozbuild/mozbuild/backend/recursivemake.py +++ b/python/mozbuild/mozbuild/backend/recursivemake.py @@ -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') diff --git a/python/mozbuild/mozbuild/frontend/context.py b/python/mozbuild/mozbuild/frontend/context.py index d77bed969a66..6dd90ad57c3a 100644 --- a/python/mozbuild/mozbuild/frontend/context.py +++ b/python/mozbuild/mozbuild/frontend/context.py @@ -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. diff --git a/python/mozbuild/mozbuild/frontend/data.py b/python/mozbuild/mozbuild/frontend/data.py index 65e33946756f..17ce51d1edf9 100644 --- a/python/mozbuild/mozbuild/frontend/data.py +++ b/python/mozbuild/mozbuild/frontend/data.py @@ -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. diff --git a/python/mozbuild/mozbuild/frontend/emitter.py b/python/mozbuild/mozbuild/frontend/emitter.py index 6580540aad57..f79ff1192e72 100644 --- a/python/mozbuild/mozbuild/frontend/emitter.py +++ b/python/mozbuild/mozbuild/frontend/emitter.py @@ -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) diff --git a/python/mozbuild/mozbuild/test/backend/data/host-defines/moz.build b/python/mozbuild/mozbuild/test/backend/data/host-defines/moz.build new file mode 100644 index 000000000000..30f8c160f757 --- /dev/null +++ b/python/mozbuild/mozbuild/test/backend/data/host-defines/moz.build @@ -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, +}) diff --git a/python/mozbuild/mozbuild/test/backend/data/variable_passthru/moz.build b/python/mozbuild/mozbuild/test/backend/data/variable_passthru/moz.build index 7466d366acfe..a78f0897a63d 100644 --- a/python/mozbuild/mozbuild/test/backend/data/variable_passthru/moz.build +++ b/python/mozbuild/mozbuild/test/backend/data/variable_passthru/moz.build @@ -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 diff --git a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py index 2f339cf7754d..7c46cbf4d811 100644 --- a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py +++ b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py @@ -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) diff --git a/python/mozbuild/mozbuild/test/frontend/data/host-defines/moz.build b/python/mozbuild/mozbuild/test/frontend/data/host-defines/moz.build new file mode 100644 index 000000000000..37628fede19c --- /dev/null +++ b/python/mozbuild/mozbuild/test/frontend/data/host-defines/moz.build @@ -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, +}) diff --git a/python/mozbuild/mozbuild/test/frontend/data/variable-passthru/moz.build b/python/mozbuild/mozbuild/test/frontend/data/variable-passthru/moz.build index 1aa7cf774faf..6616ea9131c4 100644 --- a/python/mozbuild/mozbuild/test/frontend/data/variable-passthru/moz.build +++ b/python/mozbuild/mozbuild/test/frontend/data/variable-passthru/moz.build @@ -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 diff --git a/python/mozbuild/mozbuild/test/frontend/test_emitter.py b/python/mozbuild/mozbuild/test/frontend/test_emitter.py index ce02858d9f4c..c7ce9768092b 100644 --- a/python/mozbuild/mozbuild/test/frontend/test_emitter.py +++ b/python/mozbuild/mozbuild/test/frontend/test_emitter.py @@ -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)