use std::path::PathBuf;
use clap::Args;
use consortium_builder::pipeline::{
self,
check::{self, CheckConfig, TaSkip},
tee::TeeToolchain,
};
use crate::reporter::StickyReporter;
#[derive(Args)]
pub struct CheckArgs {
#[arg(long, default_value = "Consortium.toml")]
manifest: PathBuf,
#[arg(long, value_name = "DIR")]
linux: Option<PathBuf>,
#[arg(long)]
release: bool,
#[arg(long)]
offline: bool,
#[arg(long, requires = "linux")]
skip_remoteproc_check: bool,
}
pub async fn run(args: CheckArgs) -> Result<(), String> {
let session = pipeline::load_session(&args.manifest)
.await
.map_err(|e| e.to_string())?;
let config = CheckConfig {
manifest_path: args.manifest.clone(),
linux: args.linux.clone(),
release: args.release,
offline: args.offline,
tee_toolchain: TeeToolchain::from_env(),
strict_remoteproc: !args.skip_remoteproc_check,
};
let plan = check::plan_check(&session, &config)
.await
.map_err(|e| e.to_string())?;
println!(
"Checking {} for chip {}",
args.manifest.display(),
session.database.name
);
for fw in &plan.firmware {
println!(" firmware: {} ({})", fw.core, fw.config.target);
}
match plan.ta_skipped {
Some(TaSkip::NoToolchain) => {
println!(" tee: skipped (set TA_DEV_KIT_DIR to check the trusted application)");
}
None if plan.ta.is_some() => println!(" tee: trusted application"),
None => {}
}
println!(" app: {}", plan.application.config.target);
for path in &plan.placeholder_elfs {
println!(
" dbg: {} not built yet; embedding an empty stand-in",
path.display()
);
}
match &args.linux {
Some(_) if plan.dts_files.is_empty() => println!(" dts: nothing to render"),
Some(_) => println!(" dts: {} (rendered)", plan.dts_files.join(", ")),
None => println!(" dts: skipped (pass --linux <DIR> to validate)"),
}
if args.offline {
println!(" cargo: --offline (local registry cache only)");
}
let reporter = StickyReporter::new();
match check::run_with_reporter(config, &reporter).await {
Ok(_) => reporter.finish_success("Check complete"),
Err(error) => {
reporter.finish_failure("Check failed");
return Err(error.to_string());
}
}
Ok(())
}