| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 69ded39 commit 8a5f7ad
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,23 +90,11 @@ def _find_vc2017(): | |||
| 90 | 90 | return None, None | |
| 91 | 91 | ||
| 92 | 92 | def _find_vcvarsall(plat_spec): | |
| 93 | + # bpo-38597: Removed vcruntime return value | ||
| 93 | 94 | _, best_dir = _find_vc2017() | |
| 94 | - vcruntime = None | ||
| 95 | - vcruntime_plat = 'x64' if 'amd64' in plat_spec else 'x86' | ||
| 96 | - if best_dir: | ||
| 97 | - vcredist = os.path.join(best_dir, "..", "..", "redist", "MSVC", "**", | ||
| 98 | - vcruntime_plat, "Microsoft.VC14*.CRT", "vcruntime140.dll") | ||
| 99 | - try: | ||
| 100 | - import glob | ||
| 101 | - vcruntime = glob.glob(vcredist, recursive=True)[-1] | ||
| 102 | - except (ImportError, OSError, LookupError): | ||
| 103 | - vcruntime = None | ||
| 104 | 95 | ||
| 105 | 96 | if not best_dir: | |
| 106 | 97 | best_version, best_dir = _find_vc2015() | |
| 107 | - if best_version: | ||
| 108 | - vcruntime = os.path.join(best_dir, 'redist', vcruntime_plat, | ||
| 109 | - "Microsoft.VC140.CRT", "vcruntime140.dll") | ||
| 110 | 98 | ||
| 111 | 99 | if not best_dir: | |
| 112 | 100 | log.debug("No suitable Visual C++ version found") | |
@@ -117,11 +105,7 @@ def _find_vcvarsall(plat_spec): | |||
| 117 | 105 | log.debug("%s cannot be found", vcvarsall) | |
| 118 | 106 | return None, None | |
| 119 | 107 | ||
| 120 | - if not vcruntime or not os.path.isfile(vcruntime): | ||
| 121 | - log.debug("%s cannot be found", vcruntime) | ||
| 122 | - vcruntime = None | ||
| 123 | - | ||
| 124 | - return vcvarsall, vcruntime | ||
| 108 | + return vcvarsall, None | ||
| 125 | 109 | ||
| 126 | 110 | def _get_vc_env(plat_spec): | |
| 127 | 111 | if os.getenv("DISTUTILS_USE_SDK"): | |
@@ -130,7 +114,7 @@ def _get_vc_env(plat_spec): | |||
| 130 | 114 | for key, value in os.environ.items() | |
| 131 | 115 | } | |
| 132 | 116 | ||
| 133 | - vcvarsall, vcruntime = _find_vcvarsall(plat_spec) | ||
| 117 | + vcvarsall, _ = _find_vcvarsall(plat_spec) | ||
| 134 | 118 | if not vcvarsall: | |
| 135 | 119 | raise DistutilsPlatformError("Unable to find vcvarsall.bat") | |
| 136 | 120 | ||
@@ -151,8 +135,6 @@ def _get_vc_env(plat_spec): | |||
| 151 | 135 | if key and value | |
| 152 | 136 | } | |
| 153 | 137 | ||
| 154 | - if vcruntime: | ||
| 155 | - env['py_vcruntime_redist'] = vcruntime | ||
| 156 | 138 | return env | |
| 157 | 139 | ||
| 158 | 140 | def _find_exe(exe, paths=None): | |
@@ -180,12 +162,6 @@ def _find_exe(exe, paths=None): | |||
| 180 | 162 | 'win-amd64' : 'x86_amd64', | |
| 181 | 163 | } | |
| 182 | 164 | ||
| 183 | - # A set containing the DLLs that are guaranteed to be available for | ||
| 184 | - # all micro versions of this Python version. Known extension | ||
| 185 | - # dependencies that are not in this set will be copied to the output | ||
| 186 | - # path. | ||
| 187 | - _BUNDLED_DLLS = frozenset(['vcruntime140.dll']) | ||
| 188 | - | ||
| 189 | 165 | class MSVCCompiler(CCompiler) : | |
| 190 | 166 | """Concrete class that implements an interface to Microsoft Visual C++, | |
| 191 | 167 | as defined by the CCompiler abstract class.""" | |
@@ -249,7 +225,6 @@ def initialize(self, plat_name=None): | |||
| 249 | 225 | self.rc = _find_exe("rc.exe", paths) # resource compiler | |
| 250 | 226 | self.mc = _find_exe("mc.exe", paths) # message compiler | |
| 251 | 227 | self.mt = _find_exe("mt.exe", paths) # message compiler | |
| 252 | - self._vcruntime_redist = vc_env.get('py_vcruntime_redist', '') | ||
| 253 | 228 | ||
| 254 | 229 | for dir in vc_env.get('include', '').split(os.pathsep): | |
| 255 | 230 | if dir: | |
@@ -260,13 +235,12 @@ def initialize(self, plat_name=None): | |||
| 260 | 235 | self.add_library_dir(dir.rstrip(os.sep)) | |
| 261 | 236 | ||
| 262 | 237 | self.preprocess_options = None | |
| 263 | - # If vcruntime_redist is available, link against it dynamically. Otherwise, | ||
| 264 | - # use /MT[d] to build statically, then switch from libucrt[d].lib to ucrt[d].lib | ||
| 265 | - # later to dynamically link to ucrtbase but not vcruntime. | ||
| 238 | + # bpo-38597: Always compile with dynamic linking | ||
| 239 | + # Future releases of Python 3.x will include all past | ||
| 240 | + # versions of vcruntime*.dll for compatibility. | ||
| 266 | 241 | self.compile_options = [ | |
| 267 | - '/nologo', '/Ox', '/W3', '/GL', '/DNDEBUG' | ||
| 242 | + '/nologo', '/Ox', '/W3', '/GL', '/DNDEBUG', '/MD' | ||
| 268 | 243 | ] | |
| 269 | - self.compile_options.append('/MD' if self._vcruntime_redist else '/MT') | ||
| 270 | 244 | ||
| 271 | 245 | self.compile_options_debug = [ | |
| 272 | 246 | '/nologo', '/Od', '/MDd', '/Zi', '/W3', '/D_DEBUG' | |
@@ -275,8 +249,6 @@ def initialize(self, plat_name=None): | |||
| 275 | 249 | ldflags = [ | |
| 276 | 250 | '/nologo', '/INCREMENTAL:NO', '/LTCG' | |
| 277 | 251 | ] | |
| 278 | - if not self._vcruntime_redist: | ||
| 279 | - ldflags.extend(('/nodefaultlib:libucrt.lib', 'ucrt.lib')) | ||
| 280 | 252 | ||
| 281 | 253 | ldflags_debug = [ | |
| 282 | 254 | '/nologo', '/INCREMENTAL:NO', '/LTCG', '/DEBUG:FULL' | |
@@ -518,24 +490,11 @@ def link(self, | |||
| 518 | 490 | try: | |
| 519 | 491 | log.debug('Executing "%s" %s', self.linker, ' '.join(ld_args)) | |
| 520 | 492 | self.spawn([self.linker] + ld_args) | |
| 521 | - self._copy_vcruntime(output_dir) | ||
| 522 | 493 | except DistutilsExecError as msg: | |
| 523 | 494 | raise LinkError(msg) | |
| 524 | 495 | else: | |
| 525 | 496 | log.debug("skipping %s (up-to-date)", output_filename) | |
| 526 | 497 | ||
| 527 | - def _copy_vcruntime(self, output_dir): | ||
| 528 | - vcruntime = self._vcruntime_redist | ||
| 529 | - if not vcruntime or not os.path.isfile(vcruntime): | ||
| 530 | - return | ||
| 531 | - | ||
| 532 | - if os.path.basename(vcruntime).lower() in _BUNDLED_DLLS: | ||
| 533 | - return | ||
| 534 | - | ||
| 535 | - log.debug('Copying "%s"', vcruntime) | ||
| 536 | - vcruntime = shutil.copy(vcruntime, output_dir) | ||
| 537 | - os.chmod(vcruntime, stat.S_IWRITE) | ||
| 538 | - | ||
| 539 | 498 | def spawn(self, cmd): | |
| 540 | 499 | old_path = os.getenv('path') | |
| 541 | 500 | try: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,57 +32,6 @@ def _find_vcvarsall(plat_spec): | |||
| 32 | 32 | finally: | |
| 33 | 33 | _msvccompiler._find_vcvarsall = old_find_vcvarsall | |
| 34 | 34 | ||
| 35 | - def test_compiler_options(self): | ||
| 36 | - import distutils._msvccompiler as _msvccompiler | ||
| 37 | - # suppress path to vcruntime from _find_vcvarsall to | ||
| 38 | - # check that /MT is added to compile options | ||
| 39 | - old_find_vcvarsall = _msvccompiler._find_vcvarsall | ||
| 40 | - def _find_vcvarsall(plat_spec): | ||
| 41 | - return old_find_vcvarsall(plat_spec)[0], None | ||
| 42 | - _msvccompiler._find_vcvarsall = _find_vcvarsall | ||
| 43 | - try: | ||
| 44 | - compiler = _msvccompiler.MSVCCompiler() | ||
| 45 | - compiler.initialize() | ||
| 46 | - | ||
| 47 | - self.assertIn('/MT', compiler.compile_options) | ||
| 48 | - self.assertNotIn('/MD', compiler.compile_options) | ||
| 49 | - finally: | ||
| 50 | - _msvccompiler._find_vcvarsall = old_find_vcvarsall | ||
| 51 | - | ||
| 52 | - def test_vcruntime_copy(self): | ||
| 53 | - import distutils._msvccompiler as _msvccompiler | ||
| 54 | - # force path to a known file - it doesn't matter | ||
| 55 | - # what we copy as long as its name is not in | ||
| 56 | - # _msvccompiler._BUNDLED_DLLS | ||
| 57 | - old_find_vcvarsall = _msvccompiler._find_vcvarsall | ||
| 58 | - def _find_vcvarsall(plat_spec): | ||
| 59 | - return old_find_vcvarsall(plat_spec)[0], __file__ | ||
| 60 | - _msvccompiler._find_vcvarsall = _find_vcvarsall | ||
| 61 | - try: | ||
| 62 | - tempdir = self.mkdtemp() | ||
| 63 | - compiler = _msvccompiler.MSVCCompiler() | ||
| 64 | - compiler.initialize() | ||
| 65 | - compiler._copy_vcruntime(tempdir) | ||
| 66 | - | ||
| 67 | - self.assertTrue(os.path.isfile(os.path.join( | ||
| 68 | - tempdir, os.path.basename(__file__)))) | ||
| 69 | - finally: | ||
| 70 | - _msvccompiler._find_vcvarsall = old_find_vcvarsall | ||
| 71 | - | ||
| 72 | - def test_vcruntime_skip_copy(self): | ||
| 73 | - import distutils._msvccompiler as _msvccompiler | ||
| 74 | - | ||
| 75 | - tempdir = self.mkdtemp() | ||
| 76 | - compiler = _msvccompiler.MSVCCompiler() | ||
| 77 | - compiler.initialize() | ||
| 78 | - dll = compiler._vcruntime_redist | ||
| 79 | - self.assertTrue(os.path.isfile(dll), dll or "<None>") | ||
| 80 | - | ||
| 81 | - compiler._copy_vcruntime(tempdir) | ||
| 82 | - | ||
| 83 | - self.assertFalse(os.path.isfile(os.path.join( | ||
| 84 | - tempdir, os.path.basename(dll))), dll or "<None>") | ||
| 85 | - | ||
| 86 | 35 | def test_get_vc_env_unicode(self): | |
| 87 | 36 | import distutils._msvccompiler as _msvccompiler | |
| 88 | 37 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + :mod:`distutils` will no longer statically link :file:`vcruntime140.dll` | ||
| 2 | + when a redistributable version is unavailable. All future releases of | ||
| 3 | + CPython will include a copy of this DLL to ensure distributed extensions can | ||
| 4 | + continue to load. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -469,6 +469,8 @@ | |||
| 469 | 469 | <VCRuntimeDLL Include="$(VCRedistDir)\**\vcruntime*.dll" /> | |
| 470 | 470 | </ItemGroup> | |
| 471 | 471 | <Target Name="_CopyVCRuntime" AfterTargets="Build" Inputs="@(VCRuntimeDLL)" Outputs="$(OutDir)%(Filename)%(Extension)"> | |
| 472 | + <!-- bpo-38597: When we switch to another VCRuntime DLL, include vcruntime140.dll as well --> | ||
| 473 | + <Warning Text="A copy of vcruntime140.dll is also required" Condition="!$(VCToolsRedistVersion.StartsWith(`14.`))" /> | ||
| 472 | 474 | <Copy SourceFiles="%(VCRuntimeDLL.FullPath)" DestinationFolder="$(OutDir)" /> | |
| 473 | 475 | </Target> | |
| 474 | 476 | <Target Name="_CleanVCRuntime" AfterTargets="Clean"> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments