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

Use prepended modules instead of undef for OS-specific code #18305

Merged
merged 6 commits into from
Sep 19, 2024
Merged

Conversation

dduugg
Copy link
Sponsor Member

@dduugg dduugg commented Sep 11, 2024

  • 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?

Relates to #17998

Switches from using undef, which results in (suppressed) sorbet errors, with prepended modules.

The latest proposal on the thread suggested creating an interface with three implementations, rather than using the generic-OS version in the default implementation, with methods undefined in OS-specific code. In building that out, I noticed that there wasn't a consistent, common interface among the OS variations, specifically in the case of Formula.

Thus, I've landed on OS extensions written as modules, which are then prepended to be used ahead of the generic implementations. (Note that in some cases, the modules are prepended to the singleton class, which admittedly gets pretty esoteric.)

@dduugg dduugg marked this pull request as draft September 11, 2024 02:27
Copy link
Member

@carlocab carlocab left a comment

Choose a reason for hiding this comment

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

Nice

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.

This approach looks good and makes sense to me, nice work!

I wonder if there's any way to avoid the need for the require at the bottom of the existing class? That'd be nice if possible.

Library/Homebrew/extend/os/linux/cleanup.rb Outdated Show resolved Hide resolved
Library/Homebrew/extend/os/linux/formula.rb Outdated Show resolved Hide resolved
Library/Homebrew/extend/os/mac/cleaner.rb Outdated Show resolved Hide resolved
@dduugg
Copy link
Sponsor Member Author

dduugg commented Sep 11, 2024

This approach looks good and makes sense to me, nice work!

I wonder if there's any way to avoid the need for the require at the bottom of the existing class? That'd be nice if possible.

Yes, that would be very nice, but right now sorbet/sorbet#5025 requires the prepend to come after the methods being replaced.

@dduugg dduugg force-pushed the no-undefs branch 6 times, most recently from 466fdf6 to 4465375 Compare September 18, 2024 22:46
@dduugg dduugg marked this pull request as ready for review September 18, 2024 22:47
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.

Thanks @dduugg! Still have some thoughts about the module naming/hierarchy but both the discussions and changes can 100% be done post-merge so no feedback here is blocking. Feel free to self-merge whenever you feel happy with it. Great work!

Library/Homebrew/extend/os/linux/cleanup.rb Show resolved Hide resolved
Library/Homebrew/extend/os/mac/simulate_system.rb Outdated Show resolved Hide resolved
@dduugg dduugg merged commit 3b649d1 into master Sep 19, 2024
28 checks passed
@dduugg dduugg deleted the no-undefs branch September 19, 2024 21:03
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