Skip to content

Commit

Permalink
Some more fixes for making sure the right reason gets propagated
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Oct 10, 2024
1 parent a931d7c commit 35039ac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
11 changes: 1 addition & 10 deletions crates/turborepo-lib/src/run/scope/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use miette::Diagnostic;
use tracing::debug;
use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf, AnchoredSystemPathBuf};
use turborepo_repository::{
change_mapper::{ChangeMapError, PackageChangeReason},
change_mapper::{merge_changed_packages, ChangeMapError, PackageChangeReason},
package_graph::{self, PackageGraph, PackageName},
};
use turborepo_scm::SCM;
Expand Down Expand Up @@ -99,15 +99,6 @@ impl PackageInference {
}
}

fn merge_changed_packages(
changed_packages: &mut HashMap<PackageName, PackageChangeReason>,
new_changes: impl IntoIterator<Item = (PackageName, PackageChangeReason)>,
) {
for (package, reason) in new_changes {
changed_packages.entry(package).or_insert(reason);
}
}

pub struct FilterResolver<'a, T: GitChangeDetector> {
pkg_graph: &'a PackageGraph,
turbo_root: &'a AbsoluteSystemPath,
Expand Down
23 changes: 18 additions & 5 deletions crates/turborepo-repository/src/change_mapper/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Maps changed files to changed packages in a repository.
//! Used for both `--filter` and for isolated builds.
use std::collections::HashSet;
use std::{
collections::{HashMap, HashSet},
hash::Hash,
};

pub use package::{
DefaultPackageChangeMapper, Error, GlobalDepsPackageChangeMapper, PackageChangeMapper,
Expand Down Expand Up @@ -69,10 +72,19 @@ pub enum AllPackageChangeReason {
},
}

pub fn merge_changed_packages<T: Hash + Eq>(
changed_packages: &mut HashMap<T, PackageChangeReason>,
new_changes: impl IntoIterator<Item = (T, PackageChangeReason)>,
) {
for (package, reason) in new_changes {
changed_packages.entry(package).or_insert(reason);
}
}

#[derive(Debug, PartialEq, Eq)]
pub enum PackageChanges {
All(AllPackageChangeReason),
Some(HashSet<(WorkspacePackage, PackageChangeReason)>),
Some(HashMap<WorkspacePackage, PackageChangeReason>),
}

pub struct ChangeMapper<'a, PD> {
Expand Down Expand Up @@ -145,7 +157,8 @@ impl<'a, PD: PackageChangeMapper> ChangeMapper<'a, PD> {
"found {} packages changed by lockfile",
lockfile_changes.len()
);
changed_pkgs.extend(
merge_changed_packages(
&mut changed_pkgs,
lockfile_changes
.into_iter()
.map(|pkg| (pkg, PackageChangeReason::LockfileChanged)),
Expand Down Expand Up @@ -183,7 +196,7 @@ impl<'a, PD: PackageChangeMapper> ChangeMapper<'a, PD> {
files: impl Iterator<Item = &'b AnchoredSystemPathBuf>,
) -> PackageChanges {
let root_internal_deps = self.pkg_graph.root_internal_package_dependencies();
let mut changed_packages = HashSet::new();
let mut changed_packages = HashMap::new();
for file in files {
match self.package_detector.detect_package(file) {
// Internal root dependency changed so global hash has changed
Expand All @@ -201,7 +214,7 @@ impl<'a, PD: PackageChangeMapper> ChangeMapper<'a, PD> {
}
PackageMapping::Package((pkg, reason)) => {
debug!("{} changes \"{}\"", file.to_string(), pkg.name);
changed_packages.insert((pkg, reason));
changed_packages.insert(pkg, reason);
}
PackageMapping::All(reason) => {
debug!("all packages changed due to {file:?}");
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-repository/src/change_mapper/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl<'a> PackageChangeMapper for GlobalDepsPackageChangeMapper<'a> {
name: PackageName::Root,
path: AnchoredSystemPathBuf::from_raw("").unwrap(),
},
PackageChangeReason::LockfileChanged,
PackageChangeReason::ConservativeRootLockfileChanged,
));
}
match DefaultPackageChangeMapper::new(self.pkg_dep_graph).detect_package(path) {
Expand Down

0 comments on commit 35039ac

Please sign in to comment.