mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
Use defaultConfig(of:in:)
This commit is contained in:
@@ -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) ?? [],
|
||||
|
||||
Reference in New Issue
Block a user