Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Update PathRunnable so that it subclasses Runnable #883

Merged
merged 8 commits into from
Dec 3, 2024

Conversation

georgenavarro
Copy link
Contributor

Short description 📝

PathRunnable currently does not subclass from Runnable like BuildableProductRunnable and RemoteRunnable do. This means that even if you don't care about the specific Runnable implementation, you still have to handle PathRunnable separately from the Runnable subclasses. For example, you would either need two different functions:

func doSomething(with runnable: Runnable)
func doSomething(with runnable: PathRunnable)

or a function that takes in two different parameters:

func doSomething(with runnable: Runnable?, or runnable: PathRunnable?)

Solution 📦

Refactor PathRunnable so that it subclasses from Runnable. This will allow any var or function parameter of type Runnable to hold an instance of PathRunnable. For example the following function would now be able to accept a PathRunnable as an argument in addition to a BuildableProductRunnable or RemoteRunnable:

func doSomething(with runnable: Runnable)

Since the only changes is to make PathRunnable subclass Runnable, this should be a non breaking change. No properties or functions are being added, deleted.

Implementation 👩‍💻👨‍💻

  • Made the buildableReference parameter of Runnable's init an optional parameter. The buildableReference property of Runnable was already optional so now the types match. Since PathRunnable does not use a BuildableReference, this change will allow PathRunnable to call Runnable's init with a nil BuildableReference argument.
  • Changed PathRunnable to subclass from Runnable like BuildableProductRunnable and RemoteRunnable do.
  • Removed PathRunnable's declared conformance to Equatble since it now inherits that from Runnable.
  • Removed PathRunnable's runnableDebuggingMode property since it now inherits that from Runnable.
  • Refactored the functions that PathRunnable now overrides from Runnable. I used RemoteRunnable as a model for how to accomplish this.
  • Removed the pathRunnable property from LaunchAction now that its runnable var can hold an instance of PathRunnable. This avoids the possiblity of having two different runnables, which didn't really make sense. If Xcode detects two runnables, it updates the scheme's launch action so that it only keeps one and deletes the other.
  • Updated the serialization test case for PathRunnable.

Copy link
Collaborator

@kwridan kwridan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing this @georgenavarro

Looking at the original PR that introduced PathRunnable there doesn't seem to be any specific reason why this wouldn't have been a subclass of Runnable most likely accidental. As far as I can tell there can only be one Runnable, one of which is PathRunnable so makes sense to consolidate this.

#521

That said we'll need a few small tweaks to ensure non breaking changes, perhaps with some deprecation annotations which can be cleaned up in the next major release.

public static func == (lhs: PathRunnable, rhs: PathRunnable) -> Bool {
lhs.runnableDebuggingMode == rhs.runnableDebuggingMode &&
lhs.filePath == rhs.filePath
lhs.isEqual(other: rhs) && rhs.isEqual(other: lhs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are both checks needed? Would one suffice here?

Suggested change
lhs.isEqual(other: rhs) && rhs.isEqual(other: lhs)
lhs.isEqual(other: rhs)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe your change would be sufficient to check for equality. I did it this way because RemoteRunnable had the same implementation so I thought I should follow the pattern. I'll happily make this change as well. 👍🏼

@@ -3,41 +3,47 @@ import Foundation
import PathKit

public extension XCScheme {
class PathRunnable: Equatable {
class PathRunnable: Runnable {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making PathRunnable subclass Runnable means we'll also need to update ProfileAction to support it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I overlooked this one. I'll try to add this as well.

customLLDBInitFile: String? = nil
) {
self.init(
runnable: pathRunnable ?? runnable,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also realized that I removed PathRunnable as a parameter in LaunchAction's init method which would also be a breaking change. I created a convenience init method which adds it back for backwards compatibility. I chose to have it call the designated initializer with it's pathRunnable argument nil coalesced to other runnable argument since it is the more specialized one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @georgenavarro

Two small suggestions

  • Perhaps we can mark it as deprecated and a message to use init(runnable: pathRunnable)
  • We can make the convenience init have a pathRunnable without a default to help the compiler disambiguate (and to flag the deprecation warning)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a commit addressing this feedback. Thanks @kwridan

Copy link
Collaborator

@kwridan kwridan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the updates @georgenavarro

customLLDBInitFile: String? = nil
) {
self.init(
runnable: pathRunnable ?? runnable,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @georgenavarro

Two small suggestions

  • Perhaps we can mark it as deprecated and a message to use init(runnable: pathRunnable)
  • We can make the convenience init have a pathRunnable without a default to help the compiler disambiguate (and to flag the deprecation warning)

@kwridan
Copy link
Collaborator

kwridan commented Dec 3, 2024

@all-contributors add @georgenavarro for code

Copy link
Contributor

@kwridan

I've put up a pull request to add @georgenavarro! 🎉

georgenavarro and others added 8 commits December 3, 2024 17:18
…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.
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 the dedicated pathRunnable var from LaunchAction now that the runnable var can hold a PathRunnable. Also updated the test case for PathRunnable serialization.
@pepicrft pepicrft force-pushed the pathrunnable-inheritance branch from 7681b2f to ad3e91b Compare December 3, 2024 16:38
@pepicrft pepicrft changed the title Update PathRunnable so that it subclasses Runnable refactor: Update PathRunnable so that it subclasses Runnable Dec 3, 2024
@pepicrft pepicrft merged commit 2297ad2 into tuist:main Dec 3, 2024
5 of 7 checks passed
@georgenavarro georgenavarro deleted the pathrunnable-inheritance branch December 3, 2024 18:14
runnable as? PathRunnable
}
set {
self.pathRunnable = newValue
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pepicrft Looks like this was supposed to be self.runnable = newValue. Xcode is warning about infinite recursion since it is essentially calling it's own setter.

@@ -81,6 +87,7 @@ public extension XCScheme {

// MARK: - Init

@available(*, deprecated, message: "Use the init() that consolidates pathRunnable and runnable into a single parameter.")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pepicrft I think this deprecation warning was attached to the wrong init since the other convenience init now only accepts a PathRunnable

@georgenavarro
Copy link
Contributor Author

I've opened a new PR to fix the issues I mentioned above.

@pepicrft
Copy link
Contributor

Ouch, thanks for opening a PR for those issues. Let me review it and get it merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants