Bug 1304522 - Fix the "when" argument to check_header to actually make checks conditional. r=glandium
MozReview-Commit-ID: JlYUFsPRGAV
--- a/build/moz.configure/compile-checks.configure
+++ b/build/moz.configure/compile-checks.configure
@@ -13,23 +13,24 @@
# - `body` is the code that will appear in the main function of the generated
# test program. `return 0;` is appended to the function body automatically.
# - `language` is the language selection, so that the appropriate compiler is
# used.
# - `flags` are the flags to be passed to the compiler, in addition to `-c`.
# - `check_msg` is the message to be printed to accompany compiling the test
# program.
@template
-def try_compile(includes=None, body='', language='C++', flags=None, check_msg=None):
+def try_compile(includes=None, body='', language='C++', flags=None, check_msg=None,
+ when=None):
compiler = {
'C': c_compiler,
'C++': cxx_compiler,
}[language]
- return compiler.try_compile(includes, body, flags, check_msg)
+ return compiler.try_compile(includes, body, flags, check_msg, when=when)
# Checks for the presence of the given header on the target system by compiling
# a test program including that header. The return value of the template is a
# check function returning True if the header is present, and None if it is not.
# The value of this check function is also used to set a variable (with set_define)
# corresponding to the checked header. For instance, HAVE_MALLOC_H will be set in
# defines if check_header if called with 'malloc.h' as input and malloc.h is
@@ -47,20 +48,18 @@ def check_header(header, language='C++',
when = when or always
if includes:
includes = includes[:]
else:
includes = []
includes.append(header)
- @depends_when(try_compile(includes=includes, language=language, flags=flags,
- check_msg='for %s' % header), when=when)
- def have_header(value):
- return value
+ have_header = try_compile(includes=includes, language=language, flags=flags,
+ check_msg='for %s' % header, when=when)
header_var = 'HAVE_%s' % (header.upper()
.replace('-', '_')
.replace('/', '_')
.replace('.', '_'))
set_define(header_var, have_header)
return have_header
# A convenience wrapper for check_header for checking multiple headers.
--- a/python/mozbuild/mozbuild/test/configure/test_compile_checks.py
+++ b/python/mozbuild/mozbuild/test/configure/test_compile_checks.py
@@ -175,16 +175,26 @@ class TestHeaderChecks(BaseCompileChecks
config, out, status = self.do_compile_test(cmd,
expected_test_content=expected_test_content)
self.assertEqual(status, 0)
self.assertEqual(config, {'DEFINES': {'HAVE_FOO_H': True}})
self.assertEqual(out, textwrap.dedent('''\
checking for foo.h... yes
'''))
+ def test_check_header_conditional(self):
+ cmd = textwrap.dedent('''\
+ check_headers('foo.h', 'bar.h', when=never)
+ ''')
+
+ config, out, status = self.do_compile_test(cmd)
+ self.assertEqual(status, 0)
+ self.assertEqual(out, '')
+ self.assertEqual(config, {'DEFINES':{}})
+
def test_check_header_include(self):
expected_test_content = textwrap.dedent('''\
#include <std.h>
#include <bar.h>
#include <foo.h>
int
main(void)
{