Bug 1575135 - Use functions from util.configure instead of subprocess.*. r=nalexander
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 20 Aug 2019 16:42:16 +0000
changeset 489119 f3e3d13c202ad2078d8c1e27db4970191772e74d
parent 489118 fd9f4d8f171b33418c39979623747cc7af3d5932
child 489120 9b73ac45f717562768abf889df36b71dc05dc735
push id36465
push userdvarga@mozilla.com
push dateWed, 21 Aug 2019 16:47:43 +0000
treeherdermozilla-central@4ab60925635c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1575135
milestone70.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 1575135 - Use functions from util.configure instead of subprocess.*. r=nalexander Differential Revision: https://phabricator.services.mozilla.com/D42603
build/moz.configure/init.configure
build/moz.configure/pkg.configure
build/moz.configure/toolchain.configure
build/moz.configure/windows.configure
python/mozbuild/mozbuild/test/configure/test_checks_configure.py
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -789,42 +789,40 @@ def help_host_target(help, host, target)
             os='unknown',
             endianness='unknown',
             raw_cpu='unknown',
             raw_os='unknown',
             toolchain='unknown-unknown',
         )
 
 
-@imports('subprocess')
 def config_sub(shell, triplet):
     config_sub = os.path.join(os.path.dirname(__file__), '..',
                               'autoconf', 'config.sub')
-    return subprocess.check_output([shell, config_sub, triplet]).strip()
+    return check_cmd_output(shell, config_sub, triplet).strip()
 
 
 @depends('--host', shell)
 @checking('for host system type', lambda h: h.alias)
 @imports('os')
-@imports('subprocess')
 @imports('sys')
 @imports(_from='__builtin__', _import='ValueError')
 def real_host(value, shell):
     if not value and sys.platform == 'win32':
         arch = (os.environ.get('PROCESSOR_ARCHITEW6432') or
                 os.environ.get('PROCESSOR_ARCHITECTURE'))
         if arch == 'AMD64':
             return split_triplet('x86_64-pc-mingw32')
         elif arch == 'x86':
             return split_triplet('i686-pc-mingw32')
 
     if not value:
         config_guess = os.path.join(os.path.dirname(__file__), '..',
                                     'autoconf', 'config.guess')
-        host = subprocess.check_output([shell, config_guess], universal_newlines=True).strip()
+        host = check_cmd_output(shell, config_guess, universal_newlines=True).strip()
         try:
             return split_triplet(host)
         except ValueError:
             pass
     else:
         host = value[0]
 
     host = config_sub(shell, host)
