diff --git a/CHANGELOG.md b/CHANGELOG.md index 813bc2f6..a9606ccc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ #### 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 +- Prefer default configuration names for generated schemes [#673](https://github.com/yonaskolb/XcodeGen/pull/673) @giginet + +#### Internal + +- Updated to SwiftCLI 5.3.2 [#667](https://github.com/yonaskolb/XcodeGen/pull/667) @giginet - Fixed tests in case-sensitive file system [#670](https://github.com/yonaskolb/XcodeGen/pull/670) @Qusic ## 2.8.0 diff --git a/Package.resolved b/Package.resolved index 3fbca4bd..6d7c6f0e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -60,8 +60,8 @@ "repositoryURL": "https://github.com/jakeheis/SwiftCLI.git", "state": { "branch": null, - "revision": "5318c37d3cacc8780f50b87a8840a6774320ebdf", - "version": "5.2.2" + "revision": "ba2268e67c07b9f9cfbc0801385e6238b36255eb", + "version": "5.3.2" } }, { diff --git a/Package.swift b/Package.swift index b934012d..e6389e88 100644 --- a/Package.swift +++ b/Package.swift @@ -17,7 +17,7 @@ let package = Package( .package(url: "https://github.com/kylef/Spectre.git", from: "0.9.0"), .package(url: "https://github.com/onevcat/Rainbow.git", from: "3.0.0"), .package(url: "https://github.com/tuist/xcodeproj.git", .exact("7.1.0")), - .package(url: "https://github.com/jakeheis/SwiftCLI.git", .exact("5.2.2")), + .package(url: "https://github.com/jakeheis/SwiftCLI.git", .upToNextMinor(from: "5.3.2")), ], targets: [ .target(name: "XcodeGen", dependencies: [ diff --git a/Sources/XcodeGenCLI/CommandRouter.swift b/Sources/XcodeGenCLI/CommandRouter.swift deleted file mode 100644 index aa23770a..00000000 --- a/Sources/XcodeGenCLI/CommandRouter.swift +++ /dev/null @@ -1,20 +0,0 @@ -import Foundation -import SwiftCLI - -class CommandRouter: Router { - - let defaultCommand: Command - - init(defaultCommand: Command) { - self.defaultCommand = defaultCommand - } - - func parse(commandGroup: CommandGroup, arguments: ArgumentList) throws -> (CommandPath, OptionRegistry) { - if !arguments.hasNext() || arguments.nextIsOption() { - arguments.manipulate { existing in - [defaultCommand.name] + existing - } - } - return try DefaultRouter().parse(commandGroup: commandGroup, arguments: arguments) - } -} diff --git a/Sources/XcodeGenCLI/XcodeGenCLI.swift b/Sources/XcodeGenCLI/XcodeGenCLI.swift index 6560ec6f..5a7e772c 100644 --- a/Sources/XcodeGenCLI/XcodeGenCLI.swift +++ b/Sources/XcodeGenCLI/XcodeGenCLI.swift @@ -3,7 +3,6 @@ import ProjectSpec import SwiftCLI public class XcodeGenCLI { - let cli: CLI public init(version: Version) { @@ -15,7 +14,7 @@ public class XcodeGenCLI { description: "Generates Xcode projects", commands: [generateCommand] ) - cli.parser = Parser(router: CommandRouter(defaultCommand: generateCommand)) + cli.parser.routeBehavior = .searchWithFallback(generateCommand) } public func execute(arguments: [String]? = nil) { diff --git a/Sources/XcodeGenKit/SchemeGenerator.swift b/Sources/XcodeGenKit/SchemeGenerator.swift index 0de02729..0492ac99 100644 --- a/Sources/XcodeGenKit/SchemeGenerator.swift +++ b/Sources/XcodeGenKit/SchemeGenerator.swift @@ -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 @@ -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, diff --git a/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift b/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift index be00176f..ae6b875c 100644 --- a/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift @@ -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, @@ -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),