From 50e2dffeadb150e4c1fdb10b8ab9bc0ff2f1e3c0 Mon Sep 17 00:00:00 2001 From: GregNoel Date: Thu, 28 Aug 2008 18:34:51 +0000 Subject: [PATCH] Issue 2007: backtick() doesn't use ENV git-svn-id: http://scons.tigris.org/svn/scons/trunk@3322 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/engine/SCons/Environment.py | 26 +++++++++++++++----------- src/engine/SCons/EnvironmentTests.py | 21 +++++++++++++++++---- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index db69d623..67881eb3 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -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() diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 8ebbbbca..7e6d4ca1 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -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 -- 2.26.2