Issue 2007: backtick() doesn't use ENV
authorGregNoel <GregNoel@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Thu, 28 Aug 2008 18:34:51 +0000 (18:34 +0000)
committerGregNoel <GregNoel@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Thu, 28 Aug 2008 18:34:51 +0000 (18:34 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@3322 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Environment.py
src/engine/SCons/EnvironmentTests.py

index db69d623895acc07f57a28899906ddc55421c0da..67881eb3d9afcabbe63b9006ebacae16258ecaba 100644 (file)
@@ -526,17 +526,21 @@ class SubstitutionEnvironment:
 
     def backtick(self, command):
         import subprocess
-        if SCons.Util.is_List(command): 
-            p = subprocess.Popen(command,
-                                 stdout=subprocess.PIPE,
-                                 stderr=subprocess.PIPE,
-                                 universal_newlines=True)
-        else:
-            p = subprocess.Popen(command,
-                                 stdout=subprocess.PIPE,
-                                 stderr=subprocess.PIPE,
-                                 universal_newlines=True,
-                                 shell=True)
+        # common arguments
+        kw = { 'stdout' : subprocess.PIPE,
+               'stderr' : subprocess.PIPE,
+               'universal_newlines' : True,
+             }
+        # if the command is a list, assume it's been quoted
+        # othewise force a shell
+        if not SCons.Util.is_List(command): kw['shell'] = True
+        # a SubstutionEnvironment has no ENV, so only add it
+        # to the args if it exists
+        e = self._dict.get('ENV')
+        if e: kw['env'] = e
+        # run constructed command
+        #FUTURE p = subprocess.Popen(command, **kw)
+        p = apply(subprocess.Popen, (command,), kw)
         out = p.stdout.read()
         p.stdout.close()
         err = p.stderr.read()
index 8ebbbbca6c55e46a4e6bbb5e8c01b3ca44a9251a..7e6d4ca165606362f7b168fc182420449df8b909 100644 (file)
@@ -615,6 +615,11 @@ sys.exit(0)
         test.write('fail.py', """\
 import sys
 sys.exit(1)
+""")
+        test.write('echo.py', """\
+import os, sys
+sys.stdout.write(os.environ['ECHO'] + '\\n')
+sys.exit(0)
 """)
 
         save_stderr = sys.stderr
@@ -622,22 +627,21 @@ sys.exit(1)
         python = '"' + sys.executable + '"'
 
         try:
+            sys.stderr = StringIO.StringIO()
             cmd = '%s %s' % (python, test.workpath('stdout.py'))
             output = env.backtick(cmd)
-
+            errout = sys.stderr.getvalue()
             assert output == 'this came from stdout.py\n', output
+            assert errout == '', errout
 
             sys.stderr = StringIO.StringIO()
-
             cmd = '%s %s' % (python, test.workpath('stderr.py'))
             output = env.backtick(cmd)
             errout = sys.stderr.getvalue()
-
             assert output == '', output
             assert errout == 'this came from stderr.py\n', errout
 
             sys.stderr = StringIO.StringIO()
-
             cmd = '%s %s' % (python, test.workpath('fail.py'))
             try:
                 env.backtick(cmd)
@@ -646,6 +650,15 @@ sys.exit(1)
             else:
                 self.fail("did not catch expected OSError")
 
+            sys.stderr = StringIO.StringIO()
+            cmd = '%s %s' % (python, test.workpath('echo.py'))
+            env['ENV'] = os.environ.copy()
+            env['ENV']['ECHO'] = 'this came from ECHO'
+            output = env.backtick(cmd)
+            errout = sys.stderr.getvalue()
+            assert output == 'this came from ECHO\n', output
+            assert errout == '', errout
+
         finally:
             sys.stderr = save_stderr