diff --git a/src/cache.rs b/src/cache.rs index a6cf4d5e..dccb77e2 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -204,9 +204,10 @@ impl Output { } // fetch the sources for the `cache` section - // TODO store them as finalized?! - fetch_sources( - &cache.source, + let rendered_sources = fetch_sources( + self.finalized_cache_sources + .as_ref() + .unwrap_or(&cache.source), &self.build_configuration.directories, &self.system_tools, tool_configuration, @@ -312,6 +313,7 @@ impl Output { Ok(Output { finalized_cache_dependencies: Some(finalized_dependencies), + finalized_cache_sources: Some(rendered_sources), ..self }) } else { diff --git a/src/lib.rs b/src/lib.rs index 22a9cd65..4d8972a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -373,8 +373,9 @@ pub async fn get_build_output( force_colors: args.color_build_log && console::colors_enabled(), }, finalized_dependencies: None, - finalized_cache_dependencies: None, finalized_sources: None, + finalized_cache_dependencies: None, + finalized_cache_sources: None, system_tools: SystemTools::new(), build_summary: Arc::new(Mutex::new(BuildSummary::default())), extra_meta: Some( diff --git a/src/metadata.rs b/src/metadata.rs index 799a10c1..1fce87d1 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -404,13 +404,18 @@ pub struct Output { /// dependencies have not been resolved yet. During the `run_build` /// functions, the dependencies are resolved and this field is filled. pub finalized_dependencies: Option, - /// The finalized dependencies from the cache (if there is a cache - /// instruction) - pub finalized_cache_dependencies: Option, /// The finalized sources for this output. Contain the exact git hashes for /// the sources that are used to build this output. pub finalized_sources: Option>, + /// The finalized dependencies from the cache (if there is a cache + /// instruction) + #[serde(skip_serializing_if = "Option::is_none")] + pub finalized_cache_dependencies: Option, + /// The finalized sources from the cache (if there is a cache instruction) + #[serde(skip_serializing_if = "Option::is_none")] + pub finalized_cache_sources: Option>, + /// Summary of the build #[serde(skip)] pub build_summary: Arc>, diff --git a/src/source/mod.rs b/src/source/mod.rs index 6e231ba7..c3f44a56 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -288,29 +288,19 @@ impl Output { let span = tracing::info_span!("Fetching source code"); let _enter = span.enter(); - if let Some(finalized_sources) = &self.finalized_sources { - fetch_sources( - finalized_sources, - &self.build_configuration.directories, - &self.system_tools, - tool_configuration, - ) - .await?; - - Ok(self) - } else { - let rendered_sources = fetch_sources( - &self.recipe.sources(), - &self.build_configuration.directories, - &self.system_tools, - tool_configuration, - ) - .await?; - - Ok(Output { - finalized_sources: Some(rendered_sources), - ..self - }) - } + let rendered_sources = fetch_sources( + self.finalized_sources + .as_deref() + .unwrap_or(self.recipe.sources()), + &self.build_configuration.directories, + &self.system_tools, + tool_configuration, + ) + .await?; + + Ok(Output { + finalized_sources: Some(rendered_sources), + ..self + }) } }