Bug 1520394 - Don't invoke js subconfigure as a separate process. r=nalexander
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 16 Jan 2019 23:42:12 +0000
changeset 514180 ab27c46876dd
parent 514179 adc8ba2d499e
child 514181 b88b9b479e63
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1520394
milestone66.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 1520394 - Don't invoke js subconfigure as a separate process. r=nalexander Since js configure is also python configure, we can actually create a ConfigureSandbox directly, with the right environment and arguments. Depends on D16668 Differential Revision: https://phabricator.services.mozilla.com/D16669
configure.py
js/sub.configure
--- a/configure.py
+++ b/configure.py
@@ -1,16 +1,17 @@
 # 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/.
 
 from __future__ import print_function, unicode_literals
 
 import codecs
 import itertools
+import logging
 import os
 import sys
 import textwrap
 
 
 base_dir = os.path.abspath(os.path.dirname(__file__))
 sys.path.insert(0, os.path.join(base_dir, 'python', 'mozbuild'))
 from mozbuild.configure import ConfigureSandbox
@@ -58,17 +59,17 @@ def config_status(config):
     sanitized_config['non_global_defines'] = config['non_global_defines']
     sanitized_config['topsrcdir'] = config['TOPSRCDIR']
     sanitized_config['topobjdir'] = config['TOPOBJDIR']
     sanitized_config['mozconfig'] = config.get('MOZCONFIG')
 
     # Create config.status. Eventually, we'll want to just do the work it does
     # here, when we're able to skip configure tests/use cached results/not rely
     # on autoconf.
-    print("Creating config.status", file=sys.stderr)
+    logging.getLogger('moz.configure').info('Creating config.status')
     encoding = 'mbcs' if sys.platform == 'win32' else 'utf-8'
     with codecs.open('config.status', 'w', encoding) as fh:
         fh.write(textwrap.dedent('''\
             #!%(python)s
             # coding=%(encoding)s
             from __future__ import unicode_literals
             from mozbuild.util import encode
             encoding = '%(encoding)s'
--- a/js/sub.configure
+++ b/js/sub.configure
@@ -6,19 +6,21 @@
          old_configure, old_configure_assignments, '--cache-file')
 @imports('errno')
 @imports('itertools')
 @imports('logging')
 @imports('os')
 @imports('pickle')
 @imports('subprocess')
 @imports('sys')
+@imports(_from='__main__', _import='config_status')
 @imports(_from='__builtin__', _import='OSError')
 @imports(_from='__builtin__', _import='open')
 @imports(_from='__builtin__', _import='object')
+@imports(_from='mozbuild.configure', _import='ConfigureSandbox')
 @imports(_from='mozbuild.configure.util', _import='ConfigureOutputHandler')
 @imports(_from='mozbuild.util', _import='encode')
 def js_subconfigure(build_env, prepare_configure_options, mozconfig,
                     old_configure, old_configure_assignments, cache_file):
 
     class PrefixOutput(object):
         def __init__(self, prefix, fh):
             self._fh = fh
@@ -32,17 +34,19 @@ def js_subconfigure(build_env, prepare_c
             self._begin_line = content.endswith('\n')
             if self._begin_line:
                 self._fh.write('\n')
 
         def flush(self):
             self._fh.flush()
 
     logger = logging.getLogger('moz.configure')
+    formatter = logging.Formatter('js/src> %(levelname)s: %(message)s')
     for handler in logger.handlers:
+        handler.setFormatter(formatter)
         if isinstance(handler, ConfigureOutputHandler):
             handler._stdout = PrefixOutput('js/src> ', handler._stdout)
 
     substs = dict(old_configure['substs'])
     assignments = dict(old_configure_assignments)
     environ = dict(os.environ)
     if prepare_configure_options.extra_env:
         environ.update(prepare_configure_options.extra_env)
@@ -148,42 +152,38 @@ def js_subconfigure(build_env, prepare_c
             with open(config_status_deps, 'r') as fh:
                 dep_files = fh.read().splitlines() + [configure]
             if (any(not os.path.exists(f) or
                     (os.path.getmtime(config_status_path) < os.path.getmtime(f))
                     for f in dep_files) or
                 ((previous_args or options) != options)):
                 skip_configure = False
 
+    ret = 0
     if not skip_configure:
-        # Because configure is a shell script calling a python script
-        # calling a shell script, on Windows, with msys screwing the
-        # environment, we lose the benefits from our own efforts in this
-        # script to get past the msys problems. So manually call the python
-        # script instead, so that we don't do a native->msys transition
-        # here. Then the python configure will still have the right
-        # environment when calling the shell configure.
+        oldpwd = os.getcwd()
+        os.chdir(objdir)
         command = [
-            sys.executable,
             os.path.join(build_env.topsrcdir, 'configure.py'),
             '--enable-project=js',
         ]
         environ['OLD_CONFIGURE'] = os.path.join(
             os.path.dirname(configure), 'old-configure')
         command += options
         command += ['--cache-file=%s' % cache_file]
 
         log.info('configuring')
         log.info('running %s' % ' '.join(command[:-1]))
-        proc = subprocess.Popen(
-            command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
-            cwd=objdir, env=encode(environ))
-        while True:
-            line = proc.stdout.readline()
-            if not line:
-                break
-            log.info(line.rstrip())
-        ret = proc.wait()
-        if ret:
-            log.error('subconfigure failed')
-            sys.exit(ret)
+        config = {}
+        sandbox = ConfigureSandbox(config, environ, command, logger=logger)
+        sandbox.run(os.path.join(build_env.topsrcdir, 'moz.configure'))
+        ret = config_status(config)
+        os.chdir(oldpwd)
 
-    return 0
+    # Restore unprefixed logging.
+    formatter = logging.Formatter('%(levelname)s: %(message)s')
+    for handler in logger.handlers:
+        handler.setFormatter(formatter)
+        if isinstance(handler, ConfigureOutputHandler):
+            handler._stdout.flush()
+            handler._stdout = handler._stdout._fh
+
+    return ret