diff --git a/src/render/solver.rs b/src/render/solver.rs index a4aac14a..65fcf85e 100644 --- a/src/render/solver.rs +++ b/src/render/solver.rs @@ -11,11 +11,14 @@ use futures::FutureExt; use indicatif::{HumanBytes, ProgressBar, ProgressStyle}; use itertools::Itertools; use rattler::install::{DefaultProgressFormatter, IndicatifReporter, Installer}; -use rattler_conda_types::{Channel, MatchSpec, Platform, RepoDataRecord}; +use rattler_conda_types::{Channel, 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, recipe::parser::GlobVec, + tool_configuration, +}; fn print_as_table(packages: &[RepoDataRecord]) { let mut table = Table::new(); @@ -309,12 +312,30 @@ 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, &GlobVec::default(), &GlobVec::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( diff --git a/src/source/mod.rs b/src/source/mod.rs index 156cae24..bf18b646 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -288,6 +288,11 @@ impl Output { let span = tracing::info_span!("Fetching source code"); let _enter = span.enter(); + // if the work directory already exists, we should remove it + if self.build_configuration.directories.work_dir.exists() { + fs::remove_dir_all(&self.build_configuration.directories.work_dir)?; + } + if let Some(finalized_sources) = &self.finalized_sources { fetch_sources( finalized_sources,