Skip to content

Commit bf256b9

Browse files
authored
Support for the change of indexStorePath for Xcode 14 (#523)
1 parent 242ebf4 commit bf256b9

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
##### Enhancements
88

99
- Add `--report-include` option to filter reported violations with an allowlist.
10+
- Support for reading Xcode 14 generated index stores.
1011

1112
##### Bug Fixes
1213

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ Note that when using `--skip-build` and `--index-store-path` it's vital that the
408408

409409
### Xcode
410410

411-
The index store generated by `xcodebuild` exists in DerivedData at a location dependent on your project, e.g `~/Library/Developer/Xcode/DerivedData/YourProject-abc123/Index/DataStore`.
411+
The index store generated by `xcodebuild` exists in DerivedData at a location dependent on your project, e.g `~/Library/Developer/Xcode/DerivedData/YourProject-abc123/Index/DataStore`. For Xcode 14 and later, the `Index` directory can be found as `Index.noindex`, which suppresses Spotlight indexing.
412412

413413
### SwiftPM
414414

Sources/Shared/PeripheryError.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public enum PeripheryError: Error, LocalizedError, CustomStringConvertible {
1919
case swiftVersionUnsupportedError(version: String, minimumVersion: String)
2020
case unindexedTargetsError(targets: Set<String>, indexStorePath: String)
2121
case jsonDeserializationError(error: Error, json: String)
22+
case indexStoreNotFound(derivedDataPath: String)
2223

2324
public var errorDescription: String? {
2425
switch self {
@@ -65,6 +66,8 @@ public enum PeripheryError: Error, LocalizedError, CustomStringConvertible {
6566
return "This version of Periphery only supports Swift >= \(minimumVersion), you're using \(version)."
6667
case let .jsonDeserializationError(error, json):
6768
return "JSON deserialization failed: \(describe(error))\nJSON:\n\(json)"
69+
case let .indexStoreNotFound(derivedDataPath):
70+
return "Failed to find index datastore at path: \(derivedDataPath)"
6871
}
6972
}
7073

Sources/XcodeSupport/Xcodebuild.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ public final class Xcodebuild: Injectable {
5151
}
5252

5353
func indexStorePath(project: XcodeProjectlike, schemes: [XcodeScheme]) throws -> String {
54-
(try derivedDataPath(for: project, schemes: schemes).appending("Index/DataStore")).string
54+
let derivedDataPath = try derivedDataPath(for: project, schemes: schemes)
55+
let pathsToTry = ["Index/DataStore", "Index.noindex/DataStore"]
56+
.map { derivedDataPath.appending($0).string }
57+
guard let path = pathsToTry.first(where: { path in
58+
return FileManager.default.fileExists(atPath: path)
59+
}) else {
60+
throw PeripheryError.indexStoreNotFound(derivedDataPath: derivedDataPath.string)
61+
}
62+
return path
5563
}
5664

5765
func schemes(project: XcodeProjectlike) throws -> [String] {

0 commit comments

Comments
 (0)