diff options
author | Michael Haubenwallner <haubi@gentoo.org> | 2014-05-15 08:17:03 (GMT) |
---|---|---|
committer | Michael Haubenwallner <haubi@gentoo.org> | 2014-05-15 08:17:03 (GMT) |
commit | c82684ba964183647a1965589ef852eacd9e5447 (patch) | |
tree | eeac860a5e8bba755f8f5dc091702bc78989d8a0 /src | |
parent | 80cdee0bb0319a9c14abd9c60b4123aee07f0274 (diff) | |
download | SCons-c82684ba964183647a1965589ef852eacd9e5447.zip SCons-c82684ba964183647a1965589ef852eacd9e5447.tar.gz SCons-c82684ba964183647a1965589ef852eacd9e5447.tar.bz2 |
Respect preset CC/CXX values detecting cc/c++/gcc/g++ Tools.
As the user-preset values for CC/CXX should rule always, also respect them in
exists() and generate() methods of these Tools. As a result, the value for
CCVERSION/CXXVERSION does match the CC/CXX compiler used (issue#1723).
Diffstat (limited to 'src')
-rw-r--r-- | src/engine/SCons/Environment.py | 4 | ||||
-rw-r--r-- | src/engine/SCons/Tool/ToolTests.py | 2 | ||||
-rw-r--r-- | src/engine/SCons/Tool/c++.py | 5 | ||||
-rw-r--r-- | src/engine/SCons/Tool/cc.py | 7 | ||||
-rw-r--r-- | src/engine/SCons/Tool/g++.py | 30 | ||||
-rw-r--r-- | src/engine/SCons/Tool/gcc.py | 58 |
6 files changed, 61 insertions, 45 deletions
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 3e499b6..45c40c3 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -1803,8 +1803,8 @@ class Base(SubstitutionEnvironment): pass elif SCons.Util.is_String(pathext): pathext = self.subst(pathext) - prog = self.subst(prog) - path = SCons.Util.WhereIs(prog, path, pathext, reject) + prog = SCons.Util.CLVar(self.subst(prog)) # support "program --with-args" + path = SCons.Util.WhereIs(prog[0], path, pathext, reject) if path: return path return None diff --git a/src/engine/SCons/Tool/ToolTests.py b/src/engine/SCons/Tool/ToolTests.py index 3e6da5b..a4353b1 100644 --- a/src/engine/SCons/Tool/ToolTests.py +++ b/src/engine/SCons/Tool/ToolTests.py @@ -51,6 +51,8 @@ class ToolTestCase(unittest.TestCase): return self.dict.__contains__(key) def has_key(self, key): return key in self.dict + def subst(self, string, *args, **kwargs): + return string env = Environment() env['BUILDERS'] = {} env['ENV'] = {} diff --git a/src/engine/SCons/Tool/c++.py b/src/engine/SCons/Tool/c++.py index 82a19c5..430851c 100644 --- a/src/engine/SCons/Tool/c++.py +++ b/src/engine/SCons/Tool/c++.py @@ -72,7 +72,8 @@ def generate(env): SCons.Tool.cc.add_common_cc_variables(env) - env['CXX'] = 'c++' + if 'CXX' not in env: + env['CXX'] = env.Detect(compilers) or compilers[0] env['CXXFLAGS'] = SCons.Util.CLVar('') env['CXXCOM'] = '$CXX -o $TARGET -c $CXXFLAGS $CCFLAGS $_CCCOMCOM $SOURCES' env['SHCXX'] = '$CXX' @@ -90,7 +91,7 @@ def generate(env): env['CXXFILESUFFIX'] = '.cc' def exists(env): - return env.Detect(compilers) + return env.Detect(env.get('CXX', compilers)) # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/Tool/cc.py b/src/engine/SCons/Tool/cc.py index 9b404b2..590ec5f 100644 --- a/src/engine/SCons/Tool/cc.py +++ b/src/engine/SCons/Tool/cc.py @@ -62,6 +62,8 @@ def add_common_cc_variables(env): if 'SHCCFLAGS' not in env: env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS') +compilers = ['cc'] + def generate(env): """ Add Builders and construction variables for C compilers to an Environment. @@ -76,7 +78,8 @@ def generate(env): add_common_cc_variables(env) - env['CC'] = 'cc' + if 'CC' not in env: + env['CC'] = env.Detect(compilers) or compilers[0] env['CFLAGS'] = SCons.Util.CLVar('') env['CCCOM'] = '$CC -o $TARGET -c $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES' env['SHCC'] = '$CC' @@ -93,7 +96,7 @@ def generate(env): env['CFILESUFFIX'] = '.c' def exists(env): - return env.Detect('cc') + return env.Detect(env.get('CC', compilers)) # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/Tool/g++.py b/src/engine/SCons/Tool/g++.py index e4da5fe..5cf3827 100644 --- a/src/engine/SCons/Tool/g++.py +++ b/src/engine/SCons/Tool/g++.py @@ -40,6 +40,8 @@ import subprocess import SCons.Tool import SCons.Util +import gcc + cplusplus = __import__('c++', globals(), locals(), []) compilers = ['g++'] @@ -48,9 +50,10 @@ def generate(env): """Add Builders and construction variables for g++ to an Environment.""" static_obj, shared_obj = SCons.Tool.createObjBuilders(env) - cplusplus.generate(env) + if 'CXX' not in env: + env['CXX'] = env.Detect(compilers) or compilers[0] - env['CXX'] = env.Detect(compilers) + cplusplus.generate(env) # platform specific settings if env['PLATFORM'] == 'aix': @@ -62,26 +65,13 @@ def generate(env): elif env['PLATFORM'] == 'sunos': env['SHOBJSUFFIX'] = '.pic.o' # determine compiler version - if env['CXX']: - #pipe = SCons.Action._subproc(env, [env['CXX'], '-dumpversion'], - pipe = SCons.Action._subproc(env, [env['CXX'], '--version'], - stdin = 'devnull', - stderr = 'devnull', - stdout = subprocess.PIPE) - if pipe.wait() != 0: return - # -dumpversion was added in GCC 3.0. As long as we're supporting - # GCC versions older than that, we should use --version and a - # regular expression. - #line = pipe.stdout.read().strip() - #if line: - # env['CXXVERSION'] = line - line = pipe.stdout.readline() - match = re.search(r'[0-9]+(\.[0-9]+)+', line) - if match: - env['CXXVERSION'] = match.group(0) + version = gcc.detect_version(env, env['CXX']) + if version: + env['CXXVERSION'] = version def exists(env): - return env.Detect(compilers) + # is executable, and is a GNU compiler (or accepts '--version' at least) + return gcc.detect_version(env, env.Detect(env.get('CXX', compilers))) # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/Tool/gcc.py b/src/engine/SCons/Tool/gcc.py index 71f60a3..df65647 100644 --- a/src/engine/SCons/Tool/gcc.py +++ b/src/engine/SCons/Tool/gcc.py @@ -44,34 +44,54 @@ compilers = ['gcc', 'cc'] def generate(env): """Add Builders and construction variables for gcc to an Environment.""" + + if 'CC' not in env: + env['CC'] = env.Detect(compilers) or compilers[0] + cc.generate(env) - env['CC'] = env.Detect(compilers) or 'gcc' if env['PLATFORM'] in ['cygwin', 'win32']: env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS') else: env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS -fPIC') # determine compiler version - if env['CC']: - #pipe = SCons.Action._subproc(env, [env['CC'], '-dumpversion'], - pipe = SCons.Action._subproc(env, [env['CC'], '--version'], - stdin = 'devnull', - stderr = 'devnull', - stdout = subprocess.PIPE) - if pipe.wait() != 0: return - # -dumpversion was added in GCC 3.0. As long as we're supporting - # GCC versions older than that, we should use --version and a - # regular expression. - #line = pipe.stdout.read().strip() - #if line: - # env['CCVERSION'] = line - line = pipe.stdout.readline() - match = re.search(r'[0-9]+(\.[0-9]+)+', line) - if match: - env['CCVERSION'] = match.group(0) + version = detect_version(env, env['CC']) + if version: + env['CCVERSION'] = version def exists(env): - return env.Detect(compilers) + # is executable, and is a GNU compiler (or accepts '--version' at least) + return detect_version(env, env.Detect(env.get('CC', compilers))) + +def detect_version(env, cc): + """Return the version of the GNU compiler, or None if it is not a GNU compiler.""" + cc = env.subst(cc) + if not cc: + return None + version = None + #pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['-dumpversion'], + pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['--version'], + stdin = 'devnull', + stderr = 'devnull', + stdout = subprocess.PIPE) + # -dumpversion was added in GCC 3.0. As long as we're supporting + # GCC versions older than that, we should use --version and a + # regular expression. + #line = pipe.stdout.read().strip() + #if line: + # version = line + line = pipe.stdout.readline() + match = re.search(r'[0-9]+(\.[0-9]+)+', line) + if match: + version = match.group(0) + # Non-GNU compiler's output (like AIX xlc's) may exceed the stdout buffer: + # So continue with reading to let the child process actually terminate. + while pipe.stdout.readline(): + pass + ret = pipe.wait() + if ret != 0: + return None + return version # Local Variables: # tab-width:4 |