From 2a4bf1f8480434f80e801e8009068554ba33238b Mon Sep 17 00:00:00 2001 From: LU XIANGRUI <1078666705@qq.com> Date: Wed, 2 Dec 2026 01:04:22 +0900 Subject: [PATCH] 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 <26499420+wildcatDownstairs@users.noreply.github.com> --- crates/ide-core/src/project_roots.rs | 31 +++++++++++++++++++++------- crates/ide-run/src/detect.rs | 30 +++++++++++++++++++++++++++ crates/ide-run/src/xcode.rs | 11 ++++------ 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/crates/ide-core/src/project_roots.rs b/crates/ide-core/src/project_roots.rs index 58ccaa822c..e19686c643 100644 --- a/crates/ide-core/src/project_roots.rs +++ b/crates/ide-core/src/project_roots.rs @@ -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 { 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 { 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(); diff --git a/crates/ide-run/src/detect.rs b/crates/ide-run/src/detect.rs index a51a1bb66a..e31f16232a 100644 --- a/crates/ide-run/src/detect.rs +++ b/crates/ide-run/src/detect.rs @@ -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"] + ); + } } diff --git a/crates/ide-run/src/xcode.rs b/crates/ide-run/src/xcode.rs index e0aebc55a5..2304841bf2 100644 --- a/crates/ide-run/src/xcode.rs +++ b/crates/ide-run/src/xcode.rs @@ -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"