From fb05f675f151b5bfb17f3875f7f96b0830bb769f Mon Sep 17 00:00:00 2001 From: giginet Date: Wed, 2 Oct 2019 23:57:17 +0900 Subject: [PATCH] Use defaultConfig(of:in:) --- Sources/XcodeGenKit/SchemeGenerator.swift | 38 +++++++++-------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/Sources/XcodeGenKit/SchemeGenerator.swift b/Sources/XcodeGenKit/SchemeGenerator.swift index 090c6b8e..e9e97bd2 100644 --- a/Sources/XcodeGenKit/SchemeGenerator.swift +++ b/Sources/XcodeGenKit/SchemeGenerator.swift @@ -2,27 +2,19 @@ import Foundation import ProjectSpec import XcodeProj +private func defaultConfig(of type: ConfigType, in project: Project) -> Config { + if let defaultConfig = Config.defaultConfigs.first(where: { $0.type == type }), + project.configs.contains(defaultConfig) { + return defaultConfig + } + return project.configs.first { $0.type == type }! +} + public class SchemeGenerator { let project: Project let pbxProj: PBXProj - var defaultDebugConfig: Config { - if let defaultConfig = Config.defaultConfigs.first(where: { $0.type == .debug }), - project.configs.contains(defaultConfig) { - return defaultConfig - } - return project.configs.first { $0.type == .debug }! - } - - var defaultReleaseConfig: Config { - if let defaultConfig = Config.defaultConfigs.first(where: { $0.type == .release }), - project.configs.contains(defaultConfig) { - return defaultConfig - } - return project.configs.first { $0.type == .release }! - } - public init(project: Project, pbxProj: PBXProj) { self.project = project self.pbxProj = pbxProj @@ -42,8 +34,8 @@ public class SchemeGenerator { if targetScheme.configVariants.isEmpty { let schemeName = target.name - let debugConfig = project.configs.first { $0.type == .debug }! - let releaseConfig = project.configs.first { $0.type == .release }! + let debugConfig = defaultConfig(of: .debug, in: project) + let releaseConfig = defaultConfig(of: .release, in: project) let scheme = Scheme( name: schemeName, @@ -155,7 +147,7 @@ public class SchemeGenerator { let profileVariables = scheme.profile.flatMap { $0.environmentVariables.isEmpty ? nil : $0.environmentVariables } let testAction = XCScheme.TestAction( - buildConfiguration: scheme.test?.config ?? defaultDebugConfig.name, + buildConfiguration: scheme.test?.config ?? defaultConfig(of: .debug, in: project).name, macroExpansion: buildableReference, testables: testables, preActions: scheme.test?.preActions.map(getExecutionAction) ?? [], @@ -172,7 +164,7 @@ public class SchemeGenerator { let launchAction = XCScheme.LaunchAction( runnable: shouldExecuteOnLaunch ? productRunable : nil, - buildConfiguration: scheme.run?.config ?? defaultDebugConfig.name, + buildConfiguration: scheme.run?.config ?? defaultConfig(of: .debug, in: project).name, preActions: scheme.run?.preActions.map(getExecutionAction) ?? [], postActions: scheme.run?.postActions.map(getExecutionAction) ?? [], macroExpansion: shouldExecuteOnLaunch ? nil : buildableReference, @@ -187,7 +179,7 @@ public class SchemeGenerator { let profileAction = XCScheme.ProfileAction( buildableProductRunnable: productRunable, - buildConfiguration: scheme.profile?.config ?? defaultReleaseConfig.name, + buildConfiguration: scheme.profile?.config ?? defaultConfig(of: .release, in: project).name, preActions: scheme.profile?.preActions.map(getExecutionAction) ?? [], postActions: scheme.profile?.postActions.map(getExecutionAction) ?? [], shouldUseLaunchSchemeArgsEnv: scheme.profile?.shouldUseLaunchSchemeArgsEnv ?? true, @@ -195,10 +187,10 @@ public class SchemeGenerator { environmentVariables: profileVariables ) - let analyzeAction = XCScheme.AnalyzeAction(buildConfiguration: scheme.analyze?.config ?? defaultDebugConfig.name) + let analyzeAction = XCScheme.AnalyzeAction(buildConfiguration: scheme.analyze?.config ?? defaultConfig(of: .debug, in: project).name) let archiveAction = XCScheme.ArchiveAction( - buildConfiguration: scheme.archive?.config ?? defaultReleaseConfig.name, + buildConfiguration: scheme.archive?.config ?? defaultConfig(of: .release, in: project).name, revealArchiveInOrganizer: scheme.archive?.revealArchiveInOrganizer ?? true, customArchiveName: scheme.archive?.customArchiveName, preActions: scheme.archive?.preActions.map(getExecutionAction) ?? [],