diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py index 1a411ed1113224..16bc0771509e63 100644 --- a/Lib/distutils/ccompiler.py +++ b/Lib/distutils/ccompiler.py @@ -875,9 +875,10 @@ def executable_filename(self, basename, strip_dir=0, output_dir=''): def library_filename(self, libname, lib_type='static', # or 'shared' strip_dir=0, output_dir=''): assert output_dir is not None - if lib_type not in ("static", "shared", "dylib", "xcode_stub"): - raise ValueError( - "'lib_type' must be \"static\", \"shared\", \"dylib\", or \"xcode_stub\"") + if lib_type not in ("static", "shared", "dylib", "xcode_stub", + "implib"): + raise ValueError("'lib_type' must be \"static\", \"shared\", " + "\"dylib\", \"xcode_stub\", or \"implib\"") fmt = getattr(self, lib_type + "_lib_format") ext = getattr(self, lib_type + "_lib_extension") diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py index d10a78da311405..024287c82f76b9 100644 --- a/Lib/distutils/unixccompiler.py +++ b/Lib/distutils/unixccompiler.py @@ -77,8 +77,9 @@ class UnixCCompiler(CCompiler): shared_lib_extension = ".so" dylib_lib_extension = ".dylib" xcode_stub_lib_extension = ".tbd" + implib_lib_extension = ".dll.a" static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s" - xcode_stub_lib_format = dylib_lib_format + implib_lib_format = xcode_stub_lib_format = dylib_lib_format if sys.platform == "cygwin": exe_extension = ".exe" @@ -266,6 +267,7 @@ def find_library_file(self, dirs, lib, debug=0): shared_f = self.library_filename(lib, lib_type='shared') dylib_f = self.library_filename(lib, lib_type='dylib') xcode_stub_f = self.library_filename(lib, lib_type='xcode_stub') + implib_f = self.library_filename(lib, lib_type='implib') static_f = self.library_filename(lib, lib_type='static') if sys.platform == 'darwin': @@ -294,13 +296,12 @@ def find_library_file(self, dirs, lib, debug=0): else: sysroot = m.group(1) - - for dir in dirs: shared = os.path.join(dir, shared_f) dylib = os.path.join(dir, dylib_f) static = os.path.join(dir, static_f) xcode_stub = os.path.join(dir, xcode_stub_f) + implib = os.path.join(dir, implib_f) if sys.platform == 'darwin' and ( dir.startswith('/System/') or ( @@ -310,6 +311,7 @@ def find_library_file(self, dirs, lib, debug=0): dylib = os.path.join(sysroot, dir[1:], dylib_f) static = os.path.join(sysroot, dir[1:], static_f) xcode_stub = os.path.join(sysroot, dir[1:], xcode_stub_f) + implib = os.path.join(sysroot, dir[1:], implib_f) # We're second-guessing the linker here, with not much hard # data to go on: GCC seems to prefer the shared library, so I'm @@ -319,6 +321,8 @@ def find_library_file(self, dirs, lib, debug=0): return dylib elif os.path.exists(xcode_stub): return xcode_stub + elif os.path.exists(implib): + return implib elif os.path.exists(shared): return shared elif os.path.exists(static): diff --git a/Misc/NEWS.d/next/Library/2017-10-28-01-07-44.bpo-4032.RvZFlS.rst b/Misc/NEWS.d/next/Library/2017-10-28-01-07-44.bpo-4032.RvZFlS.rst new file mode 100644 index 00000000000000..81fe8ad9393134 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2017-10-28-01-07-44.bpo-4032.RvZFlS.rst @@ -0,0 +1,2 @@ +Add .dll.a to UnixCCompiler to allow the UnixCCompiler.find_library_file to +correctly find DLL import libs on Cygwin. Patch by Masayuki Yamamoto.