From 5ac96741bcdc9942e0e5edf7ff206901049242fa Mon Sep 17 00:00:00 2001 From: Brentley Jones Date: Sun, 6 Sep 2020 00:40:32 -0500 Subject: [PATCH] Improved Application Extension scheme generation (#932) * Default extensions to launchAutomaticallySubstyle "2" * Don't use debugger launcher with extensions Xcode schemes don't use the LLDB launcher, even when debugging is enabled. Co-authored-by: Yonas Kolb --- CHANGELOG.md | 3 +- Sources/XcodeGenKit/SchemeGenerator.swift | 35 +++++++++++++++++-- .../xcschemes/iMessageExtension.xcscheme | 7 ++-- .../xcschemes/iMessageExtension.xcscheme | 7 ++-- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1689d398..98423bfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Add `Scheme.Test.TestTarget.skipped` to allow skipping of an entire test target. [#916](https://github.com/yonaskolb/XcodeGen/pull/916) @codeman9 - Added ability to set custom LLDBInit scripts for launch and test schemes [#929](https://github.com/yonaskolb/XcodeGen/pull/929) @polac24 - Adds App Clip support. [#909](https://github.com/yonaskolb/XcodeGen/pull/909) @brentleyjones @dflems +- Application extension schemes now default to `launchAutomaticallySubstyle = 2` and the correct debugger and launcher identifiers [#932](https://github.com/yonaskolb/XcodeGen/pull/932) @brentleyjones #### Internal - Updates CI to run on Xcode 12 beta. [#936](https://github.com/yonaskolb/XcodeGen/pull/936) @dflems @@ -23,7 +24,7 @@ #### Fixed - Treat all directories with known UTI as file wrapper. [#896](https://github.com/yonaskolb/XcodeGen/pull/896) @KhaosT - Generated schemes for application extensions now contain `wasCreatedForAppExtension = YES`. [#898](https://github.com/yonaskolb/XcodeGen/issues/898) @muizidn -- Allow package dependencies to use `link: false` [#920](https://github.com/yonaskolb/XcodeGen/pull/920) @k-thorat +- Allow package dependencies to use `link: false` [#920](https://github.com/yonaskolb/XcodeGen/pull/920) @k-thorat - Fixed issue computing relative paths. [#915](https://github.com/yonaskolb/XcodeGen/pull/915) @andrewreach #### Internal diff --git a/Sources/XcodeGenKit/SchemeGenerator.swift b/Sources/XcodeGenKit/SchemeGenerator.swift index 11104324..3d1686cc 100644 --- a/Sources/XcodeGenKit/SchemeGenerator.swift +++ b/Sources/XcodeGenKit/SchemeGenerator.swift @@ -240,8 +240,8 @@ public class SchemeGenerator { preActions: scheme.run?.preActions.map(getExecutionAction) ?? [], postActions: scheme.run?.postActions.map(getExecutionAction) ?? [], macroExpansion: shouldExecuteOnLaunch ? nil : buildableReference, - selectedDebuggerIdentifier: (scheme.run?.debugEnabled ?? Scheme.Run.debugEnabledDefault) ? XCScheme.defaultDebugger : "", - selectedLauncherIdentifier: (scheme.run?.debugEnabled ?? Scheme.Run.debugEnabledDefault) ? XCScheme.defaultLauncher : "Xcode.IDEFoundation.Launcher.PosixSpawn", + selectedDebuggerIdentifier: selectedDebuggerIdentifier(for: schemeTarget, run: scheme.run), + selectedLauncherIdentifier: selectedLauncherIdentifier(for: schemeTarget, run: scheme.run), askForAppToLaunch: scheme.run?.askForAppToLaunch, allowLocationSimulation: allowLocationSimulation, locationScenarioReference: locationScenarioReference, @@ -251,7 +251,7 @@ public class SchemeGenerator { environmentVariables: launchVariables, language: scheme.run?.language, region: scheme.run?.region, - launchAutomaticallySubstyle: scheme.run?.launchAutomaticallySubstyle, + launchAutomaticallySubstyle: scheme.run?.launchAutomaticallySubstyle ?? launchAutomaticallySubstyle(for: schemeTarget), customLLDBInitFile: scheme.run?.customLLDBInit ) @@ -290,6 +290,14 @@ public class SchemeGenerator { ) } + private func launchAutomaticallySubstyle(for target: Target?) -> String? { + if target?.type.isExtension == true { + return "2" + } else { + return nil + } + } + private func makeProductRunnables(for target: Target?, buildableReference: XCScheme.BuildableReference) -> (launch: XCScheme.Runnable, profile: XCScheme.BuildableProductRunnable) { let buildable = XCScheme.BuildableProductRunnable(buildableReference: buildableReference) if target?.type.isWatchApp == true { @@ -303,6 +311,22 @@ public class SchemeGenerator { return (buildable, buildable) } } + + private func selectedDebuggerIdentifier(for target: Target?, run: Scheme.Run?) -> String { + if target?.type.canUseDebugLauncher != false && run?.debugEnabled ?? Scheme.Run.debugEnabledDefault { + return XCScheme.defaultDebugger + } else { + return "" + } + } + + private func selectedLauncherIdentifier(for target: Target?, run: Scheme.Run?) -> String { + if target?.type.canUseDebugLauncher != false && run?.debugEnabled ?? Scheme.Run.debugEnabledDefault { + return XCScheme.defaultLauncher + } else { + return "Xcode.IDEFoundation.Launcher.PosixSpawn" + } + } } enum SchemeGenerationError: Error, CustomStringConvertible { @@ -380,6 +404,11 @@ extension Scheme { } extension PBXProductType { + var canUseDebugLauncher: Bool { + // Extensions don't use the lldb launcher + return !isExtension + } + var isWatchApp: Bool { switch self { case .watchApp, .watch2App: diff --git a/Tests/Fixtures/TestProject/Project.xcodeproj/xcshareddata/xcschemes/iMessageExtension.xcscheme b/Tests/Fixtures/TestProject/Project.xcodeproj/xcshareddata/xcschemes/iMessageExtension.xcscheme index 3cc5c5fa..c1fd6aaa 100644 --- a/Tests/Fixtures/TestProject/Project.xcodeproj/xcshareddata/xcschemes/iMessageExtension.xcscheme +++ b/Tests/Fixtures/TestProject/Project.xcodeproj/xcshareddata/xcschemes/iMessageExtension.xcscheme @@ -45,14 +45,15 @@ + allowLocationSimulation = "YES" + launchAutomaticallySubstyle = "2"> + allowLocationSimulation = "YES" + launchAutomaticallySubstyle = "2">