Bug 1293837 - Change try_compile() to return True when the test passes. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 10 Aug 2016 10:00:43 +0900
changeset 398945 03c95b82d42fab276dd5fde521be5bbd3bfc60c3
parent 398944 8e769b3612ef345e48b4c0ea676c12fc1422f1a4
child 398946 6d30f448a61139f5ebe0e6a4a48fe6e9564a3494
push id25681
push userbmo:mh+mozilla@glandium.org
push dateWed, 10 Aug 2016 02:27:32 +0000
reviewerschmanchester
bugs1293837
milestone51.0a1
Bug 1293837 - Change try_compile() to return True when the test passes. r?chmanchester Currently, it returns either None or the contents of the compiler's stdout, which is always expected to be an empty string, and is not very useful. So instead, return True in the latter case.
build/moz.configure/compile-checks.configure
build/moz.configure/compilers-util.configure
python/mozbuild/mozbuild/test/configure/test_compile_checks.py
--- a/build/moz.configure/compile-checks.configure
+++ b/build/moz.configure/compile-checks.configure
@@ -50,18 +50,17 @@ def check_header(header, language='C++',
         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):
-        if value is not None:
-            return True
+        return value
     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.
@@ -134,17 +133,17 @@ def check_and_add_gcc_warning(warning, c
         if check:
             result = c.try_compile(
                 flags=flags, when=result,
                 check_msg='whether the %s compiler supports %s' % (lang,
                                                                    warning))
 
         @depends(result, warnings_flags)
         def maybe_add_flag(result, warnings_flags):
-            if result is not None:
+            if result:
                 warnings_flags.append(warning)
 
 # 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
--- a/build/moz.configure/compilers-util.configure
+++ b/build/moz.configure/compilers-util.configure
@@ -33,33 +33,34 @@ def compiler_class(compiler):
                 %s
                   ;
                   return 0;
                 }
             ''' % body)
 
             if check_msg:
                 def checking_fn(fn):
-                    return checking(check_msg,
-                                    callback=lambda r: r is not None)(fn)
+                    return checking(check_msg)(fn)
             else:
                 def checking_fn(fn):
                     return fn
 
             def get_flags():
                 if flags:
                     return flags[:]
 
             @depends_when(self, extra_toolchain_flags, when=when)
             @checking_fn
             def func(compiler, extra_flags):
                 flags = get_flags() or []
                 flags += extra_flags
                 flags.append('-c')
 
-                return try_invoke_compiler(
+                if try_invoke_compiler(
                     compiler.wrapper + [compiler.compiler] + compiler.flags,
-                    compiler.language, source, flags, onerror=onerror)
+                    compiler.language, source, flags,
+                    onerror=onerror) is not None:
+                    return True
 
             return func
 
     compiler.__class__ = Compiler
     return compiler
--- a/python/mozbuild/mozbuild/test/configure/test_compile_checks.py
+++ b/python/mozbuild/mozbuild/test/configure/test_compile_checks.py
@@ -125,42 +125,33 @@ class TestHeaderChecks(BaseCompileChecks
         ''')
 
         config, out, status = self.do_compile_test(cmd, expected_flags=expected_flags)
         self.assertEqual(status, 0)
         self.assertEqual(config, {})
 
     def test_try_compile_failure(self):
         cmd = textwrap.dedent('''\
-            @depends(try_compile(body='somefn();', flags=['-funknown-flag']))
-            def have_fn(value):
-                if value is not None:
-                    return True
+            have_fn = try_compile(body='somefn();', flags=['-funknown-flag'])
             set_config('HAVE_SOMEFN', have_fn)
 
-            @depends(try_compile(body='anotherfn();', language='C'))
-            def have_another(value):
-                if value is not None:
-                    return True
+            have_another = try_compile(body='anotherfn();', language='C')
             set_config('HAVE_ANOTHERFN', have_another)
         ''')
 
         config, out, status = self.do_compile_test(cmd)
         self.assertEqual(status, 0)
         self.assertEqual(config, {
             'HAVE_ANOTHERFN': True,
         })
 
     def test_try_compile_msg(self):
         cmd = textwrap.dedent('''\
-            @depends(try_compile(language='C++', flags=['-fknown-flag'],
-                     check_msg='whether -fknown-flag works'))
-            def known_flag(result):
-                if result is not None:
-                    return True
+            known_flag = try_compile(language='C++', flags=['-fknown-flag'],
+                                     check_msg='whether -fknown-flag works')
             set_config('HAVE_KNOWN_FLAG', known_flag)
         ''')
         config, out, status = self.do_compile_test(cmd)
         self.assertEqual(status, 0)
         self.assertEqual(config, {'HAVE_KNOWN_FLAG': True})
         self.assertEqual(out, textwrap.dedent('''\
             checking whether -fknown-flag works... yes
         '''))