From bbed01d1d67a31dcd624fd671fa98569a849b962 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sun, 27 Oct 2019 09:23:35 +0900 Subject: [PATCH] Cache pbxproj by reference name --- Sources/ProjectSpec/ProjectReference.swift | 2 +- Sources/XcodeGenKit/SchemeGenerator.swift | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Sources/ProjectSpec/ProjectReference.swift b/Sources/ProjectSpec/ProjectReference.swift index 126d31d5..3781e4d0 100644 --- a/Sources/ProjectSpec/ProjectReference.swift +++ b/Sources/ProjectSpec/ProjectReference.swift @@ -1,7 +1,7 @@ import Foundation import JSONUtilities -public struct ProjectReference { +public struct ProjectReference: Hashable { public var name: String public var path: String diff --git a/Sources/XcodeGenKit/SchemeGenerator.swift b/Sources/XcodeGenKit/SchemeGenerator.swift index d830536c..9c5675ce 100644 --- a/Sources/XcodeGenKit/SchemeGenerator.swift +++ b/Sources/XcodeGenKit/SchemeGenerator.swift @@ -28,6 +28,17 @@ public class SchemeGenerator { self.pbxProj = pbxProj } + private var projects: [ProjectReference: PBXProj] = [:] + + func getPBXProj(from reference: ProjectReference) throws -> PBXProj { + if let cachedProject = projects[reference] { + return cachedProject + } + let pbxproj = try XcodeProj(pathString: reference.path).pbxproj + projects[reference] = pbxproj + return pbxproj + } + public func generateSchemes() throws -> [XCScheme] { var xcschemes: [XCScheme] = [] @@ -91,7 +102,7 @@ public class SchemeGenerator { guard let projectReference = self.project.getProjectReference(project) else { throw SchemeGenerationError.missingProject(project) } - pbxProj = try XcodeProj(pathString: projectReference.path).pbxproj + pbxProj = try getPBXProj(from: projectReference) projectFilePath = projectReference.path case .local: pbxProj = self.pbxProj