cpython: b2ee6206fa5e (original) (raw)

copy from Lib/distutils/msvccompiler.py copy to Lib/distutils/_msvccompiler.py --- a/Lib/distutils/msvccompiler.py +++ b/Lib/distutils/_msvccompiler.py @@ -1,201 +1,120 @@ -"""distutils.msvccompiler +"""distutils._msvccompiler Contains MSVCCompiler, an implementation of the abstract CCompiler class -for the Microsoft Visual Studio. +for Microsoft Visual Studio 2015. + +The module is compatible with VS 2015 and later. You can find legacy support +for older versions in distutils.msvc9compiler and distutils.msvccompiler. """

Written by Perry Stoll

hacked by Robin Becker and Thomas Heller to do a better job of

finding DevStudio (through the registry)

- -import sys, os -from distutils.errors import [](#l1.22)

-from distutils.ccompiler import [](#l1.25)

-from distutils import log +# ported to VS 2005 and VS 2008 by Christian Heimes +# ported to VS 2015 by Steve Dower -_can_read_reg = False -try:

-

-

+import os +import subprocess +import re -except ImportError:

+from distutils.errors import DistutilsExecError, DistutilsPlatformError, [](#l1.52)

+from distutils.ccompiler import CCompiler, gen_lib_options +from distutils import log +from distutils.util import get_platform

- -if _can_read_reg:

+import winreg +from itertools import count -def read_keys(base, key):

- -def read_values(base, key):

+def _find_vcvarsall():

-def convert_mbcs(s):

+

-class MacroExpander:

+def _get_vc_env(plat_spec):

-extensions must be built with a compiler than can generate compatible binaries. -Visual Studio 2003 was not found on this system. If you have Cygwin installed, -you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""") -

-

- -def get_build_version():

-def get_build_architecture():

+def _find_exe(exe, paths=None):

-def normalize_and_reduce_paths(paths):

-

- +# 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 targetting amd64.) +PLAT_TO_VCVARS = {

