Remove need for homebrew/cask to be tapped

This commit is contained in:
Rylan Polster 2021-08-06 13:02:25 -04:00
parent c32223a89c
commit 99635bf3ae
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
7 changed files with 41 additions and 15 deletions

View File

@ -6,6 +6,7 @@ require "cask/config"
require "cask/dsl"
require "cask/metadata"
require "searchable"
require "api"
module Cask
# An instance of a cask.
@ -130,14 +131,21 @@ module Cask
return []
end
latest_version = if ENV["HOMEBREW_JSON_CORE"].present? &&
(latest_cask_version = Homebrew::API::Versions.latest_cask_version(token))
DSL::Version.new latest_cask_version.to_s
else
version
end
installed = versions
current = installed.last
# not outdated unless there is a different version on tap
return [] if current == version
return [] if current == latest_version
# collect all installed versions that are different than tap version and return them
installed.reject { |v| v == version }
installed.reject { |v| v == latest_version }
end
def outdated_info(greedy, verbose, json, greedy_latest, greedy_auto_updates)

View File

@ -45,18 +45,18 @@ module Homebrew
# the formula and prints a warning unless `only` is specified.
sig {
params(
only: T.nilable(Symbol),
ignore_unavailable: T.nilable(T::Boolean),
method: T.nilable(Symbol),
uniq: T::Boolean,
prefer_loading_from_json: T::Boolean,
only: T.nilable(Symbol),
ignore_unavailable: T.nilable(T::Boolean),
method: T.nilable(Symbol),
uniq: T::Boolean,
prefer_loading_from_api: T::Boolean,
).returns(T::Array[T.any(Formula, Keg, Cask::Cask)])
}
def to_formulae_and_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, method: nil, uniq: true,
prefer_loading_from_json: false)
prefer_loading_from_api: false)
@to_formulae_and_casks ||= {}
@to_formulae_and_casks[only] ||= downcased_unique_named.flat_map do |name|
load_formula_or_cask(name, only: only, method: method, prefer_loading_from_json: prefer_loading_from_json)
load_formula_or_cask(name, only: only, method: method, prefer_loading_from_api: prefer_loading_from_api)
rescue FormulaUnreadableError, FormulaClassUnavailableError,
TapFormulaUnreadableError, TapFormulaClassUnavailableError,
Cask::CaskUnreadableError
@ -90,11 +90,11 @@ module Homebrew
end.uniq.freeze
end
def load_formula_or_cask(name, only: nil, method: nil, prefer_loading_from_json: false)
def load_formula_or_cask(name, only: nil, method: nil, prefer_loading_from_api: false)
unreadable_error = nil
if only != :cask
if prefer_loading_from_json && ENV["HOMEBREW_JSON_CORE"].present? &&
if prefer_loading_from_api && ENV["HOMEBREW_JSON_CORE"].present? &&
Homebrew::API::Bottle.available?(name)
Homebrew::API::Bottle.fetch_bottles(name)
end
@ -133,9 +133,14 @@ module Homebrew
end
if only != :formula
if prefer_loading_from_api && ENV["HOMEBREW_JSON_CORE"].present? &&
Homebrew::API::CaskSource.available?(name)
contents = Homebrew::API::CaskSource.fetch(name)
end
begin
config = Cask::Config.from_args(@parent) if @cask_options
cask = Cask::CaskLoader.load(name, config: config)
cask = Cask::CaskLoader.load(contents || name, config: config)
if unreadable_error.present?
onoe <<~EOS

View File

@ -155,7 +155,7 @@ module Homebrew
end
begin
formulae, casks = args.named.to_formulae_and_casks(prefer_loading_from_json: true)
formulae, casks = args.named.to_formulae_and_casks(prefer_loading_from_api: true)
.partition { |formula_or_cask| formula_or_cask.is_a?(Formula) }
rescue FormulaOrCaskUnavailableError, Cask::CaskUnavailableError => e
retry if Tap.install_default_cask_tap_if_necessary(force: args.cask?)

View File

@ -85,6 +85,9 @@ module Homebrew
def reinstall
args = reinstall_args.parse
# We need to use the bottle API instead of just using the formula file
# from an installed keg because it will not contain bottle information.
# As a consequence, `brew reinstall` will also upgrade outdated formulae
if ENV["HOMEBREW_JSON_CORE"].present?
args.named.each do |name|
formula = Formulary.factory(name)

View File

@ -648,7 +648,8 @@ EOS
# 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" ]]
[[ "${DIR}" = "${HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core" ||
"${DIR}" = "${HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-cask" ]]
then
continue
fi

View File

@ -225,6 +225,15 @@ module Homebrew
def upgrade_outdated_casks(casks, args:)
return false if args.formula?
if ENV["HOMEBREW_JSON_CORE"].present?
casks = casks.map do |cask|
next cask if cask.tap.present? && cask.tap != "homebrew/cask"
next cask unless Homebrew::API::CaskSource.available?(cask.token)
Cask::CaskLoader.load Homebrew::API::CaskSource.fetch(cask.token)
end
end
Cask::Cmd::Upgrade.upgrade_casks(
*casks,
force: args.force?,

View File

@ -4,7 +4,7 @@
class Tap
def self.install_default_cask_tap_if_necessary(force: false)
return false if default_cask_tap.installed?
return false if ENV["HOMEBREW_JSON_CORE"].present?
return false if !force && Tap.untapped_official_taps.include?(default_cask_tap.name)
default_cask_tap.install