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

autoremove: ignore build deps when built from src #13839

Conversation

apainintheneck
Copy link
Contributor

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

Alternate approach to #13831.

Now the build dependencies of formula that were installed from source will not be removed by brew autoremove. This is especially helpful for those who've installed brew in an alternative prefix.

The problem that could come up is that if the formula is out of date the original build dependencies will be different from those in the current formula file but this should work well in most cases. With casks we store the original cask file but we don't seem to do the same thing with formulae.

Now the build dependencies of formula that were installed from
source will not be removed by `brew autoremove`. This is especially
helpful for those who've installed brew in an alternative prefix.
@BrewTestBot
Copy link
Member

Review period will end on 2022-09-13 at 00:00:00 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Sep 10, 2022
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.

Really like this approach! Some optional, non-blocking comments/thoughts.

# An array of all installed {Formula} without {Formula} dependents
# An array of all installed {Formula} without runtime {Formula}
# dependents for bottles and without build {Formula} dependents
# for those built from source.
# @private
def self.formulae_with_no_formula_dependents(formulae)
Copy link
Member

Choose a reason for hiding this comment

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

Is this method still useful/used after being removed from leave?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, it might be worth creating another file for all of these methods. They are tangentially related to Formula but now they're getting very specific.

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 don't think it makes much sense to merge them into Cleanup though.

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 ended up moving that logic into Utils::Autoremove.

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

For my attempt at this I got very confused about these functions. They generally consider runtime & cask dependencies, but are named like no_dependents. So making an alternate version that also considered build dependencies would end up looking like no_dependents_including_build_dependents. Then you could think of recommended etc. dependencies and need 6 versions including no_dependents_at_all_i_mean_it. 😵

Anyway, I'm glad you figured out the logic and a saner organization of it to boot. 🍻

# @private
def self.formulae_with_no_formula_dependents(formulae)
return [] if formulae.blank?

formulae - formulae.flat_map(&:runtime_formula_dependencies)
formulae - formulae.each_with_object([]) do |formula, dependents|
dependents.concat(formula.runtime_formula_dependencies)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dependents.concat(formula.runtime_formula_dependencies)
dependents += formula.runtime_formula_dependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this just a style thing? From what I understand Array#concat is in-place while Array#+= always creates a new array. It probably doesn't make a big difference either way but I'm just interested in why. Happy to change it though.


# Include build dependencies when the formula is not a bottle
unless Tab.for_keg(formula.any_installed_keg).poured_from_bottle
dependents.concat(formula.deps.select(&:build?).map(&:to_formula))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dependents.concat(formula.deps.select(&:build?).map(&:to_formula))
dependents += formula.deps.select(&:build?).map(&:to_formula)

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Sep 13, 2022
@BrewTestBot
Copy link
Member

Review period ended.

@apainintheneck apainintheneck marked this pull request as ready for review September 14, 2022 06:28
@MikeMcQuaid MikeMcQuaid merged commit 1b3f598 into Homebrew:master Sep 14, 2022
@MikeMcQuaid
Copy link
Member

Great work, thanks again @apainintheneck!

@github-actions github-actions bot added the outdated PR was locked due to age label Oct 19, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2022
@apainintheneck apainintheneck deleted the no-autoremove-build-deps-when-built-from-src branch January 3, 2023 00:30
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

4 participants