19
19
except ImportError :
20
20
lzma = None
21
21
22
- if sys .platform == 'win32' :
22
+ def platform_is_win32 ():
23
+ return sys .platform == 'win32'
24
+
25
+ if platform_is_win32 ():
23
26
EXE_SUFFIX = ".exe"
24
27
else :
25
28
EXE_SUFFIX = ""
@@ -78,15 +81,14 @@ def _download(path, url, probably_big, verbose, exception):
78
81
if probably_big or verbose :
79
82
print ("downloading {}" .format (url ))
80
83
81
- platform_is_win32 = sys .platform == 'win32'
82
84
try :
83
85
if probably_big or verbose :
84
86
option = "-#"
85
87
else :
86
88
option = "-s"
87
89
# If curl is not present on Win32, we should not sys.exit
88
90
# but raise `CalledProcessError` or `OSError` instead
89
- require (["curl" , "--version" ], exception = platform_is_win32 )
91
+ require (["curl" , "--version" ], exception = platform_is_win32 () )
90
92
with open (path , "wb" ) as outfile :
91
93
run (["curl" , option ,
92
94
"-L" , # Follow redirect.
@@ -99,8 +101,8 @@ def _download(path, url, probably_big, verbose, exception):
99
101
)
100
102
except (subprocess .CalledProcessError , OSError , RuntimeError ):
101
103
# see http://serverfault.com/questions/301128/how-to-download
102
- if platform_is_win32 :
103
- run ([ "PowerShell.exe" , "/nologo" , "-Command" ,
104
+ if platform_is_win32 () :
105
+ run_powershell ([
104
106
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;" ,
105
107
"(New-Object System.Net.WebClient).DownloadFile('{}', '{}')" .format (url , path )],
106
108
verbose = verbose ,
@@ -174,6 +176,10 @@ def run(args, verbose=False, exception=False, is_bootstrap=False, **kwargs):
174
176
else :
175
177
sys .exit (err )
176
178
179
+ def run_powershell (script , * args , ** kwargs ):
180
+ """Run a powershell script"""
181
+ run (["PowerShell.exe" , "/nologo" , "-Command" ] + script , * args , ** kwargs )
182
+
177
183
178
184
def require (cmd , exit = True , exception = False ):
179
185
'''Run a command, returning its output.
@@ -229,7 +235,7 @@ def default_build_triple(verbose):
229
235
print ("pre-installed rustc not detected: {}" .format (e ))
230
236
print ("falling back to auto-detect" )
231
237
232
- required = sys . platform != 'win32'
238
+ required = not platform_is_win32 ()
233
239
ostype = require (["uname" , "-s" ], exit = required )
234
240
cputype = require (['uname' , '-m' ], exit = required )
235
241
@@ -434,6 +440,23 @@ def download_toolchain(self):
434
440
(not os .path .exists (self .rustc ()) or
435
441
self .program_out_of_date (self .rustc_stamp (), key )):
436
442
if os .path .exists (bin_root ):
443
+ # HACK: On Windows, we can't delete rust-analyzer-proc-macro-server while it's
444
+ # running. Kill it.
445
+ if platform_is_win32 ():
446
+ print ("Killing rust-analyzer-proc-macro-srv before deleting stage0 toolchain" )
447
+ regex = '{}\\ \\ (host|{})\\ \\ stage0\\ \\ libexec' .format (
448
+ os .path .basename (self .build_dir ),
449
+ self .build
450
+ )
451
+ script = (
452
+ # NOTE: can't use `taskkill` or `Get-Process -Name` because they error if
453
+ # the server isn't running.
454
+ 'Get-Process | ' +
455
+ 'Where-Object {$_.Name -eq "rust-analyzer-proc-macro-srv"} |' +
456
+ 'Where-Object {{$_.Path -match "{}"}} |' .format (regex ) +
457
+ 'Stop-Process'
458
+ )
459
+ run_powershell ([script ])
437
460
shutil .rmtree (bin_root )
438
461
tarball_suffix = '.tar.gz' if lzma is None else '.tar.xz'
439
462
filename = "rust-std-{}-{}{}" .format (
0 commit comments