selectProjectBuildRunnerPids function
Selects the build_runner PIDs that belong to projectDir.
pkill -f build_runner matched EVERY build_runner on the machine — another
checkout, a teammate's session on a shared box, a sibling job on the same CI
runner. build_runner is normally launched with the project as its working
directory (the project path rarely appears in argv, so cwd is the reliable
signal), and the lock it contends for is per-project anyway.
pidToCwd maps pid → that process's working directory.
Implementation
List<String> selectProjectBuildRunnerPids(Map<String, String> pidToCwd, String projectDir) {
final root = p.canonicalize(projectDir);
return [
for (final MapEntry(key: pid, value: cwd) in pidToCwd.entries)
if (cwd.isNotEmpty && p.equals(p.canonicalize(cwd), root) || p.isWithin(root, p.canonicalize(cwd))) pid,
];
}