Use shared repo directories to avoid duplicate checkouts.

This commit is contained in:
Tom Alexander
2026-02-14 22:11:46 -05:00
parent 47e6a32ba3
commit f688ff1351
4 changed files with 109 additions and 4 deletions

View File

@@ -63,6 +63,7 @@ impl Config {
Ok(target_config)
}
/// The root directory where all the output is stored.
pub(crate) fn get_output_directory(&self) -> Result<Cow<'_, Path>, CustomError> {
let maybe_repo_directory = self.output_directory.as_deref().map(Cow::Borrowed);
if let Some(work_dir) = maybe_repo_directory {

View File

@@ -3,6 +3,8 @@ use std::path::Path;
use serde::Deserialize;
use serde::Serialize;
use sha2::Digest;
use sha2::Sha256;
use crate::error::CustomError;
@@ -34,13 +36,31 @@ pub(crate) struct TargetConfig {
}
impl TargetConfig {
/// The folder that contains the folders for the build targets.
pub(crate) fn get_target_root_directory<'target, 'root>(
&'target self,
config_root: &'root Config,
) -> Result<Cow<'target, Path>, CustomError> {
let output_directory = config_root.get_output_directory()?;
Ok(Cow::Owned(output_directory.join("target")))
}
/// The root directory for this specific build target.
pub(crate) fn get_target_directory<'target, 'root>(
&'target self,
config_root: &'root Config,
) -> Result<Cow<'target, Path>, CustomError> {
let repo_directory = config_root.get_output_directory()?;
Ok(Cow::Owned(repo_directory.join(&self.name)))
let target_root = self.get_target_root_directory(config_root)?;
Ok(Cow::Owned(target_root.join(&self.name)))
}
/// The folder that contains the folders containing the checkouts of the git repositories.
pub(crate) fn get_repo_root_directory<'target, 'root>(
&'target self,
config_root: &'root Config,
) -> Result<Cow<'target, Path>, CustomError> {
let output_directory = config_root.get_output_directory()?;
Ok(Cow::Owned(output_directory.join("repo")))
}
/// The root of the checkout of the git repository.
@@ -48,8 +68,11 @@ impl TargetConfig {
&'target self,
config_root: &'root Config,
) -> Result<Cow<'target, Path>, CustomError> {
let target_directory = self.get_target_directory(config_root)?;
Ok(Cow::Owned(target_directory.join("repo")))
let hashed_repo = Sha256::digest(&self.repo);
let hashed_repo = hex_string(&hashed_repo);
let repo_root = self.get_repo_root_directory(config_root)?;
Ok(Cow::Owned(repo_root.join(hashed_repo)))
}
/// The directory that contains flake.nix.
@@ -99,3 +122,11 @@ impl TargetConfig {
Ok(&self.attr)
}
}
fn hex_string(data: &[u8]) -> String {
let mut out = String::with_capacity(data.len() * 2);
for byte in data {
out.push_str(format!("{:02x}", byte).as_str());
}
out
}