From ed5ec74668180de55bd7f52e4a2e9e9ac333014a Mon Sep 17 00:00:00 2001 From: Craig Siemens Date: Wed, 28 Sep 2022 22:08:37 -0600 Subject: [PATCH] Added scheme generation for aggregate targets (#1250) * Updated SchemeGenerator to generate schemes for all projectTargets. * Added changelog entry --- CHANGELOG.md | 4 ++++ Sources/ProjectSpec/AggregateTarget.swift | 2 ++ Sources/ProjectSpec/ProjectTarget.swift | 2 ++ Sources/ProjectSpec/XCProjExtensions.swift | 2 +- Sources/XcodeGenKit/SchemeGenerator.swift | 18 +++++++++--------- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1869f39..cb975bdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - Added support for `enableGPUFrameCaptureMode` #1251 @bsudekum +### Fixed + +- Fix scheme not being generated for aggregate targets #1250 @CraigSiemens + ## 2.32.0 ### Added diff --git a/Sources/ProjectSpec/AggregateTarget.swift b/Sources/ProjectSpec/AggregateTarget.swift index b2964e5b..3769e64c 100644 --- a/Sources/ProjectSpec/AggregateTarget.swift +++ b/Sources/ProjectSpec/AggregateTarget.swift @@ -1,8 +1,10 @@ import Foundation import JSONUtilities +import XcodeProj public struct AggregateTarget: ProjectTarget { public var name: String + public var type: PBXProductType = .none public var targets: [String] public var settings: Settings public var buildScripts: [BuildScript] diff --git a/Sources/ProjectSpec/ProjectTarget.swift b/Sources/ProjectSpec/ProjectTarget.swift index 0411b0eb..99fd1d77 100644 --- a/Sources/ProjectSpec/ProjectTarget.swift +++ b/Sources/ProjectSpec/ProjectTarget.swift @@ -1,8 +1,10 @@ import Foundation +import XcodeProj public protocol ProjectTarget: BuildSettingsContainer { var name: String { get } + var type: PBXProductType { get } var buildScripts: [BuildScript] { get } var scheme: TargetScheme? { get } var attributes: [String: Any] { get } diff --git a/Sources/ProjectSpec/XCProjExtensions.swift b/Sources/ProjectSpec/XCProjExtensions.swift index 9bee91be..91b4c91f 100644 --- a/Sources/ProjectSpec/XCProjExtensions.swift +++ b/Sources/ProjectSpec/XCProjExtensions.swift @@ -90,7 +90,7 @@ extension Platform { } } -extension Target { +extension ProjectTarget { public var shouldExecuteOnLaunch: Bool { // This is different from `type.isExecutable`, because we don't want to "run" a test type.isApp || type.isExtension || type.isSystemExtension || type == .commandLineTool diff --git a/Sources/XcodeGenKit/SchemeGenerator.swift b/Sources/XcodeGenKit/SchemeGenerator.swift index ec888d35..fb069c75 100644 --- a/Sources/XcodeGenKit/SchemeGenerator.swift +++ b/Sources/XcodeGenKit/SchemeGenerator.swift @@ -48,7 +48,7 @@ public class SchemeGenerator { xcschemes.append(xcscheme) } - for target in project.targets { + for target in project.projectTargets { if let targetScheme = target.scheme { if targetScheme.configVariants.isEmpty { let schemeName = target.name @@ -95,7 +95,7 @@ public class SchemeGenerator { return xcschemes } - public func generateScheme(_ scheme: Scheme, for target: Target? = nil) throws -> XCScheme { + public func generateScheme(_ scheme: Scheme, for target: ProjectTarget? = nil) throws -> XCScheme { func getBuildableReference(_ target: TargetReference) throws -> XCScheme.BuildableReference { let pbxProj: PBXProj @@ -179,7 +179,7 @@ public class SchemeGenerator { return XCScheme.ExecutionAction(scriptText: action.script, title: action.name, environmentBuildable: environmentBuildable) } - let schemeTarget: Target? + let schemeTarget: ProjectTarget? if let targetName = scheme.run?.executable { schemeTarget = project.getTarget(targetName) @@ -359,7 +359,7 @@ public class SchemeGenerator { ) } - private func launchAutomaticallySubstyle(for target: Target?) -> String? { + private func launchAutomaticallySubstyle(for target: ProjectTarget?) -> String? { if target?.type.isExtension == true { return "2" } else { @@ -367,7 +367,7 @@ public class SchemeGenerator { } } - private func makeProductRunnables(for target: Target?, buildableReference: XCScheme.BuildableReference) -> (launch: XCScheme.Runnable, profile: XCScheme.BuildableProductRunnable) { + private func makeProductRunnables(for target: ProjectTarget?, buildableReference: XCScheme.BuildableReference) -> (launch: XCScheme.Runnable, profile: XCScheme.BuildableProductRunnable) { let buildable = XCScheme.BuildableProductRunnable(buildableReference: buildableReference) if target?.type.isWatchApp == true { let remote = XCScheme.RemoteRunnable( @@ -381,7 +381,7 @@ public class SchemeGenerator { } } - private func selectedDebuggerIdentifier(for target: Target?, run: Scheme.Run?) -> String { + private func selectedDebuggerIdentifier(for target: ProjectTarget?, run: Scheme.Run?) -> String { if target?.type.canUseDebugLauncher != false && run?.debugEnabled ?? Scheme.Run.debugEnabledDefault { return XCScheme.defaultDebugger } else { @@ -389,7 +389,7 @@ public class SchemeGenerator { } } - private func selectedLauncherIdentifier(for target: Target?, run: Scheme.Run?) -> String { + private func selectedLauncherIdentifier(for target: ProjectTarget?, run: Scheme.Run?) -> String { if target?.type.canUseDebugLauncher != false && run?.debugEnabled ?? Scheme.Run.debugEnabledDefault { return XCScheme.defaultLauncher } else { @@ -420,7 +420,7 @@ enum SchemeGenerationError: Error, CustomStringConvertible { } extension Scheme { - public init(name: String, target: Target, targetScheme: TargetScheme, project: Project, debugConfig: String, releaseConfig: String) { + public init(name: String, target: ProjectTarget, targetScheme: TargetScheme, project: Project, debugConfig: String, releaseConfig: String) { self.init( name: name, build: .init( @@ -465,7 +465,7 @@ extension Scheme { ) } - private static func buildTargets(for target: Target, project: Project) -> [BuildTarget] { + private static func buildTargets(for target: ProjectTarget, project: Project) -> [BuildTarget] { let buildTarget = Scheme.BuildTarget(target: TestableTargetReference.local(target.name)) switch target.type { case .watchApp, .watch2App: