Commits

Anonymous committed 67c2c07

Refactor SDK support:
* New mssdk_exists() and mssdk_setup_env() methods as the primary
public entry points.
* Call internal sdk.*() utility functions that just return information
(like the SDK structure) not handle the actual setting.
* Give the VisualStudio definitions explicit settings for the SDK version.

Comments (0)

Files changed (4)

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

 import SCons.Platform.win32
 import SCons.Util
 
+from SCons.Tool.MSCommon.sdk import mssdk_exists, \
+                                    mssdk_setup_env
+
 from SCons.Tool.MSCommon.vc import msvc_exists, \
                                    msvc_setup_env
 

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

 import SCons.Errors
 import SCons.Util
 
-from common import debug, read_reg
+import common
+
+debug = common.debug
 
 # SDK Checks. This is of course a mess as everything else on MS platforms. Here
 # is what we do to detect the SDK:
         hkey = self.HKEY_FMT % self.hkey_data
 
         try:
-            sdk_dir = read_reg(hkey)
+            sdk_dir = common.read_reg(hkey)
         except WindowsError, e:
             debug('find_sdk_dir(): no SDK registry key %s' % repr(hkey))
             return None
         return None
 
     try:
-        val = read_reg(_CURINSTALLED_SDK_HKEY_ROOT)
+        val = common.read_reg(_CURINSTALLED_SDK_HKEY_ROOT)
         debug("Found current sdk dir in registry: %s" % val)
     except WindowsError, e:
         debug("Did not find current sdk in registry")
 
     return val
 
+def get_sdk_by_version(mssdk):
+    if not SupportedSDKMap.has_key(mssdk):
+        msg = "SDK version %s is not supported" % repr(mssdk)
+        raise SCons.Errors.UserError, msg
+    get_installed_sdks()
+    return InstalledSDKMap.get(mssdk)
 
-def detect_sdk(version=None):
+def get_default_sdk():
+    """Set up the default Platform/Windows SDK."""
+    get_installed_sdks()
+    return InstalledSDKList[0]
+
+def mssdk_setup_env(env):
+    debug('msvs_setup_env()')
+    if env.has_key('MSSDK_DIR'):
+        sdk_dir = env['MSSDK_DIR']
+        if sdk_dir is None:
+            return
+        sdk_dir = env.subst(sdk_dir)
+    elif env.has_key('MSSDK_VERSION'):
+        sdk_version = env['MSSDK_VERSION']
+        if sdk_version is None:
+            msg = "SDK version %s is not installed" % repr(mssdk)
+            raise SCons.Errors.UserError, msg
+        sdk_version = env.subst(sdk_version)
+        mssdk = get_sdk_by_version(sdk_version)
+        sdk_dir = mssdk.get_sdk_dir()
+    elif env.has_key('MSVS_VERSION'):
+        msvs_version = env['MSVS_VERSION']
+        if msvs_version is None:
+            return
+        msvs_version = env.subst(msvs_version)
+        import vs
+        msvs = vs.get_vs_by_version(msvs_version)
+        sdk_version = msvs.sdk_version
+        if not sdk_version:
+            return
+        mssdk = get_sdk_by_version(sdk_version)
+        if not mssdk:
+            mssdk = get_default_sdk()
+            if not mssdk:
+                return
+        sdk_dir = mssdk.get_sdk_dir()
+    else:
+        mssdk = get_default_sdk()
+        if not mssdk:
+            return
+        sdk_dir = mssdk.get_sdk_dir()
+
+    set_sdk_by_directory(env, sdk_dir)
+
+    #print "No MSVS_VERSION: this is likely to be a bug"
+
+def mssdk_exists(version=None):
     sdks = get_installed_sdks()
     if version is None:
         return len(sdks) > 0
     return sdks.has_key(version)
 
-def set_sdk_by_version(env, mssdk):
-    if not SupportedSDKMap.has_key(mssdk):
-        msg = "SDK version %s is not supported" % repr(mssdk)
-        raise SCons.Errors.UserError, msg
-    get_installed_sdks()
-    sdk = InstalledSDKMap.get(mssdk)
-    if not sdk:
-        msg = "SDK version %s is not installed" % repr(mssdk)
-        raise SCons.Errors.UserError, msg
-    set_sdk_by_directory(env, sdk.get_sdk_dir())
-
-def set_default_sdk(env, msver):
-    """Set up the default Platform/Windows SDK."""
-    # For MSVS < 8, use integrated windows sdk by default
-    if msver >= 8:
-        sdks = get_installed_sdks()
-        if len(sdks) > 0:
-            set_sdk_by_directory(env, sdks[0].get_sdk_dir())
-
 # Local Variables:
 # tab-width:4
 # indent-tabs-mode:nil

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

     def __init__(self, version, **kw):
         self.version = version
         kw['vc_version'] = kw.get('vc_version', version)
