17
17
CONFIG = "Release" # Release or Debug
18
18
DEVTOOLS = "MsDev" if sys .platform == "win32" else "Mono"
19
19
VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic
20
+ PLATFORM = "x64" if architecture ()[0 ] == "64bit" else "x86"
20
21
21
- def FindMsBuildPath ():
22
+
23
+ def _find_msbuild_path ():
24
+ """Return full path to msbuild.exe"""
22
25
import _winreg
23
26
24
- aReg = _winreg .ConnectRegistry (None ,_winreg .HKEY_LOCAL_MACHINE )
27
+ hreg = _winreg .ConnectRegistry (None , _winreg .HKEY_LOCAL_MACHINE )
25
28
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 :
29
37
try :
30
- aKey = _winreg .OpenKey (aReg , key )
38
+ hkey = _winreg .OpenKey (hreg , key )
31
39
break
32
40
except WindowsError :
33
41
pass
34
42
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" )
37
45
38
46
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" )
43
50
finally :
44
- aKey .Close ()
51
+ hkey .Close ()
45
52
finally :
46
- aReg .Close ()
53
+ hreg .Close ()
47
54
48
55
msbuildpath = os .path .join (val , "msbuild.exe" )
49
56
return msbuildpath
50
57
51
58
52
59
if DEVTOOLS == "MsDev" :
53
- _xbuild = "\" %s\" " % FindMsBuildPath ()
60
+ _xbuild = "\" %s\" " % _find_msbuild_path ()
54
61
_defines_sep = ";"
55
62
_config = "%sWin" % CONFIG
56
63
_npython_exe = "nPython.exe"
@@ -64,7 +71,6 @@ def FindMsBuildPath():
64
71
else :
65
72
raise NotImplementedError ("DevTools %s not supported (use MsDev or Mono)" % DEVTOOLS )
66
73
67
- _platform = "x64" if architecture ()[0 ] == "64bit" else "x86"
68
74
69
75
class PythonNET_BuildExt (build_ext ):
70
76
@@ -75,6 +81,9 @@ def build_extension(self, ext):
75
81
if ext .name != "clr" :
76
82
return build_ext .build_extension (self , ext )
77
83
84
+ # install packages using nuget
85
+ self ._install_packages ()
86
+
78
87
dest_file = self .get_ext_fullpath (ext .name )
79
88
dest_dir = os .path .dirname (dest_file )
80
89
if not os .path .exists (dest_dir ):
@@ -92,15 +101,16 @@ def build_extension(self, ext):
92
101
_xbuild ,
93
102
"pythonnet.sln" ,
94
103
"/p:Configuration=%s" % _config ,
95
- "/p:Platform=%s" % _platform ,
104
+ "/p:Platform=%s" % PLATFORM ,
96
105
"/p:DefineConstants=\" %s\" " % _defines_sep .join (defines ),
97
106
"/p:PythonBuildDir=%s" % os .path .abspath (dest_dir ),
98
107
"/verbosity:%s" % VERBOSITY ,
99
108
]
100
109
101
110
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 ))
111
+ use_shell = True if DEVTOOLS == "Mono" else False
112
+ check_call (" " .join (cmd + ["/t:Clean" ]), shell = use_shell )
113
+ check_call (" " .join (cmd + ["/t:Build" ]), shell = use_shell )
104
114
105
115
if DEVTOOLS == "Mono" :
106
116
self ._build_monoclr (ext )
@@ -157,6 +167,29 @@ def _build_monoclr(self, ext):
157
167
debug = self .debug )
158
168
159
169
170
+ def _install_packages (self ):
171
+ """install packages using nuget"""
172
+ nuget = os .path .join ("tools" , "nuget" , "nuget.exe" )
173
+ use_shell = False
174
+ if DEVTOOLS == "Mono" :
175
+ nuget = "mono %s" % nuget
176
+ use_shell = True
177
+
178
+ for dir in os .listdir ("src" ):
179
+ if DEVTOOLS == "Mono" and dir == "clrmodule" :
180
+ continue
181
+ if DEVTOOLS != "Mono" and dir == "monoclr" :
182
+ continue
183
+
184
+ packages_cfg = os .path .join ("src" , dir , "packages.config" )
185
+ if not os .path .exists (packages_cfg ):
186
+ continue
187
+
188
+ cmd = "%s install %s -o packages" % (nuget , packages_cfg )
189
+ self .announce ("Installng packages for %s: %s" % (dir , cmd ))
190
+ check_call (cmd , shell = use_shell )
191
+
192
+
160
193
class PythonNET_InstallLib (install_lib ):
161
194
162
195
def install (self ):
0 commit comments