From 91fffeeff6a5b1d9fd042716035a14698bc674be Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Wed, 14 Jul 2021 00:26:09 -0400 Subject: [PATCH 1/7] info: show latest version --- Library/Homebrew/cmd/info.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 090556c2a2..16922e2c75 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -244,7 +244,13 @@ module Homebrew specs = [] if (stable = f.stable) - s = "stable #{stable.version}" + latest_version = if ENV["HOMEBREW_JSON_CORE"].present? + BottleAPI.latest_pkg_version(f.name).version || stable.version + else + stable.version + end + + s = "stable #{latest_version}" s += " (bottled)" if stable.bottled? && f.pour_bottle? specs << s end From a0f7711ab6f8cbc21b50f0734f65ee503b3677ec Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Wed, 14 Jul 2021 00:52:15 -0400 Subject: [PATCH 2/7] update: don't update homebrew/core for preinstall if using JSON --- Library/Homebrew/cmd/update.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index 17f9c7903f..cc4ae0d1c2 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -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 @@ -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 @@ -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 From 98713e9cd1613dadf6c8c1f06d7dc6ad63f53d9e Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Wed, 14 Jul 2021 02:10:38 -0400 Subject: [PATCH 3/7] BottleAPI: only fetch dependencies if they are outdated locally --- Library/Homebrew/bottle_api.rb | 8 ++++++++ Library/Homebrew/formula.rb | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/bottle_api.rb b/Library/Homebrew/bottle_api.rb index 214e62a73d..2cba314eb7 100644 --- a/Library/Homebrew/bottle_api.rb +++ b/Library/Homebrew/bottle_api.rb @@ -71,6 +71,14 @@ module BottleAPI download_bottle(hash, bottle_tag) hash["dependencies"].each do |dep_hash| + existing_formula = begin + Formulary.factory dep_hash["name"] + rescue FormulaUnavailableError + nil + end + + next if existing_formula.present? && existing_formula.latest_version_installed? + download_bottle(dep_hash, bottle_tag) end end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 82801da112..f6c3eca64d 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -520,7 +520,13 @@ class Formula # 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. From c5df900936ed24dcdcc0f9a15d37ae5468a6d668 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Wed, 14 Jul 2021 10:14:48 -0400 Subject: [PATCH 4/7] BottleAPI: support `:all` bottles --- Library/Homebrew/bottle_api.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/bottle_api.rb b/Library/Homebrew/bottle_api.rb index 2cba314eb7..1f0d1120cd 100644 --- a/Library/Homebrew/bottle_api.rb +++ b/Library/Homebrew/bottle_api.rb @@ -66,7 +66,7 @@ module BottleAPI 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) @@ -94,6 +94,7 @@ module BottleAPI 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"]) From 3e01e02a02405278e6b74cafef1642cb940871e9 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Wed, 14 Jul 2021 10:19:29 -0400 Subject: [PATCH 5/7] Improvements based on code review --- Library/Homebrew/bottle_api.rb | 1 + Library/Homebrew/cmd/info.rb | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/bottle_api.rb b/Library/Homebrew/bottle_api.rb index 1f0d1120cd..ef48eaaecd 100644 --- a/Library/Homebrew/bottle_api.rb +++ b/Library/Homebrew/bottle_api.rb @@ -74,6 +74,7 @@ module BottleAPI 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 diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 16922e2c75..bcbe7b0e65 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -244,11 +244,8 @@ module Homebrew specs = [] if (stable = f.stable) - latest_version = if ENV["HOMEBREW_JSON_CORE"].present? - BottleAPI.latest_pkg_version(f.name).version || stable.version - else - stable.version - end + latest_version = BottleAPI.latest_pkg_version(f.name).version if ENV["HOMEBREW_JSON_CORE"].present? + latest_version ||= stable.version s = "stable #{latest_version}" s += " (bottled)" if stable.bottled? && f.pour_bottle? From fb040538336829a86f34bd63bdbcd80bc837139f Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Wed, 14 Jul 2021 18:16:23 -0400 Subject: [PATCH 6/7] info: show accurate bottle information --- Library/Homebrew/cmd/info.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index bcbe7b0e65..16610336d9 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -243,7 +243,16 @@ module Homebrew 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) latest_version = BottleAPI.latest_pkg_version(f.name).version if ENV["HOMEBREW_JSON_CORE"].present? latest_version ||= stable.version From 2524e801965b5479510a012c71620774a6818708 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Wed, 14 Jul 2021 18:20:23 -0400 Subject: [PATCH 7/7] Revert outdated changes to `brew info` --- Library/Homebrew/cmd/info.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 16610336d9..06ad93735e 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -253,10 +253,7 @@ module Homebrew s += " (bottled)" if bottle_exists specs << s elsif (stable = f.stable) - latest_version = BottleAPI.latest_pkg_version(f.name).version if ENV["HOMEBREW_JSON_CORE"].present? - latest_version ||= stable.version - - s = "stable #{latest_version}" + s = "stable #{stable.version}" s += " (bottled)" if stable.bottled? && f.pour_bottle? specs << s end