Bug 1304522 - Fix the "when" argument to check_header to actually make checks conditional. r=glandium
authorChris Manchester <cmanchester@mozilla.com>
Wed, 21 Sep 2016 22:02:43 -0700
changeset 315372 e1e55d3898c8d54b462fbf49092c490bbe4ab786
parent 315371 dad990960ba020c2fe08aea0721a39dc4559d78e
child 315373 a14b893971a6b4bdaa5d8283a1afac5ad8a846be
push id30748
push usercbook@mozilla.com
push dateWed, 28 Sep 2016 13:53:19 +0000
treeherdermozilla-central@8c84b7618840 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1304522
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1304522 - Fix the "when" argument to check_header to actually make checks conditional. r=glandium MozReview-Commit-ID: JlYUFsPRGAV
build/moz.configure/compile-checks.configure
python/mozbuild/mozbuild/test/configure/test_compile_checks.py
--- 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)
           {