Repository navigation
Read custom target paths from Package.swift for project index modules - #2910
Merged
calda merged 1 commit intoNov 14, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2910 +/- ##
========================================
Coverage 96.13% 96.13%
========================================
Files 206 206
Lines 35512 35538 +26
========================================
+ Hits 34140 34166 +26
Misses 1372 1372 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
calda
approved these changes
Nov 14, 2026
nicklockwood
pushed a commit
that referenced
this pull request
Nov 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a Swift package whose target uses a custom
path:, files get no module in the project index, so the index-aware rules fall back to their single-file heuristics. WithpropertyTypesthat produces code that doesn't compile. SwiftFormat's own repo is an example (.target(name: "SwiftFormat", path: "Sources")):cacheVersionisstatic let cacheVersion = 12inProjectIndex.swift. With a conventional layout (Sources/<Target>/...), or with noPackage.swiftat all, the index knows that and the line is left alone. A minimal package shows the same thing:moduleIdentifiers(for:in:)only assigned a module to files atSources/<Target>/orTests/<Target>/. Anything else got none, andpropertyTypeContext()then builds an index of the current file only.The change:
swiftPackageTargetPaths(in:)reads thepath:argument of target declarations (.target,.executableTarget,.testTarget,.macro,.plugin,.systemLibrary) inPackage.swift..package(path:)dependencies, absolute paths and paths with..are ignored. A target whose arguments can't be read this simply (for example a.product(...)dependency beforepath:) keeps the old convention, so the result is never less conservative than before.Package.swiftis now part of the project index configuration hashes, so changing a target path invalidates the cached snapshot like an Xcode project change does.Tests: a package with
path: "Sources"(a file directly inSources/and one inSources/Rules/get the same module),path: "./Tool/", a conventional test target and an unrelated directory;.package(path:)entries being ignored; and the manifest hash. They fail on develop (4 failures). The full suite passes (7635 tests).Found by formatting SwiftFormat's own
Sourceswith all rules enabled (except the ones that are opt-in for known reasons, likepreferSwiftStringAPI) and building it: the threecacheVersionerrors were the only build failures, and the build is clean with this change.