summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Tool/MSCommon/common.py
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2010-06-06 00:40:06 (GMT)
committerSteven Knight <knight@baldmt.com>2010-06-06 00:40:06 (GMT)
commit2fc4d8d28cfba093f9d14c4215cee301aa6602c7 (patch)
treec785d935204139f147bea5f0d80febf7ab0b63de /src/engine/SCons/Tool/MSCommon/common.py
parent2e4ed805ab3387ff33aac7b3d347febe39f13391 (diff)
downloadSCons-2fc4d8d28cfba093f9d14c4215cee301aa6602c7.zip
SCons-2fc4d8d28cfba093f9d14c4215cee301aa6602c7.tar.gz
SCons-2fc4d8d28cfba093f9d14c4215cee301aa6602c7.tar.bz2
When trying to execute v[cs]*vars*.bat scripts to fetch the Visual
{C++,Studio} environment variables, propagate %COMSPEC% and any %VS*COMNTOOLS% variables from os.environ, since they're outright required for Express versions of the scripts (and maybe others) to execute correctly. Only propagate the values if they're not manually set in the ENV execution environment. Additionally, if the script execution put anything on stderr, propagate it to our stderr so we don't swallow errors. (Unfortunately, errors don't necessarily cause these scripts to exit non-zero.)
Diffstat (limited to 'src/engine/SCons/Tool/MSCommon/common.py')
-rw-r--r--src/engine/SCons/Tool/MSCommon/common.py37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/engine/SCons/Tool/MSCommon/common.py b/src/engine/SCons/Tool/MSCommon/common.py
index 596ea2d..3ba1c1d 100644
--- a/src/engine/SCons/Tool/MSCommon/common.py
+++ b/src/engine/SCons/Tool/MSCommon/common.py
@@ -99,21 +99,25 @@ def has_reg(value):
# Functions for fetching environment variable settings from batch files.
-def normalize_env(env, keys):
+def normalize_env(env, keys, force=False):
"""Given a dictionary representing a shell environment, add the variables
from os.environ needed for the processing of .bat files; the keys are
controlled by the keys argument.
It also makes sure the environment values are correctly encoded.
- Note: the environment is copied"""
+ If force=True, then all of the key values that exist are copied
+ into the returned dictionary. If force=false, values are only
+ copied if the key does not already exist in the copied dictionary.
+
+ Note: the environment is copied."""
normenv = {}
if env:
for k in env.keys():
normenv[k] = copy.deepcopy(env[k]).encode('mbcs')
for k in keys:
- if k in os.environ:
+ if k in os.environ and (force or not k in normenv):
normenv[k] = os.environ[k].encode('mbcs')
return normenv
@@ -123,8 +127,23 @@ def get_output(vcbat, args = None, env = None):
if env is None:
# Create a blank environment, for use in launching the tools
- env= SCons.Environment.Environment(tools=[])
-
+ env = SCons.Environment.Environment(tools=[])
+
+ # TODO: This is a hard-coded list of the variables that (may) need
+ # to be imported from os.environ[] for v[sc]*vars*.bat file
+ # execution to work. This list should really be either directly
+ # controlled by vc.py, or else derived from the common_tools_var
+ # settings in vs.py.
+ vars = [
+ 'COMSPEC',
+ 'VS90COMNTOOLS',
+ 'VS80COMNTOOLS',
+ 'VS71COMNTOOLS',
+ 'VS70COMNTOOLS',
+ 'VS60COMNTOOLS',
+ ]
+ env['ENV'] = normalize_env(env['ENV'], vars, force=False)
+
if args:
debug("Calling '%s %s'" % (vcbat, args))
popen = SCons.Action._subproc(env,
@@ -144,8 +163,14 @@ def get_output(vcbat, args = None, env = None):
# .communicate() method uses the threading module on Windows
# and won't work under Pythons not built with threading.
stdout = popen.stdout.read()
+ stderr = popen.stderr.read()
+ if stderr:
+ # TODO: find something better to do with stderr;
+ # this at least prevents errors from getting swallowed.
+ import sys
+ sys.stderr.write(stderr)
if popen.wait() != 0:
- raise IOError(popen.stderr.read().decode("mbcs"))
+ raise IOError(stderr.decode("mbcs"))
output = stdout.decode("mbcs")
return output