mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-14 06:34:44 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -6,56 +6,62 @@ 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.
|
||||
"""
|
||||
|
||||
# Written by Perry Stoll
|
||||
# hacked by Robin Becker and Thomas Heller to do a better job of
|
||||
# finding DevStudio (through the registry)
|
||||
# ported to VS2005 and VS 2008 by Christian Heimes
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import re
|
||||
|
||||
from distutils.errors import DistutilsExecError, DistutilsPlatformError, \
|
||||
CompileError, LibError, LinkError
|
||||
from distutils.ccompiler import CCompiler, gen_lib_options
|
||||
from distutils import log
|
||||
from distutils.util import get_platform
|
||||
|
||||
import winreg
|
||||
|
||||
from distutils import log
|
||||
from distutils.ccompiler import CCompiler
|
||||
from distutils.ccompiler import gen_lib_options
|
||||
from distutils.errors import CompileError
|
||||
from distutils.errors import DistutilsExecError
|
||||
from distutils.errors import DistutilsPlatformError
|
||||
from distutils.errors import LibError
|
||||
from distutils.errors import LinkError
|
||||
from distutils.util import get_platform
|
||||
|
||||
RegOpenKeyEx = winreg.OpenKeyEx
|
||||
RegEnumKey = winreg.EnumKey
|
||||
RegEnumValue = winreg.EnumValue
|
||||
RegError = winreg.error
|
||||
|
||||
HKEYS = (winreg.HKEY_USERS,
|
||||
winreg.HKEY_CURRENT_USER,
|
||||
winreg.HKEY_LOCAL_MACHINE,
|
||||
winreg.HKEY_CLASSES_ROOT)
|
||||
HKEYS = (
|
||||
winreg.HKEY_USERS,
|
||||
winreg.HKEY_CURRENT_USER,
|
||||
winreg.HKEY_LOCAL_MACHINE,
|
||||
winreg.HKEY_CLASSES_ROOT,
|
||||
)
|
||||
|
||||
NATIVE_WIN64 = (sys.platform == 'win32' and sys.maxsize > 2**32)
|
||||
if NATIVE_WIN64:
|
||||
# Visual C++ is a 32-bit application, so we need to look in
|
||||
# the corresponding registry branch, if we're running a
|
||||
# 64-bit Python on Win64
|
||||
VS_BASE = r"Software\Wow6432Node\Microsoft\VisualStudio\%0.1f"
|
||||
WINSDK_BASE = r"Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows"
|
||||
NET_BASE = r"Software\Wow6432Node\Microsoft\.NETFramework"
|
||||
VS_BASE = r'Software\Wow6432Node\Microsoft\VisualStudio\%0.1f'
|
||||
WINSDK_BASE = r'Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows'
|
||||
NET_BASE = r'Software\Wow6432Node\Microsoft\.NETFramework'
|
||||
else:
|
||||
VS_BASE = r"Software\Microsoft\VisualStudio\%0.1f"
|
||||
WINSDK_BASE = r"Software\Microsoft\Microsoft SDKs\Windows"
|
||||
NET_BASE = r"Software\Microsoft\.NETFramework"
|
||||
VS_BASE = r'Software\Microsoft\VisualStudio\%0.1f'
|
||||
WINSDK_BASE = r'Software\Microsoft\Microsoft SDKs\Windows'
|
||||
NET_BASE = r'Software\Microsoft\.NETFramework'
|
||||
|
||||
# A map keyed by get_platform() return values to values accepted by
|
||||
# 'vcvarsall.bat'. Note a cross-compile may combine these (eg, 'x86_amd64' is
|
||||
# the param to cross-compile on x86 targeting amd64.)
|
||||
PLAT_TO_VCVARS = {
|
||||
'win32' : 'x86',
|
||||
'win-amd64' : 'amd64',
|
||||
'win32': 'x86',
|
||||
'win-amd64': 'amd64',
|
||||
}
|
||||
|
||||
|
||||
class Reg:
|
||||
"""Helper class to read values from the registry
|
||||
"""
|
||||
|
|
@ -109,15 +115,16 @@ class Reg:
|
|||
read_values = classmethod(read_values)
|
||||
|
||||
def convert_mbcs(s):
|
||||
dec = getattr(s, "decode", None)
|
||||
dec = getattr(s, 'decode', None)
|
||||
if dec is not None:
|
||||
try:
|
||||
s = dec("mbcs")
|
||||
s = dec('mbcs')
|
||||
except UnicodeError:
|
||||
pass
|
||||
return s
|
||||
convert_mbcs = staticmethod(convert_mbcs)
|
||||
|
||||
|
||||
class MacroExpander:
|
||||
|
||||
def __init__(self, version):
|
||||
|
|
@ -126,56 +133,60 @@ class MacroExpander:
|
|||
self.load_macros(version)
|
||||
|
||||
def set_macro(self, macro, path, key):
|
||||
self.macros["$(%s)" % macro] = Reg.get_value(path, key)
|
||||
self.macros['$(%s)' % macro] = Reg.get_value(path, key)
|
||||
|
||||
def load_macros(self, version):
|
||||
self.set_macro("VCInstallDir", self.vsbase + r"\Setup\VC", "productdir")
|
||||
self.set_macro("VSInstallDir", self.vsbase + r"\Setup\VS", "productdir")
|
||||
self.set_macro("FrameworkDir", NET_BASE, "installroot")
|
||||
self.set_macro('VCInstallDir', self.vsbase + r'\Setup\VC', 'productdir')
|
||||
self.set_macro('VSInstallDir', self.vsbase + r'\Setup\VS', 'productdir')
|
||||
self.set_macro('FrameworkDir', NET_BASE, 'installroot')
|
||||
try:
|
||||
if version >= 8.0:
|
||||
self.set_macro("FrameworkSDKDir", NET_BASE,
|
||||
"sdkinstallrootv2.0")
|
||||
self.set_macro(
|
||||
'FrameworkSDKDir', NET_BASE,
|
||||
'sdkinstallrootv2.0',
|
||||
)
|
||||
else:
|
||||
raise KeyError("sdkinstallrootv2.0")
|
||||
raise KeyError('sdkinstallrootv2.0')
|
||||
except KeyError:
|
||||
raise DistutilsPlatformError(
|
||||
"""Python was built with Visual Studio 2008;
|
||||
"""Python was built with Visual Studio 2008;
|
||||
extensions must be built with a compiler than can generate compatible binaries.
|
||||
Visual Studio 2008 was not found on this system. If you have Cygwin installed,
|
||||
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""")
|
||||
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""",
|
||||
)
|
||||
|
||||
if version >= 9.0:
|
||||
self.set_macro("FrameworkVersion", self.vsbase, "clr version")
|
||||
self.set_macro("WindowsSdkDir", WINSDK_BASE, "currentinstallfolder")
|
||||
self.set_macro('FrameworkVersion', self.vsbase, 'clr version')
|
||||
self.set_macro('WindowsSdkDir', WINSDK_BASE, 'currentinstallfolder')
|
||||
else:
|
||||
p = r"Software\Microsoft\NET Framework Setup\Product"
|
||||
p = r'Software\Microsoft\NET Framework Setup\Product'
|
||||
for base in HKEYS:
|
||||
try:
|
||||
h = RegOpenKeyEx(base, p)
|
||||
except RegError:
|
||||
continue
|
||||
key = RegEnumKey(h, 0)
|
||||
d = Reg.get_value(base, r"%s\%s" % (p, key))
|
||||
self.macros["$(FrameworkVersion)"] = d["version"]
|
||||
d = Reg.get_value(base, r'{}\{}'.format(p, key))
|
||||
self.macros['$(FrameworkVersion)'] = d['version']
|
||||
|
||||
def sub(self, s):
|
||||
for k, v in self.macros.items():
|
||||
s = s.replace(k, v)
|
||||
return s
|
||||
|
||||
|
||||
def get_build_version():
|
||||
"""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.
|
||||
"""
|
||||
prefix = "MSC v."
|
||||
prefix = 'MSC v.'
|
||||
i = sys.version.find(prefix)
|
||||
if i == -1:
|
||||
return 6
|
||||
i = i + len(prefix)
|
||||
s, rest = sys.version[i:].split(" ", 1)
|
||||
s, rest = sys.version[i:].split(' ', 1)
|
||||
majorVersion = int(s[:-2]) - 6
|
||||
if majorVersion >= 13:
|
||||
# v13 was skipped and should be v14
|
||||
|
|
@ -189,6 +200,7 @@ def get_build_version():
|
|||
# else we don't know what version of the compiler this is
|
||||
return None
|
||||
|
||||
|
||||
def normalize_and_reduce_paths(paths):
|
||||
"""Return a list of normalized paths with duplicates removed.
|
||||
|
||||
|
|
@ -203,6 +215,7 @@ def normalize_and_reduce_paths(paths):
|
|||
reduced_paths.append(np)
|
||||
return reduced_paths
|
||||
|
||||
|
||||
def removeDuplicates(variable):
|
||||
"""Remove duplicate values of an environment variable.
|
||||
"""
|
||||
|
|
@ -214,6 +227,7 @@ def removeDuplicates(variable):
|
|||
newVariable = os.pathsep.join(newList)
|
||||
return newVariable
|
||||
|
||||
|
||||
def find_vcvarsall(version):
|
||||
"""Find the vcvarsall.bat file
|
||||
|
||||
|
|
@ -222,53 +236,58 @@ def find_vcvarsall(version):
|
|||
"""
|
||||
vsbase = VS_BASE % version
|
||||
try:
|
||||
productdir = Reg.get_value(r"%s\Setup\VC" % vsbase,
|
||||
"productdir")
|
||||
productdir = Reg.get_value(
|
||||
r'%s\Setup\VC' % vsbase,
|
||||
'productdir',
|
||||
)
|
||||
except KeyError:
|
||||
log.debug("Unable to find productdir in registry")
|
||||
log.debug('Unable to find productdir in registry')
|
||||
productdir = None
|
||||
|
||||
if not productdir or not os.path.isdir(productdir):
|
||||
toolskey = "VS%0.f0COMNTOOLS" % version
|
||||
toolskey = 'VS%0.f0COMNTOOLS' % version
|
||||
toolsdir = os.environ.get(toolskey, None)
|
||||
|
||||
if toolsdir and os.path.isdir(toolsdir):
|
||||
productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
|
||||
productdir = os.path.join(toolsdir, os.pardir, os.pardir, 'VC')
|
||||
productdir = os.path.abspath(productdir)
|
||||
if not os.path.isdir(productdir):
|
||||
log.debug("%s is not a valid directory" % productdir)
|
||||
log.debug('%s is not a valid directory' % productdir)
|
||||
return None
|
||||
else:
|
||||
log.debug("Env var %s is not set or invalid" % toolskey)
|
||||
log.debug('Env var %s is not set or invalid' % toolskey)
|
||||
if not productdir:
|
||||
log.debug("No productdir found")
|
||||
log.debug('No productdir found')
|
||||
return None
|
||||
vcvarsall = os.path.join(productdir, "vcvarsall.bat")
|
||||
vcvarsall = os.path.join(productdir, 'vcvarsall.bat')
|
||||
if os.path.isfile(vcvarsall):
|
||||
return vcvarsall
|
||||
log.debug("Unable to find vcvarsall.bat")
|
||||
log.debug('Unable to find vcvarsall.bat')
|
||||
return None
|
||||
|
||||
def query_vcvarsall(version, arch="x86"):
|
||||
|
||||
def query_vcvarsall(version, arch='x86'):
|
||||
"""Launch vcvarsall.bat and read the settings from its environment
|
||||
"""
|
||||
vcvarsall = find_vcvarsall(version)
|
||||
interesting = {"include", "lib", "libpath", "path"}
|
||||
interesting = {'include', 'lib', 'libpath', 'path'}
|
||||
result = {}
|
||||
|
||||
if vcvarsall is None:
|
||||
raise DistutilsPlatformError("Unable to find vcvarsall.bat")
|
||||
raise DistutilsPlatformError('Unable to find vcvarsall.bat')
|
||||
log.debug("Calling 'vcvarsall.bat %s' (version=%s)", arch, version)
|
||||
popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch),
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
popen = subprocess.Popen(
|
||||
'"{}" {} & set'.format(vcvarsall, arch),
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
try:
|
||||
stdout, stderr = popen.communicate()
|
||||
if popen.wait() != 0:
|
||||
raise DistutilsPlatformError(stderr.decode("mbcs"))
|
||||
raise DistutilsPlatformError(stderr.decode('mbcs'))
|
||||
|
||||
stdout = stdout.decode("mbcs")
|
||||
for line in stdout.split("\n"):
|
||||
stdout = stdout.decode('mbcs')
|
||||
for line in stdout.split('\n'):
|
||||
line = Reg.convert_mbcs(line)
|
||||
if '=' not in line:
|
||||
continue
|
||||
|
|
@ -289,13 +308,15 @@ def query_vcvarsall(version, arch="x86"):
|
|||
|
||||
return result
|
||||
|
||||
|
||||
# More globals
|
||||
VERSION = get_build_version()
|
||||
if VERSION < 8.0:
|
||||
raise DistutilsPlatformError("VC %0.1f is not supported by this module" % VERSION)
|
||||
raise DistutilsPlatformError('VC %0.1f is not supported by this module' % VERSION)
|
||||
# MACROS = MacroExpander(VERSION)
|
||||
|
||||
class MSVCCompiler(CCompiler) :
|
||||
|
||||
class MSVCCompiler(CCompiler):
|
||||
"""Concrete class that implements an interface to Microsoft Visual C++,
|
||||
as defined by the CCompiler abstract class."""
|
||||
|
||||
|
|
@ -316,8 +337,10 @@ class MSVCCompiler(CCompiler) :
|
|||
|
||||
# Needed for the filename generation methods provided by the
|
||||
# base class, CCompiler.
|
||||
src_extensions = (_c_extensions + _cpp_extensions +
|
||||
_rc_extensions + _mc_extensions)
|
||||
src_extensions = (
|
||||
_c_extensions + _cpp_extensions +
|
||||
_rc_extensions + _mc_extensions
|
||||
)
|
||||
res_extension = '.res'
|
||||
obj_extension = '.obj'
|
||||
static_lib_extension = '.lib'
|
||||
|
|
@ -326,14 +349,14 @@ class MSVCCompiler(CCompiler) :
|
|||
exe_extension = '.exe'
|
||||
|
||||
def __init__(self, verbose=0, dry_run=0, force=0):
|
||||
CCompiler.__init__ (self, verbose, dry_run, force)
|
||||
CCompiler.__init__(self, verbose, dry_run, force)
|
||||
self.__version = VERSION
|
||||
self.__root = r"Software\Microsoft\VisualStudio"
|
||||
self.__root = r'Software\Microsoft\VisualStudio'
|
||||
# self.__macros = MACROS
|
||||
self.__paths = []
|
||||
# target platform (.plat_name is consistent with 'bdist')
|
||||
self.plat_name = None
|
||||
self.__arch = None # deprecated name
|
||||
self.__arch = None # deprecated name
|
||||
self.initialized = False
|
||||
|
||||
def initialize(self, plat_name=None):
|
||||
|
|
@ -344,17 +367,19 @@ class MSVCCompiler(CCompiler) :
|
|||
# sanity check for platforms to prevent obscure errors later.
|
||||
ok_plats = 'win32', 'win-amd64'
|
||||
if plat_name not in ok_plats:
|
||||
raise DistutilsPlatformError("--plat-name must be one of %s" %
|
||||
(ok_plats,))
|
||||
raise DistutilsPlatformError(
|
||||
'--plat-name must be one of %s' %
|
||||
(ok_plats,),
|
||||
)
|
||||
|
||||
if "DISTUTILS_USE_SDK" in os.environ and "MSSdk" in os.environ and self.find_exe("cl.exe"):
|
||||
if 'DISTUTILS_USE_SDK' in os.environ and 'MSSdk' in os.environ and self.find_exe('cl.exe'):
|
||||
# Assume that the SDK set up everything alright; don't try to be
|
||||
# smarter
|
||||
self.cc = "cl.exe"
|
||||
self.linker = "link.exe"
|
||||
self.lib = "lib.exe"
|
||||
self.rc = "rc.exe"
|
||||
self.mc = "mc.exe"
|
||||
self.cc = 'cl.exe'
|
||||
self.linker = 'link.exe'
|
||||
self.lib = 'lib.exe'
|
||||
self.rc = 'rc.exe'
|
||||
self.mc = 'mc.exe'
|
||||
else:
|
||||
# On x86, 'vcvars32.bat amd64' creates an env that doesn't work;
|
||||
# to cross compile, you use 'x86_amd64'.
|
||||
|
|
@ -366,7 +391,7 @@ class MSVCCompiler(CCompiler) :
|
|||
else:
|
||||
# cross compile from win32 -> some 64bit
|
||||
plat_spec = PLAT_TO_VCVARS[get_platform()] + '_' + \
|
||||
PLAT_TO_VCVARS[plat_name]
|
||||
PLAT_TO_VCVARS[plat_name]
|
||||
|
||||
vc_env = query_vcvarsall(VERSION, plat_spec)
|
||||
|
||||
|
|
@ -375,16 +400,18 @@ class MSVCCompiler(CCompiler) :
|
|||
os.environ['include'] = vc_env['include']
|
||||
|
||||
if len(self.__paths) == 0:
|
||||
raise DistutilsPlatformError("Python was built with %s, "
|
||||
"and extensions need to be built with the same "
|
||||
"version of the compiler, but it isn't installed."
|
||||
% self.__product)
|
||||
raise DistutilsPlatformError(
|
||||
'Python was built with %s, '
|
||||
'and extensions need to be built with the same '
|
||||
"version of the compiler, but it isn't installed."
|
||||
% self.__product,
|
||||
)
|
||||
|
||||
self.cc = self.find_exe("cl.exe")
|
||||
self.linker = self.find_exe("link.exe")
|
||||
self.lib = self.find_exe("lib.exe")
|
||||
self.rc = self.find_exe("rc.exe") # resource compiler
|
||||
self.mc = self.find_exe("mc.exe") # message compiler
|
||||
self.cc = self.find_exe('cl.exe')
|
||||
self.linker = self.find_exe('link.exe')
|
||||
self.lib = self.find_exe('lib.exe')
|
||||
self.rc = self.find_exe('rc.exe') # resource compiler
|
||||
self.mc = self.find_exe('mc.exe') # message compiler
|
||||
#self.set_path_env_var('lib')
|
||||
#self.set_path_env_var('include')
|
||||
|
||||
|
|
@ -395,75 +422,99 @@ class MSVCCompiler(CCompiler) :
|
|||
except KeyError:
|
||||
pass
|
||||
self.__paths = normalize_and_reduce_paths(self.__paths)
|
||||
os.environ['path'] = ";".join(self.__paths)
|
||||
os.environ['path'] = ';'.join(self.__paths)
|
||||
|
||||
self.preprocess_options = None
|
||||
if self.__arch == "x86":
|
||||
self.compile_options = [ '/nologo', '/O2', '/MD', '/W3',
|
||||
'/DNDEBUG']
|
||||
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3',
|
||||
'/Z7', '/D_DEBUG']
|
||||
if self.__arch == 'x86':
|
||||
self.compile_options = ['/nologo', '/O2', '/MD', '/W3',
|
||||
'/DNDEBUG',
|
||||
]
|
||||
self.compile_options_debug = [
|
||||
'/nologo', '/Od', '/MDd', '/W3',
|
||||
'/Z7', '/D_DEBUG',
|
||||
]
|
||||
else:
|
||||
# Win64
|
||||
self.compile_options = [ '/nologo', '/O2', '/MD', '/W3', '/GS-' ,
|
||||
'/DNDEBUG']
|
||||
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GS-',
|
||||
'/Z7', '/D_DEBUG']
|
||||
self.compile_options = ['/nologo', '/O2', '/MD', '/W3', '/GS-',
|
||||
'/DNDEBUG',
|
||||
]
|
||||
self.compile_options_debug = [
|
||||
'/nologo', '/Od', '/MDd', '/W3', '/GS-',
|
||||
'/Z7', '/D_DEBUG',
|
||||
]
|
||||
|
||||
self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']
|
||||
if self.__version >= 7:
|
||||
self.ldflags_shared_debug = [
|
||||
'/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG'
|
||||
]
|
||||
self.ldflags_static = [ '/nologo']
|
||||
'/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG',
|
||||
]
|
||||
self.ldflags_static = ['/nologo']
|
||||
|
||||
self.initialized = True
|
||||
|
||||
# -- Worker methods ------------------------------------------------
|
||||
|
||||
def object_filenames(self,
|
||||
source_filenames,
|
||||
strip_dir=0,
|
||||
output_dir=''):
|
||||
def object_filenames(
|
||||
self,
|
||||
source_filenames,
|
||||
strip_dir=0,
|
||||
output_dir='',
|
||||
):
|
||||
# Copied from ccompiler.py, extended to return .res as 'object'-file
|
||||
# for .rc input file
|
||||
if output_dir is None: output_dir = ''
|
||||
if output_dir is None:
|
||||
output_dir = ''
|
||||
obj_names = []
|
||||
for src_name in source_filenames:
|
||||
(base, ext) = os.path.splitext (src_name)
|
||||
base = os.path.splitdrive(base)[1] # Chop off the drive
|
||||
(base, ext) = os.path.splitext(src_name)
|
||||
base = os.path.splitdrive(base)[1] # Chop off the drive
|
||||
base = base[os.path.isabs(base):] # If abs, chop off leading /
|
||||
if ext not in self.src_extensions:
|
||||
# Better to raise an exception instead of silently continuing
|
||||
# and later complain about sources and targets having
|
||||
# different lengths
|
||||
raise CompileError ("Don't know how to compile %s" % src_name)
|
||||
raise CompileError("Don't know how to compile %s" % src_name)
|
||||
if strip_dir:
|
||||
base = os.path.basename (base)
|
||||
base = os.path.basename(base)
|
||||
if ext in self._rc_extensions:
|
||||
obj_names.append (os.path.join (output_dir,
|
||||
base + self.res_extension))
|
||||
obj_names.append(
|
||||
os.path.join(
|
||||
output_dir,
|
||||
base + self.res_extension,
|
||||
),
|
||||
)
|
||||
elif ext in self._mc_extensions:
|
||||
obj_names.append (os.path.join (output_dir,
|
||||
base + self.res_extension))
|
||||
obj_names.append(
|
||||
os.path.join(
|
||||
output_dir,
|
||||
base + self.res_extension,
|
||||
),
|
||||
)
|
||||
else:
|
||||
obj_names.append (os.path.join (output_dir,
|
||||
base + self.obj_extension))
|
||||
obj_names.append(
|
||||
os.path.join(
|
||||
output_dir,
|
||||
base + self.obj_extension,
|
||||
),
|
||||
)
|
||||
return obj_names
|
||||
|
||||
|
||||
def compile(self, sources,
|
||||
output_dir=None, macros=None, include_dirs=None, debug=0,
|
||||
extra_preargs=None, extra_postargs=None, depends=None):
|
||||
def compile(
|
||||
self, sources,
|
||||
output_dir=None, macros=None, include_dirs=None, debug=0,
|
||||
extra_preargs=None, extra_postargs=None, depends=None,
|
||||
):
|
||||
|
||||
if not self.initialized:
|
||||
self.initialize()
|
||||
compile_info = self._setup_compile(output_dir, macros, include_dirs,
|
||||
sources, depends, extra_postargs)
|
||||
compile_info = self._setup_compile(
|
||||
output_dir, macros, include_dirs,
|
||||
sources, depends, extra_postargs,
|
||||
)
|
||||
macros, objects, extra_postargs, pp_opts, build = compile_info
|
||||
|
||||
compile_opts = extra_preargs or []
|
||||
compile_opts.append ('/c')
|
||||
compile_opts.append('/c')
|
||||
if debug:
|
||||
compile_opts.extend(self.compile_options_debug)
|
||||
else:
|
||||
|
|
@ -481,13 +532,13 @@ class MSVCCompiler(CCompiler) :
|
|||
src = os.path.abspath(src)
|
||||
|
||||
if ext in self._c_extensions:
|
||||
input_opt = "/Tc" + src
|
||||
input_opt = '/Tc' + src
|
||||
elif ext in self._cpp_extensions:
|
||||
input_opt = "/Tp" + src
|
||||
input_opt = '/Tp' + src
|
||||
elif ext in self._rc_extensions:
|
||||
# compile .RC to .RES file
|
||||
input_opt = src
|
||||
output_opt = "/fo" + obj
|
||||
output_opt = '/fo' + obj
|
||||
try:
|
||||
self.spawn([self.rc] + pp_opts +
|
||||
[output_opt] + [input_opt])
|
||||
|
|
@ -512,85 +563,99 @@ class MSVCCompiler(CCompiler) :
|
|||
# first compile .MC to .RC and .H file
|
||||
self.spawn([self.mc] +
|
||||
['-h', h_dir, '-r', rc_dir] + [src])
|
||||
base, _ = os.path.splitext (os.path.basename (src))
|
||||
rc_file = os.path.join (rc_dir, base + '.rc')
|
||||
base, _ = os.path.splitext(os.path.basename(src))
|
||||
rc_file = os.path.join(rc_dir, base + '.rc')
|
||||
# then compile .RC to .RES file
|
||||
self.spawn([self.rc] +
|
||||
["/fo" + obj] + [rc_file])
|
||||
['/fo' + obj] + [rc_file])
|
||||
|
||||
except DistutilsExecError as msg:
|
||||
raise CompileError(msg)
|
||||
continue
|
||||
else:
|
||||
# how to handle this file?
|
||||
raise CompileError("Don't know how to compile %s to %s"
|
||||
% (src, obj))
|
||||
raise CompileError(
|
||||
"Don't know how to compile %s to %s"
|
||||
% (src, obj),
|
||||
)
|
||||
|
||||
output_opt = "/Fo" + obj
|
||||
output_opt = '/Fo' + obj
|
||||
try:
|
||||
self.spawn([self.cc] + compile_opts + pp_opts +
|
||||
[input_opt, output_opt] +
|
||||
extra_postargs)
|
||||
self.spawn(
|
||||
[self.cc] + compile_opts + pp_opts +
|
||||
[input_opt, output_opt] +
|
||||
extra_postargs,
|
||||
)
|
||||
except DistutilsExecError as msg:
|
||||
raise CompileError(msg)
|
||||
|
||||
return objects
|
||||
|
||||
|
||||
def create_static_lib(self,
|
||||
objects,
|
||||
output_libname,
|
||||
output_dir=None,
|
||||
debug=0,
|
||||
target_lang=None):
|
||||
def create_static_lib(
|
||||
self,
|
||||
objects,
|
||||
output_libname,
|
||||
output_dir=None,
|
||||
debug=0,
|
||||
target_lang=None,
|
||||
):
|
||||
|
||||
if not self.initialized:
|
||||
self.initialize()
|
||||
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
||||
output_filename = self.library_filename(output_libname,
|
||||
output_dir=output_dir)
|
||||
output_filename = self.library_filename(
|
||||
output_libname,
|
||||
output_dir=output_dir,
|
||||
)
|
||||
|
||||
if self._need_link(objects, output_filename):
|
||||
lib_args = objects + ['/OUT:' + output_filename]
|
||||
if debug:
|
||||
pass # XXX what goes here?
|
||||
pass # XXX what goes here?
|
||||
try:
|
||||
self.spawn([self.lib] + lib_args)
|
||||
except DistutilsExecError as msg:
|
||||
raise LibError(msg)
|
||||
else:
|
||||
log.debug("skipping %s (up-to-date)", output_filename)
|
||||
log.debug('skipping %s (up-to-date)', output_filename)
|
||||
|
||||
|
||||
def link(self,
|
||||
target_desc,
|
||||
objects,
|
||||
output_filename,
|
||||
output_dir=None,
|
||||
libraries=None,
|
||||
library_dirs=None,
|
||||
runtime_library_dirs=None,
|
||||
export_symbols=None,
|
||||
debug=0,
|
||||
extra_preargs=None,
|
||||
extra_postargs=None,
|
||||
build_temp=None,
|
||||
target_lang=None):
|
||||
def link(
|
||||
self,
|
||||
target_desc,
|
||||
objects,
|
||||
output_filename,
|
||||
output_dir=None,
|
||||
libraries=None,
|
||||
library_dirs=None,
|
||||
runtime_library_dirs=None,
|
||||
export_symbols=None,
|
||||
debug=0,
|
||||
extra_preargs=None,
|
||||
extra_postargs=None,
|
||||
build_temp=None,
|
||||
target_lang=None,
|
||||
):
|
||||
|
||||
if not self.initialized:
|
||||
self.initialize()
|
||||
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
||||
fixed_args = self._fix_lib_args(libraries, library_dirs,
|
||||
runtime_library_dirs)
|
||||
fixed_args = self._fix_lib_args(
|
||||
libraries, library_dirs,
|
||||
runtime_library_dirs,
|
||||
)
|
||||
(libraries, library_dirs, runtime_library_dirs) = fixed_args
|
||||
|
||||
if runtime_library_dirs:
|
||||
self.warn ("I don't know what to do with 'runtime_library_dirs': "
|
||||
+ str (runtime_library_dirs))
|
||||
self.warn(
|
||||
"I don't know what to do with 'runtime_library_dirs': " +
|
||||
str(runtime_library_dirs),
|
||||
)
|
||||
|
||||
lib_opts = gen_lib_options(self,
|
||||
library_dirs, runtime_library_dirs,
|
||||
libraries)
|
||||
lib_opts = gen_lib_options(
|
||||
self,
|
||||
library_dirs, runtime_library_dirs,
|
||||
libraries,
|
||||
)
|
||||
if output_dir is not None:
|
||||
output_filename = os.path.join(output_dir, output_filename)
|
||||
|
||||
|
|
@ -608,10 +673,12 @@ class MSVCCompiler(CCompiler) :
|
|||
|
||||
export_opts = []
|
||||
for sym in (export_symbols or []):
|
||||
export_opts.append("/EXPORT:" + sym)
|
||||
export_opts.append('/EXPORT:' + sym)
|
||||
|
||||
ld_args = (ldflags + lib_opts + export_opts +
|
||||
objects + ['/OUT:' + output_filename])
|
||||
ld_args = (
|
||||
ldflags + lib_opts + export_opts +
|
||||
objects + ['/OUT:' + output_filename]
|
||||
)
|
||||
|
||||
# The MSVC linker generates .lib and .exp files, which cannot be
|
||||
# suppressed by any linker switches. The .lib files may even be
|
||||
|
|
@ -621,11 +688,13 @@ class MSVCCompiler(CCompiler) :
|
|||
build_temp = os.path.dirname(objects[0])
|
||||
if export_symbols is not None:
|
||||
(dll_name, dll_ext) = os.path.splitext(
|
||||
os.path.basename(output_filename))
|
||||
os.path.basename(output_filename),
|
||||
)
|
||||
implib_file = os.path.join(
|
||||
build_temp,
|
||||
self.library_filename(dll_name))
|
||||
ld_args.append ('/IMPLIB:' + implib_file)
|
||||
self.library_filename(dll_name),
|
||||
)
|
||||
ld_args.append('/IMPLIB:' + implib_file)
|
||||
|
||||
self.manifest_setup_ldargs(output_filename, build_temp, ld_args)
|
||||
|
||||
|
|
@ -648,14 +717,16 @@ class MSVCCompiler(CCompiler) :
|
|||
mfinfo = self.manifest_get_embed_info(target_desc, ld_args)
|
||||
if mfinfo is not None:
|
||||
mffilename, mfid = mfinfo
|
||||
out_arg = '-outputresource:%s;%s' % (output_filename, mfid)
|
||||
out_arg = '-outputresource:{};{}'.format(output_filename, mfid)
|
||||
try:
|
||||
self.spawn(['mt.exe', '-nologo', '-manifest',
|
||||
mffilename, out_arg])
|
||||
self.spawn([
|
||||
'mt.exe', '-nologo', '-manifest',
|
||||
mffilename, out_arg,
|
||||
])
|
||||
except DistutilsExecError as msg:
|
||||
raise LinkError(msg)
|
||||
else:
|
||||
log.debug("skipping %s (up-to-date)", output_filename)
|
||||
log.debug('skipping %s (up-to-date)', output_filename)
|
||||
|
||||
def manifest_setup_ldargs(self, output_filename, build_temp, ld_args):
|
||||
# If we need a manifest at all, an embedded manifest is recommended.
|
||||
|
|
@ -665,8 +736,9 @@ class MSVCCompiler(CCompiler) :
|
|||
# Ask the linker to generate the manifest in the temp dir, so
|
||||
# we can check it, and possibly embed it, later.
|
||||
temp_manifest = os.path.join(
|
||||
build_temp,
|
||||
os.path.basename(output_filename) + ".manifest")
|
||||
build_temp,
|
||||
os.path.basename(output_filename) + '.manifest',
|
||||
)
|
||||
ld_args.append('/MANIFESTFILE:' + temp_manifest)
|
||||
|
||||
def manifest_get_embed_info(self, target_desc, ld_args):
|
||||
|
|
@ -675,8 +747,8 @@ class MSVCCompiler(CCompiler) :
|
|||
# should be embedded. See http://bugs.python.org/issue7833 for why
|
||||
# we want to avoid any manifest for extension modules if we can)
|
||||
for arg in ld_args:
|
||||
if arg.startswith("/MANIFESTFILE:"):
|
||||
temp_manifest = arg.split(":", 1)[1]
|
||||
if arg.startswith('/MANIFESTFILE:'):
|
||||
temp_manifest = arg.split(':', 1)[1]
|
||||
break
|
||||
else:
|
||||
# no /MANIFESTFILE so nothing to do.
|
||||
|
|
@ -709,17 +781,19 @@ class MSVCCompiler(CCompiler) :
|
|||
finally:
|
||||
manifest_f.close()
|
||||
pattern = re.compile(
|
||||
r"""<assemblyIdentity.*?name=("|')Microsoft\."""\
|
||||
r"""<assemblyIdentity.*?name=("|')Microsoft\."""
|
||||
r"""VC\d{2}\.CRT("|').*?(/>|</assemblyIdentity>)""",
|
||||
re.DOTALL)
|
||||
manifest_buf = re.sub(pattern, "", manifest_buf)
|
||||
pattern = r"<dependentAssembly>\s*</dependentAssembly>"
|
||||
manifest_buf = re.sub(pattern, "", manifest_buf)
|
||||
re.DOTALL,
|
||||
)
|
||||
manifest_buf = re.sub(pattern, '', manifest_buf)
|
||||
pattern = r'<dependentAssembly>\s*</dependentAssembly>'
|
||||
manifest_buf = re.sub(pattern, '', manifest_buf)
|
||||
# Now see if any other assemblies are referenced - if not, we
|
||||
# don't want a manifest embedded.
|
||||
pattern = re.compile(
|
||||
r"""<assemblyIdentity.*?name=(?:"|')(.+?)(?:"|')"""
|
||||
r""".*?(?:/>|</assemblyIdentity>)""", re.DOTALL)
|
||||
r""".*?(?:/>|</assemblyIdentity>)""", re.DOTALL,
|
||||
)
|
||||
if re.search(pattern, manifest_buf) is None:
|
||||
return None
|
||||
|
||||
|
|
@ -737,26 +811,26 @@ class MSVCCompiler(CCompiler) :
|
|||
# ccompiler.py.
|
||||
|
||||
def library_dir_option(self, dir):
|
||||
return "/LIBPATH:" + dir
|
||||
return '/LIBPATH:' + dir
|
||||
|
||||
def runtime_library_dir_option(self, dir):
|
||||
raise DistutilsPlatformError(
|
||||
"don't know how to set runtime library search path for MSVC++")
|
||||
"don't know how to set runtime library search path for MSVC++",
|
||||
)
|
||||
|
||||
def library_option(self, lib):
|
||||
return self.library_filename(lib)
|
||||
|
||||
|
||||
def find_library_file(self, dirs, lib, debug=0):
|
||||
# Prefer a debugging library if found (and requested), but deal
|
||||
# with it if we don't have one.
|
||||
if debug:
|
||||
try_names = [lib + "_d", lib]
|
||||
try_names = [lib + '_d', lib]
|
||||
else:
|
||||
try_names = [lib]
|
||||
for dir in dirs:
|
||||
for name in try_names:
|
||||
libfile = os.path.join(dir, self.library_filename (name))
|
||||
libfile = os.path.join(dir, self.library_filename(name))
|
||||
if os.path.exists(libfile):
|
||||
return libfile
|
||||
else:
|
||||
|
|
@ -781,7 +855,7 @@ class MSVCCompiler(CCompiler) :
|
|||
|
||||
# didn't find it; try existing path
|
||||
for p in os.environ['Path'].split(';'):
|
||||
fn = os.path.join(os.path.abspath(p),exe)
|
||||
fn = os.path.join(os.path.abspath(p), exe)
|
||||
if os.path.isfile(fn):
|
||||
return fn
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue