|
1 | 1 | from __future__ import division, absolute_import, print_function
|
2 | 2 |
|
3 | 3 | import os
|
4 |
| -import distutils.msvc9compiler |
5 |
| -from distutils.msvc9compiler import * |
| 4 | +from distutils.msvc9compiler import MSVCCompiler as _MSVCCompiler |
6 | 5 |
|
7 | 6 |
|
8 |
| -class MSVCCompiler(distutils.msvc9compiler.MSVCCompiler): |
| 7 | +def _merge(old, new): |
| 8 | + """Concatenate two environment paths avoiding repeats. |
| 9 | +
|
| 10 | + Here `old` is the environment string before the base class initialize |
| 11 | + function is called and `new` is the string after the call. The new string |
| 12 | + will be a fixed string if it is not obtained from the current enviroment, |
| 13 | + or the same as the old string if obtained from the same enviroment. The aim |
| 14 | + here is not to append the new string if it is already contained in the old |
| 15 | + string so as to limit the growth of the environment string. |
| 16 | +
|
| 17 | + Parameters |
| 18 | + ---------- |
| 19 | + old : string |
| 20 | + Previous enviroment string. |
| 21 | + new : string |
| 22 | + New environment string. |
| 23 | +
|
| 24 | + Returns |
| 25 | + ------- |
| 26 | + ret : string |
| 27 | + Updated environment string. |
| 28 | +
|
| 29 | + """ |
| 30 | + if new in old: |
| 31 | + return old |
| 32 | + if not old: |
| 33 | + return new |
| 34 | + |
| 35 | + # Neither new nor old is empty. Give old priority. |
| 36 | + return ';'.join([old, new]) |
| 37 | + |
| 38 | + |
| 39 | +class MSVCCompiler(_MSVCCompiler): |
9 | 40 | def __init__(self, verbose=0, dry_run=0, force=0):
|
10 |
| - distutils.msvc9compiler.MSVCCompiler.__init__(self, verbose, dry_run, force) |
| 41 | + _MSVCCompiler.__init__(self, verbose, dry_run, force) |
11 | 42 |
|
12 | 43 | def initialize(self, plat_name=None):
|
| 44 | + # The 'lib' and 'include' variables may be overwritten |
| 45 | + # by MSVCCompiler.initialize, so save them for later merge. |
13 | 46 | environ_lib = os.getenv('lib')
|
14 | 47 | environ_include = os.getenv('include')
|
15 |
| - distutils.msvc9compiler.MSVCCompiler.initialize(self, plat_name) |
16 |
| - if environ_lib is not None: |
17 |
| - os.environ['lib'] = environ_lib + os.environ['lib'] |
18 |
| - if environ_include is not None: |
19 |
| - os.environ['include'] = environ_include + os.environ['include'] |
| 48 | + _MSVCCompiler.initialize(self, plat_name) |
| 49 | + |
| 50 | + # Merge current and previous values of 'lib' and 'include' |
| 51 | + os.environ['lib'] = _merge(environ_lib, os.environ['lib']) |
| 52 | + os.environ['include'] = _merge(environ_include, os.environ['include']) |
| 53 | + |
| 54 | + # msvc9 building for 32 bits requires SSE2 to work around a |
| 55 | + # compiler bug. |
| 56 | + if platform_bits == 32: |
| 57 | + self.compile_options += ['/arch:SSE2'] |
| 58 | + self.compile_options_debug += ['/arch:SSE2'] |
20 | 59 |
|
21 | 60 | def manifest_setup_ldargs(self, output_filename, build_temp, ld_args):
|
22 | 61 | ld_args.append('/MANIFEST')
|
23 |
| - distutils.msvc9compiler.MSVCCompiler.manifest_setup_ldargs(self, |
24 |
| - output_filename, |
25 |
| - build_temp, ld_args) |
| 62 | + _MSVCCompiler.manifest_setup_ldargs(self, output_filename, |
| 63 | + build_temp, ld_args) |
0 commit comments