summary refs log tree commit diff
path: root/x.ps1
diff options
context:
space:
mode:
authorjyn <github@jyn.dev>2023-06-24 13:09:48 -0500
committerjyn <github@jyn.dev>2023-06-24 14:44:53 -0500
commitfa7e965bf0af41ddd5865ee63782d3536263f964 (patch)
tree2aa56be4334601e20a767982ea1fe5b56fcf93dd /x.ps1
parentdd314f6533c94125d08220b1ba188c6cf68226c7 (diff)
downloadrust-fa7e965bf0af41ddd5865ee63782d3536263f964.tar.gz
rust-fa7e965bf0af41ddd5865ee63782d3536263f964.zip
Give a better error on Windows if python isn't installed
Before:

```
PS C:\Users\vboxuser\rust> ./x
x.ps1

PS C:\Users\vboxuser\rust>
```

After:
```
PS C:\Users\vboxuser\rust> ./x
x.ps1

C:\Users\vboxuser\rust\x.ps1 : C:\Users\vboxuser\rust\x.ps1: error: did not find python installed
help: consider installing it from https://www.python.org/downloads/windows/
At line:1 char:1
+ ./x
+ ~~~
    + CategoryInfo          : NotInstalled: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,x.ps1
```

The existing message from the shell script is already decent and I decided not to change it:
```
$ ./x
Python was not found but can be installed from the Microsoft Store: ms-windows-store://pdp/?productid=9NJ46SX7X90P
```
Diffstat (limited to 'x.ps1')
-rwxr-xr-xx.ps112
1 files changed, 10 insertions, 2 deletions
diff --git a/x.ps1 b/x.ps1
index a156017628d..b036653e5b4 100755
--- a/x.ps1
+++ b/x.ps1
@@ -16,7 +16,13 @@ foreach ($arg in $args) {
 }
 
 function Get-Application($app) {
-    return Get-Command $app -ErrorAction SilentlyContinue -CommandType Application
+    $cmd = Get-Command $app -ErrorAction SilentlyContinue -CommandType Application | Select-Object -First 1
+    if ($cmd.source -match '.*AppData\\Local\\Microsoft\\WindowsApps\\.*exe') {
+        # Windows for some reason puts a `python3.exe` executable in PATH that just opens the windows store.
+        # Ignore it.
+        return $false
+    }
+    return $cmd
 }
 
 function Invoke-Application($application, $arguments) {
@@ -51,5 +57,7 @@ if (($null -ne $found) -and ($found.Length -ge 1)) {
     Invoke-Application $python $xpy_args
 }
 
-Write-Error "${PSCommandPath}: error: did not find python installed"
+$msg = "${PSCommandPath}: error: did not find python installed`n"
+$msg += "help: consider installing it from https://www.python.org/downloads/"
+Write-Error $msg -Category NotInstalled
 Exit 1