--- a/build/moz.configure/pkg.configure
+++ b/build/moz.configure/pkg.configure
@@ -53,36 +53,33 @@ def pkg_check_modules(var, package_desc,
             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(pkg_config, package_desc, allow_missing, when=when_and_compile_environment)
-    @imports('subprocess')
     @imports('sys')
     @imports(_from='mozbuild.configure.util', _import='LineIO')
     def package(pkg_config, package_desc, allow_missing):
         # 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():
-            try:
-                subprocess.check_output([pkg_config, '--errors-to-stdout',
-                                         '--print-errors', package_desc])
-                log.info("yes")
-                return True
-            except subprocess.CalledProcessError as e:
-                log.info("no")
-                log_writer = log.warning if allow_missing else log.error
-                with LineIO(lambda l: log_writer(l), 'replace') as o:
-                    o.write(e.output)
-                if not allow_missing:
-                    sys.exit(1)
+        retcode, stdout, stderr = get_cmd_output(
+            pkg_config, '--errors-to-stdout', '--print-errors', package_desc)
+        if retcode == 0:
+            log.info("yes")
+            return True
+        log.info("no")
+        log_writer = log.warning if allow_missing else log.error
+        with LineIO(lambda l: log_writer(l), 'replace') as o:
+            o.write(stdout)
+        if not allow_missing:
+            sys.exit(1)
 
     @depends(pkg_config, package_desc, when=package)
     @checking('%s_CFLAGS' % var, callback=lambda t: ' '.join(t))
     def pkg_cflags(pkg_config, package_desc):
         flags = check_cmd_output(pkg_config, '--cflags', package_desc)
         return tuple(flags.split())
 
     @depends(pkg_config, package_desc, when=package)
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -598,30 +598,29 @@ def check_compiler(compiler, language, t
         target_os=info.os,
         flags=flags,
     )
 
 
 @imports(_from='__builtin__', _import='open')
 @imports('json')
 @imports('os')
-@imports('subprocess')
 @imports(_from='mozbuild.util', _import='system_encoding')
 def get_vc_paths(topsrcdir):
     def vswhere(args):
         program_files = (os.environ.get('PROGRAMFILES(X86)') or
                          os.environ.get('PROGRAMFILES'))
         if not program_files:
             return []
         vswhere = os.path.join(program_files, 'Microsoft Visual Studio',
                                'Installer', 'vswhere.exe')
         if not os.path.exists(vswhere):
             return []
         return json.loads(
-            subprocess.check_output([vswhere, '-format', 'json'] + args)
+            check_cmd_output(vswhere, '-format', 'json', *args)
             .decode(system_encoding, 'replace'))
 
     for install in vswhere(['-products', '*', '-requires', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64']):
         path = install['installationPath']
         tools_version = open(os.path.join(
             path, r'VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt'), 'rb').read().strip()
         tools_path = os.path.join(
             path, r'VC\Tools\MSVC', tools_version)
--- a/build/moz.configure/windows.configure
+++ b/build/moz.configure/windows.configure
@@ -452,26 +452,22 @@ def sdk_bin_path(valid_windows_sdk_dir, 
 mt = check_prog('MT', ('mt.exe',), input='MT',
                 paths=sdk_bin_path)
 
 
 # Check that MT is not something unexpected like "magnetic tape manipulation
 # utility".
 @depends(mt)
 @checking('whether MT is really Microsoft Manifest Tool', lambda x: bool(x))
-@imports('subprocess')
 def valid_mt(path):
-    try:
-        out = subprocess.check_output([path]).splitlines()
-        out = '\n'.join(l for l in out
-                        if 'Microsoft (R) Manifest Tool' in l)
-        if out:
-            return path
-    except subprocess.CalledProcessError:
-        pass
+    out = check_cmd_output(path, onerror=lambda: '').splitlines()
+    out = '\n'.join(l for l in out
+                    if 'Microsoft (R) Manifest Tool' in l)
+    if out:
+        return path
     raise FatalCheckError('%s is not Microsoft Manifest Tool')
 
 
 set_config('MSMANIFEST_TOOL', depends(valid_mt)(lambda x: bool(x)))
 
 js_option(env='LINKER', nargs=1, help='Path to the linker')
 
 link = check_prog('LINKER', ('lld-link',), input='LINKER',
--- a/python/mozbuild/mozbuild/test/configure/test_checks_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_checks_configure.py
@@ -627,17 +627,17 @@ Java SDK directory or use '--with-java-b
             ),
         )
 
     def test_pkg_check_modules(self):
         mock_pkg_config_version = '0.10.0'
         mock_pkg_config_path = mozpath.abspath('/usr/bin/pkg-config')
 
         def mock_pkg_config(_, args):
-            if args[0:2] == ['--errors-to-stdout', '--print-errors']:
+            if args[0:2] == ('--errors-to-stdout', '--print-errors'):
                 assert len(args) == 3
                 package = args[2]
                 if package == 'unknown':
                     return (1, "Package unknown was not found in the pkg-config search path.\n"
                             "Perhaps you should add the directory containing `unknown.pc'\n"
                             "to the PKG_CONFIG_PATH environment variable\n"
                             "No package 'unknown' found", '')
                 if package == 'valid':