diff --git a/CHANGELOG.md b/CHANGELOG.md index 4105cd5e9..0b3ed77e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ ##### Enhancements -- None. +- Add support for indexing plist files via the generic `--file-targets-path` option. ##### Bug Fixes diff --git a/Sources/PeripheryKit/Generic/GenericProjectDriver.swift b/Sources/PeripheryKit/Generic/GenericProjectDriver.swift index 236ec81f1..0e61f4b24 100644 --- a/Sources/PeripheryKit/Generic/GenericProjectDriver.swift +++ b/Sources/PeripheryKit/Generic/GenericProjectDriver.swift @@ -3,42 +3,49 @@ import SystemPackage import Shared public final class GenericProjectDriver { + private enum FileKind: String { + case swift + case plist + } + public static func build() throws -> Self { let configuration = Configuration.shared let decoder = JSONDecoder() decoder.keyDecodingStrategy = .convertFromSnakeCase let sourceFiles = try configuration.fileTargetsPath - .reduce(into: [FilePath: Set]()) { result, mapPath in + .reduce(into: [FileKind: [FilePath: Set]]()) { result, mapPath in guard mapPath.exists else { throw PeripheryError.pathDoesNotExist(path: mapPath.string) } let data = try Data(contentsOf: mapPath.url) - let map = try decoder + try decoder .decode(FileTargetMapContainer.self, from: data) .fileTargets - .reduce(into: [FilePath: Set](), { (result, tuple) in - let (key, value) = tuple + .forEach { key, value in let path = FilePath.makeAbsolute(key) if !path.exists { throw PeripheryError.pathDoesNotExist(path: path.string) } + guard let ext = path.extension, let fileKind = FileKind(rawValue: ext) else { + throw PeripheryError.unsupportedFileKind(path: path) + } + let indexTargets = value.mapSet { IndexTarget(name: $0) } - result[path] = indexTargets - }) - result.merge(map) { $0.union($1) } + result[fileKind, default: [:]][path, default: []].formUnion(indexTargets) + } } return self.init(sourceFiles: sourceFiles, configuration: configuration) } - private let sourceFiles: [FilePath: Set] + private let sourceFiles: [FileKind: [FilePath: Set]] private let configuration: Configuration - init(sourceFiles: [FilePath: Set], configuration: Configuration) { + private init(sourceFiles: [FileKind: [FilePath: Set]], configuration: Configuration) { self.sourceFiles = sourceFiles self.configuration = configuration } @@ -48,7 +55,14 @@ extension GenericProjectDriver: ProjectDriver { public func build() throws {} public func index(graph: SourceGraph) throws { - try SwiftIndexer(sourceFiles: sourceFiles, graph: graph, indexStorePaths: configuration.indexStorePath).perform() + if let swiftFiles = sourceFiles[.swift] { + try SwiftIndexer(sourceFiles: swiftFiles, graph: graph, indexStorePaths: configuration.indexStorePath).perform() + } + + if let plistFiles = sourceFiles[.plist] { + try InfoPlistIndexer(infoPlistFiles: Set(plistFiles.keys), graph: graph).perform() + } + graph.indexingComplete() } } diff --git a/Sources/Shared/PeripheryError.swift b/Sources/Shared/PeripheryError.swift index d42156be4..0428f888e 100644 --- a/Sources/Shared/PeripheryError.swift +++ b/Sources/Shared/PeripheryError.swift @@ -20,6 +20,7 @@ public enum PeripheryError: Error, LocalizedError, CustomStringConvertible { case unindexedTargetsError(targets: Set, indexStorePaths: [FilePath]) case jsonDeserializationError(error: Error, json: String) case indexStoreNotFound(derivedDataPath: String) + case unsupportedFileKind(path: FilePath) public var errorDescription: String? { switch self { @@ -65,6 +66,8 @@ 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 .unsupportedFileKind(path): + return "Unsupported file kind '\(path)'." } }