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

OS::Mac: Move version methods into ::Version #11581

Merged
merged 1 commit into from Jun 23, 2021

Conversation

samford
Copy link
Member

@samford samford commented Jun 22, 2021

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

#11557 needs to know if a Sparkle feed item's minimumSystemVersion (a macOS version like 12.0.0) is a prerelease version. OS::Mac has a #prerelease? method but it can seemingly only be used to check the macOS version of the execution environment, like OS::Mac.prerelease?. We need to be able to do OS::Mac::Version.new("12.0.0").prerelease?, which isn't currently supported.

This PR moves the #outdated_release? and #prerelease? methods to OS::Mac::Version and simply calls the ::Version methods in the related OS::Mac methods. This allows for both OS::Mac.prerelease? and OS::Mac::Version.new("12.0.0").prerelease?.

It would be nice to be able to remove these methods from OS::Mac while still being able to access them like OS::Mac.prerelease?. I couldn't get either def_delegators or delegate (from ActiveSupport) to work where OS::Mac.prerelease? calls version.prerelease?). Any suggestions on how to approach this or is the present code what we would expect?

@BrewTestBot
Copy link
Member

Review period will end on 2021-06-23 at 16:18:45 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Jun 22, 2021
@samford samford force-pushed the MacOS-move-version-methods branch 2 times, most recently from 76ff839 to e0869e5 Compare June 22, 2021 17:06
Copy link

@donnacn donnacn left a comment

Choose a reason for hiding this comment

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

I'm new to this, might need some help with the technical side with fixing issues....

maxim-belkin
maxim-belkin previously approved these changes Jun 22, 2021
Copy link
Member

@maxim-belkin maxim-belkin left a comment

Choose a reason for hiding this comment

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

👍🏻 from me. Moving hard-coded versions to os/mac/version seems like a logical step to me because os/mac behaves as an aggregator of macOS-specific behavior. I specifically like that this PR defines two new constants that we can quickly update or, if desired, read or obtain from somewhere later down the road.

@maxim-belkin
Copy link
Member

Tested with:

irb(main):013:0> v = OS::Mac::Version.new("10")
=> #<OS::Mac::Version:0x00007fa4bc070310 @version="10", @detected_from_url=false, @comparison_cache={}>
irb(main):014:0> v.prerelease?
=> false
irb(main):015:0> v.outdated_release?
=> true
irb(main):016:0> 

@samford
Copy link
Member Author

samford commented Jun 22, 2021

I modified the ::Version methods to use self instead of the version variable, as it wasn't working correctly otherwise (i.e., #prerelease? was returning false for a Version like OS::Mac::Version.new("12")). I had previously modified these to use self but I lost that change while iterating on different versions of this.


Tested with:

For the same of completeness...

Here's the output for a prerelease version:

irb(main):001:0> v = OS::Mac::Version.new("12")
=> #<OS::Mac::Version:0x00007f86499ace60 @version="12", @detected_from_url=false, @comparison_cache={}>
irb(main):002:0> v.outdated_release?
=> false
irb(main):003:0> v.prerelease?
=> true

Also, the existing behavior of OS::Mac.prerelease? and OS::Mac.outdated_release? remains the same:

irb(main):001:0> OS::Mac.version
=> #<OS::Mac::Version:0x00007f9c4aa31ec8 @version="11", @detected_from_url=false, @comparison_cache={}>
irb(main):002:0> OS::Mac.outdated_release?
=> false
irb(main):003:0> OS::Mac.prerelease?
=> false

maxim-belkin
maxim-belkin previously approved these changes Jun 22, 2021
MikeMcQuaid
MikeMcQuaid previously approved these changes Jun 23, 2021
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Makes sense to me, nice API addition/cleanup. One optional thought but feel free to merge without if you'd rather.

Library/Homebrew/os/mac/version.rb Outdated Show resolved Hide resolved
@samford
Copy link
Member Author

samford commented Jun 23, 2021

I was pondering the OS::Mac#outdated_release?/OS::Mac#prerelease? situation and what do we think about updating existing references in brew to simply use OS::Mac.version.outdated_release?/OS::Mac.version.prerelease?. The methods in OS::Mac are only using version to call the methods in ::Version, so they're just a convenience at this point.

This would allow us to fully remove the methods from OS::Mac and it would also make the code more clear. To me OS::Mac.prerelease? doesn't immediately make me think that it's checking the macOS version of the execution environment but OS::Mac.version.prerelease? is more explicit and gives me a better idea of what may be happening. Maybe this is just me, though.

@samford samford dismissed stale reviews from MikeMcQuaid and maxim-belkin via c387467 June 23, 2021 12:15
@samford samford force-pushed the MacOS-move-version-methods branch from c589f66 to c387467 Compare June 23, 2021 12:15
@MikeMcQuaid
Copy link
Member

I was pondering the OS::Mac#outdated_release?/OS::Mac#prerelease? situation and what do we think about updating existing references in brew to simply use OS::Mac.version.outdated_release?/OS::Mac.version.prerelease?. The methods in OS::Mac are only using version to call the methods in ::Version, so they're just a convenience at this point.

This would allow us to fully remove the methods from OS::Mac and it would also make the code more clear. To me OS::Mac.prerelease? doesn't immediately make me think that it's checking the macOS version of the execution environment but OS::Mac.version.prerelease? is more explicit and gives me a better idea of what may be happening. Maybe this is just me, though.

Makes sense to me 👍🏻

MikeMcQuaid
MikeMcQuaid previously approved these changes Jun 23, 2021
@samford
Copy link
Member Author

samford commented Jun 23, 2021

In the latest changes, the new constants in OS::Mac::Version are private and I've updated usage of the aforementioned OS::Mac methods and properly removed them. Everything in brew now uses OS::Mac.version to access these methods.

Unless anyone sees anything else that needs to be addressed, I think that should take care of this.

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Jun 23, 2021
@BrewTestBot
Copy link
Member

Review period ended.

@samford samford merged commit 47d5150 into Homebrew:master Jun 23, 2021
@samford samford deleted the MacOS-move-version-methods branch June 23, 2021 21:03
@samford
Copy link
Member Author

samford commented Jun 23, 2021

Thanks, everyone!

@github-actions github-actions bot added the outdated PR was locked due to age label Jul 24, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants