From b48c2bac776c489ff7df42ecdc928fca3d6018c6 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Tue, 19 Dec 2017 17:10:13 -0800 Subject: [PATCH] Scan for Info.plist lazily --- Sources/XcodeGenKit/PBXProjGenerator.swift | 40 +++++++++++++--------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/Sources/XcodeGenKit/PBXProjGenerator.swift b/Sources/XcodeGenKit/PBXProjGenerator.swift index 64d13766..7fac57ef 100644 --- a/Sources/XcodeGenKit/PBXProjGenerator.swift +++ b/Sources/XcodeGenKit/PBXProjGenerator.swift @@ -151,27 +151,21 @@ public class PBXProjGenerator { let sourceFiles = try sourceGenerator.getAllSourceFiles(sources: target.sources) - // find all Info.plist files - let infoPlists: [Path] = target.sources.map { spec.basePath + $0.path }.flatMap { (path) -> [Path] in - if path.isFile { - if path.lastComponent == "Info.plist" { - return [path] - } - } else { - if let children = try? path.recursiveChildren() { - return children.filter { $0.lastComponent == "Info.plist" } - } - } - return [] - } + var plistPath: Path? = nil + var searchForPlist = true let configs: [XCBuildConfiguration] = spec.configs.map { config in var buildSettings = spec.getTargetBuildSettings(target: target, config: config) // automatically set INFOPLIST_FILE path - if let plistPath = infoPlists.first, - !spec.targetHasBuildSetting("INFOPLIST_FILE", basePath: spec.basePath, target: target, config: config) { - buildSettings["INFOPLIST_FILE"] = plistPath.byRemovingBase(path: spec.basePath) + if !spec.targetHasBuildSetting("INFOPLIST_FILE", basePath: spec.basePath, target: target, config: config) { + if searchForPlist { + plistPath = getInfoPlist(spec, target.sources) + searchForPlist = false + } + if let plistPath = plistPath { + buildSettings["INFOPLIST_FILE"] = plistPath.byRemovingBase(path: spec.basePath) + } } // automatically calculate bundle id @@ -464,6 +458,20 @@ public class PBXProjGenerator { return pbxtarget } + func getInfoPlist(_ spec: ProjectSpec, _ sources: [TargetSource]) -> Path? { + return sources + .lazy + .map { spec.basePath + $0.path } + .flatMap { (path) -> Path? in + if path.isFile { + return path.lastComponent == "Info.plist" ? path : nil + } else { + return path.first(where: { $0.lastComponent == "Info.plist" }) + } + } + .first + } + func getCarthageBuildPath(platform: Platform) -> String { let carthagePath = Path(carthageBuildPath)