From 49c0b8dfd230b2fa478902e10e52cf7fb637ddc4 Mon Sep 17 00:00:00 2001 From: "Worker Pants (Pantsbuild GitHub Automation Bot)" <133242086+WorkerPants@users.noreply.github.com> Date: Thu, 3 Oct 2024 18:18:14 -0400 Subject: [PATCH] Support trailing global flags in the native parser. (Cherry-pick of #21480) (#21485) The legacy parser supports having global flags at the end of the command-line invocation, after all specs. Now the native parser supports this too. Fixes #21478 Co-authored-by: Benjy Weinberger --- src/rust/engine/options/src/args.rs | 3 +++ src/rust/engine/options/src/args_tests.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/rust/engine/options/src/args.rs b/src/rust/engine/options/src/args.rs index 7c3acbb0057..15192e4a9dc 100644 --- a/src/rust/engine/options/src/args.rs +++ b/src/rust/engine/options/src/args.rs @@ -130,6 +130,9 @@ impl Args { }); } else if is_valid_scope_name(&arg_str) { scope = Scope::Scope(arg_str) + } else { + // The arg is a spec, so revert to global context for any trailing flags. + scope = Scope::Global; } } diff --git a/src/rust/engine/options/src/args_tests.rs b/src/rust/engine/options/src/args_tests.rs index 992703c8bf7..b2fd70a5049 100644 --- a/src/rust/engine/options/src/args_tests.rs +++ b/src/rust/engine/options/src/args_tests.rs @@ -78,6 +78,8 @@ fn test_bool() { "scope", "--no-quuxf", "--quuxt", + "path/to/target", + "--global-flag", ]); let assert_bool = @@ -91,6 +93,7 @@ fn test_bool() { assert_bool(false, option_id!(["scope"], "quxf")); assert_bool(false, option_id!(["scope"], "quuxf")); assert_bool(true, option_id!(["scope"], "quuxt")); + assert_bool(true, option_id!("global", "flag")); assert!(args.get_bool(&option_id!("dne")).unwrap().is_none()); assert!(args.get_passthrough_args().is_none());