1717CONFIG = "Release" # Release or Debug
1818DEVTOOLS = "MsDev" if sys .platform == "win32" else "Mono"
1919VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic
20+ PLATFORM = "x64" if architecture ()[0 ] == "64bit" else "x86"
2021
21- def FindMsBuildPath ():
22+
23+ def _find_msbuild_path ():
24+ """Return full path to msbuild.exe"""
2225 import _winreg
2326
24- aReg = _winreg .ConnectRegistry (None ,_winreg .HKEY_LOCAL_MACHINE )
27+ hreg = _winreg .ConnectRegistry (None , _winreg .HKEY_LOCAL_MACHINE )
2528 try :
26- keysToCheck = [r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\12.0" , r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0" , r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\3.5" , r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\2.0" ]
27- aKey = None
28- for key in keysToCheck :
29+ keys_to_check = [
30+ r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\12.0" ,
31+ r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0" ,
32+ r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\3.5" ,
33+ r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\2.0"
34+ ]
35+ hkey = None
36+ for key in keys_to_check :
2937 try :
30- aKey = _winreg .OpenKey (aReg , key )
38+ hkey = _winreg .OpenKey (hreg , key )
3139 break
3240 except WindowsError :
3341 pass
3442
35- if aKey == None :
36- raise RuntimeError ("MSBUILD .exe could not be found" )
43+ if hkey is None :
44+ raise RuntimeError ("msbuild .exe could not be found" )
3745
3846 try :
39- val , type = _winreg .QueryValueEx (aKey , "MSBuildToolsPath" )
40-
41- if type != _winreg .REG_SZ :
42- raise RuntimeError ("MSBUILD.exe could not be found" )
47+ val , type_ = _winreg .QueryValueEx (hkey , "MSBuildToolsPath" )
48+ if type_ != _winreg .REG_SZ :
49+ raise RuntimeError ("msbuild.exe could not be found" )
4350 finally :
44- aKey .Close ()
51+ hkey .Close ()
4552 finally :
46- aReg .Close ()
53+ hreg .Close ()
4754
4855 msbuildpath = os .path .join (val , "msbuild.exe" )
4956 return msbuildpath
5057
5158
5259if DEVTOOLS == "MsDev" :
53- _xbuild = "\" %s\" " % FindMsBuildPath ()
60+ _xbuild = "\" %s\" " % _find_msbuild_path ()
5461 _defines_sep = ";"
5562 _config = "%sWin" % CONFIG
5663 _npython_exe = "nPython.exe"
@@ -64,7 +71,6 @@ def FindMsBuildPath():
6471else :
6572 raise NotImplementedError ("DevTools %s not supported (use MsDev or Mono)" % DEVTOOLS )
6673
67- _platform = "x64" if architecture ()[0 ] == "64bit" else "x86"
6874
6975class PythonNET_BuildExt (build_ext ):
7076
@@ -92,15 +98,16 @@ def build_extension(self, ext):
9298 _xbuild ,
9399 "pythonnet.sln" ,
94100 "/p:Configuration=%s" % _config ,
95- "/p:Platform=%s" % _platform ,
101+ "/p:Platform=%s" % PLATFORM ,
96102 "/p:DefineConstants=\" %s\" " % _defines_sep .join (defines ),
97103 "/p:PythonBuildDir=%s" % os .path .abspath (dest_dir ),
98104 "/verbosity:%s" % VERBOSITY ,
99105 ]
100106
101107 self .announce ("Building: %s" % " " .join (cmd ))
102- check_call (" " .join (cmd + ["/t:Clean" ]), shell = (True if DEVTOOLS == "Mono" else False ))
103- check_call (" " .join (cmd + ["/t:Build" ]), shell = (True if DEVTOOLS == "Mono" else False ))
108+ use_shell = True if DEVTOOLS == "Mono" else False
109+ check_call (" " .join (cmd + ["/t:Clean" ]), shell = use_shell )
110+ check_call (" " .join (cmd + ["/t:Build" ]), shell = use_shell )
104111
105112 if DEVTOOLS == "Mono" :
106113 self ._build_monoclr (ext )
0 commit comments