From 7c2b8f6705a98024e9969a9cd096f197fa951c88 Mon Sep 17 00:00:00 2001 From: "Jamuar, Rohit" Date: Tue, 13 Dec 2016 16:24:39 -0600 Subject: [PATCH] Extend MSVCCompiler class to respect environment variables --- Lib/distutils/_msvccompiler.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Lib/distutils/_msvccompiler.py b/Lib/distutils/_msvccompiler.py index b120273..3b30d3d 100644 --- a/Lib/distutils/_msvccompiler.py +++ b/Lib/distutils/_msvccompiler.py @@ -199,15 +199,25 @@ class MSVCCompiler(CCompiler) : raise DistutilsPlatformError("Unable to find a compatible " "Visual Studio installation.") - self._paths = vc_env.get('path', '') - paths = self._paths.split(os.pathsep) - self.cc = _find_exe("cl.exe", paths) - self.linker = _find_exe("link.exe", paths) - self.lib = _find_exe("lib.exe", paths) - self.rc = _find_exe("rc.exe", paths) # resource compiler - self.mc = _find_exe("mc.exe", paths) # message compiler - self.mt = _find_exe("mt.exe", paths) # message compiler self._vcruntime_redist = vc_env.get('py_vcruntime_redist', '') + self._paths = vc_env.get('path', '') + if 'DISTUTILS_USE_SDK' in os.environ: + # If 'DISTUTILS_USE_SDK' is set to env, assume that following + # executables have already been added to PATH + self.cc = os.environ.get('CC', 'cl.exe').strip() + self.linker = os.environ.get('LD', 'link.exe').strip() + self.lib = os.environ.get('AR', 'lib.exe').strip() + self.rc = os.environ.get('RC', 'rc.exe').strip() + self.mc = os.environ.get('MC', 'mc.exe').strip() + self.mt = os.environ.get('MT', 'mt.exe').strip() + else: + paths = self._paths.split(os.pathsep) + self.cc = _find_exe("cl.exe", paths) + self.linker = _find_exe("link.exe", paths) + self.lib = _find_exe("lib.exe", paths) + self.rc = _find_exe("rc.exe", paths) # resource compiler + self.mc = _find_exe("mc.exe", paths) # message compiler + self.mt = _find_exe("mt.exe", paths) # message compiler for dir in vc_env.get('include', '').split(os.pathsep): if dir: @@ -247,6 +257,11 @@ class MSVCCompiler(CCompiler) : self.ldflags_static = [*ldflags] self.ldflags_static_debug = [*ldflags_debug] + self.compile_options.extend(os.environ.get('CFLAGS', '').strip().split()) + self.compile_options_debug.extend(os.environ.get('CFLAGS', '').strip().split()) + self.ldflags_shared.extend(os.environ.get('LDFLAGS', '').strip().split()) + self.ldflags_shared_debug.extend(os.environ.get('LDFLAGS', '').strip().split()) + self._ldflags = { (CCompiler.EXECUTABLE, None): self.ldflags_exe, (CCompiler.EXECUTABLE, False): self.ldflags_exe, -- 1.9.1