]> git.lizzy.rs Git - rust.git/blob - x.ps1
Merge commit '4bdfb0741dbcecd5279a2635c3280726db0604b5' into clippyup
[rust.git] / x.ps1
1 #!/usr/bin/env pwsh
2
3 # See ./x for why these scripts exist.
4
5 $xpy = Join-Path $PSScriptRoot x.py
6 # Start-Process for some reason splits arguments on spaces. (Isn't powershell supposed to be simpler than bash?)
7 # Double-quote all the arguments so it doesn't do that.
8 $xpy_args = @("""$xpy""")
9 foreach ($arg in $args) {
10     $xpy_args += """$arg"""
11 }
12
13 function Get-Application($app) {
14     return Get-Command $app -ErrorAction SilentlyContinue -CommandType Application
15 }
16
17 foreach ($python in "py", "python3", "python", "python2") {
18     # NOTE: this only tests that the command exists in PATH, not that it's actually
19     # executable. The latter is not possible in a portable way, see
20     # https://github.com/PowerShell/PowerShell/issues/12625.
21     if (Get-Application $python) {
22         if ($python -eq "py") {
23             # Use python3, not python2
24             $xpy_args = @("-3") + $xpy_args
25         }
26         $process = Start-Process -NoNewWindow -Wait -PassThru $python $xpy_args
27         Exit $process.ExitCode
28     }
29 }
30
31 $found = (Get-Application "python*" | Where-Object {$_.name -match '^python[2-3]\.[0-9]+(\.exe)?$'})
32 if (($null -ne $found) -and ($found.Length -ge 1)) {
33     $python = $found[0]
34     $process = Start-Process -NoNewWindow -Wait -PassThru $python $xpy_args
35     Exit $process.ExitCode
36 }
37
38 Write-Error "${PSCommandPath}: error: did not find python installed"
39 Exit 1