From 7e9a701b4f9680d5b466efba881ea18bf04768ed Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Mon, 14 Oct 2024 10:15:23 +0200 Subject: [PATCH 1/2] inject installed packages in environments --- src/render/solver.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/render/solver.rs b/src/render/solver.rs index a4aac14a..bc175bc3 100644 --- a/src/render/solver.rs +++ b/src/render/solver.rs @@ -11,7 +11,7 @@ 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; @@ -309,12 +309,15 @@ pub async fn install_packages( ) })?; + let installed_packages = PrefixRecord::collect_from_prefix(target_prefix)?; + 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 b5bd1890115e923453391eb102caa3fe9f5cbe96 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Mon, 14 Oct 2024 10:34:14 +0200 Subject: [PATCH 2/2] more host clean up --- src/render/solver.rs | 20 +++++++++++++++++++- src/source/mod.rs | 5 +++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/render/solver.rs b/src/render/solver.rs index bc175bc3..65fcf85e 100644 --- a/src/render/solver.rs +++ b/src/render/solver.rs @@ -15,7 +15,10 @@ use rattler_conda_types::{Channel, MatchSpec, Platform, PrefixRecord, RepoDataRe 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(); @@ -311,6 +314,21 @@ 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()) 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,