diff options
| author | Greg Noel <GregNoel@tigris.org> | 2008-08-28 18:34:51 (GMT) |
|---|---|---|
| committer | Greg Noel <GregNoel@tigris.org> | 2008-08-28 18:34:51 (GMT) |
| commit | 78ebf9fe184b5724861996870e1f09902efcb1eb (patch) | |
| tree | dd6c2cb10113104c29594669542862a99acc729c /src/engine | |
| parent | 7902585ee8d1e84e2ae76289306d6858cd8f2277 (diff) | |
| download | SCons-78ebf9fe184b5724861996870e1f09902efcb1eb.zip SCons-78ebf9fe184b5724861996870e1f09902efcb1eb.tar.gz SCons-78ebf9fe184b5724861996870e1f09902efcb1eb.tar.bz2 | |
Issue 2007: backtick() doesn't use ENV
Diffstat (limited to 'src/engine')
| -rw-r--r-- | src/engine/SCons/Environment.py | 26 | ||||
| -rw-r--r-- | 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 db69d62..67881eb 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 8ebbbbc..7e6d4ca 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -616,28 +616,32 @@ sys.exit(0) 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 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 |
