Commits

Anonymous committed a59797e

Copy over changes by hand from branches/core (I was working in a
directory pointing to the wrong branch):

........
r4059 | stevenknight | 2009-03-02 06:54:13 -0800 (Mon, 02 Mar 2009) | 14 lines

Initial prototypes of modules for architecture support (MSCommon/arch.py)
and Visual C/C++ configuration distinct from (and in preference to)
the Visual Studio configuration, incorporating configuration info and
ideas from Jason Kenny's latest parts/tools/MSCommon work.

This has a lot of cut-and-paste right now and does NOT actually work.
In particular, there are no changes to the rest of the infrastructure
to actually call any of this new stuff. I'm checking these in so I can
sync on other systems for continued development.

The ultimate goal is for much of the current MSCommon/vs.py module's
logic to migrate to MSCommon/vc.py, since that's what we're actually
interested in configuring.

........
r4058 | stevenknight | 2009-03-02 06:49:35 -0800 (Mon, 02 Mar 2009) | 2 lines

Fix doc string.

........
r4056 | stevenknight | 2009-03-01 06:10:31 -0800 (Sun, 01 Mar 2009) | 4 lines

Change the sanity_check file for 6.1 per Jason's update.
Add an optional version string argument to detect_sdk().
Import directly from common, not SCons.Tool.MSCommon.common.

........
r4055 | stevenknight | 2009-02-28 05:29:03 -0800 (Sat, 28 Feb 2009) | 5 lines

Minor common.py enhancements:
Refactor is_win64() to cache its return value so we don't have to hit
registry every time we want to know if the OS is 64-bit.
Accept SCONS_MSCOMMON_DEBUG=- to mean print debug messages to stdout.

........

  • Participants
  • Parent commits 034a178
  • Branches vs_revamp

Comments (0)

Files changed (4)

File src/engine/SCons/Tool/MSCommon/arch.py

+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+__doc__ = """Module to define supported Windows chip architectures.
+"""
+
+import os
+
+class ArchDefinition:
+    """
+    A class for defining architecture-specific settings and logic.
+    """
+    def __init__(self, arch, synonyms=[]):
+        self.arch = arch
+        self.synonyms = synonyms
+
+SupportedArchitectureList = [
+    ArchitectureDefinition(
+        'x86',
+        ['i386', 'i486', 'i586', 'i686'],
+    ),
+
+    ArchitectureDefinition(
+        'x86_64',
+        ['AMD64, 'amd64, 'em64t, 'EM64T, 'x86_64'],
+    ),
+
+    ArchitectureDefinition(
+        'ia64',
+        ['IA64'],
+    ),
+]
+
+SupportedArchitectureMap = {}
+for a in SupportedArchitectureList:
+    SupportedArchitectureMap[a.arch] = a
+    for s in a.synonyms:
+        SupportedArchitectureMap[s] = a
+
+def get_architecture(arch=None):
+    """Returns the definition for the specified architecture string.
+
+    If no string is specified, the system default is returned (as defined
+    by the PROCESSOR_ARCHITEW6432 or PROCESSOR_ARCHITECTURE environment
+    variables).
+    """
+    if arch is None:
+        arch = os.environ.get('PROCESSOR_ARCHITEW6432')
+        if not arch:
+            arch = os.environ['PROCESSOR_ARCHITECTURE']
+    return SupportedArchitectureMap.get(arch, '')

File src/engine/SCons/Tool/MSCommon/common.py

 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 __doc__ = """
-Common helper functions for working with
+Common helper functions for working with the Microsoft tool chain.
 """
 
 import copy
 
 
 logfile = os.environ.get('SCONS_MSCOMMON_DEBUG')
-if logfile:
+if logfile == '-':
+    def debug(x):
+        print x
+elif logfile:
     try:
         import logging
     except ImportError:
     debug = lambda x: None
 
 
-# TODO(sgk): unused
+_is_win64 = None
+
 def is_win64():
     """Return true if running on windows 64 bits."""
-    # Unfortunately, python does not seem to have anything useful: neither
-    # sys.platform nor os.name gives something different on windows running on
-    # 32 bits or 64 bits. Note that we don't care about whether python itself
-    # is 32 or 64 bits here
-    value = "Software\Wow6432Node"
-    yo = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE, value)[0]
-    if yo is None:
-        return 0
-    else:
-        return 1
+    # Unfortunately, python does not provide a useful way to determine
+    # if the underlying Windows OS is 32-bit or 64-bit.  Worse, whether
+    # the Python itself is 32-bit or 64-bit affects what it returns,
+    # so nothing in sys.* or os.* help.  So we go to the registry to
+    # look directly for a clue from Windows, caching the result to
+    # avoid repeated registry calls.
+    global _is_win64
+    if _is_win64 is None:
+        try:
+            yo = read_reg(r'Software\Wow6432Node')
+        except WindowsError:
+            yo = None
+        _is_win64 = (yo is not None)
+    return _is_win64
+
 
 def read_reg(value):
     return SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE, value)[0]

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

 import os
 
 import SCons.Errors
