14
14
import sys
15
15
import sysconfig
16
16
from distutils import spawn
17
- from distutils .command import build_ext , install_data , install_lib
17
+ from distutils .command import install , build , build_ext , install_data , install_lib
18
18
19
19
from setuptools import Extension , setup
20
20
@@ -131,6 +131,12 @@ def _get_long_description():
131
131
except ImportError :
132
132
return '.Net and Mono integration for Python'
133
133
134
+ def _update_xlat_devtools ():
135
+ global DEVTOOLS
136
+ if DEVTOOLS == "MsDev" :
137
+ DEVTOOLS = "MsDev15"
138
+ elif DEVTOOLS == "Mono" :
139
+ DEVTOOLS = "dotnet"
134
140
135
141
class BuildExtPythonnet (build_ext .build_ext ):
136
142
user_options = build_ext .build_ext .user_options + [
@@ -144,6 +150,9 @@ def finalize_options(self):
144
150
build_ext .build_ext .finalize_options (self )
145
151
146
152
def build_extension (self , ext ):
153
+ if self .xplat :
154
+ _update_xlat_devtools ()
155
+
147
156
"""Builds the .pyd file using msbuild or xbuild"""
148
157
if ext .name != "clr" :
149
158
return build_ext .build_ext .build_extension (self , ext )
@@ -174,7 +183,7 @@ def build_extension(self, ext):
174
183
if CONFIG == "Debug" :
175
184
defines .extend (["DEBUG" , "TRACE" ])
176
185
177
- if sys .platform != "win32" and DEVTOOLS == "Mono" :
186
+ if sys .platform != "win32" and ( DEVTOOLS == "Mono" or DEVTOOLS == "dotnet" ) :
178
187
on_darwin = sys .platform == "darwin"
179
188
defines .append ("MONO_OSX" if on_darwin else "MONO_LINUX" )
180
189
@@ -206,20 +215,34 @@ def build_extension(self, ext):
206
215
if DEVTOOLS == "MsDev" :
207
216
_xbuild = '"{0}"' .format (self ._find_msbuild_tool ("msbuild.exe" ))
208
217
_config = "{0}Win" .format (CONFIG )
209
-
218
+ _solution_file = 'pythonnet.sln'
219
+ _custom_define_constants = False
220
+ elif DEVTOOLS == "MsDev15" :
221
+ # Improve this with self._find_msbuild_tool_15 to find good >15.3 msbuild, currently only works under VS 15.3 developer environment.
222
+ _xbuild = '"{0}"' .format (self ._find_msbuild_tool ("msbuild.exe" ))
223
+ _config = "{0}Win" .format (CONFIG )
224
+ _solution_file = 'pythonnet.15.sln'
225
+ _custom_define_constants = True
210
226
elif DEVTOOLS == "Mono" :
211
- _xbuild = 'dotnet msbuild' if self . xplat else ' xbuild'
227
+ _xbuild = 'xbuild'
212
228
_config = "{0}Mono" .format (CONFIG )
229
+ _solution_file = 'pythonnet.sln'
230
+ _custom_define_constants = False
231
+ elif DEVTOOLS == "dotnet" :
232
+ _xbuild = 'dotnet msbuild'
233
+ _config = "{0}Mono" .format (CONFIG )
234
+ _solution_file = 'pythonnet.15.sln'
235
+ _custom_define_constants = True
213
236
else :
214
237
raise NotImplementedError (
215
- "DevTool {0} not supported (use MsDev/Mono)" .format (DEVTOOLS ))
238
+ "DevTool {0} not supported (use MsDev/MsDev15/ Mono/dotnet )" .format (DEVTOOLS ))
216
239
217
240
cmd = [
218
241
_xbuild ,
219
- 'pythonnet.15.sln' if self . xplat else 'pythonnet.sln' ,
242
+ _solution_file ,
220
243
'/p:Configuration={}' .format (_config ),
221
244
'/p:Platform={}' .format (ARCH ),
222
- '/p:{}DefineConstants="{}"' .format ('Custom' if self . xplat else '' ,'%3B' .join (defines )),
245
+ '/p:{}DefineConstants="{}"' .format ('Custom' if _custom_define_constants else '' ,'%3B' .join (defines )),
223
246
'/p:PythonBuildDir="{}"' .format (os .path .abspath (dest_dir )),
224
247
'/p:PythonInteropFile="{}"' .format (os .path .basename (interop_file )),
225
248
'/verbosity:{}' .format (VERBOSITY ),
@@ -230,16 +253,16 @@ def build_extension(self, ext):
230
253
cmd .append ('/p:PythonManifest="{0}"' .format (manifest ))
231
254
232
255
self .debug_print ("Building: {0}" .format (" " .join (cmd )))
233
- use_shell = True if DEVTOOLS == "Mono" else False
256
+ use_shell = True if DEVTOOLS == "Mono" or DEVTOOLS == "dotnet" else False
234
257
235
258
subprocess .check_call (" " .join (cmd + ["/t:Clean" ]), shell = use_shell )
236
259
subprocess .check_call (" " .join (cmd + ["/t:Build" ]), shell = use_shell )
237
260
238
- if DEVTOOLS == "Mono" :
261
+ if DEVTOOLS == "Mono" or DEVTOOLS == "dotnet" :
239
262
self ._build_monoclr ()
240
263
241
264
def _get_manifest (self , build_dir ):
242
- if DEVTOOLS != "MsDev" :
265
+ if DEVTOOLS != "MsDev" and DEVTOOLS != "MsDev15" :
243
266
return
244
267
mt = self ._find_msbuild_tool ("mt.exe" , use_windows_sdk = True )
245
268
manifest = os .path .abspath (os .path .join (build_dir , "app.manifest" ))
@@ -272,33 +295,30 @@ def _build_monoclr(self):
272
295
273
296
def _install_packages (self ):
274
297
"""install packages using nuget"""
275
- nuget = os .path .join ("tools" , "nuget" , "nuget.exe" )
276
- use_shell = False
277
- if DEVTOOLS == "Mono" :
278
- nuget = "mono {0}" .format (nuget )
279
- use_shell = True
298
+ use_shell = DEVTOOLS == "Mono" or DEVTOOLS == "dotnet"
280
299
281
- if self . xplat :
282
- if DEVTOOLS == "MsDev " :
300
+ if DEVTOOLS == "MsDev15" or DEVTOOLS == "dotnet" :
301
+ if DEVTOOLS == "MsDev15 " :
283
302
_config = "{0}Win" .format (CONFIG )
284
- elif DEVTOOLS == "Mono " :
303
+ elif DEVTOOLS == "dotnet " :
285
304
_config = "{0}Mono" .format (CONFIG )
286
- else :
287
- raise NotImplementedError (
288
- "DevTool {0} not supported (use MsDev/Mono)" .format (DEVTOOLS ))
289
305
290
306
cmd = "dotnet msbuild /t:Restore pythonnet.15.sln /p:Configuration={0} /p:Platform={1}" .format (_config , ARCH )
291
307
self .debug_print ("Updating packages with xplat: {0}" .format (cmd ))
292
308
subprocess .check_call (cmd , shell = use_shell )
293
- return ;
309
+ else :
310
+ nuget = os .path .join ("tools" , "nuget" , "nuget.exe" )
294
311
295
- cmd = "{0} update -self" .format (nuget )
296
- self .debug_print ("Updating NuGet: {0}" .format (cmd ))
297
- subprocess .check_call (cmd , shell = use_shell )
312
+ if DEVTOOLS == "Mono" :
313
+ nuget = "mono {0}" .format (nuget )
298
314
299
- cmd = "{0} restore pythonnet.sln -o packages" .format (nuget )
300
- self .debug_print ("Installing packages: {0}" .format (cmd ))
301
- subprocess .check_call (cmd , shell = use_shell )
315
+ cmd = "{0} update -self" .format (nuget )
316
+ self .debug_print ("Updating NuGet: {0}" .format (cmd ))
317
+ subprocess .check_call (cmd , shell = use_shell )
318
+
319
+ cmd = "{0} restore pythonnet.sln -o packages" .format (nuget )
320
+ self .debug_print ("Installing packages: {0}" .format (cmd ))
321
+ subprocess .check_call (cmd , shell = use_shell )
302
322
303
323
def _find_msbuild_tool (self , tool = "msbuild.exe" , use_windows_sdk = False ):
304
324
"""Return full path to one of the Microsoft build tools"""
@@ -381,6 +401,21 @@ def run(self):
381
401
382
402
return install_data .install_data .run (self )
383
403
404
+ class InstallPythonnet (install .install ):
405
+ user_options = install .install .user_options + [
406
+ ('xplat' , None , None )
407
+ ]
408
+ def initialize_options (self ):
409
+ install .install .initialize_options (self )
410
+ self .xplat = None
411
+
412
+ def finalize_options (self ):
413
+ install .install .finalize_options (self )
414
+
415
+ def run (self ):
416
+ if self .xplat :
417
+ _update_xlat_devtools ()
418
+ return install .install .run (self )
384
419
385
420
###############################################################################
386
421
setupdir = os .path .dirname (__file__ )
@@ -410,6 +445,7 @@ def run(self):
410
445
]),
411
446
],
412
447
cmdclass = {
448
+ "install" : InstallPythonnet ,
413
449
"build_ext" : BuildExtPythonnet ,
414
450
"install_lib" : InstallLibPythonnet ,
415
451
"install_data" : InstallDataPythonnet ,
0 commit comments