-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Add which entry command #21790
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
Open
ooye-sanket
wants to merge
9
commits into
Homebrew:main
Choose a base branch
from
ooye-sanket:add-which-entry-command
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add which entry command #21790
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
66af1da
cmd/tab: sync installed_as_dependency when changing installed_on_request
ooye-sanket a3c0d9b
dev-cmd: add which-entry command for executables DB
ooye-sanket ae66e65
dev-cmd: fix brew style offenses in which-entry
ooye-sanket 6c1b0ab
dev-cmd: inline helpers, add opoo warning, add basic spec
ooye-sanket 32a99d3
improve as address by maintainer
ooye-sanket eb11c44
dev-cmd: fix brew style offenses in which-entry
ooye-sanket 00d9e78
dev-cmd: fix Sorbet typecheck errors in which-entry
ooye-sanket d3ae375
Update Library/Homebrew/dev-cmd/which-entry.rb
ooye-sanket 91f72e6
dev-cmd: drop pkg_version from which-entry DB line format
ooye-sanket 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 hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # typed: strict | ||
| # frozen_string_literal: true | ||
|
|
||
| require "abstract_command" | ||
| require "formula" | ||
| require "formulary" | ||
| require "json" | ||
|
|
||
| module Homebrew | ||
| module DevCmd | ||
| class WhichEntry < AbstractCommand | ||
| cmd_args do | ||
| description <<~EOS | ||
| Generate an `executables.txt` entry for <formula> using bottle manifest metadata. | ||
| EOS | ||
| flag "--output-db=", | ||
| description: "Append or update the entry in the given `executables.txt` database file." | ||
| named_args :formula, min: 1 | ||
| end | ||
|
|
||
| sig { override.void } | ||
| def run | ||
| db_path = Pathname(args.output_db) if args.output_db | ||
| args.named.each { |name| process(name, db_path:) } | ||
| end | ||
|
|
||
| private | ||
|
|
||
| sig { params(name: String, db_path: T.nilable(Pathname)).void } | ||
| def process(name, db_path:) | ||
| formula = Formulary.factory(name) | ||
| line = db_line(formula) | ||
| if db_path | ||
| write_db(db_path, formula.full_name, line) | ||
| elsif line | ||
| puts line | ||
| end | ||
| rescue FormulaUnavailableError | ||
| write_db(db_path, name, nil) if db_path&.exist? | ||
| end | ||
|
|
||
| sig { params(db_path: Pathname, name: String, line: T.nilable(String)).void } | ||
| def write_db(db_path, name, line) | ||
| lines = db_path.readlines(chomp: true).compact_blank if db_path.exist? | ||
| lines = Array(lines).reject { |l| l.start_with?("#{name}:") } | ||
| lines << line if line | ||
| db_path.write("#{lines.sort.join("\n")}\n") | ||
| end | ||
|
|
||
| sig { params(formula: Formula).returns(T.nilable(String)) } | ||
| def db_line(formula) | ||
| return if formula.disabled? || formula.deprecated? | ||
|
|
||
| exes = executables_from_manifest(formula) | ||
| "#{formula.full_name}:#{exes.join(" ")}" | ||
| end | ||
|
|
||
| sig { params(formula: Formula).returns(T::Array[String]) } | ||
| def executables_from_manifest(formula) | ||
| return [] unless formula.bottled? | ||
|
|
||
| manifest_path = HOMEBREW_CACHE.glob("#{formula.name}_bottle_manifest--*").first | ||
| if manifest_path.blank? | ||
| bottle = formula.bottle | ||
| return [] unless bottle | ||
|
|
||
| bottle.fetch | ||
| manifest_path = HOMEBREW_CACHE.glob("#{formula.name}_bottle_manifest--*").first | ||
| end | ||
| return [] if manifest_path.blank? | ||
|
|
||
| manifest = JSON.parse(manifest_path.read) | ||
| exec_files = manifest.dig("manifests", 0, "annotations", "sh.brew.path_exec_files") | ||
| return [] if exec_files.blank? | ||
|
|
||
| exec_files.split.map { |f| File.basename(f) }.sort | ||
| rescue JSON::ParserError => e | ||
| opoo "Failed to parse bottle manifest for #{formula.name}: #{e.message}" | ||
| [] | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "cmd/shared_examples/args_parse" | ||
| require "dev-cmd/which-entry" | ||
|
|
||
| RSpec.describe Homebrew::DevCmd::WhichEntry do | ||
| it_behaves_like "parseable arguments" | ||
| end |
Oops, something went wrong.
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.
can this share any logic or constants with the relevant
bottle.rborresource.rbcode?