annotate Lib/distutils/msvc9compiler.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 4650ecdfcfb6
children b5cd3d2ec027
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
1 """distutils.msvc9compiler
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
2
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
3 Contains MSVCCompiler, an implementation of the abstract CCompiler class
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
4 for the Microsoft Visual Studio 2008.
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
5
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
6 The module is compatible with VS 2005 and VS 2008. You can find legacy support
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
7 for older versions of VS in distutils.msvccompiler.
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
8 """
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
9
26210
f465d6692bde Remove 'created by' lines; people can use CVS for this, and the information is often out of date
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
10 # Written by Perry Stoll
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
11 # hacked by Robin Becker and Thomas Heller to do a better job of
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
12 # finding DevStudio (through the registry)
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
13 # ported to VS2005 and VS 2008 by Christian Heimes
26285
42bfc98d295b Add comment to Distutil files about requiring 1.5.2 compatibility, as
Andrew M. Kuchling <amk@amk.ca>
parents: 26210
diff changeset
14
11897
017e592c0fd2 Changed '__rcsid__' to '__revision__'.
Greg Ward <gward@python.net>
parents: 11750
diff changeset
15 __revision__ = "$Id$"
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
16
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
17 import os
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
18 import subprocess
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
19 import sys
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
20
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
21 from distutils.errors import DistutilsExecError, DistutilsPlatformError, \
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
22 CompileError, LibError, LinkError
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
23 from distutils.ccompiler import CCompiler, gen_preprocess_options, \
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
24 gen_lib_options
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23274
diff changeset
25 from distutils import log
46331
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
26 from distutils.util import get_platform
11738
83d351f948ab Stylistic changes to the registry-grovelling code: code formatting, changed
Greg Ward <gward@python.net>
parents: 11735
diff changeset
27
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
28 import _winreg
12201
41dfc7d4a36b Fixed my simplification to Thomas' patch: winreg and win32api export the same
Greg Ward <gward@python.net>
parents: 12190
diff changeset
29
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
30 RegOpenKeyEx = _winreg.OpenKeyEx
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
31 RegEnumKey = _winreg.EnumKey
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
32 RegEnumValue = _winreg.EnumValue
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
33 RegError = _winreg.error
12201
41dfc7d4a36b Fixed my simplification to Thomas' patch: winreg and win32api export the same
Greg Ward <gward@python.net>
parents: 12190
diff changeset
34
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
35 HKEYS = (_winreg.HKEY_USERS,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
36 _winreg.HKEY_CURRENT_USER,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
37 _winreg.HKEY_LOCAL_MACHINE,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
38 _winreg.HKEY_CLASSES_ROOT)
12201
41dfc7d4a36b Fixed my simplification to Thomas' patch: winreg and win32api export the same
Greg Ward <gward@python.net>
parents: 12190
diff changeset
39
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
40 VS_BASE = r"Software\Microsoft\VisualStudio\%0.1f"
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
41 WINSDK_BASE = r"Software\Microsoft\Microsoft SDKs\Windows"
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
42 NET_BASE = r"Software\Microsoft\.NETFramework"
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
43
46331
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
44 # A map keyed by get_platform() return values to values accepted by
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
45 # 'vcvarsall.bat'. Note a cross-compile may combine these (eg, 'x86_amd64' is
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
46 # the param to cross-compile on x86 targetting amd64.)
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
47 PLAT_TO_VCVARS = {
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
48 'win32' : 'x86',
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
49 'win-amd64' : 'amd64',
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
50 'win-ia64' : 'ia64',
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
51 }
12201
41dfc7d4a36b Fixed my simplification to Thomas' patch: winreg and win32api export the same
Greg Ward <gward@python.net>
parents: 12190
diff changeset
52
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
53 class Reg:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
54 """Helper class to read values from the registry
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
55 """
12190
94b601faebac Simplified Thomas Heller's registry patch: just assign all those
Greg Ward <gward@python.net>
parents: 12189
diff changeset
56
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
57 def get_value(cls, path, key):
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
58 for base in HKEYS:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
59 d = cls.read_values(base, path)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
60 if d and key in d:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
61 return d[key]
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
62 raise KeyError(key)
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
63 get_value = classmethod(get_value)
11749
5c2770124904 Latest patch from Thomas Heller/Robin Becker:
Greg Ward <gward@python.net>
parents: 11738
diff changeset
64
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
65 def read_keys(cls, base, key):
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
66 """Return list of registry keys."""
11720
fdc9eeb89e0b Revised version (thank to Thomas Heller and Robin Becker) that tries a lot
Greg Ward <gward@python.net>
parents: 11664
diff changeset
67 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
68 handle = RegOpenKeyEx(base, key)
12190
94b601faebac Simplified Thomas Heller's registry patch: just assign all those
Greg Ward <gward@python.net>
parents: 12189
diff changeset
69 except RegError:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
70 return None
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
71 L = []
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
72 i = 0
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
73 while True:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
74 try:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
75 k = RegEnumKey(handle, i)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
76 except RegError:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
77 break
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
78 L.append(k)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
79 i += 1
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
80 return L
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
81 read_keys = classmethod(read_keys)
11720
fdc9eeb89e0b Revised version (thank to Thomas Heller and Robin Becker) that tries a lot
Greg Ward <gward@python.net>
parents: 11664
diff changeset
82
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
83 def read_values(cls, base, key):
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
84 """Return dict of registry keys and values.
11720
fdc9eeb89e0b Revised version (thank to Thomas Heller and Robin Becker) that tries a lot
Greg Ward <gward@python.net>
parents: 11664
diff changeset
85
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
86 All names are converted to lowercase.
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
87 """
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
88 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
89 handle = RegOpenKeyEx(base, key)
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
90 except RegError:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
91 return None
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
92 d = {}
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
93 i = 0
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
94 while True:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
95 try:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
96 name, value, type = RegEnumValue(handle, i)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
97 except RegError:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
98 break
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
99 name = name.lower()
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
100 d[cls.convert_mbcs(name)] = cls.convert_mbcs(value)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
101 i += 1
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
102 return d
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
103 read_values = classmethod(read_values)
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
104
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
105 def convert_mbcs(s):
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
106 dec = getattr(s, "decode", None)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
107 if dec is not None:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
108 try:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
109 s = dec("mbcs")
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
110 except UnicodeError:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
111 pass
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
112 return s
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
113 convert_mbcs = staticmethod(convert_mbcs)
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
114
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
115 class MacroExpander:
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
116
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
117 def __init__(self, version):
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
118 self.macros = {}
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
119 self.vsbase = VS_BASE % version
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
120 self.load_macros(version)
11720
fdc9eeb89e0b Revised version (thank to Thomas Heller and Robin Becker) that tries a lot
Greg Ward <gward@python.net>
parents: 11664
diff changeset
121
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
122 def set_macro(self, macro, path, key):
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
123 self.macros["$(%s)" % macro] = Reg.get_value(path, key)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31129
diff changeset
124
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
125 def load_macros(self, version):
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
126 self.set_macro("VCInstallDir", self.vsbase + r"\Setup\VC", "productdir")
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
127 self.set_macro("VSInstallDir", self.vsbase + r"\Setup\VS", "productdir")
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
128 self.set_macro("FrameworkDir", NET_BASE, "installroot")
34033
163409a601be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 34025
diff changeset
129 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
130 if version >= 8.0:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
131 self.set_macro("FrameworkSDKDir", NET_BASE,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
132 "sdkinstallrootv2.0")
34033
163409a601be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 34025
diff changeset
133 else:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
134 raise KeyError("sdkinstallrootv2.0")
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
135 except KeyError:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
136 raise DistutilsPlatformError(
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
137 """Python was built with Visual Studio 2008;
39309
bde58a78fc71 Mention Cygwin in distutils error message about a missing VS 2003.
Martin v. Löwis <martin@v.loewis.de>
parents: 39046
diff changeset
138 extensions must be built with a compiler than can generate compatible binaries.
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
139 Visual Studio 2008 was not found on this system. If you have Cygwin installed,
39309
bde58a78fc71 Mention Cygwin in distutils error message about a missing VS 2003.
Martin v. Löwis <martin@v.loewis.de>
parents: 39046
diff changeset
140 you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""")
11738
83d351f948ab Stylistic changes to the registry-grovelling code: code formatting, changed
Greg Ward <gward@python.net>
parents: 11735
diff changeset
141
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
142 if version >= 9.0:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
143 self.set_macro("FrameworkVersion", self.vsbase, "clr version")
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
144 self.set_macro("WindowsSdkDir", WINSDK_BASE, "currentinstallfolder")
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
145 else:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
146 p = r"Software\Microsoft\NET Framework Setup\Product"
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
147 for base in HKEYS:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
148 try:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
149 h = RegOpenKeyEx(base, p)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
150 except RegError:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
151 continue
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
152 key = RegEnumKey(h, 0)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
153 d = Reg.get_value(base, r"%s\%s" % (p, key))
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
154 self.macros["$(FrameworkVersion)"] = d["version"]
11720
fdc9eeb89e0b Revised version (thank to Thomas Heller and Robin Becker) that tries a lot
Greg Ward <gward@python.net>
parents: 11664
diff changeset
155
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
156 def sub(self, s):
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
157 for k, v in self.macros.items():
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
158 s = s.replace(k, v)
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
159 return s
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
160
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
161 def get_build_version():
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
162 """Return the version of MSVC that was used to build Python.
11749
5c2770124904 Latest patch from Thomas Heller/Robin Becker:
Greg Ward <gward@python.net>
parents: 11738
diff changeset
163
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
164 For Python 2.3 and up, the version number is included in
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
165 sys.version. For earlier versions, assume the compiler is MSVC 6.
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
166 """
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
167 prefix = "MSC v."
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
168 i = sys.version.find(prefix)
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
169 if i == -1:
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
170 return 6
29117
6ac0a672b082 Restore Python 1.5.2 compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 29054
diff changeset
171 i = i + len(prefix)
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
172 s, rest = sys.version[i:].split(" ", 1)
29918
ec9f18615485 Patch from John Anderson to enable VC 7.1 support.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29117
diff changeset
173 majorVersion = int(s[:-2]) - 6
ec9f18615485 Patch from John Anderson to enable VC 7.1 support.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29117
diff changeset
174 minorVersion = int(s[2:3]) / 10.0
ec9f18615485 Patch from John Anderson to enable VC 7.1 support.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29117
diff changeset
175 # I don't think paths are affected by minor version in version 6
ec9f18615485 Patch from John Anderson to enable VC 7.1 support.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29117
diff changeset
176 if majorVersion == 6:
ec9f18615485 Patch from John Anderson to enable VC 7.1 support.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29117
diff changeset
177 minorVersion = 0
ec9f18615485 Patch from John Anderson to enable VC 7.1 support.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29117
diff changeset
178 if majorVersion >= 6:
ec9f18615485 Patch from John Anderson to enable VC 7.1 support.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29117
diff changeset
179 return majorVersion + minorVersion
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
180 # else we don't know what version of the compiler this is
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
181 return None
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31129
diff changeset
182
41347
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
183 def normalize_and_reduce_paths(paths):
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
184 """Return a list of normalized paths with duplicates removed.
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
185
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
186 The current order of paths is maintained.
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
187 """
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
188 # Paths are normalized so things like: /a and /a/ aren't both preserved.
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
189 reduced_paths = []
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
190 for p in paths:
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
191 np = os.path.normpath(p)
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
192 # XXX(nnorwitz): O(n**2), if reduced_paths gets long perhaps use a set.
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
193 if np not in reduced_paths:
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
194 reduced_paths.append(np)
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
195 return reduced_paths
36619
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
196
48973
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
197 def removeDuplicates(variable):
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
198 """Remove duplicate values of an environment variable.
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
199 """
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
200 oldList = variable.split(os.pathsep)
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
201 newList = []
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
202 for i in oldList:
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
203 if i not in newList:
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
204 newList.append(i)
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
205 newVariable = os.pathsep.join(newList)
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
206 return newVariable
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
207
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
208 def find_vcvarsall(version):
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
209 """Find the vcvarsall.bat file
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
210
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
211 At first it tries to find the productdir of VS 2008 in the registry. If
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
212 that fails it falls back to the VS90COMNTOOLS env var.
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
213 """
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
214 vsbase = VS_BASE % version
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
215 try:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
216 productdir = Reg.get_value(r"%s\Setup\VC" % vsbase,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
217 "productdir")
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
218 except KeyError:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
219 log.debug("Unable to find productdir in registry")
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
220 productdir = None
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
221
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
222 if not productdir or not os.path.isdir(productdir):
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
223 toolskey = "VS%0.f0COMNTOOLS" % version
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
224 toolsdir = os.environ.get(toolskey, None)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
225
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
226 if toolsdir and os.path.isdir(toolsdir):
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
227 productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
228 productdir = os.path.abspath(productdir)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
229 if not os.path.isdir(productdir):
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
230 log.debug("%s is not a valid directory" % productdir)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
231 return None
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
232 else:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
233 log.debug("Env var %s is not set or invalid" % toolskey)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
234 if not productdir:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
235 log.debug("No productdir found")
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
236 return None
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
237 vcvarsall = os.path.join(productdir, "vcvarsall.bat")
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
238 if os.path.isfile(vcvarsall):
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
239 return vcvarsall
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
240 log.debug("Unable to find vcvarsall.bat")
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
241 return None
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
242
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
243 def query_vcvarsall(version, arch="x86"):
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
244 """Launch vcvarsall.bat and read the settings from its environment
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
245 """
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
246 vcvarsall = find_vcvarsall(version)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
247 interesting = set(("include", "lib", "libpath", "path"))
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
248 result = {}
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
249
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
250 if vcvarsall is None:
50383
d8975f24af8b Merged revisions 68081 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 49872
diff changeset
251 raise DistutilsPlatformError("Unable to find vcvarsall.bat")
46331
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
252 log.debug("Calling 'vcvarsall.bat %s' (version=%s)", arch, version)
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
253 popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch),
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
254 stdout=subprocess.PIPE,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
255 stderr=subprocess.PIPE)
44186
a1bc65954a9c Fixed bug #1557 by using popen.communicate() before popen.wait()
Christian Heimes <christian@cheimes.de>
parents: 44117
diff changeset
256
a1bc65954a9c Fixed bug #1557 by using popen.communicate() before popen.wait()
Christian Heimes <christian@cheimes.de>
parents: 44117
diff changeset
257 stdout, stderr = popen.communicate()
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
258 if popen.wait() != 0:
50383
d8975f24af8b Merged revisions 68081 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 49872
diff changeset
259 raise DistutilsPlatformError(stderr.decode("mbcs"))
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
260
44186
a1bc65954a9c Fixed bug #1557 by using popen.communicate() before popen.wait()
Christian Heimes <christian@cheimes.de>
parents: 44117
diff changeset
261 stdout = stdout.decode("mbcs")
a1bc65954a9c Fixed bug #1557 by using popen.communicate() before popen.wait()
Christian Heimes <christian@cheimes.de>
parents: 44117
diff changeset
262 for line in stdout.split("\n"):
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
263 line = Reg.convert_mbcs(line)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
264 if '=' not in line:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
265 continue
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
266 line = line.strip()
48973
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
267 key, value = line.split('=', 1)
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
268 key = key.lower()
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
269 if key in interesting:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
270 if value.endswith(os.pathsep):
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
271 value = value[:-1]
48973
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
272 result[key] = removeDuplicates(value)
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
273
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
274 if len(result) != len(interesting):
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
275 raise ValueError(str(list(result.keys())))
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
276
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
277 return result
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
278
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
279 # More globals
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
280 VERSION = get_build_version()
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
281 if VERSION < 8.0:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
282 raise DistutilsPlatformError("VC %0.1f is not supported by this module" % VERSION)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
283 # MACROS = MacroExpander(VERSION)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
284
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
285 class MSVCCompiler(CCompiler) :
11260
eaeea9e42369 Ditched redundant docstrings and comments (overlap with ccompiler.py).
Greg Ward <gward@python.net>
parents: 11244
diff changeset
286 """Concrete class that implements an interface to Microsoft Visual C++,
eaeea9e42369 Ditched redundant docstrings and comments (overlap with ccompiler.py).
Greg Ward <gward@python.net>
parents: 11244
diff changeset
287 as defined by the CCompiler abstract class."""
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
288
11337
334100218a4b Catch up with latest changes in CCompiler:
Greg Ward <gward@python.net>
parents: 11260
diff changeset
289 compiler_type = 'msvc'
334100218a4b Catch up with latest changes in CCompiler:
Greg Ward <gward@python.net>
parents: 11260
diff changeset
290
13015
affe10c3b92e Define the 'executables' class attribute so the CCompiler constructor
Greg Ward <gward@python.net>
parents: 12793
diff changeset
291 # Just set this so CCompiler's constructor doesn't barf. We currently
affe10c3b92e Define the 'executables' class attribute so the CCompiler constructor
Greg Ward <gward@python.net>
parents: 12793
diff changeset
292 # don't use the 'set_executables()' bureaucracy provided by CCompiler,
affe10c3b92e Define the 'executables' class attribute so the CCompiler constructor
Greg Ward <gward@python.net>
parents: 12793
diff changeset
293 # as it really isn't necessary for this sort of single-compiler class.
affe10c3b92e Define the 'executables' class attribute so the CCompiler constructor
Greg Ward <gward@python.net>
parents: 12793
diff changeset
294 # Would be nice to have a consistent interface with UnixCCompiler,
affe10c3b92e Define the 'executables' class attribute so the CCompiler constructor
Greg Ward <gward@python.net>
parents: 12793
diff changeset
295 # though, so it's worth thinking about.
affe10c3b92e Define the 'executables' class attribute so the CCompiler constructor
Greg Ward <gward@python.net>
parents: 12793
diff changeset
296 executables = {}
affe10c3b92e Define the 'executables' class attribute so the CCompiler constructor
Greg Ward <gward@python.net>
parents: 12793
diff changeset
297
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
298 # Private class data (need to distinguish C from C++ source for compiler)
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
299 _c_extensions = ['.c']
14267
98608429ca6e Add ".cxx" to the list of known C++ extensions.
Greg Ward <gward@python.net>
parents: 13844
diff changeset
300 _cpp_extensions = ['.cc', '.cpp', '.cxx']
14699
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
301 _rc_extensions = ['.rc']
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
302 _mc_extensions = ['.mc']
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
303
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
304 # Needed for the filename generation methods provided by the
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
305 # base class, CCompiler.
14699
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
306 src_extensions = (_c_extensions + _cpp_extensions +
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
307 _rc_extensions + _mc_extensions)
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
308 res_extension = '.res'
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
309 obj_extension = '.obj'
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
310 static_lib_extension = '.lib'
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
311 shared_lib_extension = '.dll'
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
312 static_lib_format = shared_lib_format = '%s%s'
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
313 exe_extension = '.exe'
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
314
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
315 def __init__(self, verbose=0, dry_run=0, force=0):
11360
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
316 CCompiler.__init__ (self, verbose, dry_run, force)
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
317 self.__version = VERSION
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
318 self.__root = r"Software\Microsoft\VisualStudio"
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
319 # self.__macros = MACROS
49872
381c62819f2e Merged revisions 67414 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 49223
diff changeset
320 self.__paths = []
46331
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
321 # target platform (.plat_name is consistent with 'bdist')
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
322 self.plat_name = None
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
323 self.__arch = None # deprecated name
34684
f87a8d0df125 Patch #1075887: Don't require MSVC in distutils if there is nothing
Martin v. Löwis <martin@v.loewis.de>
parents: 34033
diff changeset
324 self.initialized = False
f87a8d0df125 Patch #1075887: Don't require MSVC in distutils if there is nothing
Martin v. Löwis <martin@v.loewis.de>
parents: 34033
diff changeset
325
46331
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
326 def initialize(self, plat_name=None):
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
327 # multi-init means we would need to check platform same each time...
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
328 assert not self.initialized, "don't init multiple times"
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
329 if plat_name is None:
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
330 plat_name = get_platform()
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
331 # sanity check for platforms to prevent obscure errors later.
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
332 ok_plats = 'win32', 'win-amd64', 'win-ia64'
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
333 if plat_name not in ok_plats:
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
334 raise DistutilsPlatformError("--plat-name must be one of %s" %
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
335 (ok_plats,))
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
336
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
337 if "DISTUTILS_USE_SDK" in os.environ and "MSSdk" in os.environ and self.find_exe("cl.exe"):
36616
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
338 # Assume that the SDK set up everything alright; don't try to be
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
339 # smarter
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
340 self.cc = "cl.exe"
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
341 self.linker = "link.exe"
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
342 self.lib = "lib.exe"
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
343 self.rc = "rc.exe"
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
344 self.mc = "mc.exe"
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
345 else:
46331
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
346 # On x86, 'vcvars32.bat amd64' creates an env that doesn't work;
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
347 # to cross compile, you use 'x86_amd64'.
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
348 # On AMD64, 'vcvars32.bat amd64' is a native build env; to cross
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
349 # compile use 'x86' (ie, it runs the x86 compiler directly)
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
350 # No idea how itanium handles this, if at all.
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
351 if plat_name == get_platform() or plat_name == 'win32':
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
352 # native build or cross-compile to win32
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
353 plat_spec = PLAT_TO_VCVARS[plat_name]
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
354 else:
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
355 # cross compile from win32 -> some 64bit
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
356 plat_spec = PLAT_TO_VCVARS[get_platform()] + '_' + \
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
357 PLAT_TO_VCVARS[plat_name]
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
358
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
359 vc_env = query_vcvarsall(VERSION, plat_spec)
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
360
49223
c6703f4989b3 avoid putting unicode objects in the environment causing
Mark Hammond <mhammond@skippinet.com.au>
parents: 48973
diff changeset
361 # take care to only use strings in the environment.
c6703f4989b3 avoid putting unicode objects in the environment causing
Mark Hammond <mhammond@skippinet.com.au>
parents: 48973
diff changeset
362 self.__paths = vc_env['path'].encode('mbcs').split(os.pathsep)
c6703f4989b3 avoid putting unicode objects in the environment causing
Mark Hammond <mhammond@skippinet.com.au>
parents: 48973
diff changeset
363 os.environ['lib'] = vc_env['lib'].encode('mbcs')
c6703f4989b3 avoid putting unicode objects in the environment causing
Mark Hammond <mhammond@skippinet.com.au>
parents: 48973
diff changeset
364 os.environ['include'] = vc_env['include'].encode('mbcs')
29918
ec9f18615485 Patch from John Anderson to enable VC 7.1 support.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29117
diff changeset
365
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
366 if len(self.__paths) == 0:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
367 raise DistutilsPlatformError("Python was built with %s, "
36616
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
368 "and extensions need to be built with the same "
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
369 "version of the compiler, but it isn't installed."
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
370 % self.__product)
36616
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
371
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
372 self.cc = self.find_exe("cl.exe")
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
373 self.linker = self.find_exe("link.exe")
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
374 self.lib = self.find_exe("lib.exe")
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
375 self.rc = self.find_exe("rc.exe") # resource compiler
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
376 self.mc = self.find_exe("mc.exe") # message compiler
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
377 #self.set_path_env_var('lib')
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
378 #self.set_path_env_var('include')
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
379
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
380 # extend the MSVC path with the current path
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
381 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
382 for p in os.environ['path'].split(';'):
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
383 self.__paths.append(p)
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
384 except KeyError:
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
385 pass
41347
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
386 self.__paths = normalize_and_reduce_paths(self.__paths)
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
387 os.environ['path'] = ";".join(self.__paths)
11749
5c2770124904 Latest patch from Thomas Heller/Robin Becker:
Greg Ward <gward@python.net>
parents: 11738
diff changeset
388
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
389 self.preprocess_options = None
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
390 if self.__arch == "x86":
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
391 self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3',
36619
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
392 '/DNDEBUG']
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
393 self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3',
36619
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
394 '/Z7', '/D_DEBUG']
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
395 else:
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
396 # Win64
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
397 self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GS-' ,
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
398 '/DNDEBUG']
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
399 self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GS-',
36630
eb0977932e2d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 36619
diff changeset
400 '/Z7', '/D_DEBUG']
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
401
11720
fdc9eeb89e0b Revised version (thank to Thomas Heller and Robin Becker) that tries a lot
Greg Ward <gward@python.net>
parents: 11664
diff changeset
402 self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']
33954
0fe8a16a336a Avoid a linker warning: MSVC 7 doesn't support /pdb:None, the debug
Thomas Heller <theller@ctypes.org>
parents: 32736
diff changeset
403 if self.__version >= 7:
0fe8a16a336a Avoid a linker warning: MSVC 7 doesn't support /pdb:None, the debug
Thomas Heller <theller@ctypes.org>
parents: 32736
diff changeset
404 self.ldflags_shared_debug = [
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
405 '/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG', '/pdb:None'
33954
0fe8a16a336a Avoid a linker warning: MSVC 7 doesn't support /pdb:None, the debug
Thomas Heller <theller@ctypes.org>
parents: 32736
diff changeset
406 ]
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
407 self.ldflags_static = [ '/nologo']
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
408
34743
b8d905ca9e99 Port bugfix from 2.4 maint.
Tim Peters <tim.peters@gmail.com>
parents: 34693
diff changeset
409 self.initialized = True
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
410
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
411 # -- Worker methods ------------------------------------------------
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
412
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
413 def object_filenames(self,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
414 source_filenames,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
415 strip_dir=0,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
416 output_dir=''):
14699
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
417 # Copied from ccompiler.py, extended to return .res as 'object'-file
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
418 # for .rc input file
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
419 if output_dir is None: output_dir = ''
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
420 obj_names = []
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
421 for src_name in source_filenames:
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
422 (base, ext) = os.path.splitext (src_name)
35323
3fa58e5bddfb Patch #827386: Support absolute source paths in msvccompiler.py.
Martin v. Löwis <martin@v.loewis.de>
parents: 34743
diff changeset
423 base = os.path.splitdrive(base)[1] # Chop off the drive
3fa58e5bddfb Patch #827386: Support absolute source paths in msvccompiler.py.
Martin v. Löwis <martin@v.loewis.de>
parents: 34743
diff changeset
424 base = base[os.path.isabs(base):] # If abs, chop off leading /
14699
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
425 if ext not in self.src_extensions:
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
426 # Better to raise an exception instead of silently continuing
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
427 # and later complain about sources and targets having
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
428 # different lengths
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
429 raise CompileError ("Don't know how to compile %s" % src_name)
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
430 if strip_dir:
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
431 base = os.path.basename (base)
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
432 if ext in self._rc_extensions:
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
433 obj_names.append (os.path.join (output_dir,
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
434 base + self.res_extension))
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
435 elif ext in self._mc_extensions:
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
436 obj_names.append (os.path.join (output_dir,
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
437 base + self.res_extension))
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
438 else:
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
439 obj_names.append (os.path.join (output_dir,
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
440 base + self.obj_extension))
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
441 return obj_names
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
442
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
443
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
444 def compile(self, sources,
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
445 output_dir=None, macros=None, include_dirs=None, debug=0,
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
446 extra_preargs=None, extra_postargs=None, depends=None):
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
447
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
448 if not self.initialized:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
449 self.initialize()
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
450 compile_info = self._setup_compile(output_dir, macros, include_dirs,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
451 sources, depends, extra_postargs)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
452 macros, objects, extra_postargs, pp_opts, build = compile_info
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
453
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
454 compile_opts = extra_preargs or []
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
455 compile_opts.append ('/c')
11735
89d308fcf6f4 Patch from Thomas heller:
Greg Ward <gward@python.net>
parents: 11730
diff changeset
456 if debug:
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
457 compile_opts.extend(self.compile_options_debug)
11735
89d308fcf6f4 Patch from Thomas heller:
Greg Ward <gward@python.net>
parents: 11730
diff changeset
458 else:
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
459 compile_opts.extend(self.compile_options)
14699
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
460
31129
be9ef9b92d61 Compile the files in the same order they are passed to the compiler.
Thomas Heller <theller@ctypes.org>
parents: 31039
diff changeset
461 for obj in objects:
be9ef9b92d61 Compile the files in the same order they are passed to the compiler.
Thomas Heller <theller@ctypes.org>
parents: 31039
diff changeset
462 try:
be9ef9b92d61 Compile the files in the same order they are passed to the compiler.
Thomas Heller <theller@ctypes.org>
parents: 31039
diff changeset
463 src, ext = build[obj]
be9ef9b92d61 Compile the files in the same order they are passed to the compiler.
Thomas Heller <theller@ctypes.org>
parents: 31039
diff changeset
464 except KeyError:
be9ef9b92d61 Compile the files in the same order they are passed to the compiler.
Thomas Heller <theller@ctypes.org>
parents: 31039
diff changeset
465 continue
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
466 if debug:
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
467 # pass the full pathname to MSVC in debug mode,
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
468 # this allows the debugger to find the source file
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
469 # without asking the user to browse for it
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
470 src = os.path.abspath(src)
14699
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
471
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
472 if ext in self._c_extensions:
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
473 input_opt = "/Tc" + src
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
474 elif ext in self._cpp_extensions:
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
475 input_opt = "/Tp" + src
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
476 elif ext in self._rc_extensions:
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
477 # compile .RC to .RES file
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
478 input_opt = src
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
479 output_opt = "/fo" + obj
12790
f8c1c5b7dc9f Changed to catch compile/link failures and raise CompileError, LibError,
Greg Ward <gward@python.net>
parents: 12717
diff changeset
480 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
481 self.spawn([self.rc] + pp_opts +
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
482 [output_opt] + [input_opt])
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
483 except DistutilsExecError, msg:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
484 raise CompileError(msg)
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
485 continue
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
486 elif ext in self._mc_extensions:
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
487 # Compile .MC to .RC file to .RES file.
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
488 # * '-h dir' specifies the directory for the
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
489 # generated include file
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
490 # * '-r dir' specifies the target directory of the
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
491 # generated RC file and the binary message resource
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
492 # it includes
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
493 #
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
494 # For now (since there are no options to change this),
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
495 # we use the source-directory for the include file and
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
496 # the build directory for the RC file and message
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
497 # resources. This works at least for win32all.
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
498 h_dir = os.path.dirname(src)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
499 rc_dir = os.path.dirname(obj)
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
500 try:
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
501 # first compile .MC to .RC and .H file
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
502 self.spawn([self.mc] +
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
503 ['-h', h_dir, '-r', rc_dir] + [src])
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
504 base, _ = os.path.splitext (os.path.basename (src))
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
505 rc_file = os.path.join (rc_dir, base + '.rc')
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
506 # then compile .RC to .RES file
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
507 self.spawn([self.rc] +
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
508 ["/fo" + obj] + [rc_file])
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
509
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
510 except DistutilsExecError, msg:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
511 raise CompileError(msg)
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
512 continue
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
513 else:
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
514 # how to handle this file?
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
515 raise CompileError("Don't know how to compile %s to %s"
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
516 % (src, obj))
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
517
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
518 output_opt = "/Fo" + obj
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
519 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
520 self.spawn([self.cc] + compile_opts + pp_opts +
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
521 [input_opt, output_opt] +
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
522 extra_postargs)
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
523 except DistutilsExecError, msg:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
524 raise CompileError(msg)
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
525
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
526 return objects
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
527
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
528
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
529 def create_static_lib(self,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
530 objects,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
531 output_libname,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
532 output_dir=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
533 debug=0,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
534 target_lang=None):
11260
eaeea9e42369 Ditched redundant docstrings and comments (overlap with ccompiler.py).
Greg Ward <gward@python.net>
parents: 11244
diff changeset
535
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
536 if not self.initialized:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
537 self.initialize()
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
538 (objects, output_dir) = self._fix_object_args(objects, output_dir)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
539 output_filename = self.library_filename(output_libname,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
540 output_dir=output_dir)
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
541
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
542 if self._need_link(objects, output_filename):
11956
23fd7d10064e Renamed 'link_static_lib() to 'create_static_lib()', and rewrote it create
Greg Ward <gward@python.net>
parents: 11915
diff changeset
543 lib_args = objects + ['/OUT:' + output_filename]
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
544 if debug:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
545 pass # XXX what goes here?
12790
f8c1c5b7dc9f Changed to catch compile/link failures and raise CompileError, LibError,
Greg Ward <gward@python.net>
parents: 12717
diff changeset
546 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
547 self.spawn([self.lib] + lib_args)
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
548 except DistutilsExecError, msg:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
549 raise LibError(msg)
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
550 else:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23274
diff changeset
551 log.debug("skipping %s (up-to-date)", output_filename)
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
552
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14890
diff changeset
553
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
554 def link(self,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
555 target_desc,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
556 objects,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
557 output_filename,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
558 output_dir=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
559 libraries=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
560 library_dirs=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
561 runtime_library_dirs=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
562 export_symbols=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
563 debug=0,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
564 extra_preargs=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
565 extra_postargs=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
566 build_temp=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
567 target_lang=None):
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
568
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
569 if not self.initialized:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
570 self.initialize()
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
571 (objects, output_dir) = self._fix_object_args(objects, output_dir)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
572 fixed_args = self._fix_lib_args(libraries, library_dirs,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
573 runtime_library_dirs)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
574 (libraries, library_dirs, runtime_library_dirs) = fixed_args
12056
1e5cd70cee10 Added 'runtime_library_dirs' parameter to 'link_*()' methods, and warn that
Greg Ward <gward@python.net>
parents: 12016
diff changeset
575
12412
ae525ab23eef Added 'link_executable()' method (Berthold Hoellmann).
Greg Ward <gward@python.net>
parents: 12407
diff changeset
576 if runtime_library_dirs:
12056
1e5cd70cee10 Added 'runtime_library_dirs' parameter to 'link_*()' methods, and warn that
Greg Ward <gward@python.net>
parents: 12016
diff changeset
577 self.warn ("I don't know what to do with 'runtime_library_dirs': "
1e5cd70cee10 Added 'runtime_library_dirs' parameter to 'link_*()' methods, and warn that
Greg Ward <gward@python.net>
parents: 12016
diff changeset
578 + str (runtime_library_dirs))
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14890
diff changeset
579
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
580 lib_opts = gen_lib_options(self,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
581 library_dirs, runtime_library_dirs,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
582 libraries)
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
583 if output_dir is not None:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
584 output_filename = os.path.join(output_dir, output_filename)
11735
89d308fcf6f4 Patch from Thomas heller:
Greg Ward <gward@python.net>
parents: 11730
diff changeset
585
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
586 if self._need_link(objects, output_filename):
14890
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
587 if target_desc == CCompiler.EXECUTABLE:
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
588 if debug:
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
589 ldflags = self.ldflags_shared_debug[1:]
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
590 else:
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
591 ldflags = self.ldflags_shared[1:]
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
592 else:
14890
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
593 if debug:
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
594 ldflags = self.ldflags_shared_debug
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
595 else:
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
596 ldflags = self.ldflags_shared
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
597
12717
0a6af59ebffd Added support for the 'export_symbols' parameter to 'link_shared_object()'
Greg Ward <gward@python.net>
parents: 12412
diff changeset
598 export_opts = []
0a6af59ebffd Added support for the 'export_symbols' parameter to 'link_shared_object()'
Greg Ward <gward@python.net>
parents: 12412
diff changeset
599 for sym in (export_symbols or []):
0a6af59ebffd Added support for the 'export_symbols' parameter to 'link_shared_object()'
Greg Ward <gward@python.net>
parents: 12412
diff changeset
600 export_opts.append("/EXPORT:" + sym)
0a6af59ebffd Added support for the 'export_symbols' parameter to 'link_shared_object()'
Greg Ward <gward@python.net>
parents: 12412
diff changeset
601
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14890
diff changeset
602 ld_args = (ldflags + lib_opts + export_opts +
12717
0a6af59ebffd Added support for the 'export_symbols' parameter to 'link_shared_object()'
Greg Ward <gward@python.net>
parents: 12412
diff changeset
603 objects + ['/OUT:' + output_filename])
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
604
13798
031dae08a0a9 Patch from Rene Liebscher: generate an /IMPLIB: option to ensure that
Greg Ward <gward@python.net>
parents: 13241
diff changeset
605 # The MSVC linker generates .lib and .exp files, which cannot be
031dae08a0a9 Patch from Rene Liebscher: generate an /IMPLIB: option to ensure that
Greg Ward <gward@python.net>
parents: 13241
diff changeset
606 # suppressed by any linker switches. The .lib files may even be
031dae08a0a9 Patch from Rene Liebscher: generate an /IMPLIB: option to ensure that
Greg Ward <gward@python.net>
parents: 13241
diff changeset
607 # needed! Make sure they are generated in the temporary build
031dae08a0a9 Patch from Rene Liebscher: generate an /IMPLIB: option to ensure that
Greg Ward <gward@python.net>
parents: 13241
diff changeset
608 # directory. Since they have different names for debug and release
031dae08a0a9 Patch from Rene Liebscher: generate an /IMPLIB: option to ensure that
Greg Ward <gward@python.net>
parents: 13241
diff changeset
609 # builds, they can go into the same directory.
46624
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
610 build_temp = os.path.dirname(objects[0])
14890
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
611 if export_symbols is not None:
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
612 (dll_name, dll_ext) = os.path.splitext(
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
613 os.path.basename(output_filename))
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
614 implib_file = os.path.join(
46624
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
615 build_temp,
14890
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
616 self.library_filename(dll_name))
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
617 ld_args.append ('/IMPLIB:' + implib_file)
13798
031dae08a0a9 Patch from Rene Liebscher: generate an /IMPLIB: option to ensure that
Greg Ward <gward@python.net>
parents: 13241
diff changeset
618
46624
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
619 # Embedded manifests are recommended - see MSDN article titled
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
620 # "How to: Embed a Manifest Inside a C/C++ Application"
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
621 # (currently at http://msdn2.microsoft.com/en-us/library/ms235591(VS.80).aspx)
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
622 # Ask the linker to generate the manifest in the temp dir, so
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
623 # we can embed it later.
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
624 temp_manifest = os.path.join(
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
625 build_temp,
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
626 os.path.basename(output_filename) + ".manifest")
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
627 ld_args.append('/MANIFESTFILE:' + temp_manifest)
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
628
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
629 if extra_preargs:
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
630 ld_args[:0] = extra_preargs
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
631 if extra_postargs:
13798
031dae08a0a9 Patch from Rene Liebscher: generate an /IMPLIB: option to ensure that
Greg Ward <gward@python.net>
parents: 13241
diff changeset
632 ld_args.extend(extra_postargs)
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
633
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
634 self.mkpath(os.path.dirname(output_filename))
12790
f8c1c5b7dc9f Changed to catch compile/link failures and raise CompileError, LibError,
Greg Ward <gward@python.net>
parents: 12717
diff changeset
635 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
636 self.spawn([self.linker] + ld_args)
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
637 except DistutilsExecError, msg:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
638 raise LinkError(msg)
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
639
46624
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
640 # embed the manifest
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
641 # XXX - this is somewhat fragile - if mt.exe fails, distutils
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
642 # will still consider the DLL up-to-date, but it will not have a
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
643 # manifest. Maybe we should link to a temp file? OTOH, that
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
644 # implies a build environment error that shouldn't go undetected.
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
645 if target_desc == CCompiler.EXECUTABLE:
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
646 mfid = 1
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
647 else:
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
648 mfid = 2
46624
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
649 out_arg = '-outputresource:%s;%s' % (output_filename, mfid)
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
650 try:
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
651 self.spawn(['mt.exe', '-nologo', '-manifest',
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
652 temp_manifest, out_arg])
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
653 except DistutilsExecError, msg:
46624
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
654 raise LinkError(msg)
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
655 else:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23274
diff changeset
656 log.debug("skipping %s (up-to-date)", output_filename)
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
657
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
658
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
659 # -- Miscellaneous methods -----------------------------------------
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
660 # These are all used by the 'gen_lib_options() function, in
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
661 # ccompiler.py.
11360
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
662
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
663 def library_dir_option(self, dir):
11360
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
664 return "/LIBPATH:" + dir
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
665
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
666 def runtime_library_dir_option(self, dir):
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
667 raise DistutilsPlatformError(
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
668 "don't know how to set runtime library search path for MSVC++")
12016
13fd0dfec560 Changed to pay attention to the 'runtime_library_dirs' list (= 'rpath'
Greg Ward <gward@python.net>
parents: 11956
diff changeset
669
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
670 def library_option(self, lib):
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
671 return self.library_filename(lib)
11360
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
672
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
673
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
674 def find_library_file(self, dirs, lib, debug=0):
13844
b37f08635023 Added 'debug' flag to 'find_library_file()', and changed code to handle it.
Greg Ward <gward@python.net>
parents: 13799
diff changeset
675 # Prefer a debugging library if found (and requested), but deal
b37f08635023 Added 'debug' flag to 'find_library_file()', and changed code to handle it.
Greg Ward <gward@python.net>
parents: 13799
diff changeset
676 # with it if we don't have one.
b37f08635023 Added 'debug' flag to 'find_library_file()', and changed code to handle it.
Greg Ward <gward@python.net>
parents: 13799
diff changeset
677 if debug:
b37f08635023 Added 'debug' flag to 'find_library_file()', and changed code to handle it.
Greg Ward <gward@python.net>
parents: 13799
diff changeset
678 try_names = [lib + "_d", lib]
b37f08635023 Added 'debug' flag to 'find_library_file()', and changed code to handle it.
Greg Ward <gward@python.net>
parents: 13799
diff changeset
679 else:
b37f08635023 Added 'debug' flag to 'find_library_file()', and changed code to handle it.
Greg Ward <gward@python.net>
parents: 13799
diff changeset
680 try_names = [lib]
11360
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
681 for dir in dirs:
13844
b37f08635023 Added 'debug' flag to 'find_library_file()', and changed code to handle it.
Greg Ward <gward@python.net>
parents: 13799
diff changeset
682 for name in try_names:
b37f08635023 Added 'debug' flag to 'find_library_file()', and changed code to handle it.
Greg Ward <gward@python.net>
parents: 13799
diff changeset
683 libfile = os.path.join(dir, self.library_filename (name))
b37f08635023 Added 'debug' flag to 'find_library_file()', and changed code to handle it.
Greg Ward <gward@python.net>
parents: 13799
diff changeset
684 if os.path.exists(libfile):
b37f08635023 Added 'debug' flag to 'find_library_file()', and changed code to handle it.
Greg Ward <gward@python.net>
parents: 13799
diff changeset
685 return libfile
11360
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
686 else:
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
687 # Oops, didn't find it in *any* of 'dirs'
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
688 return None
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
689
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
690 # Helper methods for using the MSVC registry settings
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
691
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
692 def find_exe(self, exe):
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
693 """Return path to an MSVC executable program.
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
694
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
695 Tries to find the program in several places: first, one of the
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
696 MSVC program search paths from the registry; next, the directories
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
697 in the PATH environment variable. If any of those work, return an
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
698 absolute path that is known to exist. If none of them work, just
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
699 return the original program name, 'exe'.
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
700 """
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
701 for p in self.__paths:
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
702 fn = os.path.join(os.path.abspath(p), exe)
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
703 if os.path.isfile(fn):
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
704 return fn
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
705
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
706 # didn't find it; try existing path
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
707 for p in os.environ['Path'].split(';'):
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
708 fn = os.path.join(os.path.abspath(p),exe)
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
709 if os.path.isfile(fn):
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
710 return fn
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
711
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
712 return exe