ENH: refactor function to get msvc version.
authorcournape <cournape@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Thu, 19 Nov 2009 04:51:43 +0000 (04:51 +0000)
committercournape <cournape@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Thu, 19 Nov 2009 04:51:43 +0000 (04:51 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@4433 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Tool/MSCommon/vc.py

index 66ac68e0007ea8e478987eb57a2f954269ea5625..3d78ae894aed306e28522ee6c4abc2ed326274fd 100644 (file)
@@ -280,29 +280,29 @@ def script_env(script):
     stdout = common.get_output(script)
     return common.parse_output(stdout)
 
-def msvc_setup_env(env):
-    debug('msvc_setup_env()')
-    installed_vcs = get_installed_vcs()
-    debug('InstalledVCMap:%s'%InstalledVCMap)
+def get_default_version(env):
+    debug('get_default_version()')
+
     msvc_version = env.get('MSVC_VERSION')
     if not msvc_version:
+        installed_vcs = get_installed_vcs()
+        debug('InstalledVCMap:%s'%InstalledVCMap)
         if not installed_vcs:
             msg = 'No installed VCs'
             debug('msv %s\n' % repr(msg))
             SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, msg)
-            return
+            return None
         msvc = installed_vcs[0]
         msvc_version = msvc.version
-        env['MSVC_VERSION'] = msvc_version
         debug('msvc_setup_env: using default installed MSVC version %s\n' % repr(msvc_version))
-    else:
-        msvc = InstalledVCMap.get(msvc_version)
-        debug('msvc_setup_env: using specified MSVC version %s\n' % repr(msvc_version))
-        if not msvc:
-            msg = 'VC version %s not installed' % msvc_version
-            debug('msv %s\n' % repr(msg))
-            SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, msg)
-            return
+
+    return msvc_version
+
+def msvc_setup_env(env):
+    debug('msvc_setup_env()')
+
+    version = get_default_version(env)
+    env['MSVC_VERSION'] = version
 
     host_platform = env.get('HOST_ARCH')
     if not host_platform:
@@ -312,6 +312,14 @@ def msvc_setup_env(env):
     if not target_platform:
       target_platform = host_platform
 
+    msvc = InstalledVCMap.get(version)
+    debug('msvc_setup_env: using specified MSVC version %s\n' % repr(version))
+    if not msvc:
+        msg = 'VC version %s not installed' % version
+        debug('msv %s\n' % repr(msg))
+        SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, msg)
+        return None
+
     use_script = env.get('MSVC_USE_SCRIPT', True)
     if SCons.Util.is_String(use_script):
         debug('use_script 1 %s\n' % repr(use_script))