waf: toolchain: override find_g{xx,cc}() instead of wrapping configure()

That's more correct than setting Waf environment variables:

 (1) We don't need to worry about differences between OSes - the previous
 implementation was actually broken for Windows because the program names in
 the environment variables were missing the ".exe" extension.

 (2) That looks better than looping over possible compiler names and running
 the configuration transactionally multiple times.
This commit is contained in:
Gustavo Jose de Sousa 2016-08-03 15:50:37 -03:00 committed by Lucas De Marchi
parent 97613ef961
commit f430ef3825

View File

@ -20,30 +20,23 @@ from waflib.Tools import clang, clangxx, gcc, gxx
import os import os
import re import re
def _set_toolchain_prefix_wrapper(tool_module, var, compiler_names): @conf
original_configure = tool_module.configure def find_gxx(conf):
def new_configure(cfg): names = ['g++', 'c++']
if cfg.env.TOOLCHAIN == 'native': if conf.env.TOOLCHAIN != 'native':
original_configure(cfg) names = ['%s-%s' % (conf.env.TOOLCHAIN, n) for n in names]
return cxx = conf.find_program(names, var='CXX')
conf.get_cc_version(cxx, gcc=True)
conf.env.CXX_NAME = 'gcc'
last_exception = None @conf
for name in compiler_names: def find_gcc(conf):
cfg.env.stash() names = ['gcc', 'cc']
try: if conf.env.TOOLCHAIN != 'native':
cfg.env[var] = '%s-%s' % (cfg.env.TOOLCHAIN, name) names = ['%s-%s' % (conf.env.TOOLCHAIN, n) for n in names]
original_configure(cfg) cc = conf.find_program(names, var='CC')
except Errors.ConfigurationError as e: conf.get_cc_version(cc, gcc=True)
cfg.env.revert() conf.env.CC_NAME = 'gcc'
last_exception = e
else:
cfg.env.commit()
return
raise last_exception
tool_module.configure = new_configure
_set_toolchain_prefix_wrapper(gxx, 'CXX', ('g++', 'c++'))
_set_toolchain_prefix_wrapper(gcc, 'CC', ('gcc', 'cc'))
def _clang_cross_support(cfg): def _clang_cross_support(cfg):
if _clang_cross_support.called: if _clang_cross_support.called: