(debug=False)
| 280 | return _find_dll_in_winsxs(dll_name) or _find_dll_in_path(dll_name) |
| 281 | |
| 282 | def build_msvcr_library(debug=False): |
| 283 | if os.name != 'nt': |
| 284 | return False |
| 285 | |
| 286 | # If the version number is None, then we couldn't find the MSVC runtime at |
| 287 | # all, because we are running on a Python distribution which is customed |
| 288 | # compiled; trust that the compiler is the same as the one available to us |
| 289 | # now, and that it is capable of linking with the correct runtime without |
| 290 | # any extra options. |
| 291 | msvcr_ver = msvc_runtime_major() |
| 292 | if msvcr_ver is None: |
| 293 | log.debug('Skip building import library: ' |
| 294 | 'Runtime is not compiled with MSVC') |
| 295 | return False |
| 296 | |
| 297 | # Skip using a custom library for versions < MSVC 8.0 |
| 298 | if msvcr_ver < 80: |
| 299 | log.debug('Skip building msvcr library:' |
| 300 | ' custom functionality not present') |
| 301 | return False |
| 302 | |
| 303 | msvcr_name = msvc_runtime_library() |
| 304 | if debug: |
| 305 | msvcr_name += 'd' |
| 306 | |
| 307 | # Skip if custom library already exists |
| 308 | out_name = "lib%s.a" % msvcr_name |
| 309 | out_file = os.path.join(sys.prefix, 'libs', out_name) |
| 310 | if os.path.isfile(out_file): |
| 311 | log.debug('Skip building msvcr library: "%s" exists' % |
| 312 | (out_file,)) |
| 313 | return True |
| 314 | |
| 315 | # Find the msvcr dll |
| 316 | msvcr_dll_name = msvcr_name + '.dll' |
| 317 | dll_file = find_dll(msvcr_dll_name) |
| 318 | if not dll_file: |
| 319 | log.warn('Cannot build msvcr library: "%s" not found' % |
| 320 | msvcr_dll_name) |
| 321 | return False |
| 322 | |
| 323 | def_name = "lib%s.def" % msvcr_name |
| 324 | def_file = os.path.join(sys.prefix, 'libs', def_name) |
| 325 | |
| 326 | log.info('Building msvcr library: "%s" (from %s)' \ |
| 327 | % (out_file, dll_file)) |
| 328 | |
| 329 | # Generate a symbol definition file from the msvcr dll |
| 330 | generate_def(dll_file, def_file) |
| 331 | |
| 332 | # Create a custom mingw library for the given symbol definitions |
| 333 | cmd = ['dlltool', '-d', def_file, '-l', out_file] |
| 334 | retcode = subprocess.call(cmd) |
| 335 | |
| 336 | # Clean up symbol definitions |
| 337 | os.remove(def_file) |
| 338 | |
| 339 | return (not retcode) |
no test coverage detected