-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
dependency_helpers: rework recursive dependency resolution #15892
dependency_helpers: rework recursive dependency resolution #15892
Conversation
This is a refactor/reworking of the dependency resolution methods in the DependencyHelpers module. These methods are used by both the `brew deps` and `brew uses` commands to get a specific set of dependencies for the user based on multiple criteria. Additive Options: --include-build --include-test --include-optional Subtractive Options: --skip-recommended --missing When a user runs either command the only dependencies that are included by default are recommended and runtime dependencies. This is largely unchanged though we don't include all non-build dependencies as recommended by default anymore. The biggest change is that all installed dependencies are always removed from the list now if the --missing option is passed. This could get skipped before depending on the other options that were passed. Essentially subtractive options now will always be evaluated before additive ones (the docs will need to be updated to make this clear). Beyond that we have no special handling for the optional command anymore. We used to check that the optional dependency was not needed to build the formula but that seems redundant and confusing. Essentially, the #recursive_includes command now behaves much more like the #reject_ignores command (essentially the non-recursive version) which is a good thing for consistency's sake.
There's a part of me that wonders if we'd be better off just having a |
I don't think so as |
There is, though, an argument whether it even makes sense to support |
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.
This looks great so far, I really like the refactoring approach.
They're quite highly used in third-party taps, which makes sense given they don't necessarily use bottles like we do for homebrew-core, and are also usually only a few formulae rather than a few thousand. homebrew-ffmpeg being a popular example (and the use of |
Yeh, I'm interested whether |
Not as common as |
Cool, yeh, probably worth keeping both then, thanks @Bo98. |
Thanks for feedback everyone. I did some testing on the core repo and it seems like everything behaves the same way for the Beyond that I'll take a look at other third-party taps for testing how optional and recommended dependencies respond to these changes. I was able to find a few good ones that should be representative I hope. I'll also change the code to use |
Never mind, my earlier testing wasn't thorough enough. It looks like one of things the new algorithm wasn't handling well was I did a bit more looking around and it seems like the main difference will be with the missing flag. Other than that things should be pretty similar to before. |
- Use .required? instead of .tags.empty? - use .public_send - modify .reject_ignores to be .select_includes - checks ignores first now - Don't use runtime deps with --missing in `brew deps` command
b4be0f0
to
e314a43
Compare
Ignore all dependencies that are already installed before checking if they use the dependency in question. Remove the :satisfied? criteria before checking used dependents.
I updated the integration tests to cover more of the expected behavior. I thought about adding unit tests but that would involve lots of mocking of formulae so I'm not sure it's worth it. I'm surprised that while the behavior of the For example:
The
I assume that |
I would have liked to test the installed package behavior with |
Could try to just write the keg's directory on disk, that will likely be enough? |
These tests were very simple before and now this should result in more code coverage without affecting test performance. The only tricky thing was testing the `--missing` option without actually installing a package using `install_test_formula` because that is very slow (around 10 seconds on my machine). I ended up just writing the tab to a plausible keg directory for each package I wanted to "install". This allows us to test the behavior while also not increasing CI time by ~20 seconds (though it'd probably be faster on CI than my local machine).
- add clarification about precedence of command options - reword some options for readability - clarify the defaults in `brew deps`
b05cade
to
b2b8f0e
Compare
I updated the pr description with some more info, added more stuff to the integration tests and updated the man pages. These are breaking changes so I think they should probably wait until the next release though the previous behavior was somewhat broken to begin with. |
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.
Looks great, thanks again @apainintheneck!
Don't think it's worth waiting for next release or considering these changes breaking considering these are non-default options on a developer command. If enough people loudly complain: we can revert or gate until the next release (but I appreciate the caution nonetheless @apainintheneck). |
@carlocab When you're ✅ here: feel free to 🚢 |
To clarify: does this mean
I'm fine with changing, but just to clarify here: this is not a dev-cmd. |
TIL that |
Yes, fair point. It feels like a borderline one. |
Good catch @Bo98! That was something that hadn't crossed my mind at all. It looks like this was added in at user request to match how some undocumented behavior used to work (discussion: #5587; pr: #5648). I can look into adding this back in though I believe it's a super niche use case. It'd be nice to have a test for this too. Note: This never worked before with the |
The relevant folks here no longer seem to be maintaining taps with options and this was shortly around the time Homebrew/homebrew-core removed all options. Gonna merge as-is. We can adjust or revert as needed. Thanks @apainintheneck! |
In that case, we should remove the diff --git a/Library/Homebrew/cmd/deps.rb b/Library/Homebrew/cmd/deps.rb
index bd14a89c9..4ea97820d 100644
--- a/Library/Homebrew/cmd/deps.rb
+++ b/Library/Homebrew/cmd/deps.rb
@@ -13,8 +13,7 @@ module Homebrew
def self.deps_args
Homebrew::CLI::Parser.new do
description <<~EOS
- Show dependencies for <formula>. Additional options specific to <formula>
- may be appended to the command. When given multiple formula arguments,
+ Show dependencies for <formula>. When given multiple formula arguments,
show the intersection of dependencies for each formula. By default, `deps`
shows all required and recommended dependencies.
@@ -71,7 +70,6 @@ module Homebrew
conflicts "--installed", "--eval-all"
conflicts "--installed", "--all"
conflicts "--formula", "--cask"
- formula_options
named_args [:formula, :cask]
end CC: @blogabe and @RandomDSdevel since you both were involved in the original discussion to add |
@apainintheneck whoops, sorry, follow-up PR in #15922 |
(Apologies for the mild delay in replying.)
My efforts remain stalled in extended development purgatory; including due to external factors; this can get revisited if/as needed. |
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?Fixes #15842
This is a refactor/reworking of the dependency resolution methods in the DependencyHelpers module. These methods are used by both the
brew deps
andbrew uses
commands to get a specific set of dependencies for the user based on multiple criteria.Additive Options:
--include-build
--include-test
--include-optional
Subtractive Options:
--skip-recommended
--missing
When a user runs either command the only dependencies that are included by default are recommended and runtime dependencies. This is largely unchanged though we only used to include recommended dependencies if they were build dependencies before. I'm not entirely sure why these were included by default before though.
The biggest change is that all installed dependencies are always removed from the list now if the --missing option is passed. This could get skipped before depending on the other options that were passed. Essentially subtractive options now will always be evaluated before additive ones (the docs will need to be updated to make this clear).
Beyond that we have no special handling for the optional command anymore. We used to check that the optional dependency was not needed to build the formula but that seems redundant and confusing.
Essentially, the #recursive_includes command now behaves much more like the #reject_ignores command (essentially the non-recursive version) which is a good thing for consistency's sake.I updated the#reject_ignores
command to make sure it aligns with the new goal of giving subtractive options priority here and also renamed it to#select_includes
after refactoring.I also updated the man pages for both the
brew uses
andbrew deps
commands to clarify how they work.Note: These are technically breaking changes. I think these commands were broken before but still it's possible that someone is counting on the previous behavior. This should probably wait until the next minor release at the very least.
Todo:
I've only tested a handful of packages so far.brew deps
command with the--for-each
flag set and this returns the same results except for when--missing
is set.brew uses
, most of which are recommended or optional, and things look good here.brew uses
andbrew deps
to make things clearer.