use std::path::PathBuf;
use clap::Args;
use consortium_builder::pipeline::{
self,
fetch::{self, FetchConfig},
};
use crate::reporter::StickyReporter;
#[derive(Args)]
pub struct FetchArgs {
#[arg(long, default_value = "Consortium.toml")]
manifest: PathBuf,
#[arg(long)]
skip_hmi: bool,
#[arg(long)]
skip_rust_targets: bool,
}
pub async fn run(args: FetchArgs) -> Result<(), String> {
let session = pipeline::load_session(&args.manifest)
.await
.map_err(|e| e.to_string())?;
let manifest_dir = args
.manifest
.parent()
.map(std::path::Path::to_path_buf)
.unwrap_or_else(|| PathBuf::from("."));
let hmi = if args.skip_hmi {
None
} else {
fetch::derive_hmi_fetch(&session, &manifest_dir).map_err(|e| e.to_string())?
};
let config = FetchConfig {
manifest_path: args.manifest.clone(),
hmi,
rust_targets: !args.skip_rust_targets,
};
let plan = fetch::plan_fetch(&session, &manifest_dir, config.hmi.clone())
.map_err(|e| e.to_string())?;
println!(
"Fetching dependencies for {} (chip {})",
args.manifest.display(),
session.database.name
);
for entry in &plan.cargo {
println!(" cargo: {} ({})", entry.label, entry.target);
}
if let Some(hmi) = &plan.hmi {
println!(" hmi: {}", hmi.project_dir.display());
}
if !args.skip_rust_targets {
println!(" targets: {}", plan.rust_targets().join(" "));
}
let reporter = StickyReporter::new();
match fetch::run_with_reporter(config, &reporter).await {
Ok(_) => reporter.finish_success("Fetch complete"),
Err(error) => {
reporter.finish_failure("Fetch failed");
return Err(error.to_string());
}
}
println!(
"Dependencies cached; `csti build --linux <DIR> --offline` can now run without network access."
);
Ok(())
}