From 71e1d6d9b6c08d60cdd21eb5798f5614c2cbc083 Mon Sep 17 00:00:00 2001 From: rjamuar Date: Wed, 4 May 2016 13:51:36 -0500 Subject: [PATCH] distutils patch to make MSVCCompiler class respect env vars For Py2.7 --- Lib/distutils/msvc9compiler.py | 26 +++++++++++++++++--------- Lib/distutils/msvccompiler.py | 25 ++++++++++++++++--------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/Lib/distutils/msvc9compiler.py b/Lib/distutils/msvc9compiler.py index 22de4ba..ea7d135 100644 --- a/Lib/distutils/msvc9compiler.py +++ b/Lib/distutils/msvc9compiler.py @@ -340,6 +340,7 @@ class MSVCCompiler(CCompiler) : CCompiler.__init__ (self, verbose, dry_run, force) self.__version = VERSION self.__root = r"Software\Microsoft\VisualStudio" + self.__product = "Visual Studio version %s" % self.__version # self.__macros = MACROS self.__paths = [] # target platform (.plat_name is consistent with 'bdist') @@ -358,14 +359,14 @@ class MSVCCompiler(CCompiler) : 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: # 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 = 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() else: # On x86, 'vcvars32.bat amd64' creates an env that doesn't work; # to cross compile, you use 'x86_amd64'. @@ -424,13 +425,19 @@ class MSVCCompiler(CCompiler) : '/Z7', '/D_DEBUG'] self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO'] + cflags_env = os.environ.get('CFLAGS', '').strip().split() + ldflags_env = os.environ.get('LDFLAGS', '').strip().split() if self.__version >= 7: self.ldflags_shared_debug = [ '/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG' ] + self.ldflags_shared_debug.extend(ldflags_env) self.ldflags_static = [ '/nologo'] self.initialized = True + self.compile_options.extend(cflags_env) + self.compile_options_debug.extend(cflags_env) + self.ldflags_shared.extend(ldflags_env) # -- Worker methods ------------------------------------------------ @@ -779,7 +786,7 @@ class MSVCCompiler(CCompiler) : # Helper methods for using the MSVC registry settings def find_exe(self, exe): - """Return path to an MSVC executable program. + """Return path to an executable program. Tries to find the program in several places: first, one of the MSVC program search paths from the registry; next, the directories @@ -795,7 +802,8 @@ 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) - if os.path.isfile(fn): - return fn + for abs_path in [fn, fn+'.exe']: + if os.path.isfile(fn): + return fn return exe diff --git a/Lib/distutils/msvccompiler.py b/Lib/distutils/msvccompiler.py index 0e69fd3..6c69a45 100644 --- a/Lib/distutils/msvccompiler.py +++ b/Lib/distutils/msvccompiler.py @@ -251,14 +251,14 @@ class MSVCCompiler (CCompiler) : def initialize(self): self.__paths = [] - 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: # 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 = 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() else: self.__paths = self.get_msvc_paths("path") @@ -299,10 +299,13 @@ class MSVCCompiler (CCompiler) : '/Z7', '/D_DEBUG'] self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO'] + cflags_env = os.environ.get('CFLAGS', '').strip().split() + ldflags_env = os.environ.get('LDFLAGS', '').strip().split() if self.__version >= 7: self.ldflags_shared_debug = [ '/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG' ] + self.ldflags_shared_debug.extend(ldflags_env) else: self.ldflags_shared_debug = [ '/DLL', '/nologo', '/INCREMENTAL:no', '/pdb:None', '/DEBUG' @@ -310,6 +313,9 @@ class MSVCCompiler (CCompiler) : self.ldflags_static = [ '/nologo'] self.initialized = True + self.compile_options.extend(cflags_env) + self.compile_options_debug.extend(cflags_env) + self.ldflags_shared.extend(ldflags_env) # -- Worker methods ------------------------------------------------ @@ -577,7 +583,7 @@ class MSVCCompiler (CCompiler) : # Helper methods for using the MSVC registry settings def find_exe(self, exe): - """Return path to an MSVC executable program. + """Return path to an executable program. Tries to find the program in several places: first, one of the MSVC program search paths from the registry; next, the directories @@ -594,8 +600,9 @@ class MSVCCompiler (CCompiler) : # didn't find it; try existing path for p in string.split(os.environ['Path'],';'): fn = os.path.join(os.path.abspath(p),exe) - if os.path.isfile(fn): - return fn + for abs_path in [fn, fn+'.exe']: + if os.path.isfile(fn): + return fn return exe -- 1.9.1