Skip to content

Commit

Permalink
Detect conflicting index store units. Closes #462 (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
ileitch authored Nov 20, 2022
1 parent 034f0f3 commit a1696ea
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
]

Expand Down
6 changes: 5 additions & 1 deletion Sources/PeripheryKit/Indexer/SwiftIndexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ public final class SwiftIndexer {
let jobs = try unitsByFile.map { (file, units) -> Job in
let modules = try units.reduce(into: Set<String>()) { (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)
Expand Down
9 changes: 9 additions & 0 deletions Sources/Shared/PeripheryError.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import SystemPackage

public enum PeripheryError: Error, LocalizedError, CustomStringConvertible {
case shellCommandFailed(cmd: String, args: [String], status: Int32, output: String)
Expand All @@ -20,6 +21,7 @@ public enum PeripheryError: Error, LocalizedError, CustomStringConvertible {
case unindexedTargetsError(targets: Set<String>, indexStorePath: String)
case jsonDeserializationError(error: Error, json: String)
case indexStoreNotFound(derivedDataPath: String)
case conflictingIndexUnitsError(file: FilePath, module: String, unitTargets: Set<String>)

public var errorDescription: String? {
switch self {
Expand Down Expand Up @@ -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: " ")
}
}

Expand Down

0 comments on commit a1696ea

Please sign in to comment.