Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select suitable configs for auto-generated schemes #673

Merged
merged 8 commits into from Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
#### Fixed
- Fixed macOS unit test setting preset [#665](https://github.com/yonaskolb/XcodeGen/pull/665) @yonaskolb
- Add `rcproject` files to sources build phase instead of resources [#669](https://github.com/yonaskolb/XcodeGen/pull/669) @Qusic
- Fixed configuration selection behaviors for auto-generated schemes [#673](https://github.com/yonaskolb/XcodeGen/pull/673) @giginet

## 2.8.0

Expand Down
12 changes: 10 additions & 2 deletions Sources/XcodeGenKit/SchemeGenerator.swift
Expand Up @@ -2,6 +2,14 @@ import Foundation
import ProjectSpec
import XcodeProj

private func suitableConfig(for 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
Expand Down Expand Up @@ -34,8 +42,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 = suitableConfig(for: .debug, in: project)
let releaseConfig = suitableConfig(for: .release, in: project)

let scheme = Scheme(
name: schemeName,
Expand Down
36 changes: 36 additions & 0 deletions Tests/XcodeGenKitTests/SchemeGeneratorTests.swift
Expand Up @@ -19,6 +19,12 @@ private let framework = Target(
platform: .iOS
)

private let frameworkTest = Target(
name: "MyFrameworkTests",
type: .unitTestBundle,
platform: .iOS
)

private let optionalFramework = Target(
name: "MyOptionalFramework",
type: .framework,
Expand Down Expand Up @@ -92,6 +98,36 @@ class SchemeGeneratorTests: XCTestCase {
try expect(xcscheme.testAction?.selectedDebuggerIdentifier) == XCScheme.defaultDebugger
}

$0.it("generates scheme with multiple configs") {
let configs: [Config] = [
Config(name: "Beta", type: .debug),
Config(name: "Debug", type: .debug),
Config(name: "Production", type: .release),
Config(name: "Release", type: .release),
]
let framework = Target(
name: "MyFramework",
type: .application,
platform: .iOS,
scheme: TargetScheme(testTargets: [.init(name: "MyFrameworkTests")])
)
let project = Project(
name: "test",
configs: configs,
targets: [framework, frameworkTest]
)
let xcodeProject = try project.generateXcodeProject()
guard let xcscheme = xcodeProject.sharedData?.schemes.first else {
throw failure("Scheme not found")
}

try expect(xcscheme.launchAction?.buildConfiguration) == "Debug"
try expect(xcscheme.testAction?.buildConfiguration) == "Debug"
try expect(xcscheme.profileAction?.buildConfiguration) == "Release"
try expect(xcscheme.analyzeAction?.buildConfiguration) == "Debug"
try expect(xcscheme.archiveAction?.buildConfiguration) == "Release"
}

$0.it("sets environment variables for a scheme") {
let runVariables: [XCScheme.EnvironmentVariable] = [
XCScheme.EnvironmentVariable(variable: "RUN_ENV", value: "ENABLED", enabled: true),
Expand Down