Back to index

python3.2  3.2.2
Classes | Functions | Variables
distutils.msvc9compiler Namespace Reference

Classes

class  Reg
class  MacroExpander
class  MSVCCompiler

Functions

def get_build_version
def normalize_and_reduce_paths
def removeDuplicates
def find_vcvarsall
def query_vcvarsall

Variables

 RegOpenKeyEx = winreg.OpenKeyEx
 RegEnumKey = winreg.EnumKey
 RegEnumValue = winreg.EnumValue
 RegError = winreg.error
tuple HKEYS
tuple NATIVE_WIN64 = (sys.platform == 'win32' and sys.maxsize > 2**32)
string VS_BASE = r"Software\Wow6432Node\Microsoft\VisualStudio\%0.1f"
string WINSDK_BASE = r"Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows"
string NET_BASE = r"Software\Wow6432Node\Microsoft\.NETFramework"
dictionary PLAT_TO_VCVARS
tuple VERSION = get_build_version()

Detailed Description

distutils.msvc9compiler

Contains MSVCCompiler, an implementation of the abstract CCompiler class
for the Microsoft Visual Studio 2008.

The module is compatible with VS 2005 and VS 2008. You can find legacy support
for older versions of VS in distutils.msvccompiler.

Function Documentation

Find the vcvarsall.bat file

At first it tries to find the productdir of VS 2008 in the registry. If
that fails it falls back to the VS90COMNTOOLS env var.

Definition at line 216 of file msvc9compiler.py.

00216 
00217 def find_vcvarsall(version):
00218     """Find the vcvarsall.bat file
00219 
00220     At first it tries to find the productdir of VS 2008 in the registry. If
00221     that fails it falls back to the VS90COMNTOOLS env var.
00222     """
00223     vsbase = VS_BASE % version
00224     try:
00225         productdir = Reg.get_value(r"%s\Setup\VC" % vsbase,
00226                                    "productdir")
00227     except KeyError:
00228         log.debug("Unable to find productdir in registry")
00229         productdir = None
00230 
00231     if not productdir or not os.path.isdir(productdir):
00232         toolskey = "VS%0.f0COMNTOOLS" % version
00233         toolsdir = os.environ.get(toolskey, None)
00234 
00235         if toolsdir and os.path.isdir(toolsdir):
00236             productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
00237             productdir = os.path.abspath(productdir)
00238             if not os.path.isdir(productdir):
00239                 log.debug("%s is not a valid directory" % productdir)
00240                 return None
00241         else:
00242             log.debug("Env var %s is not set or invalid" % toolskey)
00243     if not productdir:
00244         log.debug("No productdir found")
00245         return None
00246     vcvarsall = os.path.join(productdir, "vcvarsall.bat")
00247     if os.path.isfile(vcvarsall):
00248         return vcvarsall
00249     log.debug("Unable to find vcvarsall.bat")
00250     return None

Here is the caller graph for this function:

Return the version of MSVC that was used to build Python.

For Python 2.3 and up, the version number is included in
sys.version.  For earlier versions, assume the compiler is MSVC 6.

Definition at line 169 of file msvc9compiler.py.

00169 
00170 def get_build_version():
00171     """Return the version of MSVC that was used to build Python.
00172 
00173     For Python 2.3 and up, the version number is included in
00174     sys.version.  For earlier versions, assume the compiler is MSVC 6.
00175     """
00176     prefix = "MSC v."
00177     i = sys.version.find(prefix)
00178     if i == -1:
00179         return 6
00180     i = i + len(prefix)
00181     s, rest = sys.version[i:].split(" ", 1)
00182     majorVersion = int(s[:-2]) - 6
00183     minorVersion = int(s[2:3]) / 10.0
00184     # I don't think paths are affected by minor version in version 6
00185     if majorVersion == 6:
00186         minorVersion = 0
00187     if majorVersion >= 6:
00188         return majorVersion + minorVersion
00189     # else we don't know what version of the compiler this is
00190     return None

Here is the call graph for this function:

Here is the caller graph for this function:

Return a list of normalized paths with duplicates removed.

The current order of paths is maintained.

Definition at line 191 of file msvc9compiler.py.

