1919except ImportError :
2020 lzma = None
2121
22- if sys .platform == 'win32' :
22+ def platform_is_win32 ():
23+ return sys .platform == 'win32'
24+
25+ if platform_is_win32 ():
2326 EXE_SUFFIX = ".exe"
2427else :
2528 EXE_SUFFIX = ""
@@ -78,15 +81,14 @@ def _download(path, url, probably_big, verbose, exception):
7881 if probably_big or verbose :
7982 print ("downloading {}" .format (url ))
8083
81- platform_is_win32 = sys .platform == 'win32'
8284 try :
8385 if probably_big or verbose :
8486 option = "-#"
8587 else :
8688 option = "-s"
8789 # If curl is not present on Win32, we should not sys.exit
8890 # but raise `CalledProcessError` or `OSError` instead
89- require (["curl" , "--version" ], exception = platform_is_win32 )
91+ require (["curl" , "--version" ], exception = platform_is_win32 () )
9092 with open (path , "wb" ) as outfile :
9193 run (["curl" , option ,
9294 "-L" , # Follow redirect.
@@ -99,8 +101,8 @@ def _download(path, url, probably_big, verbose, exception):
99101 )
100102 except (subprocess .CalledProcessError , OSError , RuntimeError ):
101103 # 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 ([
104106 "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;" ,
105107 "(New-Object System.Net.WebClient).DownloadFile('{}', '{}')" .format (url , path )],
106108 verbose = verbose ,
@@ -174,6 +176,10 @@ def run(args, verbose=False, exception=False, is_bootstrap=False, **kwargs):
174176 else :
175177 sys .exit (err )
176178
179+ def run_powershell (script , * args , ** kwargs ):
180+ """Run a powershell script"""
181+ run (["PowerShell.exe" , "/nologo" , "-Command" ] + script , * args , ** kwargs )
182+
177183
178184def require (cmd , exit = True , exception = False ):
179185 '''Run a command, returning its output.
@@ -229,7 +235,7 @@ def default_build_triple(verbose):
229235 print ("pre-installed rustc not detected: {}" .format (e ))
230236 print ("falling back to auto-detect" )
231237
232- required = sys . platform != 'win32'
238+ required = not platform_is_win32 ()
233239 ostype = require (["uname" , "-s" ], exit = required )
234240 cputype = require (['uname' , '-m' ], exit = required )
235241
@@ -434,6 +440,23 @@ def download_toolchain(self):
434440 (not os .path .exists (self .rustc ()) or
435441 self .program_out_of_date (self .rustc_stamp (), key )):
436442 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 ])
437460 shutil .rmtree (bin_root )
438461 tarball_suffix = '.tar.gz' if lzma is None else '.tar.xz'
439462 filename = "rust-std-{}-{}{}" .format (
0 commit comments