Bug 1307355 - Add an implicit dependency on --enable-compile-environment to pkg_check_modules. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 04 Oct 2016 15:33:37 +0900
changeset 420740 9a2f671a2cf29f0d1d1ec6bf6d32c5519d283c34
parent 420691 884a935cf32303930bfce8c664a95ad01225933c
child 532872 66ce8a2c3cd2a7bda3f41796035f1333f99f4769
push id31270
push userbmo:mh+mozilla@glandium.org
push dateTue, 04 Oct 2016 14:06:18 +0000
reviewerschmanchester
bugs1307355
milestone52.0a1
Bug 1307355 - Add an implicit dependency on --enable-compile-environment to pkg_check_modules. r?chmanchester
build/moz.configure/init.configure
build/moz.configure/pkg.configure
moz.configure
python/mozbuild/mozbuild/test/configure/test_checks_configure.py
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -798,21 +798,16 @@ def js_option(*args, **kwargs):
     @depends(opt.option, build_project)
     def js_option(value, build_project):
         if build_project != 'js':
             return value.format(opt.option)
 
     add_old_configure_arg(js_option)
 
 
-include('pkg.configure')
-# Make this assignment here rather than in pkg.configure to avoid
-# requiring this file in unit tests.
-add_old_configure_assignment('PKG_CONFIG', pkg_config)
-
 # Bug 1278542: This function is a workaround to resolve
 # |android_ndk_include|'s dependency on 'gonkdir.' The
 # actual implementation is located in b2g/moz.configure.
 # Remove this function as soon as 'android_ndk_include'
 # depends on 'target.'
 @dependable
 def gonkdir():
     return None
--- a/build/moz.configure/pkg.configure
+++ b/build/moz.configure/pkg.configure
@@ -1,15 +1,20 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # 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/.
 
-pkg_config = check_prog('PKG_CONFIG', ('pkg-config',), allow_missing=True)
+@depends('--enable-compile-environment')
+def pkg_config(compile_env):
+    if compile_env:
+        return ('pkg-config',)
+
+pkg_config = check_prog('PKG_CONFIG', pkg_config, allow_missing=True)
 
 @depends_if(pkg_config)
 @checking('for pkg-config version')
 @imports('subprocess')
 def pkg_config_version(pkg_config):
     return Version(check_cmd_output(pkg_config, '--version').rstrip())
 
 # Locates the given module using pkg-config.
@@ -26,28 +31,33 @@ def pkg_config_version(pkg_config):
 #   Returns `True` when the package description is fulfilled.
 @template
 def pkg_check_modules(var, package_desc, when=always,
                       allow_missing=False):
     if isinstance(package_desc, (tuple, list)):
         package_desc = ' '.join(package_desc)
     package_desc = dependable(package_desc)
 
-    @depends_when(pkg_config, pkg_config_version, when=when)
+    @depends(when, '--enable-compile-environment')
+    def when_and_compile_environment(when, compile_environment):
+        return when and compile_environment
+
+    @depends_when(pkg_config, pkg_config_version,
+                  when=when_and_compile_environment)
     def check_pkg_config(pkg_config, version):
         min_version = '0.9.0'
         if pkg_config is None:
             die("*** The pkg-config script could not be found. Make sure it is\n"
                 "*** in your path, or set the PKG_CONFIG environment variable\n"
                 "*** to the full path to pkg-config.")
         if version < min_version:
             die("*** Your version of pkg-config is too old. You need version %s or newer.",
                 min_version)
 
-    @depends_when(pkg_config, package_desc, when=when)
+    @depends_when(pkg_config, package_desc, when=when_and_compile_environment)
     @imports('subprocess')
     @imports('sys')
     @imports(_from='mozbuild.configure.util', _import='LineIO')
     def package(pkg_config, package_desc):
         # package_desc may start as a depends function, so we can't use
         # @checking here.
         log.info("checking for %s... " % package_desc)
         with log.queue_debug():
