Skip to content

Commit

Permalink
refactor: Update PathRunnable so that it subclasses Runnable (#883)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
georgenavarro and pepicrft authored Dec 3, 2024
1 parent 4b9f495 commit 2297ad2
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 29 deletions.
115 changes: 102 additions & 13 deletions Sources/XcodeProj/Scheme/XCScheme+LaunchAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ public extension XCScheme {
public var buildConfiguration: String
public var launchStyle: Style
public var askForAppToLaunch: Bool?
public var pathRunnable: PathRunnable?
public var pathRunnable: PathRunnable? {
// For backwards compatibility
get {
runnable as? PathRunnable
}
set {
self.pathRunnable = newValue
}
}

public var customWorkingDirectory: String?
public var useCustomWorkingDirectory: Bool
public var ignoresPersistentStateOnLaunch: Bool
Expand Down Expand Up @@ -78,6 +87,7 @@ public extension XCScheme {

// MARK: - Init

@available(*, deprecated, message: "Use the init() that consolidates pathRunnable and runnable into a single parameter.")
public init(runnable: Runnable?,
buildConfiguration: String,
preActions: [ExecutionAction] = [],
Expand All @@ -87,7 +97,7 @@ public extension XCScheme {
selectedLauncherIdentifier: String = XCScheme.defaultLauncher,
launchStyle: Style = .auto,
askForAppToLaunch: Bool? = nil,
pathRunnable: PathRunnable? = nil,
pathRunnable _: PathRunnable? = nil,
customWorkingDirectory: String? = nil,
useCustomWorkingDirectory: Bool = false,
ignoresPersistentStateOnLaunch: Bool = false,
Expand Down Expand Up @@ -126,7 +136,6 @@ public extension XCScheme {
self.selectedDebuggerIdentifier = selectedDebuggerIdentifier
self.selectedLauncherIdentifier = selectedLauncherIdentifier
self.askForAppToLaunch = askForAppToLaunch
self.pathRunnable = pathRunnable
self.customWorkingDirectory = customWorkingDirectory
self.useCustomWorkingDirectory = useCustomWorkingDirectory
self.ignoresPersistentStateOnLaunch = ignoresPersistentStateOnLaunch
Expand Down Expand Up @@ -161,6 +170,93 @@ public extension XCScheme {
super.init(preActions, postActions)
}

public convenience init(
pathRunnable: PathRunnable?,
buildConfiguration: String,
preActions: [ExecutionAction] = [],
postActions: [ExecutionAction] = [],
macroExpansion: BuildableReference? = nil,
selectedDebuggerIdentifier: String = XCScheme.defaultDebugger,
selectedLauncherIdentifier: String = XCScheme.defaultLauncher,
launchStyle: Style = .auto,
askForAppToLaunch: Bool? = nil,
customWorkingDirectory: String? = nil,
useCustomWorkingDirectory: Bool = false,
ignoresPersistentStateOnLaunch: Bool = false,
debugDocumentVersioning: Bool = true,
debugServiceExtension: String = LaunchAction.defaultDebugServiceExtension,
allowLocationSimulation: Bool = true,
locationScenarioReference: LocationScenarioReference? = nil,
enableGPUFrameCaptureMode: GPUFrameCaptureMode = LaunchAction.defaultGPUFrameCaptureMode,
disableGPUValidationMode: Bool = false,
enableGPUShaderValidationMode: Bool = false,
showGraphicsOverview: Bool = false,
logGraphicsOverview: Bool = false,
enableAddressSanitizer: Bool = false,
enableASanStackUseAfterReturn: Bool = false,
enableThreadSanitizer: Bool = false,
stopOnEveryThreadSanitizerIssue: Bool = false,
enableUBSanitizer: Bool = false,
stopOnEveryUBSanitizerIssue: Bool = false,
disableMainThreadChecker: Bool = false,
disablePerformanceAntipatternChecker: Bool = false,
stopOnEveryMainThreadCheckerIssue: Bool = false,
additionalOptions: [AdditionalOption] = [],
commandlineArguments: CommandLineArguments? = nil,
environmentVariables: [EnvironmentVariable]? = nil,
language: String? = nil,
region: String? = nil,
showNonLocalizedStrings: Bool = false,
launchAutomaticallySubstyle: String? = nil,
storeKitConfigurationFileReference: StoreKitConfigurationFileReference? = nil,
customLaunchCommand: String? = nil,
customLLDBInitFile: String? = nil
) {
self.init(
runnable: pathRunnable,
buildConfiguration: buildConfiguration,
preActions: preActions,
postActions: postActions,
macroExpansion: macroExpansion,
selectedDebuggerIdentifier: selectedDebuggerIdentifier,
selectedLauncherIdentifier: selectedLauncherIdentifier,
launchStyle: launchStyle,
askForAppToLaunch: askForAppToLaunch,
pathRunnable: pathRunnable,
customWorkingDirectory: customWorkingDirectory,
useCustomWorkingDirectory: useCustomWorkingDirectory,
ignoresPersistentStateOnLaunch: ignoresPersistentStateOnLaunch,
debugDocumentVersioning: debugDocumentVersioning,
debugServiceExtension: debugServiceExtension,
allowLocationSimulation: allowLocationSimulation,
locationScenarioReference: locationScenarioReference,
enableGPUFrameCaptureMode: enableGPUFrameCaptureMode,
disableGPUValidationMode: disableGPUValidationMode,
enableGPUShaderValidationMode: enableGPUShaderValidationMode,
showGraphicsOverview: showGraphicsOverview,
logGraphicsOverview: logGraphicsOverview,
enableAddressSanitizer: enableAddressSanitizer,
enableASanStackUseAfterReturn: enableASanStackUseAfterReturn,
enableThreadSanitizer: enableThreadSanitizer,
stopOnEveryThreadSanitizerIssue: stopOnEveryThreadSanitizerIssue,
enableUBSanitizer: enableUBSanitizer,
stopOnEveryUBSanitizerIssue: stopOnEveryUBSanitizerIssue,
disableMainThreadChecker: disableMainThreadChecker,
disablePerformanceAntipatternChecker: disablePerformanceAntipatternChecker,
stopOnEveryMainThreadCheckerIssue: stopOnEveryMainThreadCheckerIssue,
additionalOptions: additionalOptions,
commandlineArguments: commandlineArguments,
environmentVariables: environmentVariables,
language: language,
region: region,
showNonLocalizedStrings: showNonLocalizedStrings,
launchAutomaticallySubstyle: launchAutomaticallySubstyle,
storeKitConfigurationFileReference: storeKitConfigurationFileReference,
customLaunchCommand: customLaunchCommand,
customLLDBInitFile: customLLDBInitFile
)
}

// swiftlint:disable:next function_body_length
override init(element: AEXMLElement) throws {
buildConfiguration = element.attributes["buildConfiguration"] ?? LaunchAction.defaultBuildConfiguration
Expand All @@ -177,15 +273,13 @@ public extension XCScheme {
// Runnable
let buildableProductRunnableElement = element["BuildableProductRunnable"]
let remoteRunnableElement = element["RemoteRunnable"]
let pathRunnable = element["PathRunnable"]
if buildableProductRunnableElement.error == nil {
runnable = try BuildableProductRunnable(element: buildableProductRunnableElement)
} else if remoteRunnableElement.error == nil {
runnable = try RemoteRunnable(element: remoteRunnableElement)
}

let pathRunnable = element["PathRunnable"]
if pathRunnable.error == nil {
self.pathRunnable = try PathRunnable(element: pathRunnable)
} else if pathRunnable.error == nil {
runnable = try PathRunnable(element: pathRunnable)
}

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

if let pathRunnable {
element.addChild(pathRunnable.xmlElement())
}

if let locationScenarioReference {
element.addChild(locationScenarioReference.xmlElement())
}
Expand Down Expand Up @@ -395,7 +485,6 @@ public extension XCScheme {
buildConfiguration == rhs.buildConfiguration &&
launchStyle == rhs.launchStyle &&
askForAppToLaunch == rhs.askForAppToLaunch &&
pathRunnable == rhs.pathRunnable &&
customWorkingDirectory == rhs.customWorkingDirectory &&
useCustomWorkingDirectory == rhs.useCustomWorkingDirectory &&
ignoresPersistentStateOnLaunch == rhs.ignoresPersistentStateOnLaunch &&
Expand Down
34 changes: 20 additions & 14 deletions Sources/XcodeProj/Scheme/XCScheme+PathRunnable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,47 @@ import Foundation
import PathKit

public extension XCScheme {
class PathRunnable: Equatable {
class PathRunnable: Runnable {
// MARK: - Attributes

public var runnableDebuggingMode: String
public var filePath: String

// MARK: - Init

public init(filePath: String,
runnableDebuggingMode: String = "0") {
self.filePath = filePath
self.runnableDebuggingMode = runnableDebuggingMode
super.init(buildableReference: nil,
runnableDebuggingMode: runnableDebuggingMode)
}

init(element: AEXMLElement) throws {
runnableDebuggingMode = element.attributes["runnableDebuggingMode"] ?? "0"
override init(element: AEXMLElement) throws {
filePath = element.attributes["FilePath"] ?? ""
try super.init(element: element)
}

// MARK: - XML

func xmlElement() -> AEXMLElement {
AEXMLElement(name: "PathRunnable",
value: nil,
attributes: [
"runnableDebuggingMode": runnableDebuggingMode,
"FilePath": filePath,
])
override func xmlElement() -> AEXMLElement {
let element = super.xmlElement()
element.name = "PathRunnable"
element.attributes["FilePath"] = filePath
return element
}

// MARK: - Equatable

override func isEqual(other: XCScheme.Runnable) -> Bool {
guard let other = other as? PathRunnable else {
return false
}

return super.isEqual(other: other) &&
filePath == other.filePath
}

public static func == (lhs: PathRunnable, rhs: PathRunnable) -> Bool {
lhs.runnableDebuggingMode == rhs.runnableDebuggingMode &&
lhs.filePath == rhs.filePath
lhs.isEqual(other: rhs)
}
}
}
3 changes: 3 additions & 0 deletions Sources/XcodeProj/Scheme/XCScheme+ProfileAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@ public extension XCScheme {
// Runnable
let buildableProductRunnableElement = element["BuildableProductRunnable"]
let remoteRunnableElement = element["RemoteRunnable"]
let pathRunnableElement = element["PathRunnable"]
if buildableProductRunnableElement.error == nil {
runnable = try BuildableProductRunnable(element: buildableProductRunnableElement)
} else if remoteRunnableElement.error == nil {
runnable = try RemoteRunnable(element: remoteRunnableElement)
} else if pathRunnableElement.error == nil {
runnable = try PathRunnable(element: pathRunnableElement)
}

let buildableReferenceElement = element["MacroExpansion"]["BuildableReference"]
Expand Down
2 changes: 1 addition & 1 deletion Sources/XcodeProj/Scheme/XCScheme+Runnable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public extension XCScheme {

// MARK: - Init

public init(buildableReference: BuildableReference,
public init(buildableReference: BuildableReference?,
runnableDebuggingMode: String = "0") {
self.buildableReference = buildableReference
self.runnableDebuggingMode = runnableDebuggingMode
Expand Down
2 changes: 1 addition & 1 deletion Tests/XcodeProjTests/Scheme/XCSchemeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ final class XCSchemeIntegrationTests: XCTestCase {
// Given
let filePath = "/usr/bin/foo"
let pathRunnable = XCScheme.PathRunnable(filePath: filePath, runnableDebuggingMode: "0")
let subject = XCScheme.LaunchAction(runnable: nil, buildConfiguration: "Debug", pathRunnable: pathRunnable)
let subject = XCScheme.LaunchAction(runnable: pathRunnable, buildConfiguration: "Debug")

// When
let element = subject.xmlElement()
Expand Down

0 comments on commit 2297ad2

Please sign in to comment.