Bug 1264482 - Move compiler invocation for preprocessing to a separate function. r=ted
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 06 Apr 2016 11:32:03 +0900
changeset 331690 3abd062e590cf38b1addb1fd3a24fe38a5cc7d6d
parent 331689 4e3809b7b919db8ed2ba458b8514bda62c9917ef
child 331691 a1a03c58109d5bfc8e86d8ce49c883409817d791
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs1264482
milestone48.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 1264482 - Move compiler invocation for preprocessing to a separate function. r=ted
build/moz.configure/toolchain.configure
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -145,74 +145,80 @@ def toolchain_prefix(value, target, host
 set_config('TOOLCHAIN_PREFIX', toolchain_prefix)
 add_old_configure_assignment('TOOLCHAIN_PREFIX', toolchain_prefix)
 
 
 # Compilers
 # ==============================================================
 @imports('os')
 @imports('subprocess')
-@imports(_from='mozbuild.configure.constants', _import='CompilerType')
 @imports(_from='mozbuild.configure.util', _import='LineIO')
 @imports(_from='mozbuild.shellutil', _import='quote')
 @imports(_from='tempfile', _import='mkstemp')
+def try_preprocess(compiler, language, source):
+    suffix = {
+        'C': '.c',
+        'C++': '.cpp',
+    }[language]
+
+    fd, path = mkstemp(prefix='conftest.', suffix=suffix)
+    try:
+        source = source.encode('ascii', 'replace')
+
+        log.debug('Creating `%s` with content:', path)
+        with LineIO(lambda l: log.debug('| %s', l)) as out:
+            out.write(source)
+
+        os.write(fd, source)
+        os.close(fd)
+
+        cmd = compiler + ['-E', path]
+        log.debug('Executing: `%s`', quote(*cmd))
+        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+                                stderr=subprocess.PIPE)
+        stdout, stderr = proc.communicate()
+        retcode = proc.wait()
+        if retcode == 0:
+            return stdout
+
+        log.debug('The command returned non-zero exit status %d.', retcode)
+        for out, desc in ((stdout, 'output'), (stderr, 'error output')):
+            if out:
+                log.debug('Its %s was:', desc)
+                with LineIO(lambda l: log.debug('| %s', l)) as o:
+                    o.write(out)
+    finally:
+        os.remove(path)
+
+
+@imports(_from='mozbuild.configure.constants', _import='CompilerType')
 @imports(_from='textwrap', _import='dedent')
 def check_compiler(compiler, language):
     check = dedent('''\
         #if defined(_MSC_VER)
         #if defined(__clang__)
         COMPILER clang-cl _MSC_VER
         #else
         COMPILER msvc _MSC_FULL_VER
         #endif
         #elif defined(__clang__)
         COMPILER clang __clang_major__.__clang_minor__.__clang_patchlevel__
         #elif defined(__GNUC__)
         COMPILER gcc __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__
         #endif
     ''')
 
-    suffix = {
-        'C': '.c',
-        'C++': '.cpp',
-    }[language]
-
-    fd, path = mkstemp(prefix='conftest.', suffix=suffix)
-    try:
-        source = check.encode('ascii', 'replace')
-
-        log.debug('Creating `%s` with content:', path)
-        with LineIO(lambda l: log.debug('| %s', l)) as out:
-            out.write(source)
-
-        os.write(fd, source)
-        os.close(fd)
+    result = try_preprocess(compiler, language, check)
 
-        cmd = compiler + ['-E', path]
-        log.debug('Executing: `%s`', quote(*cmd))
-        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
-                                stderr=subprocess.PIPE)
-        stdout, stderr = proc.communicate()
-        retcode = proc.wait()
-        if retcode == 0:
-            for line in stdout.splitlines():
-                if line.startswith('COMPILER '):
-                    _, type, version = line.split(None, 2)
-                    version = version.replace(' ', '')
-                    return CompilerType(type), version
-            return
-
-        log.debug('The command returned non-zero exit status %d.', retcode)
-        for out, desc in ((stdout, 'output'), (stderr, 'error output')):
-            if out:
-                log.debug('Its %s was:', desc)
-                with LineIO(lambda l: log.debug('| %s', l)) as o:
-                    o.write(out)
-    finally:
-        os.remove(path)
+    if result:
+        for line in result.splitlines():
+            if line.startswith('COMPILER '):
+                _, type, version = line.split(None, 2)
+                version = version.replace(' ', '')
+                return CompilerType(type), version
 
 
 @template
 def default_c_compilers(host_or_target):
     '''Template defining the set of default C compilers for the host and
     target platforms.
     `host_or_target` is either `host` or `target` (the @depends functions
     from init.configure.