-
-
Notifications
You must be signed in to change notification settings - Fork 320
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
Conversation
There was a problem hiding this 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.
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) |
There was a problem hiding this comment.
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?
lhs.isEqual(other: rhs) && rhs.isEqual(other: lhs) | |
lhs.isEqual(other: rhs) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 apathRunnable
without a default to help the compiler disambiguate (and to flag the deprecation warning)
There was a problem hiding this comment.
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
There was a problem hiding this 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, |
There was a problem hiding this comment.
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 apathRunnable
without a default to help the compiler disambiguate (and to flag the deprecation warning)
@all-contributors add @georgenavarro for code |
I've put up a pull request to add @georgenavarro! 🎉 |
…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.
…ackwards compatibility
…arameter for backwards compatibility
7681b2f
to
ad3e91b
Compare
runnable as? PathRunnable | ||
} | ||
set { | ||
self.pathRunnable = newValue |
There was a problem hiding this comment.
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.") |
There was a problem hiding this comment.
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
I've opened a new PR to fix the issues I mentioned above. |
Ouch, thanks for opening a PR for those issues. Let me review it and get it merged. |
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:
or a function that takes in two different parameters:
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:
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 👩💻👨💻