fix(run): skip SourcePackages, Pods, Carthage and DerivedData when discovering run configurations (#7263)

Run configuration discovery walks three levels deep and its shared skip list only knew node_modules, target, build and a few others, so an iOS project with resolved Swift packages in SourcePackages/checkouts listed every dependency's Rakefiles, CMake targets, Makefiles, Swift packages and Xcode schemes (252 configurations on a real Tuist app, 218 of them from dependencies).

project_roots now exposes the skip list as is_skipped_dir and adds SourcePackages, Pods, Carthage and DerivedData. Xcode's project_stamp uses the same list (plus Tuist) instead of its own copy, so build discovery, run discovery and the settings stamp agree on one list.

Fixes #7261

Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
LU XIANGRUIтаwildcatDownstairs authored and GitHub committed 2026-12-02 00:04:22 +08:00
1 джерело 3e41c93a95
коміт 2a4bf1f848
3 files changed
+58 -14

No files matched your search

+24 -7
Переглянути файл
@@ -5,6 +5,29 @@ use std::path::{Component, Path, PathBuf};
pub const SEARCH_DEPTH: usize = 3;
/// Folders that hold dependencies or build output rather than the project's own builds: hidden
/// folders (`.build`, `.git`), package checkouts (`node_modules`, `SourcePackages`, `Pods`,
/// `Carthage`) and build products (`target`, `build`, `DerivedData`, …).
pub fn is_skipped_dir(name: &str) -> bool {
name.starts_with('.')
|| matches!(
name,
"node_modules"
| "target"
| "build"
| "dist"
| "vendor"
| "out"
| "bin"
| "obj"
| "venv"
| "SourcePackages"
| "Pods"
| "Carthage"
| "DerivedData"
)
}
pub fn children(dir: &Path) -> Vec<PathBuf> {
let Ok(entries) = std::fs::read_dir(dir) else { return Vec::new() };
let mut dirs: Vec<_> = entries
@@ -13,13 +36,7 @@ pub fn children(dir: &Path) -> Vec<PathBuf> {
if !entry.file_type().is_ok_and(|kind| kind.is_dir()) {
return false;
}
let name = entry.file_name();
let name = name.to_string_lossy();
!name.starts_with('.')
&& !matches!(
name.as_ref(),
"node_modules" | "target" | "build" | "dist" | "vendor" | "out" | "bin" | "obj" | "venv"
)
!is_skipped_dir(&entry.file_name().to_string_lossy())
})
.map(|entry| entry.path())
.collect();
+30
Переглянути файл
@@ -1846,4 +1846,34 @@ mod tests {
assert!(configs.iter().all(|c| c.command == "UE/UnrealEditor.exe" && c.cwd.is_none()));
assert!(configs.iter().all(|c| c.debug_adapter.as_deref() == Some("lldb-dap") && c.kind == "unreal"));
}
#[test]
fn dependency_and_build_folders_contribute_no_configurations() {
let dir = tempfile::tempdir().unwrap();
let root = dir.path();
let write = |path: &str, text: &str| {
let path = root.join(path);
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(path, text).unwrap();
};
let scheme = fs::read_to_string(
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/xcode/App.xcodeproj/xcshareddata/xcschemes/App.xcscheme"),
)
.unwrap();
let package = "// swift-tools-version:5.9\nimport PackageDescription\nlet package = Package(\n name: \"Tool\",\n products: [.executable(name: \"tool\", targets: [\"Tool\"])],\n targets: [.executableTarget(name: \"Tool\")]\n)\n";
write("App.xcodeproj/xcshareddata/xcschemes/App.xcscheme", &scheme);
write("Packages/Tool/Package.swift", package);
write("SourcePackages/checkouts/lib/Rakefile", "task :build do\nend\n");
write("SourcePackages/checkouts/lib/Package.swift", package);
write("Pods/Pods.xcodeproj/xcshareddata/xcschemes/Pod.xcscheme", &scheme);
write("Carthage/Checkouts/lib/Makefile", "all:\n\ttrue\n");
write("DerivedData/App/SourcePackages/checkouts/lib/Package.swift", package);
let mut ids: Vec<_> = detect(root).into_iter().map(|c| c.id).collect();
ids.sort();
assert_eq!(
ids,
["swiftpm:run:tool:Packages/Tool", "xcode:run:App.xcodeproj:App", "xcode:test:App.xcodeproj:App"]
);
}
}
+4 -7
Переглянути файл
@@ -503,14 +503,11 @@ fn cached_settings(
Ok(settings)
}
/// Folders [`project_stamp`] doesn't look into: dependencies and build output.
const UNSTAMPED_DIRS: [&str; 7] =
["SourcePackages", "Pods", "Carthage", "DerivedData", "build", "node_modules", "Tuist"];
/// A hash of the paths and modification times of the files in `dir` that decide build settings:
/// `project.pbxproj`, `contents.xcworkspacedata`, `*.xcscheme`, `*.xcconfig` and
/// `Package.resolved`, four levels deep, outside hidden and [`UNSTAMPED_DIRS`] folders. A change
/// there (Tuist or XcodeGen regenerating the project, an edited xcconfig) reads the settings again.
/// `Package.resolved`, four levels deep, outside `Tuist` and the folders discovery skips
/// ([`ide_core::project_roots::is_skipped_dir`]). A change there (Tuist or XcodeGen regenerating
/// the project, an edited xcconfig) reads the settings again.
/// An xcconfig deeper than that, or an `#include` from outside `dir`, is missed until the IDE restarts.
pub fn project_stamp(dir: &Path) -> u64 {
use std::hash::{Hash, Hasher};
@@ -523,7 +520,7 @@ pub fn project_stamp(dir: &Path) -> u64 {
let name = name.to_string_lossy();
let Ok(meta) = entry.metadata() else { continue };
if meta.is_dir() {
if depth > 1 && !name.starts_with('.') && !UNSTAMPED_DIRS.contains(&name.as_ref()) {
if depth > 1 && name != "Tuist" && !ide_core::project_roots::is_skipped_dir(&name) {
walk(&entry.path(), depth - 1, hasher);
}
} else if name == "project.pbxproj"