-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add x.sh
and x.ps1
shell scripts
#99992
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
jyn514 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
$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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, could we not simply try running the command? If
Start-Process
fails then we could simply move on to the next.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does PowerShell distinguish "failed to start process" from "process ended with an error code"? The latter isn't correct because x.py will exit with an error if the build fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... I think it should throw an exception if the process failed to start. Which can then be caught and ignored. I would need to investigate more tho. Maybe something for a follow up PR?