Issues 2076 and 2232, use ENV and suppress stderr when checking GCC version ID
authorGregNoel <GregNoel@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 10 Sep 2008 06:33:28 +0000 (06:33 +0000)
committerGregNoel <GregNoel@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 10 Sep 2008 06:33:28 +0000 (06:33 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@3382 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Tool/g++.py
src/engine/SCons/Tool/gcc.py

index 917229faafc3fbe1fa8a0031dbb561615efe5f84..0745c03fd014f27a3a2b9b51a714e6a5bc7fee91 100644 (file)
@@ -35,8 +35,8 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os.path
 import re
+import subprocess
 
-import SCons.Defaults
 import SCons.Tool
 import SCons.Util
 
@@ -63,11 +63,23 @@ def generate(env):
         env['SHOBJSUFFIX'] = '.pic.o'
     # determine compiler version
     if env['CXX']:
-        line = os.popen(env['CXX'] + ' --version').readline()
+        try:
+            pipe = subprocess.Popen([env['CXX'], '--version'],
+                                    env=env['ENV'],
+                                    stderr = subprocess.PIPE,
+                                    stdout = subprocess.PIPE)
+        except OSError:
+           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)
 
-
 def exists(env):
     return env.Detect(compilers)
index ad02e0deb52b49973bf9a12a2ace825228abc92f..4e81ba847a6dcac4e188600701eddd6927ff4cef 100644 (file)
@@ -33,11 +33,12 @@ selection method.
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
-import SCons.Util
-
 import cc
 import os
 import re
+import subprocess
+
+import SCons.Util
 
 compilers = ['gcc', 'cc']
 
@@ -52,7 +53,20 @@ def generate(env):
         env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS -fPIC')
     # determine compiler version
     if env['CC']:
-        line = os.popen(env['CC'] + ' --version').readline()
+        try:
+            pipe = subprocess.Popen([env['CC'], '--version'],
+                                    env=env['ENV'],
+                                    stderr = subprocess.PIPE,
+                                    stdout = subprocess.PIPE)
+        except OSError:
+           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)