diff --git a/CHANGELOG.md b/CHANGELOG.md index b804937b0..23111cd7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Workaround Swift shorthand if-let syntax bug (https://github.com/apple/swift/issues/61509). Global properties are not handled by this workaround. - Fix retaining inferred associated types. - Fix redundant public accessibility analysis for types used in closure signatures. +- Conflicting index store units are now detected and result in an error. ## 2.10.0 (2022-10-10) diff --git a/Package.resolved b/Package.resolved index d8db9bc73..e2c54cc61 100644 --- a/Package.resolved +++ b/Package.resolved @@ -39,11 +39,11 @@ }, { "package": "SwiftIndexStore", - "repositoryURL": "https://github.com/kateinoigakukun/swift-indexstore", + "repositoryURL": "https://github.com/ileitch/swift-indexstore", "state": { "branch": null, - "revision": "ea41d13796dbbc4dc36d97ba5edb20a021aaf4e4", - "version": "0.1.5" + "revision": "f4e55301ca7d6d25057c514bea0e7407a1620f5f", + "version": null } }, { diff --git a/Package.swift b/Package.swift index 1ecab8e8c..f10e063e3 100644 --- a/Package.swift +++ b/Package.swift @@ -6,7 +6,7 @@ var dependencies: [Package.Dependency] = [ .package(url: "https://github.com/jpsim/Yams", from: "5.0.0"), .package(url: "https://github.com/tadija/AEXML", from: "4.0.0"), .package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"), - .package(name: "SwiftIndexStore", url: "https://github.com/kateinoigakukun/swift-indexstore", from: "0.0.0"), + .package(name: "SwiftIndexStore", url: "https://github.com/ileitch/swift-indexstore", .revision("f4e55301ca7d6d25057c514bea0e7407a1620f5f")), .package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", .revision("a82041008d2c678a97407fbd0ce420d3ab047538")) ] diff --git a/Sources/PeripheryKit/Indexer/SwiftIndexer.swift b/Sources/PeripheryKit/Indexer/SwiftIndexer.swift index c08a03511..3b84f70ec 100644 --- a/Sources/PeripheryKit/Indexer/SwiftIndexer.swift +++ b/Sources/PeripheryKit/Indexer/SwiftIndexer.swift @@ -75,7 +75,11 @@ public final class SwiftIndexer { let jobs = try unitsByFile.map { (file, units) -> Job in let modules = try units.reduce(into: Set()) { (set, unit) in if let name = try indexStore.moduleName(for: unit) { - set.insert(name) + let (didInsert, _) = set.insert(name) + if !didInsert { + let targets = try Set(units.compactMap { try indexStore.target(for: $0) }) + throw PeripheryError.conflictingIndexUnitsError(file: file, module: name, unitTargets: targets) + } } } let sourceFile = SourceFile(path: file, modules: modules) diff --git a/Sources/Shared/PeripheryError.swift b/Sources/Shared/PeripheryError.swift index 3bea79bf4..002840da3 100644 --- a/Sources/Shared/PeripheryError.swift +++ b/Sources/Shared/PeripheryError.swift @@ -1,4 +1,5 @@ import Foundation +import SystemPackage public enum PeripheryError: Error, LocalizedError, CustomStringConvertible { case shellCommandFailed(cmd: String, args: [String], status: Int32, output: String) @@ -20,6 +21,7 @@ public enum PeripheryError: Error, LocalizedError, CustomStringConvertible { case unindexedTargetsError(targets: Set, indexStorePath: String) case jsonDeserializationError(error: Error, json: String) case indexStoreNotFound(derivedDataPath: String) + case conflictingIndexUnitsError(file: FilePath, module: String, unitTargets: Set) public var errorDescription: String? { switch self { @@ -68,6 +70,13 @@ public enum PeripheryError: Error, LocalizedError, CustomStringConvertible { return "JSON deserialization failed: \(describe(error))\nJSON:\n\(json)" case let .indexStoreNotFound(derivedDataPath): return "Failed to find index datastore at path: \(derivedDataPath)" + case let .conflictingIndexUnitsError(file, module, targets): + var parts = ["Found conflicting index store units for '\(file)' in module '\(module)'."] + if targets.count > 1 { + parts.append("The units have conflicting build targets: \(targets.sorted().joined(separator: ", ")).") + } + parts.append("If you passed the '--index-store-path' option, ensure that Xcode is not open with a project that may write to this index store while Periphery is running.") + return parts.joined(separator: " ") } }