mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-10-15 04:21:44 +00:00
Stage sandbox plugins in Cargo profile output directories
This commit is contained in:
parent
02dba22b0c
commit
c3e7f04ef3
1 changed files with 38 additions and 12 deletions
|
|
@ -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<String> {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
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::<Vec<_>>();
|
||||
assert_eq!(output_profile(&args), directory, "{args:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue