Bug 1426555 - Allow to add host compiler flags from python configure. r?build draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 21 Dec 2017 11:11:22 +0900
changeset 713853 632cb70705ae211ad263b35c05fa137589970492
parent 713852 100545bb0a2b50b629825899df30917aea83fb9c
child 713854 aaa17323c8f705a83d2ab29fda4088416262a9cf
child 713855 07d18a1943e292e13a0d4362eb84b50df768f122
push id93779
push userbmo:mh+mozilla@glandium.org
push dateThu, 21 Dec 2017 03:02:50 +0000
reviewersbuild
bugs1426555, 1325632
milestone59.0a1
Bug 1426555 - Allow to add host compiler flags from python configure. r?build Bug 1325632 added some facility to add target compiler flags. This change extends it to add allow adding host compiler flags as well.
build/moz.configure/compile-checks.configure
build/moz.configure/flags.configure
build/moz.configure/warnings.configure
js/src/old-configure.in
old-configure.in
python/mozbuild/mozbuild/test/configure/test_compile_checks.py
--- a/build/moz.configure/compile-checks.configure
+++ b/build/moz.configure/compile-checks.configure
@@ -76,31 +76,30 @@ def check_headers(*headers, **kwargs):
     for header in headers:
         checks.append(check_header(header, **kwargs))
     return checks
 
 
 # Determine whether to add a given flag to the given lists of flags for C or
 # C++ compilation.
 # - `flag` is the flag to test
-# - `cflags` is a @depends function for the list of C compiler flags to add to
-# - `cxxflags` is a @depends function for the list of C++ compiler flags to
-#   add to
+# - `flags_collection` is a @depends function for a namespace of lists of
+#    C/C++ compiler flags to add to.
 # - `test_flags` is a list of flags to pass to the compiler instead of merely
 #   passing `flag`. This is especially useful for checking warning flags. If
 #   this list is empty, `flag` will be passed on its own.
 # - `compiler` (optional) is the compiler to test against (c_compiler or
 #   cxx_compiler, from toolchain.configure). When omitted, both compilers
 #   are tested; the list of flags added to is dependent on the compiler tested.
 # - `when` (optional) is a @depends function or option name conditioning
 #   when the warning flag is wanted.
 # - `check`, when not set, skips checking whether the flag is supported and
 #   adds it to the list of flags unconditionally.
 @template
