From 3db744ef9f79f188ccc7b42ce7a1e174ed445169 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Wed, 4 Dec 2024 16:12:13 +0100 Subject: [PATCH 1/2] overwrite previous build more lazily --- src/build.rs | 5 +++++ src/render/solver.rs | 24 ++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/build.rs b/src/build.rs index 4bfd3a20..973525ab 100644 --- a/src/build.rs +++ b/src/build.rs @@ -114,6 +114,11 @@ pub async fn run_build( let directories = output.build_configuration.directories.clone(); + // if the work directory already exists, we should remove it + if directories.work_dir.exists() { + fs_err::remove_dir_all(&directories.work_dir).into_diagnostic()?; + } + let output = if output.recipe.cache.is_some() { output.build_or_fetch_cache(tool_configuration).await? } else { diff --git a/src/render/solver.rs b/src/render/solver.rs index 39db5417..330cfe26 100644 --- a/src/render/solver.rs +++ b/src/render/solver.rs @@ -11,11 +11,11 @@ use futures::FutureExt; use indicatif::{HumanBytes, ProgressBar, ProgressStyle}; use itertools::Itertools; use rattler::install::{DefaultProgressFormatter, IndicatifReporter, Installer}; -use rattler_conda_types::{Channel, ChannelUrl, MatchSpec, Platform, RepoDataRecord}; +use rattler_conda_types::{Channel, ChannelUrl, MatchSpec, Platform, PrefixRecord, RepoDataRecord}; use rattler_solve::{resolvo::Solver, ChannelPriority, SolveStrategy, SolverImpl, SolverTask}; use url::Url; -use crate::{metadata::PlatformWithVirtualPackages, tool_configuration}; +use crate::{metadata::PlatformWithVirtualPackages, packaging::Files, tool_configuration}; fn print_as_table(packages: &[RepoDataRecord]) { let mut table = Table::new(); @@ -311,12 +311,32 @@ pub async fn install_packages( ) })?; + let installed_packages = PrefixRecord::collect_from_prefix(target_prefix)?; + + if !installed_packages.is_empty() && name.starts_with("host") { + // we have to clean up extra files in the prefix + let extra_files = + Files::from_prefix(target_prefix, &Default::default(), &Default::default())?; + + tracing::info!( + "Cleaning up {} files in the prefix from a previous build.", + extra_files.new_files.len() + ); + + for f in extra_files.new_files { + if !f.is_dir() { + fs_err::remove_file(target_prefix.join(f))?; + } + } + } + tracing::info!("\nInstalling {name} environment\n"); Installer::new() .with_download_client(tool_configuration.client.clone()) .with_target_platform(target_platform) .with_execute_link_scripts(true) .with_package_cache(tool_configuration.package_cache.clone()) + .with_installed_packages(installed_packages) .with_reporter( IndicatifReporter::builder() .with_multi_progress( From 7d54a050277f6cfb801b301e49e31e472ff3d6ab Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Wed, 4 Dec 2024 17:04:28 +0100 Subject: [PATCH 2/2] fix up --- src/build.rs | 7 +------ src/metadata.rs | 11 ++++++++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/build.rs b/src/build.rs index 973525ab..52c945b1 100644 --- a/src/build.rs +++ b/src/build.rs @@ -105,7 +105,7 @@ pub async fn run_build( output .build_configuration .directories - .create_build_dir() + .create_build_dir(true) .into_diagnostic()?; let span = tracing::info_span!("Running build for", recipe = output.identifier()); @@ -114,11 +114,6 @@ pub async fn run_build( let directories = output.build_configuration.directories.clone(); - // if the work directory already exists, we should remove it - if directories.work_dir.exists() { - fs_err::remove_dir_all(&directories.work_dir).into_diagnostic()?; - } - let output = if output.recipe.cache.is_some() { output.build_or_fetch_cache(tool_configuration).await? } else { diff --git a/src/metadata.rs b/src/metadata.rs index 1fce87d1..0735fb6f 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -185,8 +185,13 @@ impl Directories { } /// Creates the build directory. - pub fn create_build_dir(&self) -> Result<(), std::io::Error> { - fs::create_dir_all(self.build_dir.join("work"))?; + pub fn create_build_dir(&self, remove_existing_work_dir: bool) -> Result<(), std::io::Error> { + if remove_existing_work_dir && self.work_dir.exists() { + fs::remove_dir_all(&self.work_dir)?; + } + + fs::create_dir_all(&self.work_dir)?; + Ok(()) } @@ -784,7 +789,7 @@ mod test { &chrono::Utc::now(), ) .unwrap(); - directories.create_build_dir().unwrap(); + directories.create_build_dir(false).unwrap(); // test yaml roundtrip let yaml = serde_yaml::to_string(&directories).unwrap();