Make CocoaPods an attribute of the Graph model

This commit is contained in:
Pedro Piñera 2020-03-23 19:32:01 +01:00
parent 1a9b2a840d
commit 8dc7d4df27
5 changed files with 12 additions and 14 deletions

View File

@ -28,11 +28,13 @@ public class Graph: Encodable {
public let name: String public let name: String
public let entryPath: AbsolutePath public let entryPath: AbsolutePath
public let entryNodes: [GraphNode] public let entryNodes: [GraphNode]
/// Projects that are part of the graph. /// Dictionary whose keys are paths to directories where projects are defined, and the values are the representation of the projects.
public var projects: [AbsolutePath: Project] public var projects: [AbsolutePath: Project]
/// Dictionary whose keys are paths to directories where projects are defined, and the values are the CocoaPods nodes define in them.
public var cocoapods: [AbsolutePath: CocoaPodsNode]
// MARK: - Init // MARK: - Init
public convenience init(name: String, entryPath: AbsolutePath, cache: GraphLoaderCaching) { public convenience init(name: String, entryPath: AbsolutePath, cache: GraphLoaderCaching) {
@ -50,7 +52,8 @@ public class Graph: Encodable {
self.entryPath = entryPath self.entryPath = entryPath
self.cache = cache self.cache = cache
self.entryNodes = entryNodes self.entryNodes = entryNodes
self.projects = cache.projects projects = cache.projects
cocoapods = cache.cocoapodsNodes
} }
// MARK: - Encodable // MARK: - Encodable
@ -67,11 +70,6 @@ public class Graph: Encodable {
// MARK: - Graphing // MARK: - Graphing
/// Returns all the CocoaPods nodes that are part of the graph.
public var cocoapods: [CocoaPodsNode] {
Array(cache.cocoapodsNodes.values)
}
/// Returns all the SwiftPM package nodes that are part of the graph. /// Returns all the SwiftPM package nodes that are part of the graph.
public var packages: [PackageNode] { public var packages: [PackageNode] {
cache.packages.values.flatMap { $0 } cache.packages.values.flatMap { $0 }

View File

@ -68,6 +68,7 @@ public extension Graph {
} }
let cache = GraphLoaderCache() let cache = GraphLoaderCache()
projects.forEach(cache.add(project:))
let graph = Graph.test(name: projects.first?.name ?? "Test", let graph = Graph.test(name: projects.first?.name ?? "Test",
entryPath: projects.first?.path ?? AbsolutePath("/test/path"), entryPath: projects.first?.path ?? AbsolutePath("/test/path"),
cache: cache, cache: cache,

View File

@ -156,7 +156,7 @@ public class GraphLinter: GraphLinting {
/// - Parameter graph: Project graph. /// - Parameter graph: Project graph.
/// - Returns: Linting issues. /// - Returns: Linting issues.
private func lintCocoaPodsDependencies(graph: Graph) -> [LintingIssue] { private func lintCocoaPodsDependencies(graph: Graph) -> [LintingIssue] {
graph.cocoapods.compactMap { node in graph.cocoapods.values.compactMap { node in
let podfilePath = node.podfilePath let podfilePath = node.podfilePath
if !FileHandler.shared.exists(podfilePath) { if !FileHandler.shared.exists(podfilePath) {
return LintingIssue(reason: "The Podfile at path \(podfilePath) referenced by some projects does not exist", severity: .error) return LintingIssue(reason: "The Podfile at path \(podfilePath) referenced by some projects does not exist", severity: .error)

View File

@ -64,7 +64,7 @@ public final class CocoaPodsInteractor: CocoaPodsInteracting {
let canUseBundler = canUseCocoaPodsThroughBundler() let canUseBundler = canUseCocoaPodsThroughBundler()
let canUseSystem = canUseSystemPod() let canUseSystem = canUseSystemPod()
try graph.cocoapods.forEach { node in try graph.cocoapods.values.forEach { node in
var command: [String] var command: [String]
if canUseBundler { if canUseBundler {

View File

@ -38,8 +38,7 @@ final class WorkspaceGeneratorIntegrationTests: TuistTestCase {
(project: project, target: target, dependencies: []) (project: project, target: target, dependencies: [])
} }
}) })
let workspace = Workspace.test(path: temporaryPath, let workspace = Workspace.test(path: temporaryPath, projects: projects.map(\.path))
projects: projects.map(\.path))
// When / Then // When / Then
try (0 ..< 50).forEach { _ in try (0 ..< 50).forEach { _ in