diff --git a/cmd/which-update.rb b/cmd/which-update.rb index 52935e96..9afd5775 100755 --- a/cmd/which-update.rb +++ b/cmd/which-update.rb @@ -20,6 +20,8 @@ def which_update_args description: "Update database entries with outdated formula versions." switch "--install-missing", description: "Install and update formulae that are missing from the database and don't have bottles." + switch "--eval-all", + description: "Evaluate all installed taps, rather than just the core tap." flag "--max-downloads=", description: "Specify a maximum number of formulae to download and update." conflicts "--stats", "--commit" @@ -39,7 +41,8 @@ def which_update Homebrew::WhichUpdate.update_and_save! source: args.named.first, commit: args.commit?, update_existing: args.update_existing?, install_missing: args.install_missing?, - max_downloads: args.max_downloads + max_downloads: args.max_downloads, + eval_all: args.eval_all? end end end diff --git a/lib/executables_db.rb b/lib/executables_db.rb index b92c0dae..464748a2 100644 --- a/lib/executables_db.rb +++ b/lib/executables_db.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true require "formula" +require "formulary" +require "tap" module Homebrew # ExecutablesDB represents a DB associating formulae to the binaries they @@ -51,43 +53,50 @@ def changed? # update the DB with the installed formulae # @see #save! - def update!(update_existing: false, install_missing: false, max_downloads: nil) + def update!(update_existing: false, install_missing: false, max_downloads: nil, eval_all: false) downloads = 0 disabled_formulae = [] - Formula.all.each do |f| - break if max_downloads.present? && downloads > max_downloads.to_i - next if f.tap? - name = f.full_name - - if f.disabled? - disabled_formulae << name - next - end - - update_formula = missing_formula?(f) || (update_existing && outdated_formula?(f)) - - # Install unbottled formulae if they should be added/updated - if !f.bottled? && install_missing && update_formula - downloads += 1 - ohai "Installing #{f}" - system HOMEBREW_BREW_FILE, "install", "--formula", f.to_s - end - - # We don't need to worry about updating outdated versions unless update_existing is true - if f.latest_version_installed? - update_installed_formula f - elsif f.bottled? && update_formula - downloads += 1 - update_bottled_formula f - end - - # renamed formulae - mv f.oldname, name if !f.oldname.nil? && @exes[f.oldname] - - # aliased formulae - f.aliases.each do |a| - mv a, name if @exes[a] + # Evaluate only the core tap by default. + taps = eval_all ? Tap.each.to_a : [CoreTap.instance] + taps.each do |tap| + tap.formula_files_by_name.each do |name, path| + f = Formulary.load_formula_from_path(name, path) + + break if max_downloads.present? && downloads > max_downloads.to_i + next if f.tap? + + name = f.full_name + + if f.disabled? + disabled_formulae << name + next + end + + update_formula = missing_formula?(f) || (update_existing && outdated_formula?(f)) + + # Install unbottled formulae if they should be added/updated + if !f.bottled? && install_missing && update_formula + downloads += 1 + ohai "Installing #{f}" + system HOMEBREW_BREW_FILE, "install", "--formula", f.to_s + end + + # We don't need to worry about updating outdated versions unless update_existing is true + if f.latest_version_installed? + update_installed_formula f + elsif f.bottled? && update_formula + downloads += 1 + update_bottled_formula f + end + + # renamed formulae + mv f.oldname, name if !f.oldname.nil? && @exes[f.oldname] + + # aliased formulae + f.aliases.each do |a| + mv a, name if @exes[a] + end end end diff --git a/lib/which_update.rb b/lib/which_update.rb index e8a6b1ce..23593fbd 100755 --- a/lib/which_update.rb +++ b/lib/which_update.rb @@ -45,10 +45,11 @@ def stats(source: nil) end def update_and_save!(source: nil, commit: false, update_existing: false, install_missing: false, - max_downloads: nil) + max_downloads: nil, eval_all: false) source ||= default_source db = ExecutablesDB.new source - db.update!(update_existing: update_existing, install_missing: install_missing, max_downloads: max_downloads) + db.update!(update_existing: update_existing, install_missing: install_missing, + max_downloads: max_downloads, eval_all: eval_all) db.save! return if !commit || !db.changed?