+} class MSVCCompiler(CCompiler) : """Concrete class that implements an interface to Microsoft Visual C++, @@ -227,83 +146,75 @@ class MSVCCompiler(CCompiler) : static_lib_format = shared_lib_format = '%s%s' exe_extension = '.exe' + def init(self, verbose=0, dry_run=0, force=0): CCompiler.init (self, verbose, dry_run, force)

-

+

+

self.preprocess_options = None

self.initialized = True @@ -313,31 +224,31 @@ class MSVCCompiler(CCompiler) : source_filenames, strip_dir=0, output_dir=''):

+

+

def compile(self, sources, @@ -351,12 +262,15 @@ class MSVCCompiler(CCompiler) : macros, objects, extra_postargs, pp_opts, build = compile_info compile_opts = extra_preargs or []

+

+ for obj in objects: try: src, ext = build[obj] @@ -372,13 +286,13 @@ class MSVCCompiler(CCompiler) : input_opt = "/Tc" + src elif ext in self._cpp_extensions: input_opt = "/Tp" + src

@@ -398,27 +312,29 @@ class MSVCCompiler(CCompiler) : rc_dir = os.path.dirname(obj) try: # first compile .MC to .RC and .H file

except DistutilsExecError as msg: raise CompileError(msg) continue else: # how to handle this file?

+ try:

@@ -434,7 +350,7 @@ class MSVCCompiler(CCompiler) : if not self.initialized: self.initialize()

@@ -467,14 +383,14 @@ class MSVCCompiler(CCompiler) : if not self.initialized: self.initialize()

if runtime_library_dirs:

lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs, @@ -483,16 +399,10 @@ class MSVCCompiler(CCompiler) : output_filename = os.path.join(output_dir, output_filename) if self._need_link(objects, output_filename):

export_opts = [] for sym in (export_symbols or []): @@ -506,14 +416,17 @@ class MSVCCompiler(CCompiler) : # needed! Make sure they are generated in the temporary build # directory. Since they have different names for debug and release # builds, they can go into the same directory.

+ if extra_preargs: ld_args[:0] = extra_preargs if extra_postargs: @@ -525,9 +438,97 @@ class MSVCCompiler(CCompiler) : except DistutilsExecError as msg: raise LinkError(msg)

+

+

+

# -- Miscellaneous methods ----------------------------------------- # These are all used by the 'gen_lib_options() function, in @@ -538,12 +539,11 @@ class MSVCCompiler(CCompiler) : def runtime_library_dir_option(self, dir): raise DistutilsPlatformError(

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. @@ -553,91 +553,9 @@ class MSVCCompiler(CCompiler) : try_names = [lib] for dir in dirs: for name in try_names:

-

-

-

-

-

-

-

-

-

-

-

-

- - -if get_build_version() >= 8.0:

--- a/Lib/distutils/ccompiler.py +++ b/Lib/distutils/ccompiler.py @@ -959,7 +959,7 @@ def get_default_compiler(osname=None, pl

is assumed to be in the 'distutils' package.)

compiler_class = { 'unix': ('unixccompiler', 'UnixCCompiler', "standard UNIX-style compiler"),

--- a/Lib/distutils/command/bdist_wininst.py +++ b/Lib/distutils/command/bdist_wininst.py @@ -303,7 +303,6 @@ class bdist_wininst(Command): return installer_name def get_exe_bytes(self):

@@ -313,20 +312,28 @@ class bdist_wininst(Command): # We can then execute this program to obtain any info we need, such # as the real sys.version string for the build. cur_version = get_python_version()

+

+ # wininst-x.y.exe is in the same directory as this file directory = os.path.dirname(file)

--- a/Lib/distutils/command/build_ext.py +++ b/Lib/distutils/command/build_ext.py @@ -19,10 +19,6 @@ from distutils import log from site import USER_BASE -if os.name == 'nt':

-

An extension name is just a dot-separated list of Python NAMEs (ie.

the same as a fully-qualified module name).

extension_name_re = re.compile [](#l4.13) @@ -206,27 +202,17 @@ class build_ext(Command): _sys_home = getattr(sys, '_home', None) if _sys_home: self.library_dirs.append(_sys_home)

# for extensions under Cygwin and AtheOS Python's library directory must be # appended to library_dirs @@ -716,7 +702,7 @@ class build_ext(Command): # to need it mentioned explicitly, though, so that's what we do. # Append '_d' to the python import library on debug builds. if sys.platform == "win32":

copy from Lib/distutils/tests/test_msvc9compiler.py copy to Lib/distutils/tests/test_msvccompiler.py --- a/Lib/distutils/tests/test_msvc9compiler.py +++ b/Lib/distutils/tests/test_msvccompiler.py @@ -1,4 +1,4 @@ -"""Tests for distutils.msvc9compiler.""" +"""Tests for distutils._msvccompiler.""" import sys import unittest import os @@ -90,56 +90,32 @@ from test.support import run_unittest """ -if sys.platform=="win32":

-else:

+SKIP_MESSAGE = (None if sys.platform == "win32" else

@unittest.skipUnless(SKIP_MESSAGE is None, SKIP_MESSAGE) -class msvc9compilerTestCase(support.TempdirManager, +class msvccompilerTestCase(support.TempdirManager, unittest.TestCase): def test_no_compiler(self): # makes sure query_vcvarsall raises # a DistutilsPlatformError if the compiler # is not found

-

-

-

-

def test_remove_visual_c_ref(self):

@@ -163,7 +139,7 @@ class msvc9compilerTestCase(support.Temp self.assertEqual(content, _CLEANED_MANIFEST) def test_remove_entire_manifest(self):

@@ -178,7 +154,7 @@ class msvc9compilerTestCase(support.Temp def test_suite():

if name == "main": run_unittest(test_suite())

--- a/Lib/test/test_sundry.py +++ b/Lib/test/test_sundry.py @@ -22,8 +22,6 @@ class TestUntestedModules(unittest.TestC import distutils.ccompiler import distutils.cygwinccompiler import distutils.filelist