summaryrefslogtreecommitdiff
path: root/src/engine/SCons/Tool/gcc.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/SCons/Tool/gcc.py')
-rw-r--r--src/engine/SCons/Tool/gcc.py51
1 files changed, 31 insertions, 20 deletions
diff --git a/src/engine/SCons/Tool/gcc.py b/src/engine/SCons/Tool/gcc.py
index f241c7b..2532427 100644
--- a/src/engine/SCons/Tool/gcc.py
+++ b/src/engine/SCons/Tool/gcc.py
@@ -9,7 +9,7 @@ selection method.
"""
#
-# Copyright (c) 2001 - 2017 The SCons Foundation
+# Copyright (c) 2001 - 2019 The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -31,7 +31,7 @@ selection method.
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-__revision__ = "src/engine/SCons/Tool/gcc.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
+__revision__ = "src/engine/SCons/Tool/gcc.py e724ae812eb96f4858a132f5b8c769724744faf6 2019-07-21 00:04:47 bdeegan"
from . import cc
import os
@@ -42,6 +42,7 @@ import SCons.Util
compilers = ['gcc', 'cc']
+
def generate(env):
"""Add Builders and construction variables for gcc to an Environment."""
@@ -59,38 +60,48 @@ def generate(env):
if version:
env['CCVERSION'] = version
+
def exists(env):
# 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."""
+ version = None
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)
+ return version
+
# -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 = SCons.Util.to_str(pipe.stdout.readline())
+ # 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)
+ if pipe.wait() != 0:
+ return version
+
+ with pipe.stdout:
+ # -dumpversion variant:
+ # line = pipe.stdout.read().strip()
+ # --version variant:
+ line = SCons.Util.to_str(pipe.stdout.readline())
+ # 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 SCons.Util.to_str(pipe.stdout.readline()):
+ pass
+
+ # -dumpversion variant:
+ # if line:
+ # version = line
+ # --version variant:
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 SCons.Util.to_str(pipe.stdout.readline()):
- pass
- ret = pipe.wait()
- if ret != 0:
- return None
+
return version
# Local Variables: