-
-
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
cmd/deps: add --os
and --arch
#17122
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,10 @@ | |
"debugging the `--installed`/`--eval-all` display mode." | ||
switch "--HEAD", | ||
description: "Show dependencies for HEAD version instead of stable version." | ||
flag "--os=", | ||
description: "Show dependencies for the given operating system." | ||
flag "--arch=", | ||
description: "Show dependencies for the given CPU architecture." | ||
switch "--formula", "--formulae", | ||
description: "Treat all named arguments as formulae." | ||
switch "--cask", "--casks", | ||
|
@@ -82,85 +86,93 @@ | |
|
||
sig { override.void } | ||
def run | ||
raise UsageError, "`brew deps --os=all` is not supported" if args.os == "all" | ||
raise UsageError, "`brew deps --arch=all` is not supported" if args.arch == "all" | ||
|
||
os, arch = T.must(args.os_arch_combinations.first) | ||
all = args.eval_all? | ||
|
||
Formulary.enable_factory_cache! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I double-checked to make sure that the caching strategy supports multiple platforms. |
||
|
||
recursive = !args.direct? | ||
installed = args.installed? || dependents(args.named.to_formulae_and_casks).all?(&:any_version_installed?) | ||
|
||
@use_runtime_dependencies = installed && recursive && | ||
!args.tree? && | ||
!args.graph? && | ||
!args.HEAD? && | ||
!args.include_build? && | ||
!args.include_test? && | ||
!args.include_optional? && | ||
!args.skip_recommended? && | ||
!args.missing? | ||
|
||
if args.tree? || args.graph? | ||
dependents = if args.named.present? | ||
sorted_dependents(args.named.to_formulae_and_casks) | ||
elsif args.installed? | ||
case args.only_formula_or_cask | ||
SimulateSystem.with(os:, arch:) do | ||
recursive = !args.direct? | ||
installed = args.installed? || dependents(args.named.to_formulae_and_casks).all?(&:any_version_installed?) | ||
|
||
@use_runtime_dependencies = installed && recursive && | ||
!args.tree? && | ||
!args.graph? && | ||
!args.HEAD? && | ||
!args.include_build? && | ||
!args.include_test? && | ||
!args.include_optional? && | ||
!args.skip_recommended? && | ||
!args.missing? && | ||
args.os.nil? && | ||
args.arch.nil? | ||
|
||
if args.tree? || args.graph? | ||
dependents = if args.named.present? | ||
sorted_dependents(args.named.to_formulae_and_casks) | ||
elsif args.installed? | ||
case args.only_formula_or_cask | ||
when :formula | ||
sorted_dependents(Formula.installed) | ||
when :cask | ||
sorted_dependents(Cask::Caskroom.casks) | ||
else | ||
sorted_dependents(Formula.installed + Cask::Caskroom.casks) | ||
end | ||
else | ||
raise FormulaUnspecifiedError | ||
end | ||
|
||
if args.graph? | ||
dot_code = dot_code(dependents, recursive:) | ||
if args.dot? | ||
puts dot_code | ||
else | ||
exec_browser "https://dreampuf.github.io/GraphvizOnline/##{ERB::Util.url_encode(dot_code)}" | ||
end | ||
return | ||
end | ||
|
||
puts_deps_tree(dependents, recursive:) | ||
return | ||
elsif all | ||
puts_deps(sorted_dependents( | ||
Formula.all(eval_all: args.eval_all?) + Cask::Cask.all(eval_all: args.eval_all?), | ||
), recursive:) | ||
return | ||
elsif !args.no_named? && args.for_each? | ||
puts_deps(sorted_dependents(args.named.to_formulae_and_casks), recursive:) | ||
return | ||
end | ||
|
||
if args.no_named? | ||
raise FormulaUnspecifiedError unless args.installed? | ||
|
||
sorted_dependents_formulae_and_casks = case args.only_formula_or_cask | ||
when :formula | ||
sorted_dependents(Formula.installed) | ||
when :cask | ||
sorted_dependents(Cask::Caskroom.casks) | ||
else | ||
sorted_dependents(Formula.installed + Cask::Caskroom.casks) | ||
end | ||
else | ||
raise FormulaUnspecifiedError | ||
end | ||
|
||
if args.graph? | ||
dot_code = dot_code(dependents, recursive:) | ||
if args.dot? | ||
puts dot_code | ||
else | ||
exec_browser "https://dreampuf.github.io/GraphvizOnline/##{ERB::Util.url_encode(dot_code)}" | ||
end | ||
puts_deps(sorted_dependents_formulae_and_casks, recursive:) | ||
return | ||
end | ||
|
||
puts_deps_tree(dependents, recursive:) | ||
return | ||
elsif all | ||
puts_deps(sorted_dependents( | ||
Formula.all(eval_all: args.eval_all?) + Cask::Cask.all(eval_all: args.eval_all?), | ||
), recursive:) | ||
return | ||
elsif !args.no_named? && args.for_each? | ||
puts_deps(sorted_dependents(args.named.to_formulae_and_casks), recursive:) | ||
return | ||
end | ||
|
||
if args.no_named? | ||
raise FormulaUnspecifiedError unless args.installed? | ||
dependents = dependents(args.named.to_formulae_and_casks) | ||
check_head_spec(dependents) if args.HEAD? | ||
|
||
sorted_dependents_formulae_and_casks = case args.only_formula_or_cask | ||
when :formula | ||
sorted_dependents(Formula.installed) | ||
when :cask | ||
sorted_dependents(Cask::Caskroom.casks) | ||
else | ||
sorted_dependents(Formula.installed + Cask::Caskroom.casks) | ||
end | ||
puts_deps(sorted_dependents_formulae_and_casks, recursive:) | ||
return | ||
all_deps = deps_for_dependents(dependents, recursive:, &(args.union? ? :| : :&)) | ||
condense_requirements(all_deps) | ||
all_deps.map! { |d| dep_display_name(d) } | ||
all_deps.uniq! | ||
all_deps.sort! unless args.topological? | ||
puts all_deps | ||
end | ||
|
||
dependents = dependents(args.named.to_formulae_and_casks) | ||
check_head_spec(dependents) if args.HEAD? | ||
|
||
all_deps = deps_for_dependents(dependents, recursive:, &(args.union? ? :| : :&)) | ||
condense_requirements(all_deps) | ||
all_deps.map! { |d| dep_display_name(d) } | ||
all_deps.uniq! | ||
all_deps.sort! unless args.topological? | ||
puts all_deps | ||
end | ||
|
||
private | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Tangential: Do we list supported operating systems and architectures in the docs anywhere? If not, that might be a good thing to add at some point since this pattern is showing up in a few commands.
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 don't think it is documented. Closest may be
on_*
docs - https://docs.brew.sh/Formula-Cookbook#handling-different-system-configurationsSupported architectures at least show up if unsupported one is passed in, e.g.