Bug 1520377 - Replace/Inline subconfigure.{prefix_lines,execute_and_prefix}. r=nalexander
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 16 Jan 2019 21:44:54 +0000
changeset 514172 e0fd6ca971ae522dd9398d49f564fe3f7263112b
parent 514171 e822bc175cee7ba13449081a4864bbec22cf3fc9
child 514173 939c78a89e7d29fda19d764e110bacca71f48e60
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
bugs1520377
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 1520377 - Replace/Inline subconfigure.{prefix_lines,execute_and_prefix}. r=nalexander Use an I/O wrapper on the configure output handler to add the "js/src>" prefix. Depends on D16643 Differential Revision: https://phabricator.services.mozilla.com/D16644
build/subconfigure.py
js/sub.configure
--- a/build/subconfigure.py
+++ b/build/subconfigure.py
@@ -52,26 +52,8 @@ def prepare(srcdir, objdir, args):
     except OSError as e:
         if e.errno != errno.EEXIST:
             raise
 
     with open(data_file, 'wb') as f:
         pickle.dump(data, f)
 
     return data
-
-
-def prefix_lines(text, prefix):
-    return ''.join('%s> %s' % (prefix, line) for line in text.splitlines(True))
-
-
-def execute_and_prefix(*args, **kwargs):
-    prefix = kwargs['prefix']
-    del kwargs['prefix']
-    proc = subprocess.Popen(*args, stdout=subprocess.PIPE,
-                            stderr=subprocess.STDOUT, **kwargs)
-    while True:
-        line = proc.stdout.readline()
-        if not line:
-            break
-        print(prefix_lines(line.rstrip(), prefix))
-        sys.stdout.flush()
-    return proc.wait()
--- a/js/sub.configure
+++ b/js/sub.configure
@@ -1,22 +1,49 @@
 # 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/.
 
 @depends(check_build_environment, prepare_configure_options, prepare_mozconfig,
          old_configure, old_configure_assignments, '--cache-file')
 @imports('itertools')
+@imports('logging')
 @imports('os')
 @imports('subconfigure')
+@imports('subprocess')
 @imports('sys')
 @imports(_from='__builtin__', _import='open')
+@imports(_from='__builtin__', _import='object')
+@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
+            self._begin_line = True
+            self._prefix = prefix
+
+        def write(self, content):
+            if self._begin_line:
+                self._fh.write(self._prefix)
+            self._fh.write(('\n' + self._prefix).join(content.splitlines()))
+            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')
+    for handler in logger.handlers:
+        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)
 
     options = [
         o for o in prepare_configure_options.options
@@ -125,17 +152,24 @@ def js_subconfigure(build_env, prepare_c
             os.path.join(build_env.topsrcdir, 'configure.py'),
             '--enable-project=js',
         ]
         environ['OLD_CONFIGURE'] = os.path.join(
             os.path.dirname(configure), 'old-configure')
         command += data['args']
         command += ['--cache-file=%s' % cache_file]
 
-        log.info(subconfigure.prefix_lines('configuring', 'js/src'))
-        log.info(subconfigure.prefix_lines('running %s' % ' '.join(command[:-1]), 'js/src'))
-        ret = subconfigure.execute_and_prefix(command, cwd=objdir, env=encode(environ),
-                                              prefix='js/src')
+        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)
 
     return 0