--- a/moz.configure
+++ b/moz.configure
@@ -88,16 +88,21 @@ set_define('GTEST_HAS_CLONE',
 js_option('--enable-debug',
           nargs='?',
           help='Enable building with developer debug info '
                '(using the given compiler flags).')
 
 add_old_configure_assignment('MOZ_DEBUG',
                              depends('--enable-debug')(lambda v: bool(v)))
 
+include('build/moz.configure/pkg.configure')
+# Make this assignment here rather than in pkg.configure to avoid
+# requiring this file in unit tests.
+add_old_configure_assignment('PKG_CONFIG', pkg_config)
+
 include_when('build/moz.configure/toolchain.configure',
              when='--enable-compile-environment')
 include_when('build/moz.configure/memory.configure',
              when='--enable-compile-environment')
 include_when('build/moz.configure/headers.configure',
              when='--enable-compile-environment')
 include_when('build/moz.configure/warnings.configure',
              when='--enable-compile-environment')
--- a/python/mozbuild/mozbuild/test/configure/test_checks_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_checks_configure.py
@@ -696,69 +696,74 @@ class TestChecksConfigure(unittest.TestC
                 return 0, '-I/usr/include/%s' % args[1], ''
             if args[0] == '--libs':
                 assert len(args) == 2
                 return 0, '-l%s' % args[1], ''
             if args[0] == '--version':
                 return 0, mock_pkg_config_version, ''
             self.fail("Unexpected arguments to mock_pkg_config: %s" % args)
 
+        def get_result(cmd, args=[], extra_paths=None):
+            return self.get_result(textwrap.dedent('''\
+                option('--disable-compile-environment', help='compile env')
+                include('%(topsrcdir)s/build/moz.configure/util.configure')
+                include('%(topsrcdir)s/build/moz.configure/checks.configure')
+                include('%(topsrcdir)s/build/moz.configure/pkg.configure')
+            ''' % {'topsrcdir': topsrcdir}) + cmd, args=args, extra_paths=extra_paths,
+                                                   includes=())
+
         extra_paths = {
             mock_pkg_config_path: mock_pkg_config,
         }
         includes = ('util.configure', 'checks.configure', 'pkg.configure')
 
-        config, output, status = self.get_result("pkg_check_modules('MOZ_VALID', 'valid')",
-                                                 includes=includes)
+        config, output, status = get_result("pkg_check_modules('MOZ_VALID', 'valid')")
         self.assertEqual(status, 1)
         self.assertEqual(output, textwrap.dedent('''\
             checking for pkg_config... not found
             ERROR: *** The pkg-config script could not be found. Make sure it is
             *** in your path, or set the PKG_CONFIG environment variable
             *** to the full path to pkg-config.
         '''))
 
 
-        config, output, status = self.get_result("pkg_check_modules('MOZ_VALID', 'valid')",
-                                                 extra_paths=extra_paths,
-                                                 includes=includes)
+        config, output, status = get_result("pkg_check_modules('MOZ_VALID', 'valid')",
+                                            extra_paths=extra_paths)
         self.assertEqual(status, 0)
         self.assertEqual(output, textwrap.dedent('''\
             checking for pkg_config... %s
             checking for pkg-config version... %s
             checking for valid... yes
             checking MOZ_VALID_CFLAGS... -I/usr/include/valid
             checking MOZ_VALID_LIBS... -lvalid
         ''' % (mock_pkg_config_path, mock_pkg_config_version)))
         self.assertEqual(config, {
             'PKG_CONFIG': mock_pkg_config_path,
             'MOZ_VALID_CFLAGS': ('-I/usr/include/valid',),
             'MOZ_VALID_LIBS': ('-lvalid',),
         })
 
-        config, output, status = self.get_result("pkg_check_modules('MOZ_UKNOWN', 'unknown')",
-                                                 extra_paths=extra_paths,
-                                                 includes=includes)
+        config, output, status = get_result("pkg_check_modules('MOZ_UKNOWN', 'unknown')",
+                                            extra_paths=extra_paths)
         self.assertEqual(status, 1)
         self.assertEqual(output, textwrap.dedent('''\
             checking for pkg_config... %s
             checking for pkg-config version... %s
             checking for unknown... no
             ERROR: Package unknown was not found in the pkg-config search path.
             ERROR: Perhaps you should add the directory containing `unknown.pc'
             ERROR: to the PKG_CONFIG_PATH environment variable
             ERROR: No package 'unknown' found
         ''' % (mock_pkg_config_path, mock_pkg_config_version)))
         self.assertEqual(config, {
             'PKG_CONFIG': mock_pkg_config_path,
         })
 
-        config, output, status = self.get_result("pkg_check_modules('MOZ_NEW', 'new > 1.1')",
-                                                 extra_paths=extra_paths,
-                                                 includes=includes)
+        config, output, status = get_result("pkg_check_modules('MOZ_NEW', 'new > 1.1')",
+                                            extra_paths=extra_paths)
         self.assertEqual(status, 1)
         self.assertEqual(output, textwrap.dedent('''\
             checking for pkg_config... %s
             checking for pkg-config version... %s
             checking for new > 1.1... no
             ERROR: Requested 'new > 1.1' but version of new is 1.1
         ''' % (mock_pkg_config_path, mock_pkg_config_version)))
         self.assertEqual(config, {
@@ -769,43 +774,47 @@ class TestChecksConfigure(unittest.TestC
         cmd = textwrap.dedent('''\
         have_new_module = pkg_check_modules('MOZ_NEW', 'new > 1.1', allow_missing=True)
         @depends(have_new_module)
         def log_new_module_error(mod):
             if mod is not True:
                 log.info('Module not found.')
         ''')
 
-        config, output, status = self.get_result(cmd,
-                                                 extra_paths=extra_paths,
-                                                 includes=includes)
+        config, output, status = get_result(cmd, extra_paths=extra_paths)
         self.assertEqual(status, 0)
         self.assertEqual(output, textwrap.dedent('''\
             checking for pkg_config... %s
             checking for pkg-config version... %s
             checking for new > 1.1... no
             WARNING: Requested 'new > 1.1' but version of new is 1.1
             Module not found.
         ''' % (mock_pkg_config_path, mock_pkg_config_version)))
         self.assertEqual(config, {
             'PKG_CONFIG': mock_pkg_config_path,
         })
 
+        config, output, status = get_result(cmd,
+                                            args=['--disable-compile-environment'],
+                                            extra_paths=extra_paths)
+        self.assertEqual(status, 0)
+        self.assertEqual(output, 'Module not found.\n')
+        self.assertEqual(config, {})
+
         def mock_old_pkg_config(_, args):
             if args[0] == '--version':
                 return 0, '0.8.10', ''
             self.fail("Unexpected arguments to mock_old_pkg_config: %s" % args)
 
         extra_paths = {
             mock_pkg_config_path: mock_old_pkg_config,
         }
 
-        config, output, status = self.get_result("pkg_check_modules('MOZ_VALID', 'valid')",
-                                                 extra_paths=extra_paths,
-                                                 includes=includes)
+        config, output, status = get_result("pkg_check_modules('MOZ_VALID', 'valid')",
+                                            extra_paths=extra_paths)
         self.assertEqual(status, 1)
         self.assertEqual(output, textwrap.dedent('''\
             checking for pkg_config... %s
             checking for pkg-config version... 0.8.10
             ERROR: *** Your version of pkg-config is too old. You need version 0.9.0 or newer.
         ''' % mock_pkg_config_path))
 
     def test_simple_keyfile(self):