annotate Lib/distutils/msvc9compiler.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents a27df4b88d67
children
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
57554
96954e7dd9b6 Merged revisions 76651 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 50383
diff changeset
20 import re
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
21
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
22 from distutils.errors import (DistutilsExecError, DistutilsPlatformError,
57847
3e2b7965ada9 massive import cleaning in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57553
diff changeset
23 CompileError, LibError, LinkError)
3e2b7965ada9 massive import cleaning in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57553
diff changeset
24 from distutils.ccompiler import CCompiler, 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
62423
a101d073a5cd Merged revisions 82130 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 57554
diff changeset
40 NATIVE_WIN64 = (sys.platform == 'win32' and sys.maxsize > 2**32)
a101d073a5cd Merged revisions 82130 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 57554
diff changeset
41 if NATIVE_WIN64:
a101d073a5cd Merged revisions 82130 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 57554
diff changeset
42 # Visual C++ is a 32-bit application, so we need to look in
a101d073a5cd Merged revisions 82130 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 57554
diff changeset
43 # the corresponding registry branch, if we're running a
a101d073a5cd Merged revisions 82130 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 57554
diff changeset
44 # 64-bit Python on Win64
a101d073a5cd Merged revisions 82130 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 57554
diff changeset
45 VS_BASE = r"Software\Wow6432Node\Microsoft\VisualStudio\%0.1f"
62421
1a86d845fbc6 fix finding visual studio 2008 on 64 bit #8854
Benjamin Peterson <benjamin@python.org>
parents: 59387
diff changeset
46 VSEXPRESS_BASE = r"Software\Wow6432Node\Microsoft\VCExpress\%0.1f"
62423
a101d073a5cd Merged revisions 82130 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 57554
diff changeset
47 WINSDK_BASE = r"Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows"
a101d073a5cd Merged revisions 82130 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 57554
diff changeset
48 NET_BASE = r"Software\Wow6432Node\Microsoft\.NETFramework"
a101d073a5cd Merged revisions 82130 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 57554
diff changeset
49 else:
a101d073a5cd Merged revisions 82130 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 57554
diff changeset
50 VS_BASE = r"Software\Microsoft\VisualStudio\%0.1f"
62421
1a86d845fbc6 fix finding visual studio 2008 on 64 bit #8854
Benjamin Peterson <benjamin@python.org>
parents: 59387
diff changeset
51 VSEXPRESS_BASE = r"Software\Microsoft\VCExpress\%0.1f"
62423
a101d073a5cd Merged revisions 82130 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 57554
diff changeset
52 WINSDK_BASE = r"Software\Microsoft\Microsoft SDKs\Windows"
a101d073a5cd Merged revisions 82130 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 57554
diff changeset
53 NET_BASE = r"Software\Microsoft\.NETFramework"
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
54
46331
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
55 # 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
56 # '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
57 # 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
58 PLAT_TO_VCVARS = {
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
59 'win32' : 'x86',
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
60 'win-amd64' : 'amd64',
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
61 'win-ia64' : 'ia64',
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
62 }
12201
41dfc7d4a36b Fixed my simplification to Thomas' patch: winreg and win32api export the same
Greg Ward <gward@python.net>
parents: 12190
diff changeset
63
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
64 class Reg:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
65 """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
66 """
12190
94b601faebac Simplified Thomas Heller's registry patch: just assign all those
Greg Ward <gward@python.net>
parents: 12189
diff changeset
67
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
68 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
69 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
70 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
71 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
72 return d[key]
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
73 raise KeyError(key)
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
74 get_value = classmethod(get_value)
11749
5c2770124904 Latest patch from Thomas Heller/Robin Becker:
Greg Ward <gward@python.net>
parents: 11738
diff changeset
75
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
76 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
77 """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
78 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
79 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
80 except RegError:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
81 return None
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
82 L = []
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
83 i = 0
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
84 while True:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
85 try:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
86 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
87 except RegError:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
88 break
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
89 L.append(k)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
90 i += 1
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
91 return L
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
92 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
93
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
94 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
95 """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
96
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
97 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
98 """
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
99 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
100 handle = RegOpenKeyEx(base, key)
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
101 except RegError:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
102 return None
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
103 d = {}
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
104 i = 0
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
105 while True:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
106 try:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
107 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
108 except RegError:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
109 break
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
110 name = name.lower()
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
111 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
112 i += 1
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
113 return d
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
114 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
115
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
116 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
117 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
118 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
119 try:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
120 s = dec("mbcs")
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
121 except UnicodeError:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
122 pass
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
123 return s
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
124 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
125
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
126 class MacroExpander:
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
127
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
128 def __init__(self, version):
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
129 self.macros = {}
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
130 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
131 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
132
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
133 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
134 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
135
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
136 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
137 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
138 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
139 self.set_macro("FrameworkDir", NET_BASE, "installroot")
34033
163409a601be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 34025
diff changeset
140 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
141 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
142 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
143 "sdkinstallrootv2.0")
34033
163409a601be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 34025
diff changeset
144 else:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
145 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
146 except KeyError:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
147 raise DistutilsPlatformError(
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
148 """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
149 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
150 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
151 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
152
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
153 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
154 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
155 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
156 else:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
157 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
158 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
159 try:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
160 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
161 except RegError:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
162 continue
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
163 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
164 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
165 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
166
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
167 def sub(self, s):
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
168 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
169 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
170 return s
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
171
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
172 def get_build_version():
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
173 """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
174
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
175 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
176 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
177 """
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
178 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
179 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
180 if i == -1:
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
181 return 6
29117
6ac0a672b082 Restore Python 1.5.2 compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 29054
diff changeset
182 i = i + len(prefix)
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
183 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
184 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
185 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
186 # 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
187 if majorVersion == 6:
ec9f18615485 Patch from John Anderson to enable VC 7.1 support.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29117
diff changeset
188 minorVersion = 0
ec9f18615485 Patch from John Anderson to enable VC 7.1 support.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29117
diff changeset
189 if majorVersion >= 6:
ec9f18615485 Patch from John Anderson to enable VC 7.1 support.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29117
diff changeset
190 return majorVersion + minorVersion
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
191 # 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
192 return None
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31129
diff changeset
193
41347
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
194 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
195 """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
196
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
197 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
198 """
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
199 # 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
200 reduced_paths = []
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
201 for p in paths:
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
202 np = os.path.normpath(p)
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
203 # 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
204 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
205 reduced_paths.append(np)
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
206 return reduced_paths
36619
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
207
48973
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
208 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
209 """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
210 """
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
211 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
212 newList = []
2d80d00b1ef3 Issue 2975: when compiling multiple extension modules with visual studio 2008
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46624
diff changeset
213 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
214 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
215 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
216 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
217 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
218
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
219 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
220 """Find the vcvarsall.bat file
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
221
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
222 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
223 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
224 """
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
225 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
226 try:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
227 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
228 "productdir")
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
229 except KeyError:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
230 productdir = None
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
231
59387
4a119d84d0b5 search in the alternative location for VCExpress
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58503
diff changeset
232 # trying Express edition
4a119d84d0b5 search in the alternative location for VCExpress
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58503
diff changeset
233 if productdir is None:
4a119d84d0b5 search in the alternative location for VCExpress
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58503
diff changeset
234 vsbase = VSEXPRESS_BASE % version
4a119d84d0b5 search in the alternative location for VCExpress
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58503
diff changeset
235 try:
4a119d84d0b5 search in the alternative location for VCExpress
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58503
diff changeset
236 productdir = Reg.get_value(r"%s\Setup\VC" % vsbase,
4a119d84d0b5 search in the alternative location for VCExpress
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58503
diff changeset
237 "productdir")
4a119d84d0b5 search in the alternative location for VCExpress
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58503
diff changeset
238 except KeyError:
4a119d84d0b5 search in the alternative location for VCExpress
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58503
diff changeset
239 productdir = None
4a119d84d0b5 search in the alternative location for VCExpress
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58503
diff changeset
240 log.debug("Unable to find productdir in registry")
4a119d84d0b5 search in the alternative location for VCExpress
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58503
diff changeset
241
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
242 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
243 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
244 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
245
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
246 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
247 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
248 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
249 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
250 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
251 return None
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
252 else:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
253 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
254 if not productdir:
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
255 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
256 return None
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
257 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
258 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
259 return vcvarsall
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
260 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
261 return None
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
262
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
263 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
264 """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
265 """
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
266 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
267 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
268 result = {}
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
269
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
270 if vcvarsall is None:
50383
d8975f24af8b Merged revisions 68081 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 49872
diff changeset
271 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
272 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
273 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
274 stdout=subprocess.PIPE,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
275 stderr=subprocess.PIPE)
66008
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 62421
diff changeset
276 try:
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 62421
diff changeset
277 stdout, stderr = popen.communicate()
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 62421
diff changeset
278 if popen.wait() != 0:
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 62421
diff changeset
279 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
280
66171
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
281 stdout = stdout.decode("mbcs")
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
282 for line in stdout.split("\n"):
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
283 line = Reg.convert_mbcs(line)
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
284 if '=' not in line:
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
285 continue
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
286 line = line.strip()
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
287 key, value = line.split('=', 1)
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
288 key = key.lower()
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
289 if key in interesting:
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
290 if value.endswith(os.pathsep):
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
291 value = value[:-1]
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
292 result[key] = removeDuplicates(value)
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
293
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
294 finally:
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
295 popen.stdout.close()
d2ef88e71b4a Merged revisions 86274,86276 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66008
diff changeset
296 popen.stderr.close()
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
297
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
298 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
299 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
300
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
301 return result
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
302
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
303 # More globals
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
304 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
305 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
306 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
307 # MACROS = MacroExpander(VERSION)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
308
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
309 class MSVCCompiler(CCompiler) :
11260
eaeea9e42369 Ditched redundant docstrings and comments (overlap with ccompiler.py).
Greg Ward <gward@python.net>
parents: 11244
diff changeset
310 """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
311 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
312
11337
334100218a4b Catch up with latest changes in CCompiler:
Greg Ward <gward@python.net>
parents: 11260
diff changeset
313 compiler_type = 'msvc'
334100218a4b Catch up with latest changes in CCompiler:
Greg Ward <gward@python.net>
parents: 11260
diff changeset
314
13015
affe10c3b92e Define the 'executables' class attribute so the CCompiler constructor
Greg Ward <gward@python.net>
parents: 12793
diff changeset
315 # 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
316 # 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
317 # 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
318 # 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
319 # 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
320 executables = {}
affe10c3b92e Define the 'executables' class attribute so the CCompiler constructor
Greg Ward <gward@python.net>
parents: 12793
diff changeset
321
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
322 # 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
323 _c_extensions = ['.c']
14267
98608429ca6e Add ".cxx" to the list of known C++ extensions.
Greg Ward <gward@python.net>
parents: 13844
diff changeset
324 _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
325 _rc_extensions = ['.rc']
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
326 _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
327
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
328 # 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
329 # base class, CCompiler.
14699
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
330 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
331 _rc_extensions + _mc_extensions)
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
332 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
333 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
334 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
335 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
336 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
337 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
338
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
339 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
340 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
341 self.__version = VERSION
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
342 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
343 # self.__macros = MACROS
49872
381c62819f2e Merged revisions 67414 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 49223
diff changeset
344 self.__paths = []
46331
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
345 # 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
346 self.plat_name = None
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
347 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
348 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
349
46331
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
350 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
351 # 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
352 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
353 if plat_name is None:
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
354 plat_name = get_platform()
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
355 # 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
356 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
357 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
358 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
359 (ok_plats,))
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
360
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
361 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
362 # 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
363 # smarter
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
364 self.cc = "cl.exe"
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
365 self.linker = "link.exe"
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
366 self.lib = "lib.exe"
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
367 self.rc = "rc.exe"
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
368 self.mc = "mc.exe"
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
369 else:
46331
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
370 # 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
371 # 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
372 # 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
373 # 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
374 # 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
375 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
376 # 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
377 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
378 else:
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
379 # 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
380 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
381 PLAT_TO_VCVARS[plat_name]
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
382
a93d2919ea59 Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 44186
diff changeset
383 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
384
49223
c6703f4989b3 avoid putting unicode objects in the environment causing
Mark Hammond <mhammond@skippinet.com.au>
parents: 48973
diff changeset
385 # 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
386 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
387 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
388 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
389
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
390 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
391 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
392 "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
393 "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
394 % self.__product)
36616
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
395
c36e37a18f1a Let the SDK setup override distutils logic.
Martin v. Löwis <martin@v.loewis.de>
parents: 35323
diff changeset
396 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
397 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
398 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
399 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
400 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
401 #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
402 #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
403
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
404 # 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
405 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
406 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
407 self.__paths.append(p)
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
408 except KeyError:
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
409 pass
41347
7dee7f7d29f0 SF #1685563, MSVCCompiler creates redundant and long PATH strings
Neal Norwitz <nnorwitz@gmail.com>
parents: 39309
diff changeset
410 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
411 os.environ['path'] = ";".join(self.__paths)
11749
5c2770124904 Latest patch from Thomas Heller/Robin Becker:
Greg Ward <gward@python.net>
parents: 11738
diff changeset
412
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
413 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
414 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
415 self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3',
36619
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
416 '/DNDEBUG']
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
417 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
418 '/Z7', '/D_DEBUG']
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
419 else:
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
420 # Win64
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
421 self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GS-' ,
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
422 '/DNDEBUG']
b766ed03d425 Detect Win64 builds.
Martin v. Löwis <martin@v.loewis.de>
parents: 36616
diff changeset
423 self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GS-',
36630
eb0977932e2d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 36619
diff changeset
424 '/Z7', '/D_DEBUG']
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
425
11720
fdc9eeb89e0b Revised version (thank to Thomas Heller and Robin Becker) that tries a lot
Greg Ward <gward@python.net>
parents: 11664
diff changeset
426 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
427 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
428 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
429 '/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
430 ]
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
431 self.ldflags_static = [ '/nologo']
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
432
34743
b8d905ca9e99 Port bugfix from 2.4 maint.
Tim Peters <tim.peters@gmail.com>
parents: 34693
diff changeset
433 self.initialized = True
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
434
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
435 # -- Worker methods ------------------------------------------------
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
436
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
437 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
438 source_filenames,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
439 strip_dir=0,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
440 output_dir=''):
14699
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
441 # 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
442 # for .rc input file
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
443 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
444 obj_names = []
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
445 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
446 (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
447 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
448 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
449 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
450 # 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
451 # 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
452 # different lengths
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
453 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
454 if strip_dir:
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
455 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
456 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
457 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
458 base + self.res_extension))
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
459 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
460 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
461 base + self.res_extension))
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
462 else:
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
463 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
464 base + self.obj_extension))
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
465 return obj_names
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
466
fa82820bd3ff *Very* belated application of Thomas Heller's patch to handle
Greg Ward <gward@python.net>
parents: 14270
diff changeset
467
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
468 def compile(self, sources,
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
469 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
470 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
471
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
472 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
473 self.initialize()
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
474 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
475 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
476 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
477
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
478 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
479 compile_opts.append ('/c')
11735
89d308fcf6f4 Patch from Thomas heller:
Greg Ward <gward@python.net>
parents: 11730
diff changeset
480 if debug:
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
481 compile_opts.extend(self.compile_options_debug)
11735
89d308fcf6f4 Patch from Thomas heller:
Greg Ward <gward@python.net>
parents: 11730
diff changeset
482 else:
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
483 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
484
31129
be9ef9b92d61 Compile the files in the same order they are passed to the compiler.
Thomas Heller <theller@ctypes.org>
parents: 31039
diff changeset
485 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
486 try:
be9ef9b92d61 Compile the files in the same order they are passed to the compiler.
Thomas Heller <theller@ctypes.org>
parents: 31039
diff changeset
487 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
488 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
489 continue
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
490 if debug:
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
491 # pass the full pathname to MSVC in debug mode,
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
492 # this allows the debugger to find the source file
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
493 # without asking the user to browse for it
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
494 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
495
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
496 if ext in self._c_extensions:
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
497 input_opt = "/Tc" + src
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
498 elif ext in self._cpp_extensions:
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
499 input_opt = "/Tp" + src
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
500 elif ext in self._rc_extensions:
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
501 # compile .RC to .RES file
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
502 input_opt = src
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
503 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
504 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
505 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
506 [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
507 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
508 raise CompileError(msg)
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
509 continue
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
510 elif ext in self._mc_extensions:
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
511 # Compile .MC to .RC file to .RES file.
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
512 # * '-h dir' specifies the directory for the
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
513 # generated include file
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
514 # * '-r dir' specifies the target directory of the
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
515 # generated RC file and the binary message resource
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
516 # it includes
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 # 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
519 # 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
520 # the build directory for the RC file and message
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
521 # 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
522 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
523 rc_dir = os.path.dirname(obj)
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
524 try:
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
525 # 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
526 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
527 ['-h', h_dir, '-r', rc_dir] + [src])
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
528 base, _ = os.path.splitext (os.path.basename (src))
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
529 rc_file = os.path.join (rc_dir, base + '.rc')
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
530 # 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
531 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
532 ["/fo" + obj] + [rc_file])
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
533
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
534 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
535 raise CompileError(msg)
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
536 continue
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
537 else:
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
538 # 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
539 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
540 % (src, obj))
23823
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
541
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
542 output_opt = "/Fo" + obj
c48bf5df614a Refactor compile() method implementations.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
543 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
544 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
545 [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
546 extra_postargs)
52048
4650ecdfcfb6 Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50383
diff changeset
547 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
548 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
549
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
550 return objects
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
551
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
552
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
553 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
554 objects,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
555 output_libname,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
556 output_dir=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
557 debug=0,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
558 target_lang=None):
11260
eaeea9e42369 Ditched redundant docstrings and comments (overlap with ccompiler.py).
Greg Ward <gward@python.net>
parents: 11244
diff changeset
559
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
560 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
561 self.initialize()
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
562 (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
563 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
564 output_dir=output_dir)
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
565
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
566 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
567 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
568 if debug:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
569 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
570 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
571 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
572 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
573 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
574 else:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23274
diff changeset
575 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
576
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14890
diff changeset
577
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
578 def link(self,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
579 target_desc,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
580 objects,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
581 output_filename,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
582 output_dir=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
583 libraries=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
584 library_dirs=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
585 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
586 export_symbols=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
587 debug=0,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
588 extra_preargs=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
589 extra_postargs=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
590 build_temp=None,
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
591 target_lang=None):
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
592
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
593 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
594 self.initialize()
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
595 (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
596 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
597 runtime_library_dirs)
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
598 (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
599
12412
ae525ab23eef Added 'link_executable()' method (Berthold Hoellmann).
Greg Ward <gward@python.net>
parents: 12407
diff changeset
600 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
601 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
602 + str (runtime_library_dirs))
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14890
diff changeset
603
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
604 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
605 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
606 libraries)
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
607 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
608 output_filename = os.path.join(output_dir, output_filename)
11735
89d308fcf6f4 Patch from Thomas heller:
Greg Ward <gward@python.net>
parents: 11730
diff changeset
609
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
610 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
611 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
612 if debug:
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
613 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
614 else:
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
615 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
616 else:
14890
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
617 if debug:
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
618 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
619 else:
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
620 ldflags = self.ldflags_shared
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
621
12717
0a6af59ebffd Added support for the 'export_symbols' parameter to 'link_shared_object()'
Greg Ward <gward@python.net>
parents: 12412
diff changeset
622 export_opts = []
0a6af59ebffd Added support for the 'export_symbols' parameter to 'link_shared_object()'
Greg Ward <gward@python.net>
parents: 12412
diff changeset
623 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
624 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
625
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14890
diff changeset
626 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
627 objects + ['/OUT:' + output_filename])
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
628
13798
031dae08a0a9 Patch from Rene Liebscher: generate an /IMPLIB: option to ensure that
Greg Ward <gward@python.net>
parents: 13241
diff changeset
629 # 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
630 # 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
631 # 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
632 # 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
633 # 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
634 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
635 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
636 (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
637 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
638 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
639 build_temp,
14890
afd7ece37c46 Big patch from Rene Liebscher to simplify the CCompiler API and
Greg Ward <gward@python.net>
parents: 14699
diff changeset
640 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
641 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
642
72951
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
643 self.manifest_setup_ldargs(output_filename, build_temp, ld_args)
46624
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
644
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
645 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
646 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
647 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
648 ld_args.extend(extra_postargs)
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
649
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
650 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
651 try:
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
652 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
653 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
654 raise LinkError(msg)
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
655
46624
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
656 # embed the manifest
0ba12c32e2b5 #2581: Vista UAC/elevation support for bdist_wininst
Mark Hammond <mhammond@skippinet.com.au>
parents: 46331
diff changeset
657 # 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
658 # 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
659 # 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
660 # implies a build environment error that shouldn't go undetected.
72951
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
661 mfinfo = self.manifest_get_embed_info(target_desc, ld_args)
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
662 if mfinfo is not None:
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
663 mffilename, mfid = mfinfo
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
664 out_arg = '-outputresource:%s;%s' % (output_filename, mfid)
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
665 try:
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
666 self.spawn(['mt.exe', '-nologo', '-manifest',
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
667 mffilename, out_arg])
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
668 except DistutilsExecError, msg:
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
669 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
670 else:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23274
diff changeset
671 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
672
72951
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
673 def manifest_setup_ldargs(self, output_filename, build_temp, ld_args):
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
674 # If we need a manifest at all, an embedded manifest is recommended.
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
675 # See MSDN article titled
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
676 # "How to: Embed a Manifest Inside a C/C++ Application"
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
677 # (currently at http://msdn2.microsoft.com/en-us/library/ms235591(VS.80).aspx)
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
678 # Ask the linker to generate the manifest in the temp dir, so
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
679 # we can check it, and possibly embed it, later.
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
680 temp_manifest = os.path.join(
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
681 build_temp,
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
682 os.path.basename(output_filename) + ".manifest")
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
683 ld_args.append('/MANIFESTFILE:' + temp_manifest)
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
684
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
685 def manifest_get_embed_info(self, target_desc, ld_args):
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
686 # If a manifest should be embedded, return a tuple of
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
687 # (manifest_filename, resource_id). Returns None if no manifest
72954
a27df4b88d67 normalize whitespace in Lib/distutils/msvc9compiler.py
Mark Hammond <mhammond@skippinet.com.au>
parents: 72951
diff changeset
688 # should be embedded. See http://bugs.python.org/issue7833 for why
72951
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
689 # we want to avoid any manifest for extension modules if we can)
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
690 for arg in ld_args:
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
691 if arg.startswith("/MANIFESTFILE:"):
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
692 temp_manifest = arg.split(":", 1)[1]
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
693 break
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
694 else:
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
695 # no /MANIFESTFILE so nothing to do.
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
696 return None
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
697 if target_desc == CCompiler.EXECUTABLE:
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
698 # by default, executables always get the manifest with the
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
699 # CRT referenced.
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
700 mfid = 1
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
701 else:
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
702 # Extension modules try and avoid any manifest if possible.
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
703 mfid = 2
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
704 temp_manifest = self._remove_visual_c_ref(temp_manifest)
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
705 if temp_manifest is None:
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
706 return None
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
707 return temp_manifest, mfid
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
708
57882
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
709 def _remove_visual_c_ref(self, manifest_file):
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
710 try:
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
711 # Remove references to the Visual C runtime, so they will
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
712 # fall through to the Visual C dependency of Python.exe.
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
713 # This way, when installed for a restricted user (e.g.
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
714 # runtimes are not in WinSxS folder, but in Python's own
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
715 # folder), the runtimes do not need to be in every folder
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
716 # with .pyd's.
72951
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
717 # Returns either the filename of the modified manifest or
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
718 # None if no manifest should be embedded.
57882
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
719 manifest_f = open(manifest_file)
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
720 try:
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
721 manifest_buf = manifest_f.read()
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
722 finally:
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
723 manifest_f.close()
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
724 pattern = re.compile(
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
725 r"""<assemblyIdentity.*?name=("|')Microsoft\."""\
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
726 r"""VC\d{2}\.CRT("|').*?(/>|</assemblyIdentity>)""",
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
727 re.DOTALL)
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
728 manifest_buf = re.sub(pattern, "", manifest_buf)
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
729 pattern = "<dependentAssembly>\s*</dependentAssembly>"
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
730 manifest_buf = re.sub(pattern, "", manifest_buf)
72954
a27df4b88d67 normalize whitespace in Lib/distutils/msvc9compiler.py
Mark Hammond <mhammond@skippinet.com.au>
parents: 72951
diff changeset
731 # Now see if any other assemblies are referenced - if not, we
72951
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
732 # don't want a manifest embedded.
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
733 pattern = re.compile(
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
734 r"""<assemblyIdentity.*?name=(?:"|')(.+?)(?:"|')"""
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
735 r""".*?(?:/>|</assemblyIdentity>)""", re.DOTALL)
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
736 if re.search(pattern, manifest_buf) is None:
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
737 return None
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
738
57882
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
739 manifest_f = open(manifest_file, 'w')
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
740 try:
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
741 manifest_f.write(manifest_buf)
72951
fb886858024c Issue #7833: Ext. modules built using distutils on Windows no longer get a manifest
Mark Hammond <mhammond@skippinet.com.au>
parents: 68256
diff changeset
742 return manifest_file
57882
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
743 finally:
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
744 manifest_f.close()
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
745 except IOError:
30bedbc29763 backported r76993 and r76994 so the trunk behaves the same way with MSVC Manifest files editing
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
746 pass
11244
4385b1bcbc3b Added msvccompiler module exactly as supplied by Perry Stoll.
Greg Ward <gward@python.net>
parents:
diff changeset
747
11915
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
748 # -- Miscellaneous methods -----------------------------------------
7922d08426ca Serious overhaul of the C compiler interface and the two classes that
Greg Ward <gward@python.net>
parents: 11897
diff changeset
749 # 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
750 # ccompiler.py.
11360
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
751
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
752 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
753 return "/LIBPATH:" + dir
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
754
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
755 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
756 raise DistutilsPlatformError(
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
757 "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
758
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
759 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
760 return self.library_filename(lib)
11360
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
761
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
762
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 41347
diff changeset
763 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
764 # 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
765 # 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
766 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
767 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
768 else:
b37f08635023 Added 'debug' flag to 'find_library_file()', and changed code to handle it.
Greg Ward <gward@python.net>
parents: 13799
diff changeset
769 try_names = [lib]
11360
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
770 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
771 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
772 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
773 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
774 return libfile
11360
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
775 else:
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
776 # 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
777 return None
4c7d6043b43a Catch up with changes in 'gen_lib_options()':
Greg Ward <gward@python.net>
parents: 11337
diff changeset
778
29052
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
779 # 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
780
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
781 def find_exe(self, exe):
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
782 """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
783
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
784 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
785 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
786 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
787 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
788 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
789 """
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
790 for p in self.__paths:
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
791 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
792 if os.path.isfile(fn):
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
793 return fn
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
794
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
795 # 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
796 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
797 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
798 if os.path.isfile(fn):
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
799 return fn
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
800
143fff8d2189 Variant of SF patch 614770: MSVC 7 support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27564
diff changeset
801 return exe