From 4d574928404920d19b4a58697a1cf69da8beb3f0 Mon Sep 17 00:00:00 2001 From: gold-silver-copper <157451540+gold-silver-copper@users.noreply.github.com> Date: Sun, 25 Oct 2026 04:34:53 -0700 Subject: [PATCH 1/4] fix: plan cargo as argv; filters name whole paths Implements [[tasks/harmony-2756]] --- Cargo.toml | 1 - src/lib.rs | 57 +++++++++++++++++++++--------------------------------- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cfca9d7..2817894 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ path = "src/lib.rs" [dependencies] meta_plugin_protocol = { path = "../meta_plugin_protocol" } -shlex = "1" colored = "2" indexmap = "2" diff --git a/src/lib.rs b/src/lib.rs index 30aca61..af1527f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,11 +23,6 @@ pub fn execute_command( return CommandResult::ShowHelp(None); } - let cmd = match command_line(args) { - Ok(cmd) => cmd, - Err(e) => return CommandResult::Error(format!("Cannot quote cargo arguments: {e}")), - }; - let dirs: Vec = if projects.is_empty() { vec![".".to_string()] } else { @@ -35,7 +30,7 @@ pub fn execute_command( }; // Notes name repos by their path from the meta root, which meta_cli lists first. let root = cwd.join(dirs.first().map_or(".", String::as_str)); - let (rust_dirs, other_dirs): (Vec, Vec) = filter_dirs(dirs, options) + let (rust_dirs, other_dirs): (Vec, Vec) = filter_dirs(dirs, &root, options) .into_iter() .partition(|dir| cwd.join(dir).join("Cargo.toml").is_file()); @@ -52,39 +47,24 @@ pub fn execute_command( .into_iter() .map(|dir| PlannedCommand { dir, - cmd: cmd.clone(), + argv: std::iter::once("cargo".to_string()) + .chain(args.iter().cloned()) + .collect(), env: None, }) .collect(); CommandResult::Plan(commands, Some(options.parallel)) } -/// `cargo ` quoted for the `$SHELL -c` that loop_lib runs plans with. -#[cfg(not(windows))] -fn command_line(args: &[String]) -> Result { - shlex::try_join(std::iter::once("cargo").chain(args.iter().map(String::as_str))) - .map_err(|e| e.to_string()) -} - -/// loop_lib runs plans with `cmd.exe /c`, which has no POSIX quoting, so the -/// args are joined as given. -#[cfg(windows)] -fn command_line(args: &[String]) -> Result { - Ok(format!("cargo {}", args.join(" "))) -} - -/// Keep the dirs loop_lib will run in (its substring match), so the skip note -/// names only selected repos. -fn filter_dirs(mut dirs: Vec, options: &PluginRequestOptions) -> Vec { +/// Keep the dirs loop_lib will run in, so the skip note names only selected +/// repos. meta_cli sends the filters as whole paths from the root. +fn filter_dirs(mut dirs: Vec, root: &Path, options: &PluginRequestOptions) -> Vec { + let named = |filters: &[String], dir: &str| filters.iter().any(|f| *f == display(dir, root)); if let Some(includes) = options.include_filters.as_ref().filter(|f| !f.is_empty()) { - dirs.retain(|dir| includes.iter().any(|f| dir.contains(f.as_str()))); + dirs.retain(|dir| named(includes, dir)); } if let Some(excludes) = &options.exclude_filters { - dirs.retain(|dir| { - !excludes - .iter() - .any(|f| dir.contains(f.trim_end_matches('/'))) - }); + dirs.retain(|dir| !named(excludes, dir)); } dirs } @@ -92,7 +72,11 @@ fn filter_dirs(mut dirs: Vec, options: &PluginRequestOptions) -> Vec String { match root.join(dir).strip_prefix(root) { Ok(rel) if rel.as_os_str().is_empty() => ".".to_string(), - Ok(rel) => rel.display().to_string(), + Ok(rel) => rel + .components() + .map(|c| c.as_os_str().to_string_lossy()) + .collect::>() + .join("/"), Err(_) => dir.to_string(), } } @@ -114,7 +98,7 @@ mod tests { match execute_command(&args, options, &projects, Path::new(".")) { CommandResult::Plan(commands, _) => commands .into_iter() - .map(|c| format!("{}: {}", c.dir, c.cmd)) + .map(|c| format!("{}: {:?}", c.dir, c.argv)) .collect(), _ => panic!("Expected Plan result"), } @@ -134,8 +118,11 @@ mod tests { let args = ["fmt", "--check", "--", "--config", "a b"]; let commands = plan(&args, &[root, &rust, &docs], &Default::default()); - let quoted = if cfg!(windows) { "a b" } else { "'a b'" }; - let expected = format!("{}: cargo fmt --check -- --config {quoted}", rust.display()); + let expected = format!( + "{}: {:?}", + rust.display(), + ["cargo", "fmt", "--check", "--", "--config", "a b"] + ); assert_eq!(commands, [expected]); } @@ -153,7 +140,7 @@ mod tests { }; let filtered = plan(&["run"], &[root, &member], &only_member); - let run_in = |dir: &Path| format!("{}: cargo run", dir.display()); + let run_in = |dir: &Path| format!("{}: {:?}", dir.display(), ["cargo", "run"]); assert_eq!(all, [run_in(root), run_in(&member)]); assert_eq!(filtered, [run_in(&member)]); } From c3e679bb762eab3985f20128bcfd239172ecd8d4 Mon Sep 17 00:00:00 2001 From: t Date: Sun, 25 Oct 2026 04:55:43 -0700 Subject: [PATCH 2/4] refactor: drop own include/exclude filtering; meta sends selected repos Implements [[tasks/harmony-2756]] --- src/lib.rs | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index af1527f..dbca687 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ pub fn execute_command( }; // Notes name repos by their path from the meta root, which meta_cli lists first. let root = cwd.join(dirs.first().map_or(".", String::as_str)); - let (rust_dirs, other_dirs): (Vec, Vec) = filter_dirs(dirs, &root, options) + let (rust_dirs, other_dirs): (Vec, Vec) = dirs .into_iter() .partition(|dir| cwd.join(dir).join("Cargo.toml").is_file()); @@ -56,27 +56,10 @@ pub fn execute_command( CommandResult::Plan(commands, Some(options.parallel)) } -/// Keep the dirs loop_lib will run in, so the skip note names only selected -/// repos. meta_cli sends the filters as whole paths from the root. -fn filter_dirs(mut dirs: Vec, root: &Path, options: &PluginRequestOptions) -> Vec { - let named = |filters: &[String], dir: &str| filters.iter().any(|f| *f == display(dir, root)); - if let Some(includes) = options.include_filters.as_ref().filter(|f| !f.is_empty()) { - dirs.retain(|dir| named(includes, dir)); - } - if let Some(excludes) = &options.exclude_filters { - dirs.retain(|dir| !named(excludes, dir)); - } - dirs -} - fn display(dir: &str, root: &Path) -> String { match root.join(dir).strip_prefix(root) { Ok(rel) if rel.as_os_str().is_empty() => ".".to_string(), - Ok(rel) => rel - .components() - .map(|c| c.as_os_str().to_string_lossy()) - .collect::>() - .join("/"), + Ok(rel) => rel.display().to_string(), Err(_) => dir.to_string(), } } @@ -127,22 +110,19 @@ mod tests { } #[test] - fn workspace_members_run_in_their_own_repos_within_filters() { + fn workspace_members_run_in_their_own_repos() { let temp = TempDir::new().unwrap(); let (root, member) = (temp.path(), temp.path().join("member")); write(root, "Cargo.toml", "[workspace]\nmembers = [\"member\"]\n"); write(&member, "Cargo.toml", "[package]\nname = \"member\"\n"); + // meta_cli sends only the repos --include/--exclude select let all = plan(&["run"], &[root, &member], &Default::default()); - let only_member = PluginRequestOptions { - include_filters: Some(vec!["member".to_string()]), - ..Default::default() - }; - let filtered = plan(&["run"], &[root, &member], &only_member); + let only_member = plan(&["run"], &[&member], &Default::default()); let run_in = |dir: &Path| format!("{}: {:?}", dir.display(), ["cargo", "run"]); assert_eq!(all, [run_in(root), run_in(&member)]); - assert_eq!(filtered, [run_in(&member)]); + assert_eq!(only_member, [run_in(&member)]); } #[test] From afdcd35f59cc2fd7f925ce6ea2cc7e532bb1bf5f Mon Sep 17 00:00:00 2001 From: t Date: Sun, 25 Oct 2026 05:17:49 -0700 Subject: [PATCH 3/4] fix: --help and -h after -- are arguments, not a help request Implements [[tasks/harmony-2756]] --- src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dbca687..903fabd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,7 +19,11 @@ pub fn execute_command( // `meta cargo` and any `--help`/`-h` show this plugin's help instead of // running cargo once per repo. meta_cli sends help requests without the // repo list, so cargo's own help could not reach each repo anyway. - if args.is_empty() || args.iter().any(|a| a == "--help" || a == "-h") { + let help = args + .iter() + .take_while(|a| *a != "--") + .any(|a| a == "--help" || a == "-h"); + if args.is_empty() || help { return CommandResult::ShowHelp(None); } @@ -127,7 +131,7 @@ mod tests { #[test] fn bare_or_help_shows_plugin_help() { - for args in [&[][..], &["test", "--", "--help"][..]] { + for args in [&[][..], &["test", "--help"][..]] { let args: Vec = args.iter().map(|a| a.to_string()).collect(); let result = execute_command(&args, &Default::default(), &[], Path::new(".")); assert!(matches!(result, CommandResult::ShowHelp(None))); From 65140cb67c0923c672368e1a779672aabf7c9c81 Mon Sep 17 00:00:00 2001 From: t Date: Sun, 25 Oct 2026 05:54:42 -0700 Subject: [PATCH 4/4] fix: name skipped repos from the cwd; test --help after -- meta sends only the selected repos, so the first one is no longer the meta root. Implements [[tasks/harmony-2756]] --- src/lib.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 903fabd..949a5ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,14 +32,13 @@ pub fn execute_command( } else { projects.to_vec() }; - // Notes name repos by their path from the meta root, which meta_cli lists first. - let root = cwd.join(dirs.first().map_or(".", String::as_str)); let (rust_dirs, other_dirs): (Vec, Vec) = dirs .into_iter() .partition(|dir| cwd.join(dir).join("Cargo.toml").is_file()); if !options.silent && !other_dirs.is_empty() { - let names: Vec = other_dirs.iter().map(|dir| display(dir, &root)).collect(); + // meta_cli sends only the selected repos, so name them from the cwd + let names: Vec = other_dirs.iter().map(|dir| display(dir, cwd)).collect(); eprintln!("meta-rust: skipping {} (no Cargo.toml)", names.join(", ")); } @@ -129,6 +128,23 @@ mod tests { assert_eq!(only_member, [run_in(&member)]); } + #[test] + fn help_after_double_dash_goes_to_cargo() { + let temp = TempDir::new().unwrap(); + write(temp.path(), "Cargo.toml", "[package]\nname = \"x\"\n"); + let commands = plan( + &["test", "--", "--help"], + &[temp.path()], + &Default::default(), + ); + let expected = format!( + "{}: {:?}", + temp.path().display(), + ["cargo", "test", "--", "--help"] + ); + assert_eq!(commands, [expected]); + } + #[test] fn bare_or_help_shows_plugin_help() { for args in [&[][..], &["test", "--help"][..]] {