Make cocoapods a weak array
This commit is contained in:
parent
6dccd9700e
commit
437879c428
|
@ -37,7 +37,8 @@ public class Graph: Encodable {
|
|||
public let 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 let cocoapods: [AbsolutePath: CocoaPodsNode]
|
||||
/// If none of the nodes of the graph references a CocoaPods node, the node gets released from memory.
|
||||
public let cocoapods: WeakArray<CocoaPodsNode>
|
||||
|
||||
/// Dictionary whose keys are path to directories where projects are defined, and the values are packages defined in that project.
|
||||
public let packages: [AbsolutePath: [PackageNode]]
|
||||
|
@ -58,7 +59,7 @@ public class Graph: Encodable {
|
|||
entryPath: entryPath,
|
||||
entryNodes: entryNodes,
|
||||
projects: cache.projects,
|
||||
cocoapods: cache.cocoapodsNodes,
|
||||
cocoapods: Array(cache.cocoapodsNodes.values),
|
||||
packages: cache.packages,
|
||||
precompiled: cache.precompiledNodes,
|
||||
targets: cache.targetNodes)
|
||||
|
@ -68,7 +69,7 @@ public class Graph: Encodable {
|
|||
entryPath: AbsolutePath,
|
||||
entryNodes: [GraphNode],
|
||||
projects: [AbsolutePath: Project],
|
||||
cocoapods: [AbsolutePath: CocoaPodsNode],
|
||||
cocoapods: [CocoaPodsNode],
|
||||
packages: [AbsolutePath: [PackageNode]],
|
||||
precompiled: [AbsolutePath: PrecompiledNode],
|
||||
targets: [AbsolutePath: [String: TargetNode]]) {
|
||||
|
@ -76,7 +77,7 @@ public class Graph: Encodable {
|
|||
self.entryPath = entryPath
|
||||
self.entryNodes = entryNodes
|
||||
self.projects = projects
|
||||
self.cocoapods = cocoapods
|
||||
self.cocoapods = WeakArray(cocoapods)
|
||||
self.packages = packages
|
||||
self.precompiled = precompiled
|
||||
self.targets = targets
|
||||
|
|
|
@ -7,7 +7,7 @@ public extension Graph {
|
|||
entryPath: AbsolutePath = AbsolutePath("/test/graph"),
|
||||
entryNodes: [GraphNode] = [],
|
||||
projects: [AbsolutePath: Project] = [:],
|
||||
cocoapods: [AbsolutePath: CocoaPodsNode] = [:],
|
||||
cocoapods: [CocoaPodsNode] = [],
|
||||
packages: [AbsolutePath: [PackageNode]] = [:],
|
||||
precompiled: [AbsolutePath: PrecompiledNode] = [:],
|
||||
targets: [AbsolutePath: [String: TargetNode]] = [:]) -> Graph {
|
||||
|
|
|
@ -156,7 +156,8 @@ public class GraphLinter: GraphLinting {
|
|||
/// - Parameter graph: Project graph.
|
||||
/// - Returns: Linting issues.
|
||||
private func lintCocoaPodsDependencies(graph: Graph) -> [LintingIssue] {
|
||||
graph.cocoapods.values.compactMap { node in
|
||||
graph.cocoapods.compactMap { node in
|
||||
guard let node = node else { return nil }
|
||||
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)
|
||||
|
|
|
@ -64,7 +64,8 @@ public final class CocoaPodsInteractor: CocoaPodsInteracting {
|
|||
let canUseBundler = canUseCocoaPodsThroughBundler()
|
||||
let canUseSystem = canUseSystemPod()
|
||||
|
||||
try graph.cocoapods.values.forEach { node in
|
||||
try graph.cocoapods.forEach { node in
|
||||
guard let node = node else { return }
|
||||
var command: [String]
|
||||
|
||||
if canUseBundler {
|
||||
|
|
|
@ -98,7 +98,7 @@ final class ProjectEditorMapper: ProjectEditorMapping {
|
|||
entryPath: sourceRootPath,
|
||||
entryNodes: [],
|
||||
projects: [sourceRootPath: project],
|
||||
cocoapods: [:],
|
||||
cocoapods: [],
|
||||
packages: [:],
|
||||
precompiled: [:],
|
||||
targets: [sourceRootPath: nodes])
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
import Foundation
|
||||
|
||||
public struct WeakArray<Element: AnyObject>: Collection {
|
||||
private var items: [WeakBox<Element>] = []
|
||||
|
||||
public init(_ elements: [Element]) {
|
||||
items = elements.map { WeakBox($0) }
|
||||
}
|
||||
|
||||
// MARK: - Collection
|
||||
|
||||
public var startIndex: Int { return items.startIndex }
|
||||
public var endIndex: Int { return items.endIndex }
|
||||
|
||||
public subscript(_ index: Int) -> Element? {
|
||||
return items[index].value
|
||||
}
|
||||
|
||||
public func index(after idx: Int) -> Int {
|
||||
return items.index(after: idx)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
import Foundation
|
||||
|
||||
public class WeakBox<Element: AnyObject> {
|
||||
public weak var value: Element?
|
||||
public init(_ value: Element) {
|
||||
self.value = value
|
||||
}
|
||||
}
|
|
@ -36,7 +36,7 @@ final class GraphContentHasherTests: XCTestCase {
|
|||
let graph = Graph.test(entryPath: path,
|
||||
entryNodes: [],
|
||||
projects: [:],
|
||||
cocoapods: [:],
|
||||
cocoapods: [],
|
||||
packages: [:],
|
||||
precompiled: [:],
|
||||
targets: [path: [
|
||||
|
|
|
@ -44,7 +44,7 @@ final class GraphLinterTests: TuistUnitTestCase {
|
|||
// Given
|
||||
let temporaryPath = try self.temporaryPath()
|
||||
let cocoapods = CocoaPodsNode(path: temporaryPath)
|
||||
let graph = Graph.test(cocoapods: [cocoapods.path: cocoapods])
|
||||
let graph = Graph.test(cocoapods: [cocoapods])
|
||||
let podfilePath = temporaryPath.appending(component: "Podfile")
|
||||
|
||||
// When
|
||||
|
|
|
@ -38,7 +38,7 @@ final class CocoaPodsInteractorTests: TuistUnitTestCase {
|
|||
throw NSError.test()
|
||||
}
|
||||
let cocoapods = CocoaPodsNode.test()
|
||||
let graph = Graph.test(cocoapods: [cocoapods.path: cocoapods])
|
||||
let graph = Graph.test(cocoapods: [cocoapods])
|
||||
|
||||
// Then
|
||||
XCTAssertThrowsSpecific(try subject.install(graph: graph),
|
||||
|
@ -48,7 +48,7 @@ final class CocoaPodsInteractorTests: TuistUnitTestCase {
|
|||
func test_install_when_theCocoaPodsFromBundlerCanBeUsed() throws {
|
||||
// Given
|
||||
let cocoapods = CocoaPodsNode.test()
|
||||
let graph = Graph.test(cocoapods: [cocoapods.path: cocoapods])
|
||||
let graph = Graph.test(cocoapods: [cocoapods])
|
||||
|
||||
system.succeedCommand(["bundle", "show", "cocoapods"])
|
||||
system.succeedCommand(["bundle", "exec", "pod", "install", "--project-directory=\(cocoapods.path.pathString)"])
|
||||
|
@ -63,7 +63,7 @@ final class CocoaPodsInteractorTests: TuistUnitTestCase {
|
|||
func test_install_when_theCocoaPodsFromTheSystemCanBeUsed() throws {
|
||||
// Given
|
||||
let cocoapods = CocoaPodsNode.test()
|
||||
let graph = Graph.test(cocoapods: [cocoapods.path: cocoapods])
|
||||
let graph = Graph.test(cocoapods: [cocoapods])
|
||||
|
||||
system.errorCommand(["bundle", "show", "cocoapods"])
|
||||
system.whichStub = {
|
||||
|
@ -82,7 +82,7 @@ final class CocoaPodsInteractorTests: TuistUnitTestCase {
|
|||
func test_install_when_theCocoaPodsSpecsRepoIsOutdated() throws {
|
||||
// Given
|
||||
let cocoapods = CocoaPodsNode.test()
|
||||
let graph = Graph.test(cocoapods: [cocoapods.path: cocoapods])
|
||||
let graph = Graph.test(cocoapods: [cocoapods])
|
||||
|
||||
system.succeedCommand(["bundle", "show", "cocoapods"])
|
||||
system.errorCommand(["bundle", "exec", "pod", "install", "--project-directory=\(cocoapods.path.pathString)"], error: "[!] CocoaPods could not find compatible versions for pod")
|
||||
|
|
Loading…
Reference in New Issue