Skip to content

Commit

Permalink
Merge pull request #11715 from Rylan12/json-improvements
Browse files Browse the repository at this point in the history
Improvements to JSON bottle handling
  • Loading branch information
Rylan12 committed Jul 16, 2021
2 parents 83821cf + 2524e80 commit a4e093d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
12 changes: 11 additions & 1 deletion Library/Homebrew/bottle_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,20 @@ def fetch_bottles(name)
hash = fetch(name)
bottle_tag = Utils::Bottles.tag.to_s

odie "No bottle available for current OS" unless hash["bottles"].key? bottle_tag
odie "No bottle available for current OS" if !hash["bottles"].key?(bottle_tag) && !hash["bottles"].key?("all")

download_bottle(hash, bottle_tag)

hash["dependencies"].each do |dep_hash|
existing_formula = begin
Formulary.factory dep_hash["name"]
rescue FormulaUnavailableError
# The formula might not exist if it's not installed and homebrew/core isn't tapped
nil
end

next if existing_formula.present? && existing_formula.latest_version_installed?

download_bottle(dep_hash, bottle_tag)
end
end
Expand All @@ -86,6 +95,7 @@ def checksum_from_url(url)
sig { params(hash: Hash, tag: Symbol).void }
def download_bottle(hash, tag)
bottle = hash["bottles"][tag]
bottle ||= hash["bottles"]["all"]
return if bottle.blank?

sha256 = bottle["sha256"] || checksum_from_url(bottle["url"])
Expand Down
11 changes: 10 additions & 1 deletion Library/Homebrew/cmd/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,16 @@ def github_info(f)
def info_formula(f, args:)
specs = []

if (stable = f.stable)
if ENV["HOMEBREW_JSON_CORE"].present? && BottleAPI.bottle_available?(f.name)
info = BottleAPI.fetch(f.name)

latest_version = info["pkg_version"].split("_").first
bottle_exists = info["bottles"].key?(Utils::Bottles.tag.to_s) || info["bottles"].key?("all")

s = "stable #{latest_version}"
s += " (bottled)" if bottle_exists
specs << s
elsif (stable = f.stable)
s = "stable #{stable.version}"
s += " (bottled)" if stable.bottled? && f.pour_bottle?
specs << s
Expand Down
16 changes: 15 additions & 1 deletion Library/Homebrew/cmd/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ EOS
[[ -d "${HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core" ]]
then
safe_cd "${HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core"
echo "HOMEBREW_CORE_GIT_REMOTE set: using ${HOMEBREW_CORE_GIT_REMOTE} for Homebrew/brew Git remote."
echo "HOMEBREW_CORE_GIT_REMOTE set: using ${HOMEBREW_CORE_GIT_REMOTE} for Homebrew/core Git remote."
git remote set-url origin "${HOMEBREW_CORE_GIT_REMOTE}"
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch --force origin refs/heads/master:refs/remotes/origin/master
Expand All @@ -498,6 +498,12 @@ EOS

for DIR in "${HOMEBREW_REPOSITORY}" "${HOMEBREW_LIBRARY}"/Taps/*/*
do
if [[ -n "${HOMEBREW_JSON_CORE}" ]] && [[ -n "${HOMEBREW_UPDATE_PREINSTALL}" ]] &&
[[ "${DIR}" = "${HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core" ]]
then
continue
fi

[[ -d "${DIR}/.git" ]] || continue
cd "${DIR}" || continue

Expand Down Expand Up @@ -639,6 +645,14 @@ EOS

for DIR in "${HOMEBREW_REPOSITORY}" "${HOMEBREW_LIBRARY}"/Taps/*/*
do
# HOMEBREW_UPDATE_PREINSTALL wasn't modified in subshell.
# shellcheck disable=SC2031
if [[ -n "${HOMEBREW_JSON_CORE}" ]] && [[ -n "${HOMEBREW_UPDATE_PREINSTALL}" ]] &&
[[ "${DIR}" = "${HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core" ]]
then
continue
fi

[[ -d "${DIR}/.git" ]] || continue
cd "${DIR}" || continue

Expand Down
8 changes: 7 additions & 1 deletion Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,13 @@ def aliases
# exists and is not empty.
# @private
def latest_version_installed?
(dir = latest_installed_prefix).directory? && !dir.children.empty?
latest_prefix = if ENV["HOMEBREW_JSON_CORE"].present?
prefix BottleAPI.latest_pkg_version(name)
else
latest_installed_prefix
end

(dir = latest_prefix).directory? && !dir.children.empty?
end

# If at least one version of {Formula} is installed.
Expand Down

0 comments on commit a4e093d

Please sign in to comment.