From 8dc7d4df277042b5b68d8e9d83eabc64519a45cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Pi=C3=B1era?= Date: Mon, 23 Mar 2020 19:32:01 +0100 Subject: [PATCH] Make CocoaPods an attribute of the Graph model --- Sources/TuistCore/Graph/Graph.swift | 18 ++++++++---------- .../Graph/Graph+TestData.swift | 1 + .../TuistGenerator/Linter/GraphLinter.swift | 2 +- .../Utils/CocoaPodsInteractor.swift | 2 +- .../WorkspaceGeneratorIntegrationTests.swift | 3 +-- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Sources/TuistCore/Graph/Graph.swift b/Sources/TuistCore/Graph/Graph.swift index 144b81a15..09fe73808 100644 --- a/Sources/TuistCore/Graph/Graph.swift +++ b/Sources/TuistCore/Graph/Graph.swift @@ -28,11 +28,13 @@ public class Graph: Encodable { public let name: String public let entryPath: AbsolutePath 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] - - + + /// 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 public convenience init(name: String, entryPath: AbsolutePath, cache: GraphLoaderCaching) { @@ -50,7 +52,8 @@ public class Graph: Encodable { self.entryPath = entryPath self.cache = cache self.entryNodes = entryNodes - self.projects = cache.projects + projects = cache.projects + cocoapods = cache.cocoapodsNodes } // MARK: - Encodable @@ -67,11 +70,6 @@ public class Graph: Encodable { // 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. public var packages: [PackageNode] { cache.packages.values.flatMap { $0 } diff --git a/Sources/TuistCoreTesting/Graph/Graph+TestData.swift b/Sources/TuistCoreTesting/Graph/Graph+TestData.swift index 318668b7b..a58c9d98c 100644 --- a/Sources/TuistCoreTesting/Graph/Graph+TestData.swift +++ b/Sources/TuistCoreTesting/Graph/Graph+TestData.swift @@ -68,6 +68,7 @@ public extension Graph { } let cache = GraphLoaderCache() + projects.forEach(cache.add(project:)) let graph = Graph.test(name: projects.first?.name ?? "Test", entryPath: projects.first?.path ?? AbsolutePath("/test/path"), cache: cache, diff --git a/Sources/TuistGenerator/Linter/GraphLinter.swift b/Sources/TuistGenerator/Linter/GraphLinter.swift index cd8366e69..eb7c91b42 100644 --- a/Sources/TuistGenerator/Linter/GraphLinter.swift +++ b/Sources/TuistGenerator/Linter/GraphLinter.swift @@ -156,7 +156,7 @@ public class GraphLinter: GraphLinting { /// - Parameter graph: Project graph. /// - Returns: Linting issues. private func lintCocoaPodsDependencies(graph: Graph) -> [LintingIssue] { - graph.cocoapods.compactMap { node in + graph.cocoapods.values.compactMap { node in let podfilePath = node.podfilePath if !FileHandler.shared.exists(podfilePath) { return LintingIssue(reason: "The Podfile at path \(podfilePath) referenced by some projects does not exist", severity: .error) diff --git a/Sources/TuistGenerator/Utils/CocoaPodsInteractor.swift b/Sources/TuistGenerator/Utils/CocoaPodsInteractor.swift index f8b1d84b8..5026357fd 100644 --- a/Sources/TuistGenerator/Utils/CocoaPodsInteractor.swift +++ b/Sources/TuistGenerator/Utils/CocoaPodsInteractor.swift @@ -64,7 +64,7 @@ public final class CocoaPodsInteractor: CocoaPodsInteracting { let canUseBundler = canUseCocoaPodsThroughBundler() let canUseSystem = canUseSystemPod() - try graph.cocoapods.forEach { node in + try graph.cocoapods.values.forEach { node in var command: [String] if canUseBundler { diff --git a/Tests/TuistGeneratorIntegrationTests/Generator/WorkspaceGeneratorIntegrationTests.swift b/Tests/TuistGeneratorIntegrationTests/Generator/WorkspaceGeneratorIntegrationTests.swift index 2e91509aa..2bb968328 100644 --- a/Tests/TuistGeneratorIntegrationTests/Generator/WorkspaceGeneratorIntegrationTests.swift +++ b/Tests/TuistGeneratorIntegrationTests/Generator/WorkspaceGeneratorIntegrationTests.swift @@ -38,8 +38,7 @@ final class WorkspaceGeneratorIntegrationTests: TuistTestCase { (project: project, target: target, dependencies: []) } }) - let workspace = Workspace.test(path: temporaryPath, - projects: projects.map(\.path)) + let workspace = Workspace.test(path: temporaryPath, projects: projects.map(\.path)) // When / Then try (0 ..< 50).forEach { _ in