Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: keep installed packages in environments #1119

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
11 changes: 8 additions & 3 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down Expand Up @@ -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();
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
Loading