-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[codex] Make justfile recipes Windows-aware #24983
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
Merged
+134
−16
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8f4cc03
Make justfile recipes Windows-aware
iceweasel-oai d5a70cf
Address Windows justfile review feedback
iceweasel-oai 5810eed
Format SDK justfile test update
iceweasel-oai 24c4114
Format SDK justfile test
iceweasel-oai 101855e
Require pwsh for Windows just recipes
iceweasel-oai c28620a
Use cross-platform just shell adapter
iceweasel-oai d6ce694
Simplify just shell adapter lookup
iceweasel-oai 65a0210
Unify bazel lock update recipe
iceweasel-oai 957aca2
Unify argument comment lint source recipe
iceweasel-oai fce27d4
Unify fmt just recipe
iceweasel-oai 1ed627c
Fix justfile CI checks
iceweasel-oai 9c9e305
Exec Unix just shell adapter
iceweasel-oai 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 hidden or 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 hidden or 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,72 @@ | ||
| #!/usr/bin/env python3 | ||
| """Cross-platform shell launcher for `just` recipes. | ||
|
|
||
| This keeps recipe bodies as normal shell snippets while giving the justfile one | ||
| portable placeholder, `{args}`, for forwarding variadic recipe arguments. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import shutil | ||
| import subprocess | ||
| import sys | ||
|
|
||
|
|
||
| ARGS_TOKEN = "{args}" | ||
| STDERR_NULL_TOKEN = "{stderr-null}" | ||
| POWERSHELL_ARGS = "@($args | Select-Object -Skip 1)" | ||
| POWERSHELL_STDERR_NULL = '2>$null; exit $LASTEXITCODE' | ||
| SH_ARGS = '"$@"' | ||
| SH_STDERR_NULL = "2>/dev/null" | ||
|
|
||
|
|
||
| def main() -> int: | ||
| if len(sys.argv) < 2: | ||
| print("just shell adapter expected a recipe command.", file=sys.stderr) | ||
| return 1 | ||
|
|
||
| command = sys.argv[1] | ||
| recipe_name = sys.argv[2] if len(sys.argv) > 2 else "" | ||
| recipe_args = sys.argv[3:] | ||
|
|
||
| if os.name == "nt": | ||
| return run_powershell(command, recipe_name, recipe_args) | ||
| else: | ||
| return run_sh(command, recipe_name, recipe_args) | ||
|
|
||
|
|
||
| def run_sh(command: str, recipe_name: str, recipe_args: list[str]) -> int: | ||
| command = command.replace(ARGS_TOKEN, SH_ARGS) | ||
| command = command.replace(STDERR_NULL_TOKEN, SH_STDERR_NULL) | ||
| os.execvp("sh", ["sh", "-cu", command, recipe_name, *recipe_args]) | ||
|
|
||
|
|
||
| def run_powershell(command: str, recipe_name: str, recipe_args: list[str]) -> int: | ||
| pwsh = shutil.which("pwsh.exe") or shutil.which("pwsh") | ||
| if pwsh is None: | ||
| print( | ||
| "PowerShell ('pwsh') is required for Windows just recipes. " | ||
| "Run 'just install' to install it.", | ||
| file=sys.stderr, | ||
| ) | ||
| return 1 | ||
|
|
||
| command = command.replace(ARGS_TOKEN, POWERSHELL_ARGS) | ||
| command = command.replace(STDERR_NULL_TOKEN, POWERSHELL_STDERR_NULL) | ||
| return subprocess.run( | ||
| [ | ||
| pwsh, | ||
| "-NoLogo", | ||
| "-NoProfile", | ||
| "-CommandWithArgs", | ||
| command, | ||
| recipe_name, | ||
| *recipe_args, | ||
| ], | ||
| check=False, | ||
| ).returncode | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) |
This file contains hidden or 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
Oops, something went wrong.
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.
Can be done in a follow-up, but maybe this should be a platform-independent Python script?
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.
agreed - will look at that as a follow-up.