From 4b8ea717a8e07ed0952ac7f8e2082eb42f2f19ce Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Sat, 30 Nov 2024 11:05:58 +0100 Subject: [PATCH] use source from cache key --- src/build.rs | 2 +- src/cache.rs | 24 ++++++++++++++++-------- src/source/mod.rs | 14 +------------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/build.rs b/src/build.rs index 2513cc25..4bfd3a20 100644 --- a/src/build.rs +++ b/src/build.rs @@ -118,7 +118,7 @@ pub async fn run_build( output.build_or_fetch_cache(tool_configuration).await? } else { output - .fetch_sources(None, tool_configuration) + .fetch_sources(tool_configuration) .await .into_diagnostic()? }; diff --git a/src/cache.rs b/src/cache.rs index fb7dc642..a6cf4d5e 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -15,11 +15,14 @@ use crate::{ env_vars, metadata::{build_reindexed_channels, Output}, packaging::{contains_prefix_binary, contains_prefix_text, content_type, Files}, - recipe::parser::{Dependency, Requirements, Source}, + recipe::parser::{Dependency, Requirements}, render::resolved_dependencies::{ install_environments, resolve_dependencies, FinalizedDependencies, }, - source::copy_dir::{copy_file, create_symlink, CopyDir, CopyOptions}, + source::{ + copy_dir::{copy_file, create_symlink, CopyDir, CopyOptions}, + fetch_sources, + }, }; /// Error type for cache key generation @@ -186,7 +189,7 @@ impl Output { Ok(cache) => { tracing::info!("Restoring cache from {:?}", cache_dir); self = self - .fetch_sources(Some(cache.sources.clone()), tool_configuration) + .fetch_sources(tool_configuration) .await .into_diagnostic()?; return self.restore_cache(cache, cache_dir).await; @@ -200,10 +203,16 @@ impl Output { } } - self = self - .fetch_sources(None, tool_configuration) - .await - .into_diagnostic()?; + // fetch the sources for the `cache` section + // TODO store them as finalized?! + fetch_sources( + &cache.source, + &self.build_configuration.directories, + &self.system_tools, + tool_configuration, + ) + .await + .into_diagnostic()?; let target_platform = self.build_configuration.target_platform; let mut env_vars = env_vars::vars(&self, "BUILD"); @@ -296,7 +305,6 @@ impl Output { prefix_files: copied_files, work_dir_files: work_dir_files.copied_paths().to_vec(), prefix: self.prefix().to_path_buf(), - sources: self.recipe.source.clone(), }; let cache_file = cache_dir.join("cache.json"); diff --git a/src/source/mod.rs b/src/source/mod.rs index 47411370..6e231ba7 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -283,7 +283,6 @@ impl Output { /// Fetches the sources for the given output and returns a new output with the finalized sources attached pub async fn fetch_sources( self, - already_fetched: Option>, tool_configuration: &tool_configuration::Configuration, ) -> Result { let span = tracing::info_span!("Fetching source code"); @@ -300,19 +299,8 @@ impl Output { Ok(self) } else { - let sources_to_fetch = if let Some(already_fetched) = already_fetched { - self.recipe - .sources() - .iter() - .filter(|&s| !already_fetched.iter().any(|fetched| fetched == s)) - .cloned() - .collect() - } else { - self.recipe.sources().to_vec() - }; - let rendered_sources = fetch_sources( - &sources_to_fetch, + &self.recipe.sources(), &self.build_configuration.directories, &self.system_tools, tool_configuration,