Skip to content
Open
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
40 changes: 38 additions & 2 deletions packages/nx/src/native/tasks/hash_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,9 @@ fn drop_ultracache_duplicates(pool: &InstructionPool, ids: &mut Vec<u32>) {
/// fileset that reads from a directory containing, or sitting inside, an
/// output an upstream task declares. An output inside a project nested below
/// the glob's own is not read by it, so it does not count. Any other
/// disk-backed fileset hashes up front like a tracked one.
/// disk-backed fileset hashes up front like a tracked one. A task that hashes
/// its absolute cwd also waits: under distribution it runs on an agent whose
/// cwd differs from the coordinator's.
fn deferred_tasks(
plans: &HashMap<String, Vec<u32>>,
pool: &InstructionPool,
Expand All @@ -1691,7 +1693,9 @@ fn deferred_tasks(
let mut disk_roots: Vec<(String, Vec<String>)> = Vec::new();
for id in ids.iter() {
match &*pool.get(*id) {
HashInstruction::TaskOutput(_, _) => return true,
HashInstruction::TaskOutput(_, _) | HashInstruction::Cwd(CwdMode::Absolute) => {
return true;
}
HashInstruction::IgnoredFileSet {
globs,
project_roots,
Expand Down Expand Up @@ -2787,6 +2791,38 @@ mod tests {
);
}

#[test]
fn defers_a_task_that_hashes_its_absolute_cwd() {
let pool = InstructionPool::new();
let plans: HashMap<String, Vec<u32>> = [
("app:absolute", CwdMode::Absolute),
("app:relative", CwdMode::Relative),
]
.into_iter()
.map(|(id, mode)| {
(
id.to_string(),
vec![pool.intern(HashInstruction::Cwd(mode))],
)
})
.collect();
let task_graph = TaskGraph {
roots: vec![],
tasks: ["app:absolute", "app:relative"]
.into_iter()
.map(|id| {
let (project, target) = id.split_once(':').unwrap();
(id.to_string(), Task::new(project, target))
})
.collect(),
dependencies: HashMap::new(),
continuous_dependencies: HashMap::new(),
};

let deferred = deferred_tasks(&plans, &pool, &task_graph);
assert_eq!(deferred, HashSet::from(["app:absolute".to_string()]));
}

#[test]
fn does_not_defer_for_an_output_in_a_nested_project_the_glob_skips() {
let pool = InstructionPool::new();
Expand Down
8 changes: 4 additions & 4 deletions packages/nx/src/native/tasks/task_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,9 @@ impl TaskHasher {
/// Like `hash_plans`, but only for the plans the planner did not defer
/// (`HashPlans::deferred`: a task that reads another task's outputs, or a
/// disk-backed fileset whose directory contains, or sits inside, an
/// upstream task's output). The rest are left out and hash once those
/// tasks have run; their ids are absent from the result and need no entry
/// in `per_task_envs`.
/// upstream task's output, or one that hashes its absolute cwd). The rest
/// are left out and hash where they run; their ids are absent from the
/// result and need no entry in `per_task_envs`.
#[napi(ts_return_type = "Record<string, HashDetails>")]
pub fn hash_plans_upfront(
&self,
Expand All @@ -618,7 +618,7 @@ impl TaskHasher {
let partition_duration = function_start.elapsed();
let (upfront_count, total_count) = (plans.len(), hash_plans.plans.len());
trace!(
"hash_plans_upfront: {} of {} plans hash up front, {} wait for other tasks' outputs (partition: {:?})",
"hash_plans_upfront: {} of {} plans hash up front, {} deferred (partition: {:?})",
upfront_count,
total_count,
total_count - upfront_count,
Expand Down
7 changes: 4 additions & 3 deletions packages/nx/src/native/tasks/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,10 @@ impl InstructionPool {
pub struct HashPlans {
pub pool: Arc<InstructionPool>,
pub plans: HashMap<String, Vec<u32>>,
/// Tasks the up-front batch leaves out: the directory a disk-backed
/// fileset of theirs reads from contains, or sits inside, an output a
/// task they depend on declares.
/// Tasks the up-front batch leaves out: they read a dependent task's
/// outputs, the directory a disk-backed fileset of theirs reads from
/// contains, or sits inside, an output a task they depend on declares, or
/// they hash their absolute cwd.
pub deferred: std::collections::HashSet<String>,
}

Expand Down
Loading