Gary Oberbrunner  committed c6befd6 Merge

Merged in Syeberman/scons/msvs-vcvars-caching (pull request #105)

Add caching to MSCommon.script_env

  • Participants
  • Parent commits 252bd85, c4556c9

Comments (0)

Files changed (1)

File src/engine/SCons/Tool/MSCommon/

     """Make it try again to find VC.  This is just for the tests."""
+# Running these batch files isn't cheap: most of the time spent in
+# msvs.generate() is due to vcvars*.bat.  In a build that uses "tools='msvs'"
+# in multiple environments, for example:
+#    env1 = Environment(tools='msvs')
+#    env2 = Environment(tools='msvs')
+# we can greatly improve the speed of the second and subsequent Environment
+# (or Clone) calls by memoizing the environment variables set by vcvars*.bat.
+script_env_stdout_cache = {}
 def script_env(script, args=None):
-    stdout = common.get_output(script, args)
+    cache_key = (script, args)
+    stdout = script_env_stdout_cache.get(cache_key, None)
+    if stdout is None:
+        stdout = common.get_output(script, args)
+        script_env_stdout_cache[cache_key] = stdout
     # Stupid batch files do not set return code: we take a look at the
     # beginning of the output for an error message instead
     olines = stdout.splitlines()
         if not vc_script and sdk_script:
             debug(' use_script 4: trying sdk script: %s'%(sdk_script))
-                d = script_env(sdk_script,args=[])
+                d = script_env(sdk_script)
             except BatchFileExecutionError,e:
                 debug(' use_script 5: failed running SDK script %s: Error:%s'%(repr(sdk_script),e))