-def check_and_add_flags(flag, cflags, cxxflags, test_flags,
+def check_and_add_flags(flag, flags_collection, test_flags,
                         compiler=None, when=None, check=True):
     if compiler is not None:
         compilers = (compiler,)
     else:
         compilers = (c_compiler, cxx_compiler)
 
     if when is None:
         when = always
@@ -108,20 +107,23 @@ def check_and_add_flags(flag, cflags, cx
     results = []
 
     if test_flags:
         flags = test_flags
     else:
         flags = [flag]
 
     for c in compilers:
-        assert c in (c_compiler, cxx_compiler)
+        assert c in (c_compiler, cxx_compiler,
+                     host_c_compiler, host_cxx_compiler)
         lang, list_of_flags = {
-            c_compiler: ('C', cflags),
-            cxx_compiler: ('C++', cxxflags),
+            c_compiler: ('C', flags_collection.cflags),
+            cxx_compiler: ('C++', flags_collection.cxxflags),
+            host_c_compiler: ('host C', flags_collection.host_cflags),
+            host_cxx_compiler: ('host C++', flags_collection.host_cxxflags),
         }[c]
 
         @depends(c, when)
         def result(c, when):
             if when and c.type in ('clang', 'gcc'):
                 return True
 
         if check:
@@ -135,23 +137,18 @@ def check_and_add_flags(flag, cflags, cx
                 list_of_flags.append(flag)
 
         results.append(result)
 
     return tuple(results)
 
 
 @dependable
-def warnings_cflags():
-    return []
-
-
-@dependable
-def warnings_cxxflags():
-    return []
+def warnings_flags():
+    return namespace(cflags=[], cxxflags=[], host_cflags=[], host_cxxflags=[])
 
 
 # Tests whether GCC or clang support the given warning flag, and if it is,
 # add it to the list of warning flags for the build.
 # - `warning` is the warning flag (e.g. -Wfoo)
 # - `compiler` (optional) is the compiler to test against (c_compiler or
 #   cxx_compiler, from toolchain.configure). When omitted, both compilers
 #   are tested.
@@ -169,18 +166,18 @@ def check_and_add_gcc_warning(warning, c
     # add the negated form to the flags variable.
     if warning.startswith('-Wno-') and not warning.startswith('-Wno-error='):
         flags = ['-Werror', '-W' + warning[5:]]
     elif warning.startswith('-Werror='):
         flags = [warning]
     else:
         flags = ['-Werror', warning]
 
-    return check_and_add_flags(warning, warnings_cflags, warnings_cxxflags,
-                               flags, compiler=compiler, when=when, check=check)
+    return check_and_add_flags(warning, warnings_flags, flags,
+                               compiler=compiler, when=when, check=check)
 
 
 # Add the given warning to the list of warning flags for the build.
 # - `warning` is the warning flag (e.g. -Wfoo)
 # - `compiler` (optional) is the compiler to add the flag for (c_compiler or
 #   cxx_compiler, from toolchain.configure). When omitted, the warning flag
 #   is added for both compilers.
 # - `when` (optional) is a @depends function or option name conditioning
@@ -189,23 +186,18 @@ def check_and_add_gcc_warning(warning, c
 
 @template
 def add_gcc_warning(warning, compiler=None, when=None):
     check_and_add_gcc_warning(warning, compiler, when, check=False)
 
 
 # Like the warning checks above, but for general compilation flags.
 @dependable
-def compilation_cflags():
-    return []
-
-
-@dependable
-def compilation_cxxflags():
-    return []
+def compilation_flags():
+    return namespace(cflags=[], cxxflags=[], host_cflags=[], host_cxxflags=[])
 
 
 # Tests whether GCC or clang support the given compilation flag; if the flag
 # is supported, add it to the list of compilation flags for the build.
 # - `flag` is the flag to test
 # - `compiler` (optional) is the compiler to test against (c_compiler or
 #   cxx_compiler, from toolchain.configure). When omitted, both compilers
 #   are tested.
@@ -213,18 +205,18 @@ def compilation_cxxflags():
 #   when the warning flag is wanted.
 # - `check`, when not set, skips checking whether the flag is supported and
 #   adds it to the list of flags unconditionally. This is only meant for
 #   add_gcc_flag().
 @template
 def check_and_add_gcc_flag(flag, compiler=None, when=None, check=True):
     flags = ['-Werror', flag]
 
-    return check_and_add_flags(flag, compilation_cflags, compilation_cxxflags,
-                               flags, compiler=compiler, when=when, check=check)
+    return check_and_add_flags(flag, compilation_flags, flags,
+                               compiler=compiler, when=when, check=check)
 
 
 # Add the given flag to the list of flags for the build.
 # - `flag` is the flag (e.g. -fno-sized-deallocation)
 # - `compiler` (optional) is the compiler to add the flag for (c_compiler or
 #   cxx_compiler, from toolchain.configure). When omitted, the flag is added
 #   for both compilers.
 # - `when` (optional) is a @depends function or option name conditioning
--- a/build/moz.configure/flags.configure
+++ b/build/moz.configure/flags.configure
@@ -4,10 +4,15 @@
 # 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/.
 
 # We support C++14, but we don't want to enable the sized deallocation
 # facilities in C++14 yet.
 check_and_add_gcc_flag('-fno-sized-deallocation', compiler=cxx_compiler)
 
 # Please keep these last in this file.
-add_old_configure_assignment('_COMPILATION_CFLAGS', compilation_cflags)
-add_old_configure_assignment('_COMPILATION_CXXFLAGS', compilation_cxxflags)
+add_old_configure_assignment('_COMPILATION_CFLAGS', compilation_flags.cflags)
+add_old_configure_assignment(
+    '_COMPILATION_CXXFLAGS', compilation_flags.cxxflags)
+add_old_configure_assignment(
+    '_COMPILATION_HOST_CFLAGS', compilation_flags.host_cflags)
+add_old_configure_assignment(
+    '_COMPILATION_HOST_CXXFLAGS', compilation_flags.host_cxxflags)
--- a/build/moz.configure/warnings.configure
+++ b/build/moz.configure/warnings.configure
@@ -144,10 +144,14 @@ check_and_add_gcc_warning('-Wno-gnu-zero
 # limited to a potential public ABI.
 # Currently only affecting js/
 check_and_add_gcc_warning('-Wno-noexcept-type', cxx_compiler,
                           when=depends(build_project)
                           (lambda build_project: build_project == 'js'))
 
 
 # Please keep these last in this file
-add_old_configure_assignment('_WARNINGS_CFLAGS', warnings_cflags)
-add_old_configure_assignment('_WARNINGS_CXXFLAGS', warnings_cxxflags)
+add_old_configure_assignment('_WARNINGS_CFLAGS', warnings_flags.cflags)
+add_old_configure_assignment('_WARNINGS_CXXFLAGS', warnings_flags.cxxflags)
+add_old_configure_assignment(
+    '_WARNINGS_HOST_CFLAGS', warnings_flags.host_cflags)
+add_old_configure_assignment(
+    '_WARNINGS_HOST_CXXFLAGS', warnings_flags.host_cxxflags)
--- a/js/src/old-configure.in
+++ b/js/src/old-configure.in
@@ -1818,19 +1818,23 @@ COMPILE_CFLAGS=`echo \
     $_DEFINES_CFLAGS \
     $COMPILE_CFLAGS`
 
 COMPILE_CXXFLAGS=`echo \
     $_DEFINES_CXXFLAGS \
     $COMPILE_CXXFLAGS`
 
 HOST_CFLAGS=`echo \
+    $_WARNINGS_HOST_CFLAGS \
+    $_COMPILATION_HOST_CFLAGS \
     $HOST_CFLAGS`
 
 HOST_CXXFLAGS=`echo \
+    $_WARNINGS_HOST_CXXFLAGS \
+    $_COMPILATION_HOST_CXXFLAGS \
     $HOST_CXXFLAGS`
 
 AC_SUBST(_DEPEND_CFLAGS)
 AC_SUBST(MOZ_SYSTEM_NSPR)
 
 OS_CFLAGS="$CFLAGS"
 OS_CXXFLAGS="$CXXFLAGS"
 OS_CPPFLAGS="$CPPFLAGS"
--- a/old-configure.in
+++ b/old-configure.in
@@ -4638,19 +4638,23 @@ COMPILE_CFLAGS=`echo \
     $_DEFINES_CFLAGS \
     $COMPILE_CFLAGS`
 
 COMPILE_CXXFLAGS=`echo \
     $_DEFINES_CXXFLAGS \
     $COMPILE_CXXFLAGS`
 
 HOST_CFLAGS=`echo \
+    $_WARNINGS_HOST_CFLAGS \
+    $_COMPILATION_HOST_CFLAGS \
     $HOST_CFLAGS`
 
 HOST_CXXFLAGS=`echo \
+    $_WARNINGS_HOST_CXXFLAGS \
+    $_COMPILATION_HOST_CXXFLAGS \
     $HOST_CXXFLAGS`
 
 AC_SUBST(_DEPEND_CFLAGS)
 AC_SUBST(MOZ_SYSTEM_JPEG)
 AC_SUBST(MOZ_SYSTEM_PNG)
 AC_SUBST(MOZ_SYSTEM_BZ2)
 
 AC_SUBST_LIST(MOZ_JPEG_CFLAGS)
--- a/python/mozbuild/mozbuild/test/configure/test_compile_checks.py
+++ b/python/mozbuild/mozbuild/test/configure/test_compile_checks.py
@@ -67,24 +67,46 @@ class BaseCompileChecks(unittest.TestCas
                     type='gcc',
                     compiler=os.path.abspath('/usr/bin/mockcc'),
                     wrapper=[],
                     language='C',
                 )
 
             @wrap_compiler
             @depends(when=True)
+            def host_c_compiler():
+                return namespace(
+                    flags=[],
+                    type='gcc',
+                    compiler=os.path.abspath('/usr/bin/mockcc'),
+                    wrapper=[],
+                    language='C',
+                )
+
+            @wrap_compiler
+            @depends(when=True)
             def cxx_compiler():
                 return namespace(
                     flags=[],
                     type='gcc',
                     compiler=os.path.abspath('/usr/bin/mockcc'),
                     wrapper=[],
                     language='C++',
                 )
+
+            @wrap_compiler
+            @depends(when=True)
+            def host_cxx_compiler():
+                return namespace(
+                    flags=[],
+                    type='gcc',
+                    compiler=os.path.abspath('/usr/bin/mockcc'),
+                    wrapper=[],
+                    language='C++',
+                )
         ''' % mozpath.normsep(base_dir))
 
         config = {}
         out = StringIO()
         sandbox = ConfigureTestSandbox(paths, config, {}, ['/bin/configure'],
                                        out, out)
         sandbox.include_file(os.path.join(base_dir, 'util.configure'))
         sandbox.include_file(os.path.join(base_dir, 'checks.configure'))
@@ -267,18 +289,18 @@ class TestHeaderChecks(BaseCompileChecks
             checking for baz/foo-bar.h... no
             checking for baz-quux/foo-bar.h... no
         '''))
 
 
 class TestWarningChecks(BaseCompileChecks):
     def get_warnings(self):
         return textwrap.dedent('''\
-            set_config('_WARNINGS_CFLAGS', warnings_cflags)
-            set_config('_WARNINGS_CXXFLAGS', warnings_cxxflags)
+            set_config('_WARNINGS_CFLAGS', warnings_flags.cflags)
+            set_config('_WARNINGS_CXXFLAGS', warnings_flags.cxxflags)
         ''')
 
     def test_check_and_add_gcc_warning(self):
         for flag, expected_flags in (
             ('-Wfoo', ['-Werror', '-Wfoo']),
             ('-Wno-foo', ['-Werror', '-Wfoo']),
             ('-Werror=foo', ['-Werror=foo']),
             ('-Wno-error=foo', ['-Wno-error=foo']),