-from SCons.Tool.MSCommon.common import debug, read_reg
 import SCons.Util
 
+from common import debug, read_reg
+
 # SDK Checks. This is of course a mess as everything else on MS platforms. Here
 # is what we do to detect the SDK:
 #
 # If you update this list, update the documentation in Tool/mssdk.xml.
 SupportedSDKList = [
     WindowsSDK('6.1',
-                sanity_check_file=r'include\windows.h'),
+                sanity_check_file=r'bin\SetEnv.Cmd'),
 
     WindowsSDK('6.0A',
                sanity_check_file=r'include\windows.h'),
     return val
 
 
-def detect_sdk():
-    return (len(get_installed_sdks()) > 0)
+def detect_sdk(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):

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

+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+__doc__ = """Module for Visual C/C++ detection and configuration.
+"""
+
+import os
+
+import common
+
+class VisualC:
+    """
+    An base class for finding installed versions of Visual C/C++.
+    """
+    def __init__(self, version, **kw):
+        self.version = version
+        self.__dict__.update(kw)
+
+    def vcbin_arch(self):
+        if common.is_win64():
+            result = {
+                'x86_64' : ['amd64', r'BIN\x86_amd64'],
+                'ia64' : [r'BIN\ia64'],
+            }.get(target_arch, [])
+        else:
+            result = {
+                'x86_64' : ['x86_amd64'],
+                'ia64' : ['x86_ia64'],
+            }.get(target_arch, [])
+        # TODO(1.5)
+        #return ';'.join(result)
+        return string.join(result, ';')
+
+    #
+
+    batch_file_map = {
+        # Indexed by (target_architecture, host_architecture).
+        ('x86_64', 'x86') : [
+            r'bin\x86_amd64\vcvarsx86_amd64.bat',
+        ],
+        ('x86_64', 'x86') : [
+            r'bin\ia64\vcvarsia64.bat',
+            r'bin\x86_ia64\vcvarsx86_ia64.bat',
+        ],
+        ('x86_64', 'x86_64') : [
+            r'bin\amd64\vcvarsamd64.bat',
+            r'bin\x86_amd64\vcvarsx86_amd64.bat',
+        ],
+        ('ia64', 'ia64') : [
+            r'bin\x86_ia64\vcvarsx86_ia64.bat',
+        ],
+        ('x86', 'x86') : [
+            r'bin\vcvars32.bat',
+        ],
+    }
+
+    def find_batch_file(self):
+        key = (target_architecture, host_architecture)
+        potential_batch_files = self.batch_file_map.get(key)
+        if potential_batch_files:
+            product_dir = self.msvc_root_dir()
+            for batch_file in potential_batch_files:
+                bf = os.path.join(product_dir, batch_file)
+                if os.path.isfile(bf):
+                    return bf
+        return None
+
+    #
+
+    def get_batch_file(self):
+        try:
+            return self._cache['batch_file']
+        except KeyError:
+            executable = self.find_batch_file()
+            self._cache['batch_file'] = batch_file
+            return batch_file
+        
+
+# The list of supported Visual C/C++ versions we know how to detect.
+#
+# The first VC found in the list is the one used by default if there
+# are multiple VC installed.  Barring good reasons to the contrary,
+# this means we should list VC with from most recent to oldest.
+#
+# If you update this list, update the documentation in Tool/vc.xml.
+SupportedVisualCList = [
+    VisualC('9.0',
+            hkey_root=[
+                r'Software%sMicrosoft\VisualStudio\9.0\Setup\VC\ProductDir',
+                r'Software%sMicrosoft\VCExpress\9.0\Setup\VC\ProductDir',
+            ],
+            default_install=r'Microsoft Visual Studio 9.0\VC',
+            common_tools_var='VS90COMNTOOLS',
+            vc_sub_dir='VC\\',
+            batch_file_base='vcvars',
+            supported_arch=['x86', 'x86_64', 'ia64'],
+            atlmc_include_subdir = [r'ATLMFC\INCLUDE'],
+            atlmfc_lib_subdir = {
+                'x86'       : r'ATLMFC\LIB',
+                'x86_64'    : r'ATLMFC\LIB\amd64',
+                'ia64'      : r'ATLMFC\LIB\ia64',
+            },
+            crt_lib_subdir = {
+                'x86_64'    : r'LIB\amd64',
+                'ia64'      : r'LIB\ia64',
+            },
+    ),
+    VisualC('8.0',
+            hkey_root=[
+                r'Software%sMicrosoft\VisualStudio\8.0\Setup\VC\ProductDir',
+                r'Software%sMicrosoft\VCExpress\8.0\Setup\VC\ProductDir',
+            ],
+            default_install=r'%s\Microsoft Visual Studio 8\VC',
+            common_tools_var='VS80COMNTOOLS',
+            vc_sub_dir='VC\\',
+            batch_file_base='vcvars',
+            supported_arch=['x86', 'x86_64', 'ia64'],
+            atlmc_include_subdir = [r'ATLMFC\INCLUDE'],
+            atlmfc_lib_subdir = {
+                'x86'       : r'ATLMFC\LIB',
+                'x86_64'    : r'ATLMFC\LIB\amd64',
+                'ia64'      : r'ATLMFC\LIB\ia64',
+            },
+            crt_lib_subdir = {
+                'x86_64'    : r'LIB\amd64',
+                'ia64'      : r'LIB\ia64',
+            },
+    ),
+    VisualC('7.1',
+            hkey_root=[
+                r'Software%sMicrosoft\VisualStudio\7.1\Setup\VC\ProductDir',
+            ],
+            default_install=r'%s\Microsoft Visual Studio 7.1.NET 2003\VC7',
+            common_tools_var='VS71COMNTOOLS',
+            vc_sub_dir='VC7\\',
+            batch_file_base='vcvars',
+            supported_arch=['x86'],
+            atlmc_include_subdir = [r'ATLMFC\INCLUDE'],
+            atlmfc_lib_subdir = {
+                'x86' : r'ATLMFC\LIB',
+            },
+    ),
+    VisualC('7.0',
+            hkey_root=[
+                r'Software%sMicrosoft\VisualStudio\7.0\Setup\VC\ProductDir',
+            ],
+            default_install=r'%s\Microsoft Visual Studio .NET\VC7',
+            common_tools_var='VS70COMNTOOLS',
+            vc_sub_dir='VC7\\',
+            batch_file_base='vcvars',
+            supported_arch=['x86'],
+            atlmc_include_subdir = [r'ATLMFC\INCLUDE'],
+            atlmfc_lib_subdir = {
+                'x86' : r'ATLMFC\LIB',
+            },
+    ),
+    VisualC('6.0',
+            hkey_root=[
+                r'Software%sMicrosoft\VisualStudio\6.0\Setup\Microsoft Visual C++\ProductDir',
+            ],
+            default_install=r'%s\Microsoft Visual Studio\VC98',
+            common_tools_var='VS60COMNTOOLS',
+            vc_sub_dir='VC98\\',
+            batch_file_base='vcvars',
+            supported_arch=['x86'],
+            atlmc_include_subdir = [r'ATL\INCLUDE', r'MFC\INCLUDE'],
+            atlmfc_lib_subdir = {
+                'x86' : r'MFC\LIB',
+            },
+    ),
+]
+
+SupportedVCMap = {}
+for vc in SupportedVCList:
+    SupportedVCMap[vc.version] = vc
+
+
+# Finding installed versions of Visual C/C++ isn't cheap, because it goes
+# not only to the registry but also to the disk to sanity-check that there
+# is, in fact, something installed there and that the registry entry isn't
+# just stale.  Find this information once, when requested, and cache it.
+
+InstalledVCList = None
+InstalledVCMap = None
+
+def get_installed_vcs():
+    global InstalledVCList
+    global InstalledVCMap
+    if InstalledVCList is None:
+        InstalledVCList = []
+        InstalledVCMap = {}
+        for vc in SupportedVCList:
+            debug('trying to find VC %s' % vc.version)
+            if vc.get_vc_dir():
+                debug('found VC %s' % vc.version)
+                InstalledVCList.append(vc)
+                InstalledVCMap[vc.version] = vc
+    return InstalledVCList
+
+
+def detect_vc(version=None):
+    vcs = get_installed_vcs()
+    if version is None:
+        return len(vcs) > 0
+    return vcs.has_key(version)
+
+def set_vc_by_version(env, msvc):
+    if not SupportedVCMap.has_key(msvc):
+        msg = "VC version %s is not supported" % repr(msvc)
+        raise SCons.Errors.UserError, msg
+    get_installed_vcs()
+    vc = InstalledVCMap.get(msvc)
+    if not vc:
+        msg = "VC version %s is not installed" % repr(msvc)
+        raise SCons.Errors.UserError, msg
+    set_vc_by_directory(env, vc.get_vc_dir())
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: