From c3e7f04ef319023659d1b59eef5c596c9fa4a858 Mon Sep 17 00:00:00 2001 From: Scott Werner Date: Mon, 21 Sep 2026 20:14:05 -0400 Subject: [PATCH] Stage sandbox plugins in Cargo profile output directories --- .../fabro-dev/src/commands/build.rs | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/lib/foundation/fabro-dev/src/commands/build.rs b/lib/foundation/fabro-dev/src/commands/build.rs index 86d745a8a..5ac0e5a85 100644 --- a/lib/foundation/fabro-dev/src/commands/build.rs +++ b/lib/foundation/fabro-dev/src/commands/build.rs @@ -23,18 +23,7 @@ pub(crate) fn build(args: BuildArgs) -> Result<()> { let target = argument(&args.cargo_args, "--target").or_else(|| std::env::var("CARGO_BUILD_TARGET").ok()); let directory = plugins::prepare(&root, target.as_deref(), false)?; - let profile = argument(&args.cargo_args, "--profile").unwrap_or_else(|| { - if args - .cargo_args - .iter() - .any(|arg| arg == "--release" || arg == "-r") - { - "release".to_owned() - } else { - "debug".to_owned() - } - }); - let output_profile = if profile == "dev" { "debug" } else { &profile }; + let output_profile = output_profile(&args.cargo_args); let default_root = directory .parent() .and_then(std::path::Path::parent) @@ -65,3 +54,40 @@ fn argument(args: &[String], name: &str) -> Option { } }) } + +fn output_profile(args: &[String]) -> String { + let profile = argument(args, "--profile").unwrap_or_else(|| { + if args.iter().any(|arg| arg == "--release" || arg == "-r") { + "release".to_owned() + } else { + "dev".to_owned() + } + }); + match profile.as_str() { + "dev" | "test" => "debug".to_owned(), + "release" | "bench" => "release".to_owned(), + _ => profile, + } +} + +#[cfg(test)] +mod tests { + use super::output_profile; + + #[test] + fn forwarded_cargo_profiles_use_cargos_output_directories() { + for (args, directory) in [ + (vec![], "debug"), + (vec!["--release"], "release"), + (vec!["-r"], "release"), + (vec!["--profile", "dev"], "debug"), + (vec!["--profile", "test"], "debug"), + (vec!["--profile=bench"], "release"), + (vec!["--profile=release"], "release"), + (vec!["--profile", "custom"], "custom"), + ] { + let args = args.into_iter().map(str::to_owned).collect::>(); + assert_eq!(output_profile(&args), directory, "{args:?}"); + } + } +}