msvc9compiler.py 2.1 KB

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