Bug 1426555 - Allow to add host compiler flags from python configure. r=chmanchester

Bug 1325632 added some facility to add target compiler flags. This
change extends it to add allow adding host compiler flags as well.

--HG--
extra : rebase_source : 424b405a1d8f9a4778ff75c3308c9622f050e194
This commit is contained in:
Mike Hommey 2017-12-21 11:11:22 +09:00
Родитель 21011a977a
Коммит ec8fa73867
6 изменённых файлов: 62 добавлений и 31 удалений

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

@ -81,9 +81,8 @@ def check_headers(*headers, **kwargs):
# 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.
@ -95,7 +94,7 @@ def check_headers(*headers, **kwargs):
# - `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,)
@ -113,10 +112,13 @@ def check_and_add_flags(flag, cflags, cxxflags, test_flags,
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)
@ -140,13 +142,8 @@ def check_and_add_flags(flag, cflags, cxxflags, test_flags,
@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,
@ -174,8 +171,8 @@ def check_and_add_gcc_warning(warning, compiler=None, when=None, check=True):
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.
@ -194,13 +191,8 @@ def add_gcc_warning(warning, compiler=None, when=None):
# 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
@ -218,8 +210,8 @@ def compilation_cxxflags():
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.

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

@ -9,5 +9,10 @@
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)

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

@ -149,5 +149,9 @@ check_and_add_gcc_warning('-Wno-noexcept-type', cxx_compiler,
# 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)

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

@ -1823,9 +1823,13 @@ COMPILE_CXXFLAGS=`echo \
$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)

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

@ -4643,9 +4643,13 @@ COMPILE_CXXFLAGS=`echo \
$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)

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

@ -70,6 +70,17 @@ class BaseCompileChecks(unittest.TestCase):
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():
@ -80,6 +91,17 @@ class BaseCompileChecks(unittest.TestCase):
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 = {}
@ -272,8 +294,8 @@ class TestHeaderChecks(BaseCompileChecks):
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):