Skip to content

Commit

Permalink
Have arg_parse perform the interpolations in rustc_action arguments
Browse files Browse the repository at this point in the history
Summary:
I just noticed there is a built-in way in the Python `argparse` library to do this. We don't need to parse the command line as `List[str]` and then manually replace the parsed list with one that has a function applied to each argument.

We already use a similar `type=key_value_arg` for flags like `--env`, where it's responsible for splitting `--env K=V` into a tuple `("K", "V")`.

https://www.internalfb.com/code/fbsource/[a6d422d969cd7e6615d6992fbcc52a772ab16954]/fbcode/buck2/prelude/rust/tools/rustc_action.py?lines=79-85

https://www.internalfb.com/code/fbsource/[a6d422d969cd7e6615d6992fbcc52a772ab16954]/fbcode/buck2/prelude/rust/tools/rustc_action.py?lines=44-48

Reviewed By: zertosh

Differential Revision: D58790340

fbshipit-source-id: 4f92d96d00fa60501bc34f418f54479e82937e76
  • Loading branch information
David Tolnay authored and facebook-github-bot committed Jun 19, 2024
1 parent e925605 commit 15feff9
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions prelude/rust/tools/rustc_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def arg_parse() -> Args:
parser.add_argument(
"rustc",
nargs=argparse.REMAINDER,
type=str,
type=arg_eval,
help="Compiler command line",
)

Expand Down Expand Up @@ -235,7 +235,6 @@ async def handle_output( # noqa: C901

async def main() -> int:
args = arg_parse()
args = args._replace(rustc=[arg_eval(arg) for arg in args.rustc])

if args.echo:
args.echo.write("".join(arg + "\n" for arg in args.rustc).encode("utf-8"))
Expand Down

0 comments on commit 15feff9

Please sign in to comment.