MCPcopy Index your code
hub / github.com/python/cpython / MacroExpander

Class MacroExpander

Tools/c-analyzer/distutils/msvc9compiler.py:119–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117 convert_mbcs = staticmethod(convert_mbcs)
118
119class MacroExpander:
120
121 def __init__(self, version):
122 self.macros = {}
123 self.vsbase = VS_BASE % version
124 self.load_macros(version)
125
126 def set_macro(self, macro, path, key):
127 self.macros["$(%s)" % macro] = Reg.get_value(path, key)
128
129 def load_macros(self, version):
130 self.set_macro("VCInstallDir", self.vsbase + r"\Setup\VC", "productdir")
131 self.set_macro("VSInstallDir", self.vsbase + r"\Setup\VS", "productdir")
132 self.set_macro("FrameworkDir", NET_BASE, "installroot")
133 try:
134 if version >= 8.0:
135 self.set_macro("FrameworkSDKDir", NET_BASE,
136 "sdkinstallrootv2.0")
137 else:
138 raise KeyError("sdkinstallrootv2.0")
139 except KeyError:
140 raise DistutilsPlatformError(
141 """Python was built with Visual Studio 2008;
142extensions must be built with a compiler than can generate compatible binaries.
143Visual Studio 2008 was not found on this system. If you have Cygwin installed,
144you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""")
145
146 if version >= 9.0:
147 self.set_macro("FrameworkVersion", self.vsbase, "clr version")
148 self.set_macro("WindowsSdkDir", WINSDK_BASE, "currentinstallfolder")
149 else:
150 p = r"Software\Microsoft\NET Framework Setup\Product"
151 for base in HKEYS:
152 try:
153 h = RegOpenKeyEx(base, p)
154 except RegError:
155 continue
156 key = RegEnumKey(h, 0)
157 d = Reg.get_value(base, r"%s\%s" % (p, key))
158 self.macros["$(FrameworkVersion)"] = d["version"]
159
160 def sub(self, s):
161 for k, v in self.macros.items():
162 s = s.replace(k, v)
163 return s
164
165def get_build_version():
166 """Return the version of MSVC that was used to build Python.

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…