forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#99992 - jyn514:shell-scripts, r=Mark-Simula…
…crum Add `x.sh` and `x.ps1` shell scripts This is a more ambitious version of rust-lang#98716. It still changes the x.py shebang back to python3, for compatibility with non-Unix systems, but also adds alternative entrypoints for systems without `python3` installed. These scripts will be necessary for the rust entrypoint (rust-lang#94829), so I see little downside in adding them early. I'll update the dev-guide to suggest using these instead of x.py once this is merged. Fixes rust-lang#98650 r? `@Mark-Simulacrum` cc `@dtolnay` `@CAD97` `@yoshuawuyts`
- Loading branch information
Showing
6 changed files
with
94 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env pwsh | ||
|
||
# See x.sh for why these scripts exist. | ||
|
||
$xpy = Join-Path $PSScriptRoot x.py | ||
# Start-Process for some reason splits arguments on spaces. (Isn't powershell supposed to be simpler than bash?) | ||
# Double-quote all the arguments so it doesn't do that. | ||
$xpy_args = @("""$xpy""") | ||
foreach ($arg in $args) { | ||
$xpy_args += """$arg""" | ||
} | ||
|
||
foreach ($python in "py", "python3", "python", "python2") { | ||
# NOTE: this only tests that the command exists in PATH, not that it's actually | ||
# executable. The latter is not possible in a portable way, see | ||
# https://github.com/PowerShell/PowerShell/issues/12625. | ||
if (Get-Command $python -ErrorAction SilentlyContinue) { | ||
if ($python -eq "py") { | ||
# Use python3, not python2 | ||
$xpy_args = @("-3") + $xpy_args | ||
} | ||
$process = Start-Process -NoNewWindow -Wait -PassThru $python $xpy_args | ||
Exit $process.ExitCode | ||
} | ||
} | ||
|
||
Write-Error "${PSCommandPath}: error: did not find python installed" | ||
Exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/sh | ||
|
||
# Modern Linux and macOS systems commonly only have a thing called `python3` and | ||
# not `python`, while Windows commonly does not have `python3`, so we cannot | ||
# directly use python in the x.py shebang and have it consistently work. Instead we | ||
# have a shell script to look for a python to run x.py. | ||
|
||
set -eu | ||
|
||
realpath() { | ||
if [ -d "$1" ]; then | ||
CDPATH='' command cd "$1" && pwd -P | ||
else | ||
echo "$(realpath "$(dirname "$1")")/$(basename "$1")" | ||
fi | ||
} | ||
|
||
xpy=$(dirname "$(realpath "$0")")/x.py | ||
|
||
# On Windows, `py -3` sometimes works. We need to try it first because `python3` | ||
# sometimes tries to launch the app store on Windows. | ||
for SEARCH_PYTHON in py python3 python python2; do | ||
if python=$(command -v $SEARCH_PYTHON) && [ -x "$python" ]; then | ||
if [ $SEARCH_PYTHON = py ]; then | ||
extra_arg="-3" | ||
else | ||
extra_arg="" | ||
fi | ||
exec "$python" $extra_arg "$xpy" "$@" | ||
fi | ||
done | ||
echo "$0: error: did not find python installed" >&2 | ||
exit 1 |