Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl Cache {
&self,
config: &Config,
key: CacheKey,
outputs: &BTreeMap<String, Utf8PathBuf>,
outputs: BTreeMap<String, Utf8PathBuf>,
) -> RunResult<'static, CacheStatus> {
let hash = Hash::json(&key).map_err(|source| Error::CacheKeySerialize { source })?;

Expand Down Expand Up @@ -47,6 +47,7 @@ impl Cache {
let Some(entry) = CacheEntry::load(&file, &path)? else {
return Ok(CacheStatus::Miss(CacheLock {
file,
outputs,
path,
recipe: key.recipe.clone(),
}));
Expand All @@ -58,11 +59,12 @@ impl Cache {
.map(|(name, output)| (name, Some(output)))
.collect();

if Self::outputs(outputs)? == expected {
if Self::outputs(&outputs)? == expected {
Ok(CacheStatus::Hit)
} else {
Ok(CacheStatus::Miss(CacheLock {
file,
outputs,
path,
recipe: key.recipe.clone(),
}))
Expand Down
14 changes: 13 additions & 1 deletion src/cache_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ use super::*;

pub(crate) struct CacheLock {
pub(crate) file: File,
pub(crate) outputs: BTreeMap<String, Utf8PathBuf>,
pub(crate) path: Utf8PathBuf,
pub(crate) recipe: Modulepath,
}

impl CacheLock {
pub(crate) fn save(mut self, outputs: BTreeMap<String, CacheOutput>) -> RunResult<'static> {
pub(crate) fn save(mut self, recipe: &str) -> RunResult<'_> {
let outputs = Cache::outputs(&self.outputs)?
.into_iter()
.map(|(name, output)| match output {
Some(output) => Ok((name, output)),
None => Err(Error::CacheOutputMissing {
recipe,
output: name,
}),
})
.collect::<RunResult<BTreeMap<String, CacheOutput>>>()?;

let context = |source| Error::FilesystemIo {
source,
path: self.path.clone(),
Expand Down
23 changes: 7 additions & 16 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ impl<'src> Recipe<'src> {
}
});

let (cache_lock, outputs) = if !config.no_cache
let cache_lock = if !config.no_cache
&& let Some(Attribute::Cache {
environment: environment_attribute,
extra,
Expand Down Expand Up @@ -651,7 +651,7 @@ impl<'src> Recipe<'src> {
working_directory: Some(&working_directory),
};

let lock = match cache.status(config, key, &outputs)? {
let lock = match cache.status(config, key, outputs)? {
CacheStatus::Hit => {
if config.verbosity.loquacious() {
eprintln!(
Expand All @@ -669,9 +669,9 @@ impl<'src> Recipe<'src> {
CacheStatus::Miss(lock) => lock,
};

(Some(lock), outputs)
Some(lock)
} else {
(None, BTreeMap::new())
None
};

let tempdir = context.tempdir(self)?;
Expand Down Expand Up @@ -740,18 +740,9 @@ impl<'src> Recipe<'src> {
}
}

let outputs = Cache::outputs(&outputs)?
.into_iter()
.map(|(name, output)| match output {
Some(output) => Ok((name, output)),
None => Err(Error::CacheOutputMissing {
recipe: self.name(),
output: name,
}),
})
.collect::<RunResult<BTreeMap<String, CacheOutput>>>()?;

cache_lock.map(|lock| lock.save(outputs)).transpose()?;
if let Some(cache_lock) = cache_lock {
cache_lock.save(self.name())?;
}

Ok(())
}
Expand Down
Loading