diff options
Diffstat (limited to 'engine/SCons/Tool/gcc.py')
-rw-r--r-- | engine/SCons/Tool/gcc.py | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/engine/SCons/Tool/gcc.py b/engine/SCons/Tool/gcc.py index a30483d..880fc80 100644 --- a/engine/SCons/Tool/gcc.py +++ b/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 74b2c53bc42290e911b334a6b44f187da698a668 2017/11/14 13:16:53 bdbaddog" +__revision__ = "src/engine/SCons/Tool/gcc.py a56bbd8c09fb219ab8a9673330ffcd55279219d0 2019-03-26 23:16:31 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: |