--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -147,18 +147,54 @@ add_old_configure_assignment('TOOLCHAIN_
# Compilers
# ==============================================================
@imports('os')
@imports('subprocess')
@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.util', _import='LimitedString')
-@imports(_from='tempfile', _import='mkstemp')
@imports(_from='textwrap', _import='dedent')
def check_compiler(compiler, language):
class CompilerType(LimitedString):
POSSIBLE_VALUES = ('msvc', 'clang-cl', 'clang', 'gcc')
check = dedent('''\
#if defined(_MSC_VER)
#if defined(__clang__)
@@ -168,54 +204,24 @@ def check_compiler(compiler, language):
#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.