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

Fix brew info --json regressions around install status #14609

Merged
merged 1 commit into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Library/Homebrew/cask/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def eql?(other)
def to_h
if loaded_from_api && Homebrew::EnvConfig.install_from_api?
json_cask = Homebrew::API::Cask.all_casks[token]
return Homebrew::API.merge_variations(json_cask)
return api_to_local_hash(Homebrew::API.merge_variations(json_cask))
end

{
Expand Down Expand Up @@ -262,7 +262,9 @@ def to_h
end

def to_hash_with_variations
return Homebrew::API::Cask.all_casks[token] if loaded_from_api && Homebrew::EnvConfig.install_from_api?
if loaded_from_api && Homebrew::EnvConfig.install_from_api?
return api_to_local_hash(Homebrew::API::Cask.all_casks[token])
end

hash = to_h
variations = {}
Expand Down Expand Up @@ -300,6 +302,13 @@ def to_hash_with_variations

private

def api_to_local_hash(hash)
hash["token"] = token
hash["installed"] = versions.last
hash["outdated"] = outdated?
hash
end

def artifacts_list
artifacts.map do |artifact|
case artifact
Expand Down
25 changes: 18 additions & 7 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2074,11 +2074,6 @@ def missing_dependencies(hide: nil)

# @private
def to_hash
if self.class.loaded_from_api && Homebrew::EnvConfig.install_from_api?
json_formula = Homebrew::API::Formula.all_formulae[name]
return Homebrew::API.merge_variations(json_formula)
end

dependencies = deps

hsh = {
Expand Down Expand Up @@ -2185,16 +2180,32 @@ def to_hash
}
end

# TODO: can we implement these in Formulary?
if self.class.loaded_from_api && Homebrew::EnvConfig.install_from_api?
json_formula = Homebrew::API::Formula.all_formulae[name]
json_formula = Homebrew::API.merge_variations(json_formula)
hsh["oldname"] = json_formula["oldname"]
hsh["requirements"] = json_formula["requirements"]
end
Comment on lines +2183 to +2189
Copy link
Contributor

Choose a reason for hiding this comment

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

Were these things missing even before the most recent regression?

Copy link
Member Author

@Bo98 Bo98 Feb 13, 2023

Choose a reason for hiding this comment

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

Yes. I hand tested by comparing with and without HOMEBREW_NO_INSTALL_FROM_API. See qt@5 as an example.

We do not currently read requirements or oldname from the JSON file. This will be fixed after 4.0.0 - I don't think people would be happy if I tried to get something larger before 4.0.0. 😅

Variations also don't work without the original source, hence why that has the hybrid of API + local.


hsh
end

# @private
def to_hash_with_variations
hash = to_hash

# Take from API, merging in local install status.
if self.class.loaded_from_api && Homebrew::EnvConfig.install_from_api?
return Homebrew::API::Formula.all_formulae[name]
json_formula = Homebrew::API::Formula.all_formulae[name].dup
json_formula["name"] = hash["name"]
json_formula["installed"] = hash["installed"]
json_formula["linked_keg"] = hash["linked_keg"]
json_formula["pinned"] = hash["pinned"]
json_formula["outdated"] = hash["outdated"]
return json_formula
end

hash = to_hash
variations = {}

os_versions = [*MacOSVersions::SYMBOLS.keys, :linux]
Expand Down