+        kw['sdk_version'] = kw.get('sdk_version', version)
         self.__dict__.update(kw)
         self._cache = {}
 
     # The batch file we look for is in the VC directory,
     # so the devenv.com executable is up in ..\..\Common7\IDE.
     VisualStudio('9.0',
+                 sdk_version='6.1',
                  hkeys=[r'Microsoft\VisualStudio\9.0'],
                  common_tools_var='VS90COMNTOOLS',
                  executable_path=r'Common7\IDE\devenv.com',
     # so the VCExpress.exe executable is up in ..\..\Common7\IDE.
     VisualStudio('9.0Exp',
                  vc_version='9.0',
+                 sdk_version='6.1',
                  hkeys=[r'Microsoft\VisualStudio\9.0'],
                  common_tools_var='VS90COMNTOOLS',
                  executable_path=r'Common7\IDE\VCExpress.exe',
     # The batch file we look for is in the VC directory,
     # so the devenv.com executable is up in ..\..\Common7\IDE.
     VisualStudio('8.0',
+                 sdk_version='6.0A',
                  hkeys=[r'Microsoft\VisualStudio\8.0'],
                  common_tools_var='VS80COMNTOOLS',
                  executable_path=r'Common7\IDE\devenv.com',
     # so the VCExpress.exe executable is up in ..\..\Common7\IDE.
     VisualStudio('8.0Exp',
                  vc_version='8.0',
+                 sdk_version='6.0A',
                  hkeys=[r'Microsoft\VCExpress\8.0'],
                  common_tools_var='VS80COMNTOOLS',
                  executable_path=r'Common7\IDE\VCExpress.exe',
     # The batch file we look for is in the Common7\Tools directory,
     # so the devenv.com executable is next door in ..\IDE.
     VisualStudio('7.1',
+                 sdk_version='6.0',
                  hkeys=[r'Microsoft\VisualStudio\7.1'],
                  common_tools_var='VS71COMNTOOLS',
                  executable_path=r'IDE\devenv.com',
     # The batch file we look for is in the Common7\Tools directory,
     # so the devenv.com executable is next door in ..\IDE.
     VisualStudio('7.0',
+                 sdk_version='2003R2',
                  hkeys=[r'Microsoft\VisualStudio\7.0'],
                  common_tools_var='VS70COMNTOOLS',
                  executable_path=r'IDE\devenv.com',
 
     # Visual Studio 6.0
     VisualStudio('6.0',
+                 sdk_version='2003R1',
                  hkeys=[r'Microsoft\VisualStudio\6.0'],
                  common_tools_var='VS60COMNTOOLS',
                  executable_path=r'Common\MSDev98\Bin\MSDEV.COM',

src/engine/SCons/Tool/mssdk.py

 selection method.
 """
 
-from SCons.Tool.MSCommon.sdk import detect_sdk, \
-                                    set_default_sdk, \
-                                    set_sdk_by_directory, \
-                                    set_sdk_by_version
+from MSCommon import mssdk_exists, \
+                     mssdk_setup_env
 
 def generate(env):
     """Add construction variables for an MS SDK to an Environment."""
-    if env.has_key('MSSDK_DIR'):
-        set_sdk_by_directory(env, env.subst('$MSSDK_DIR'))
-        return
-
-    if env.has_key('MSSDK_VERSION'):
-        set_sdk_by_version(env, env.subst('$MSSDK_VERSION'))
-        return
-
-    if env.has_key('MSVS_VERSION'):
-        set_default_sdk(env, env['MSVS_VERSION'])
-
-    #print "No MSVS_VERSION: this is likely to be a bug"
-    return
+    mssdk_setup_env(env)
 
 def exists(env):
-    return detect_sdk()
+    return mssdk_exists()
 
 # Local Variables:
 # tab-width:4