00191 
00192 def normalize_and_reduce_paths(paths):
00193     """Return a list of normalized paths with duplicates removed.
00194 
00195     The current order of paths is maintained.
00196     """
00197     # Paths are normalized so things like:  /a and /a/ aren't both preserved.
00198     reduced_paths = []
00199     for p in paths:
00200         np = os.path.normpath(p)
00201         # XXX(nnorwitz): O(n**2), if reduced_paths gets long perhaps use a set.
00202         if np not in reduced_paths:
00203             reduced_paths.append(np)
00204     return reduced_paths

def distutils.msvc9compiler.query_vcvarsall (   version,
  arch = "x86" 
)
Launch vcvarsall.bat and read the settings from its environment

Definition at line 251 of file msvc9compiler.py.

00251 
00252 def query_vcvarsall(version, arch="x86"):
00253     """Launch vcvarsall.bat and read the settings from its environment
00254     """
00255     vcvarsall = find_vcvarsall(version)
00256     interesting = set(("include", "lib", "libpath", "path"))
00257     result = {}
00258 
00259     if vcvarsall is None:
00260         raise DistutilsPlatformError("Unable to find vcvarsall.bat")
00261     log.debug("Calling 'vcvarsall.bat %s' (version=%s)", arch, version)
00262     popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch),
00263                              stdout=subprocess.PIPE,
00264                              stderr=subprocess.PIPE)
00265     try:
00266         stdout, stderr = popen.communicate()
00267         if popen.wait() != 0:
00268             raise DistutilsPlatformError(stderr.decode("mbcs"))
00269 
00270         stdout = stdout.decode("mbcs")
00271         for line in stdout.split("\n"):
00272             line = Reg.convert_mbcs(line)
00273             if '=' not in line:
00274                 continue
00275             line = line.strip()
00276             key, value = line.split('=', 1)
00277             key = key.lower()
00278             if key in interesting:
00279                 if value.endswith(os.pathsep):
00280                     value = value[:-1]
00281                 result[key] = removeDuplicates(value)
00282 
00283     finally:
00284         popen.stdout.close()
00285         popen.stderr.close()
00286 
00287     if len(result) != len(interesting):
00288         raise ValueError(str(list(result.keys())))
00289 
00290     return result
00291 
# More globals

Here is the call graph for this function:

Remove duplicate values of an environment variable.

Definition at line 205 of file msvc9compiler.py.

00205 
00206 def removeDuplicates(variable):
00207     """Remove duplicate values of an environment variable.
00208     """
00209     oldList = variable.split(os.pathsep)
00210     newList = []
00211     for i in oldList:
00212         if i not in newList:
00213             newList.append(i)
00214     newVariable = os.pathsep.join(newList)
00215     return newVariable

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 (winreg.HKEY_USERS,
00002          winreg.HKEY_CURRENT_USER,
00003          winreg.HKEY_LOCAL_MACHINE,
00004          winreg.HKEY_CLASSES_ROOT)

Definition at line 34 of file msvc9compiler.py.

tuple distutils.msvc9compiler.NATIVE_WIN64 = (sys.platform == 'win32' and sys.maxsize > 2**32)

Definition at line 39 of file msvc9compiler.py.

string distutils.msvc9compiler.NET_BASE = r"Software\Wow6432Node\Microsoft\.NETFramework"

Definition at line 46 of file msvc9compiler.py.

Initial value:
00001 {
00002     'win32' : 'x86',
00003     'win-amd64' : 'amd64',
00004     'win-ia64' : 'ia64',
00005 }

Definition at line 55 of file msvc9compiler.py.

Definition at line 30 of file msvc9compiler.py.

Definition at line 31 of file msvc9compiler.py.

Definition at line 32 of file msvc9compiler.py.

Definition at line 29 of file msvc9compiler.py.

Definition at line 292 of file msvc9compiler.py.

string distutils.msvc9compiler.VS_BASE = r"Software\Wow6432Node\Microsoft\VisualStudio\%0.1f"

Definition at line 44 of file msvc9compiler.py.

string distutils.msvc9compiler.WINSDK_BASE = r"Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows"

Definition at line 45 of file msvc9compiler.py.