Skip to content

Commit 2297ad2

Browse files
refactor: Update PathRunnable so that it subclasses Runnable (#883)
* Made the buildableReference parameter of Runnable's init an optional parameter. The buildableReference property of Runnable was optional so now the init parameter type will match. This change will allow PathRunnable, which does not use a BuildableReference to subclass Runnable like BuildableProductRunnable and RemoteRunnable do. * Refactored PathRunnable to subclass from Runnable. Making PathRunnable subclass from Runnable will bring it line with BuildableProductRunnable and RemoteRunnable. Now all three will now be able to be abstracted behind a Runnable var or parameter. * Removed pathRunnable property from LaunchAction Removed the dedicated pathRunnable var from LaunchAction now that the runnable var can hold a PathRunnable. Also updated the test case for PathRunnable serialization. * Brought back pathRunnable var on LaunchAction as a computed var for backwards compatibility * Removed excessive isEqual check in PathRunnable's == implementation * Added support for PathRunnable in ProfileAction * Added a convenience init method to LaunchAction with a PathRunnable parameter for backwards compatibility * Make the inits non-breaking --------- Co-authored-by: Pedro <[email protected]>
1 parent 4b9f495 commit 2297ad2

File tree

5 files changed

+127
-29
lines changed

5 files changed

+127
-29
lines changed

Sources/XcodeProj/Scheme/XCScheme+LaunchAction.swift

Lines changed: 102 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ public extension XCScheme {
4242
public var buildConfiguration: String
4343
public var launchStyle: Style
4444
public var askForAppToLaunch: Bool?
45-
public var pathRunnable: PathRunnable?
45+
public var pathRunnable: PathRunnable? {
46+
// For backwards compatibility
47+
get {
48+
runnable as? PathRunnable
49+
}
50+
set {
51+
self.pathRunnable = newValue
52+
}
53+
}
54+
4655
public var customWorkingDirectory: String?
4756
public var useCustomWorkingDirectory: Bool
4857
public var ignoresPersistentStateOnLaunch: Bool
@@ -78,6 +87,7 @@ public extension XCScheme {
7887

7988
// MARK: - Init
8089

90+
@available(*, deprecated, message: "Use the init() that consolidates pathRunnable and runnable into a single parameter.")
8191
public init(runnable: Runnable?,
8292
buildConfiguration: String,
8393
preActions: [ExecutionAction] = [],
@@ -87,7 +97,7 @@ public extension XCScheme {
8797
selectedLauncherIdentifier: String = XCScheme.defaultLauncher,
8898
launchStyle: Style = .auto,
8999
askForAppToLaunch: Bool? = nil,
90-
pathRunnable: PathRunnable? = nil,
100+
pathRunnable _: PathRunnable? = nil,
91101
customWorkingDirectory: String? = nil,
92102
useCustomWorkingDirectory: Bool = false,
93103
ignoresPersistentStateOnLaunch: Bool = false,
@@ -126,7 +136,6 @@ public extension XCScheme {
126136
self.selectedDebuggerIdentifier = selectedDebuggerIdentifier
127137
self.selectedLauncherIdentifier = selectedLauncherIdentifier
128138
self.askForAppToLaunch = askForAppToLaunch
129-
self.pathRunnable = pathRunnable
130139
self.customWorkingDirectory = customWorkingDirectory
131140
self.useCustomWorkingDirectory = useCustomWorkingDirectory
132141
self.ignoresPersistentStateOnLaunch = ignoresPersistentStateOnLaunch
@@ -161,6 +170,93 @@ public extension XCScheme {
161170
super.init(preActions, postActions)
162171
}
163172

173+
public convenience init(
174+
pathRunnable: PathRunnable?,
175+
buildConfiguration: String,
176+
preActions: [ExecutionAction] = [],
177+
postActions: [ExecutionAction] = [],
178+
macroExpansion: BuildableReference? = nil,
179+
selectedDebuggerIdentifier: String = XCScheme.defaultDebugger,
180+
selectedLauncherIdentifier: String = XCScheme.defaultLauncher,
181+
launchStyle: Style = .auto,
182+
askForAppToLaunch: Bool? = nil,
183+
customWorkingDirectory: String? = nil,
184+
useCustomWorkingDirectory: Bool = false,
185+
ignoresPersistentStateOnLaunch: Bool = false,
186+
debugDocumentVersioning: Bool = true,
187+
debugServiceExtension: String = LaunchAction.defaultDebugServiceExtension,
188+
allowLocationSimulation: Bool = true,
189+
locationScenarioReference: LocationScenarioReference? = nil,
190+
enableGPUFrameCaptureMode: GPUFrameCaptureMode = LaunchAction.defaultGPUFrameCaptureMode,
191+
disableGPUValidationMode: Bool = false,
192+
enableGPUShaderValidationMode: Bool = false,
193+
showGraphicsOverview: Bool = false,
194+
logGraphicsOverview: Bool = false,
195+
enableAddressSanitizer: Bool = false,
196+
enableASanStackUseAfterReturn: Bool = false,
197+
enableThreadSanitizer: Bool = false,
198+
stopOnEveryThreadSanitizerIssue: Bool = false,
199+
enableUBSanitizer: Bool = false,
200+
stopOnEveryUBSanitizerIssue: Bool = false,
201+
disableMainThreadChecker: Bool = false,
202+
disablePerformanceAntipatternChecker: Bool = false,
203+
stopOnEveryMainThreadCheckerIssue: Bool = false,
204+
additionalOptions: [AdditionalOption] = [],
205+
commandlineArguments: CommandLineArguments? = nil,
206+
environmentVariables: [EnvironmentVariable]? = nil,
207+
language: String? = nil,
208+
region: String? = nil,
209+
showNonLocalizedStrings: Bool = false,
210+
launchAutomaticallySubstyle: String? = nil,
211+
storeKitConfigurationFileReference: StoreKitConfigurationFileReference? = nil,
212+
customLaunchCommand: String? = nil,
213+
customLLDBInitFile: String? = nil
214+
) {
215+
self.init(
216+
runnable: pathRunnable,
217+
buildConfiguration: buildConfiguration,
218+
preActions: preActions,
219+
postActions: postActions,
220+
macroExpansion: macroExpansion,
221+
selectedDebuggerIdentifier: selectedDebuggerIdentifier,
222+
selectedLauncherIdentifier: selectedLauncherIdentifier,
223+
launchStyle: launchStyle,
224+
askForAppToLaunch: askForAppToLaunch,
225+
pathRunnable: pathRunnable,
226+
customWorkingDirectory: customWorkingDirectory,
227+
useCustomWorkingDirectory: useCustomWorkingDirectory,
228+
ignoresPersistentStateOnLaunch: ignoresPersistentStateOnLaunch,
229+
debugDocumentVersioning: debugDocumentVersioning,
230+
debugServiceExtension: debugServiceExtension,
231+
allowLocationSimulation: allowLocationSimulation,
232+
locationScenarioReference: locationScenarioReference,
233+
enableGPUFrameCaptureMode: enableGPUFrameCaptureMode,
234+
disableGPUValidationMode: disableGPUValidationMode,
235+
enableGPUShaderValidationMode: enableGPUShaderValidationMode,
236+
showGraphicsOverview: showGraphicsOverview,
237+
logGraphicsOverview: logGraphicsOverview,
238+
enableAddressSanitizer: enableAddressSanitizer,
239+
enableASanStackUseAfterReturn: enableASanStackUseAfterReturn,
240+
enableThreadSanitizer: enableThreadSanitizer,
241+
stopOnEveryThreadSanitizerIssue: stopOnEveryThreadSanitizerIssue,
242+
enableUBSanitizer: enableUBSanitizer,
243+
stopOnEveryUBSanitizerIssue: stopOnEveryUBSanitizerIssue,
244+
disableMainThreadChecker: disableMainThreadChecker,
245+
disablePerformanceAntipatternChecker: disablePerformanceAntipatternChecker,
246+
stopOnEveryMainThreadCheckerIssue: stopOnEveryMainThreadCheckerIssue,
247+
additionalOptions: additionalOptions,
248+
commandlineArguments: commandlineArguments,
249+
environmentVariables: environmentVariables,
250+
language: language,
251+
region: region,
252+
showNonLocalizedStrings: showNonLocalizedStrings,
253+
launchAutomaticallySubstyle: launchAutomaticallySubstyle,
254+
storeKitConfigurationFileReference: storeKitConfigurationFileReference,
255+
customLaunchCommand: customLaunchCommand,
256+
customLLDBInitFile: customLLDBInitFile
257+
)
258+
}
259+
164260
// swiftlint:disable:next function_body_length
165261
override init(element: AEXMLElement) throws {
166262
buildConfiguration = element.attributes["buildConfiguration"] ?? LaunchAction.defaultBuildConfiguration
@@ -177,15 +273,13 @@ public extension XCScheme {
177273
// Runnable
178274
let buildableProductRunnableElement = element["BuildableProductRunnable"]
179275
let remoteRunnableElement = element["RemoteRunnable"]
276+
let pathRunnable = element["PathRunnable"]
180277
if buildableProductRunnableElement.error == nil {
181278
runnable = try BuildableProductRunnable(element: buildableProductRunnableElement)
182279
} else if remoteRunnableElement.error == nil {
183280
runnable = try RemoteRunnable(element: remoteRunnableElement)
184-
}
185-
186-
let pathRunnable = element["PathRunnable"]
187-
if pathRunnable.error == nil {
188-
self.pathRunnable = try PathRunnable(element: pathRunnable)
281+
} else if pathRunnable.error == nil {
282+
runnable = try PathRunnable(element: pathRunnable)
189283
}
190284

191285
let buildableReferenceElement = element["MacroExpansion"]["BuildableReference"]
@@ -324,10 +418,6 @@ public extension XCScheme {
324418
element.addChild(runnable.xmlElement())
325419
}
326420

327-
if let pathRunnable {
328-
element.addChild(pathRunnable.xmlElement())
329-
}
330-
331421
if let locationScenarioReference {
332422
element.addChild(locationScenarioReference.xmlElement())
333423
}
@@ -395,7 +485,6 @@ public extension XCScheme {
395485
buildConfiguration == rhs.buildConfiguration &&
396486
launchStyle == rhs.launchStyle &&
397487
askForAppToLaunch == rhs.askForAppToLaunch &&
398-
pathRunnable == rhs.pathRunnable &&
399488
customWorkingDirectory == rhs.customWorkingDirectory &&
400489
useCustomWorkingDirectory == rhs.useCustomWorkingDirectory &&
401490
ignoresPersistentStateOnLaunch == rhs.ignoresPersistentStateOnLaunch &&

Sources/XcodeProj/Scheme/XCScheme+PathRunnable.swift

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,47 @@ import Foundation
33
import PathKit
44

55
public extension XCScheme {
6-
class PathRunnable: Equatable {
6+
class PathRunnable: Runnable {
77
// MARK: - Attributes
88

9-
public var runnableDebuggingMode: String
109
public var filePath: String
1110

1211
// MARK: - Init
1312

1413
public init(filePath: String,
1514
runnableDebuggingMode: String = "0") {
1615
self.filePath = filePath
17-
self.runnableDebuggingMode = runnableDebuggingMode
16+
super.init(buildableReference: nil,
17+
runnableDebuggingMode: runnableDebuggingMode)
1818
}
1919

20-
init(element: AEXMLElement) throws {
21-
runnableDebuggingMode = element.attributes["runnableDebuggingMode"] ?? "0"
20+
override init(element: AEXMLElement) throws {
2221
filePath = element.attributes["FilePath"] ?? ""
22+
try super.init(element: element)
2323
}
2424

2525
// MARK: - XML
2626

27-
func xmlElement() -> AEXMLElement {
28-
AEXMLElement(name: "PathRunnable",
29-
value: nil,
30-
attributes: [
31-
"runnableDebuggingMode": runnableDebuggingMode,
32-
"FilePath": filePath,
33-
])
27+
override func xmlElement() -> AEXMLElement {
28+
let element = super.xmlElement()
29+
element.name = "PathRunnable"
30+
element.attributes["FilePath"] = filePath
31+
return element
3432
}
3533

3634
// MARK: - Equatable
3735

36+
override func isEqual(other: XCScheme.Runnable) -> Bool {
37+
guard let other = other as? PathRunnable else {
38+
return false
39+
}
40+
41+
return super.isEqual(other: other) &&
42+
filePath == other.filePath
43+
}
44+
3845
public static func == (lhs: PathRunnable, rhs: PathRunnable) -> Bool {
39-
lhs.runnableDebuggingMode == rhs.runnableDebuggingMode &&
40-
lhs.filePath == rhs.filePath
46+
lhs.isEqual(other: rhs)
4147
}
4248
}
4349
}

Sources/XcodeProj/Scheme/XCScheme+ProfileAction.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,13 @@ public extension XCScheme {
115115
// Runnable
116116
let buildableProductRunnableElement = element["BuildableProductRunnable"]
117117
let remoteRunnableElement = element["RemoteRunnable"]
118+
let pathRunnableElement = element["PathRunnable"]
118119
if buildableProductRunnableElement.error == nil {
119120
runnable = try BuildableProductRunnable(element: buildableProductRunnableElement)
120121
} else if remoteRunnableElement.error == nil {
121122
runnable = try RemoteRunnable(element: remoteRunnableElement)
123+
} else if pathRunnableElement.error == nil {
124+
runnable = try PathRunnable(element: pathRunnableElement)
122125
}
123126

124127
let buildableReferenceElement = element["MacroExpansion"]["BuildableReference"]

Sources/XcodeProj/Scheme/XCScheme+Runnable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public extension XCScheme {
1010

1111
// MARK: - Init
1212

13-
public init(buildableReference: BuildableReference,
13+
public init(buildableReference: BuildableReference?,
1414
runnableDebuggingMode: String = "0") {
1515
self.buildableReference = buildableReference
1616
self.runnableDebuggingMode = runnableDebuggingMode

Tests/XcodeProjTests/Scheme/XCSchemeTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ final class XCSchemeIntegrationTests: XCTestCase {
159159
// Given
160160
let filePath = "/usr/bin/foo"
161161
let pathRunnable = XCScheme.PathRunnable(filePath: filePath, runnableDebuggingMode: "0")
162-
let subject = XCScheme.LaunchAction(runnable: nil, buildConfiguration: "Debug", pathRunnable: pathRunnable)
162+
let subject = XCScheme.LaunchAction(runnable: pathRunnable, buildConfiguration: "Debug")
163163

164164
// When
165165
let element = subject.xmlElement()

0 commit comments

Comments
 (0)