2026-02-14 13:31:21 -05:00
|
|
|
use crate::cli::parameters::BuildArgs;
|
|
|
|
|
use crate::config::Config;
|
|
|
|
|
use crate::config::TargetConfig;
|
|
|
|
|
use crate::error::CustomError;
|
2026-02-14 16:00:37 -05:00
|
|
|
use crate::fs_util::assert_directory;
|
|
|
|
|
use crate::fs_util::is_git_repo;
|
|
|
|
|
use crate::git_util::git_force_into_state;
|
|
|
|
|
use crate::git_util::git_init_at_rev;
|
2026-02-14 13:31:21 -05:00
|
|
|
|
|
|
|
|
pub(crate) async fn run_build(args: BuildArgs) -> Result<(), CustomError> {
|
|
|
|
|
println!("{:?}", args);
|
|
|
|
|
let config = Config::load_from_file(args.config).await?;
|
|
|
|
|
println!("{:?}", config);
|
|
|
|
|
|
|
|
|
|
for target_name in args.target {
|
|
|
|
|
let target_config = {
|
|
|
|
|
let target_config = config.get_target_config(&target_name)?;
|
|
|
|
|
if let Some(conf) = target_config {
|
|
|
|
|
conf
|
|
|
|
|
} else {
|
|
|
|
|
return Err(format!("Could not find target {}", target_name).into());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-14 16:00:37 -05:00
|
|
|
prepare_flake_repo(&config, target_config).await?;
|
2026-02-14 13:31:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 16:00:37 -05:00
|
|
|
async fn prepare_flake_repo(
|
|
|
|
|
config_root: &Config,
|
|
|
|
|
target_config: &TargetConfig,
|
|
|
|
|
) -> Result<(), CustomError> {
|
|
|
|
|
let flake_directory = target_config.get_flake_directory(config_root)?;
|
|
|
|
|
assert_directory!(
|
|
|
|
|
&flake_directory,
|
|
|
|
|
"Creating flake directory {}",
|
|
|
|
|
(&flake_directory).to_string_lossy()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if is_git_repo(&flake_directory).await? {
|
|
|
|
|
// Clean up the existing clone
|
|
|
|
|
git_force_into_state(
|
|
|
|
|
&flake_directory,
|
|
|
|
|
target_config.get_branch()?,
|
|
|
|
|
"origin",
|
|
|
|
|
target_config.get_repo()?,
|
|
|
|
|
target_config.get_revision()?,
|
|
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
} else {
|
|
|
|
|
git_init_at_rev(
|
|
|
|
|
&flake_directory,
|
|
|
|
|
target_config.get_branch()?,
|
|
|
|
|
target_config.get_repo()?,
|
|
|
|
|
target_config.get_revision()?,
|
|
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
2026-02-14 13:31:21 -05:00
|
|
|
}
|