Latest patch from Thomas Heller/Robin Becker:
* tweak my docstrings * fix None returns to empty list * reshuffle responsibilities between '_find_exe()', '_find_SET()', and the MSVCCompiler constructor -- now the constructor worries about fetching the version list and determining the most recent one * added "/W3" compile option Also, I added/tweaked some docstrings.
This commit is contained in:
parent
4eb504c2af
commit
699880931e
|
@ -17,12 +17,12 @@ from distutils.ccompiler import \
|
||||||
|
|
||||||
|
|
||||||
def get_devstudio_versions ():
|
def get_devstudio_versions ():
|
||||||
|
|
||||||
"""Get list of devstudio versions from the Windows registry. Return a
|
"""Get list of devstudio versions from the Windows registry. Return a
|
||||||
list of strings (???) containing version numbers; the list will be
|
list of strings containing version numbers; the list will be
|
||||||
empty if we were unable to access the registry (eg. couldn't import
|
empty if we were unable to access the registry (eg. couldn't import
|
||||||
a registry-access module) or the appropriate registry keys weren't
|
a registry-access module) or the appropriate registry keys weren't
|
||||||
found. (XXX is this correct???)"""
|
found."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import win32api
|
import win32api
|
||||||
import win32con
|
import win32con
|
||||||
|
@ -56,12 +56,15 @@ def get_devstudio_versions ():
|
||||||
|
|
||||||
|
|
||||||
def get_msvc_paths (path, version='6.0', platform='x86'):
|
def get_msvc_paths (path, version='6.0', platform='x86'):
|
||||||
"""Get a devstudio path (include, lib or path)."""
|
"""Get a list of devstudio directories (include, lib or path). Return
|
||||||
|
a list of strings; will be empty list if unable to access the
|
||||||
|
registry or appropriate registry keys not found."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import win32api
|
import win32api
|
||||||
import win32con
|
import win32con
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return None
|
return []
|
||||||
|
|
||||||
L = []
|
L = []
|
||||||
if path=='lib':
|
if path=='lib':
|
||||||
|
@ -96,37 +99,45 @@ def get_msvc_paths (path, version='6.0', platform='x86'):
|
||||||
# get_msvc_paths()
|
# get_msvc_paths()
|
||||||
|
|
||||||
|
|
||||||
def _find_exe(exe):
|
def find_exe (exe, version_number):
|
||||||
for v in get_devstudio_versions():
|
"""Try to find an MSVC executable program 'exe' (from version
|
||||||
for p in get_msvc_paths('path',v):
|
'version_number' of MSVC) in several places: first, one of the MSVC
|
||||||
fn = os.path.join(os.path.abspath(p),exe)
|
program search paths from the registry; next, the directories in the
|
||||||
if os.path.isfile(fn):
|
PATH environment variable. If any of those work, return an absolute
|
||||||
return fn
|
path that is known to exist. If none of them work, just return the
|
||||||
|
original program name, 'exe'."""
|
||||||
|
|
||||||
#didn't find it; try existing path
|
for p in get_msvc_paths ('path', version_number):
|
||||||
try:
|
fn = os.path.join (os.path.abspath(p), exe)
|
||||||
for p in string.split(os.environ['Path'],';'):
|
if os.path.isfile(fn):
|
||||||
fn=os.path.join(os.path.abspath(p),exe)
|
return fn
|
||||||
if os.path.isfile(fn):
|
|
||||||
return fn
|
# didn't find it; try existing path
|
||||||
# XXX BAD BAD BAD BAD BAD BAD BAD BAD BAD BAD BAD BAD !!!!!!!!!!!!!!!!
|
for p in string.split (os.environ['Path'],';'):
|
||||||
except: # XXX WHAT'S BEING CAUGHT HERE?!?!?
|
fn = os.path.join(os.path.abspath(p),exe)
|
||||||
pass
|
if os.path.isfile(fn):
|
||||||
return exe #last desperate hope
|
return fn
|
||||||
|
|
||||||
|
return exe # last desperate hope
|
||||||
|
|
||||||
|
|
||||||
def _find_SET(n):
|
def _find_SET(name,version_number):
|
||||||
for v in get_devstudio_versions():
|
"""looks up in the registry and returns a list of values suitable for
|
||||||
p = get_msvc_paths(n,v)
|
use in a SET command eg SET name=value. Normally the value will be a
|
||||||
if p:
|
';' separated list similar to a path list.
|
||||||
return p
|
|
||||||
return []
|
name is the name of an MSVC path and version_number is a version_number
|
||||||
|
of an MSVC installation."""
|
||||||
|
return get_msvc_paths(name, version_number)
|
||||||
|
|
||||||
|
|
||||||
def _do_SET(n):
|
def _do_SET(name, version_number):
|
||||||
p = _find_SET(n)
|
"""sets os.environ[name] to an MSVC path type value obtained from
|
||||||
|
_find_SET. This is equivalent to a SET command prior to execution of
|
||||||
|
spawned commands."""
|
||||||
|
p=_find_SET(name, version_number)
|
||||||
if p:
|
if p:
|
||||||
os.environ[n] = string.join(p,';')
|
os.environ[name]=string.join(p,';')
|
||||||
|
|
||||||
|
|
||||||
class MSVCCompiler (CCompiler) :
|
class MSVCCompiler (CCompiler) :
|
||||||
|
@ -144,21 +155,31 @@ class MSVCCompiler (CCompiler) :
|
||||||
|
|
||||||
self.add_library_dir( os.path.join( sys.exec_prefix, 'libs' ) )
|
self.add_library_dir( os.path.join( sys.exec_prefix, 'libs' ) )
|
||||||
|
|
||||||
self.cc = _find_exe("cl.exe")
|
vNum = get_devstudio_versions ()
|
||||||
self.link = _find_exe("link.exe")
|
|
||||||
_do_SET('lib')
|
if vNum:
|
||||||
_do_SET('include')
|
vNum = vNum[0] # highest version
|
||||||
path=_find_SET('path')
|
|
||||||
try:
|
self.cc = _find_exe("cl.exe", vNum)
|
||||||
for p in string.split(os.environ['path'],';'):
|
self.link = _find_exe("link.exe", vNum)
|
||||||
path.append(p)
|
_do_SET('lib', vNum)
|
||||||
except KeyError:
|
_do_SET('include', vNum)
|
||||||
pass
|
path=_find_SET('path', vNum)
|
||||||
os.environ['path'] = string.join(path,';')
|
try:
|
||||||
|
for p in string.split(os.environ['path'],';'):
|
||||||
|
path.append(p)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
os.environ['path'] = string.join(path,';')
|
||||||
|
else:
|
||||||
|
# devstudio not found in the registry
|
||||||
|
self.cc = "cl.exe"
|
||||||
|
self.link = "link.exe"
|
||||||
|
|
||||||
self.preprocess_options = None
|
self.preprocess_options = None
|
||||||
self.compile_options = [ '/nologo', '/Ox', '/MD' ]
|
self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3' ]
|
||||||
self.compile_options_debug = [
|
self.compile_options_debug = [
|
||||||
'/nologo', '/Od', '/MDd', '/Z7', '/D_DEBUG'
|
'/nologo', '/Od', '/MDd', '/W3', '/Z7', '/D_DEBUG'
|
||||||
]
|
]
|
||||||
|
|
||||||
self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']
|
self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']
|
||||||
|
|
Loading…
Reference in New Issue