Skip to content

Commit

Permalink
overwrite previous build more lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Dec 4, 2024
1 parent 15f70b2 commit 3db744e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 22 additions & 2 deletions src/render/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 3db744e

Please sign in to comment.