use super::Cli;
#[cfg(target_os = "macos")]
pub(super) fn reexec_with_metal_validation(cli: &Cli) {
use super::Commands;
use std::os::unix::process::CommandExt;
let requested = match cli.resolved_command() {
Commands::Run(args) => args.validation,
Commands::Debug(args) => args.validation,
Commands::Editor(args) => args.validation,
_ => return,
};
if !requested.unwrap_or(cfg!(debug_assertions)) {
return;
}
if std::env::var_os("MTL_DEBUG_LAYER").is_some() {
return;
}
let exe = match std::env::current_exe() {
Ok(p) => p,
Err(e) => {
eprintln!("validation: cannot locate current executable to re-exec: {e}");
return;
}
};
let err = std::process::Command::new(exe)
.args(std::env::args_os().skip(1))
.env("MTL_DEBUG_LAYER", "1")
.exec();
eprintln!("validation: failed to re-exec with Metal validation enabled: {err}");
}
#[cfg(not(target_os = "macos"))]
pub(super) fn reexec_with_metal_validation(_cli: &Cli) {}
#[cfg(all(test, target_os = "macos"))]
mod tests {
use super::*;
use clap::Parser;
#[test]
fn metal_validation_reexec_declines_when_not_requested() {
for args in [
["concinnity", "run", "--validation", "false"],
["concinnity", "editor", "--validation", "false"],
["concinnity", "debug", "--validation", "false"],
] {
reexec_with_metal_validation(&Cli::try_parse_from(args).unwrap());
}
reexec_with_metal_validation(&Cli::try_parse_from(["concinnity", "list"]).unwrap());
reexec_with_metal_validation(&Cli::try_parse_from(["concinnity", "mcp"]).unwrap());
}
}