Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Only regenerate shell_gc_root if store path changes #498

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 19 additions & 1 deletion src/build_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::builder;
use crate::daemon::LoopHandlerEvent;
use crate::error::BuildError;
use crate::nix::options::NixOptions;
use crate::nix::StorePath;
use crate::pathreduction::reduce_paths;
use crate::project::roots;
use crate::project::roots::Roots;
Expand Down Expand Up @@ -63,6 +64,9 @@ pub struct BuildLoop<'a> {
watch: Watch,
/// Extra options to pass to each nix invocation
extra_nix_options: NixOptions,
/// The store path of the last loop iteration is stored so relinking can
/// be avoided when there is no change.
last_store_path: Option<StorePath>,
}

impl<'a> BuildLoop<'a> {
Expand All @@ -73,6 +77,7 @@ impl<'a> BuildLoop<'a> {
project,
watch: Watch::try_new().expect("Failed to initialize watch"),
extra_nix_options,
last_store_path: None,
}
}

Expand Down Expand Up @@ -199,7 +204,12 @@ impl<'a> BuildLoop<'a> {
&self.extra_nix_options,
)?;
self.register_paths(&run_result.referenced_paths)?;
self.root_result(run_result.result)
if Some(&run_result.result.path) != self.last_store_path.as_ref() {
self.last_store_path = Some(run_result.result.path.clone());
self.root_result(run_result.result)
} else {
self.root_result_cached()
}
}

fn register_paths(&mut self, paths: &[PathBuf]) -> Result<(), notify::Error> {
Expand All @@ -213,6 +223,14 @@ impl<'a> BuildLoop<'a> {
Ok(())
}

fn root_result_cached(&self) -> Result<BuildResults, BuildError> {
let roots = Roots::from_project(&self.project);

Ok(BuildResults {
output_paths: roots.paths(),
})
}

fn root_result(&mut self, build: builder::RootedPath) -> Result<BuildResults, BuildError> {
let roots = Roots::from_project(&self.project);

Expand Down