Merge branch 'Homebrew:master' into mohammad

This commit is contained in:
Mohammad Zain Abbas 2022-08-08 19:23:04 +02:00 committed by GitHub
commit 1742a72a96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 72 additions and 24 deletions

View File

@ -90,13 +90,14 @@ module Cask
end
def os_versions
# TODO: use #to_hash_with_variations instead once all casks use on_system blocks
@os_versions ||= begin
version_os_hash = {}
actual_version = MacOS.full_version.to_s
MacOSVersions::SYMBOLS.each do |os_name, os_version|
MacOS.full_version = os_version
cask = CaskLoader.load(token)
cask = CaskLoader.load(full_name)
version_os_hash[os_name] = cask.version if cask.version != version
end

View File

@ -156,24 +156,33 @@ module Homebrew
def self.install_formula_clean!(f, dry_run: false)
return if Homebrew::EnvConfig.no_install_cleanup?
return unless f.latest_version_installed?
return if skip_clean_formula?(f)
cleanup = Cleanup.new(dry_run: dry_run)
if cleanup.periodic_clean_due?
cleanup.periodic_clean!
elsif f.latest_version_installed? && !Cleanup.skip_clean_formula?(f)
if dry_run
ohai "Would run `brew cleanup #{f}`"
else
ohai "Running `brew cleanup #{f}`..."
puts_no_install_cleanup_disable_message_if_not_already!
cleanup.cleanup_formula(f)
end
puts_no_install_cleanup_disable_message_if_not_already!
return if dry_run
Cleanup.new.cleanup_formula(f)
end
def self.puts_no_install_cleanup_disable_message_if_not_already!
def self.puts_no_install_cleanup_disable_message
return if Homebrew::EnvConfig.no_env_hints?
return if Homebrew::EnvConfig.no_install_cleanup?
return if @puts_no_install_cleanup_disable_message_if_not_already
puts "Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP."
puts "Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`)."
end
def self.puts_no_install_cleanup_disable_message_if_not_already!
return if @puts_no_install_cleanup_disable_message_if_not_already
puts_no_install_cleanup_disable_message
@puts_no_install_cleanup_disable_message_if_not_already = true
end
@ -184,7 +193,7 @@ module Homebrew
skip_clean_formulae.include?(f.name) || (skip_clean_formulae & f.aliases).present?
end
def periodic_clean_due?
def self.periodic_clean_due?
return false if Homebrew::EnvConfig.no_install_cleanup?
unless PERIODIC_CLEAN_FILE.exist?
@ -196,19 +205,20 @@ module Homebrew
PERIODIC_CLEAN_FILE.mtime < CLEANUP_DEFAULT_DAYS.days.ago
end
def periodic_clean!
return false unless periodic_clean_due?
def self.periodic_clean!(dry_run: false)
return if Homebrew::EnvConfig.no_install_cleanup?
return unless periodic_clean_due?
if dry_run?
ohai "Would run `brew cleanup` which has not been run in the last #{CLEANUP_DEFAULT_DAYS} days"
if dry_run
oh1 "Would run `brew cleanup` which has not been run in the last #{CLEANUP_DEFAULT_DAYS} days"
else
ohai "`brew cleanup` has not been run in the last #{CLEANUP_DEFAULT_DAYS} days, running now..."
oh1 "`brew cleanup` has not been run in the last #{CLEANUP_DEFAULT_DAYS} days, running now..."
end
Cleanup.puts_no_install_cleanup_disable_message_if_not_already!
return if dry_run?
puts_no_install_cleanup_disable_message
return if dry_run
clean!(quiet: true, periodic: true)
Cleanup.new.clean!(quiet: true, periodic: true)
end
def clean!(quiet: false, periodic: false)

View File

@ -253,6 +253,8 @@ module Homebrew
verbose: args.verbose?,
)
Cleanup.periodic_clean!
Homebrew.messages.display_messages(display_times: args.display_times?)
rescue FormulaUnreadableError, FormulaClassUnavailableError,
TapFormulaUnreadableError, TapFormulaClassUnavailableError => e

View File

@ -151,6 +151,8 @@ module Homebrew
)
end
Cleanup.periodic_clean!
Homebrew.messages.display_messages(display_times: args.display_times?)
end
end

View File

@ -110,6 +110,8 @@ module Homebrew
upgrade_outdated_formulae(formulae, args: args) unless only_upgrade_casks
upgrade_outdated_casks(casks, args: args) unless only_upgrade_formulae
Cleanup.periodic_clean!(dry_run: args.dry_run?)
Homebrew.messages.display_messages(display_times: args.display_times?)
end

View File

@ -69,9 +69,6 @@ class Formula
extend Cachable
extend Predicable
# @!method inreplace(paths, before = nil, after = nil)
# @see Utils::Inreplace.inreplace
# The name of this {Formula}.
# e.g. `this-formula`
attr_reader :name
@ -2201,6 +2198,30 @@ class Formula
# end</pre>
def install; end
# Sometimes we have to change a bit before we install. Mostly we
# prefer a patch, but if you need the {Formula#prefix prefix} of
# this formula in the patch you have to resort to `inreplace`,
# because in the patch you don't have access to any variables
# defined by the formula, as only `HOMEBREW_PREFIX` is available
# in the {DATAPatch embedded patch}.
#
# `inreplace` supports regular expressions:
# <pre>inreplace "somefile.cfg", /look[for]what?/, "replace by #{bin}/tool"</pre>
#
# `inreplace` supports blocks:
# <pre>inreplace "Makefile" do |s|
# s.gsub! "/usr/local", HOMEBREW_PREFIX.to_s
# end
# </pre>
#
# @see Utils::Inreplace.inreplace
# @api public
def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
super(paths, before, after, audit_result)
rescue Utils::Inreplace::Error
raise BuildError.new(self, "inreplace", paths, nil)
end
protected
def setup_home(home)

View File

@ -576,6 +576,16 @@ describe Formula do
end
end
describe "::inreplace" do
specify "raises build error on failure" do
f = formula do
url "https://brew.sh/test-1.0.tbz"
end
expect { f.inreplace([]) }.to raise_error(BuildError)
end
end
describe "::installed_with_alias_path" do
specify "with alias path with nil" do
expect(described_class.installed_with_alias_path(nil)).to be_empty

View File

@ -10,7 +10,7 @@ module Utils
module Inreplace
extend T::Sig
# Error during replacement.
# Error during text replacement.
class Error < RuntimeError
def initialize(errors)
formatted_errors = errors.reduce(+"inreplace failed\n") do |s, (path, errs)|
@ -70,7 +70,7 @@ module Utils
Pathname(path).atomic_write(s.inreplace_string)
end
raise Error, errors unless errors.empty?
raise Utils::Inreplace::Error, errors if errors.present?
end
# @api private
@ -86,7 +86,7 @@ module Utils
contents.gsub!(old, new)
end
raise Error, path => contents.errors unless contents.errors.empty?
raise Utils::Inreplace::Error, path => contents.errors if contents.errors.present?
Pathname(path).atomic_write(contents.inreplace_string) unless read_only_run
contents.inreplace_string