Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade: list upgradeable dependencies on dry run #11947

Merged
merged 1 commit into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/cmd/upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def self.upgrade_casks(
end

verb = dry_run ? "Would upgrade" : "Upgrading"
oh1 "#{verb} #{outdated_casks.count} #{"outdated package".pluralize(outdated_casks.count)}:"
oh1 "#{verb} #{outdated_casks.count} outdated #{"package".pluralize(outdated_casks.count)}:"

caught_exceptions = []

Expand Down
12 changes: 8 additions & 4 deletions Library/Homebrew/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ def initialize(*args, dry_run: false, scrub: false, days: nil, cache: HOMEBREW_C
@cleaned_up_paths = Set.new
end

def self.install_formula_clean!(f)
def self.install_formula_clean!(f, dry_run: false)
return if Homebrew::EnvConfig.no_install_cleanup?

cleanup = Cleanup.new
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)
Expand Down Expand Up @@ -187,8 +187,12 @@ def periodic_clean_due?
def periodic_clean!
return false unless periodic_clean_due?

ohai "`brew cleanup` has not been run in #{CLEANUP_DEFAULT_DAYS} days, running now..."
clean!(quiet: true, periodic: true)
if dry_run?
ohai "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..."
clean!(quiet: true, periodic: true)
end
end

def clean!(quiet: false, periodic: false)
Expand Down
5 changes: 3 additions & 2 deletions Library/Homebrew/cmd/migrate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def migrate_args
switch "-f", "--force",
description: "Treat installed <formula> and provided <formula> as if they are from "\
"the same taps and migrate them anyway."
switch "-n", "--dry-run",
description: "Show what would be migrated, but do not actually migrate anything."

named_args :installed_formula, min: 1
end
Expand All @@ -35,8 +37,7 @@ def migrate
odie "#{rack} is a symlink" if rack.symlink?
end

migrator = Migrator.new(f, force: args.force?)
migrator.migrate
Migrator.migrate_if_needed(f, force: args.force?, dry_run: args.dry_run?)
end
end
end
29 changes: 14 additions & 15 deletions Library/Homebrew/cmd/upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,21 +187,20 @@ def upgrade_outdated_formulae(formulae, args:)
puts formulae_upgrades.join("\n")
end

unless args.dry_run?
Upgrade.upgrade_formulae(
formulae_to_install,
flags: args.flags_only,
installed_on_request: args.named.present?,
force_bottle: args.force_bottle?,
build_from_source_formulae: args.build_from_source_formulae,
interactive: args.interactive?,
keep_tmp: args.keep_tmp?,
force: args.force?,
debug: args.debug?,
quiet: args.quiet?,
verbose: args.verbose?,
)
end
Upgrade.upgrade_formulae(
formulae_to_install,
flags: args.flags_only,
dry_run: args.dry_run?,
installed_on_request: args.named.present?,
force_bottle: args.force_bottle?,
build_from_source_formulae: args.build_from_source_formulae,
interactive: args.interactive?,
keep_tmp: args.keep_tmp?,
force: args.force?,
debug: args.debug?,
quiet: args.quiet?,
verbose: args.verbose?,
)

Upgrade.check_installed_dependents(
formulae_to_install,
Expand Down
6 changes: 5 additions & 1 deletion Library/Homebrew/migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,14 @@ def self.needs_migration?(formula)
true
end

def self.migrate_if_needed(formula, force:)
def self.migrate_if_needed(formula, force:, dry_run: false)
return unless Migrator.needs_migration?(formula)

begin
if dry_run
ohai "Would migrate #{formula.oldname} to #{formula.name}"
return
end
migrator = Migrator.new(formula, force: force)
migrator.migrate
rescue => e
Expand Down
34 changes: 28 additions & 6 deletions Library/Homebrew/upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Upgrade
def upgrade_formulae(
formulae_to_install,
flags:,
dry_run: false,
installed_on_request: false,
force_bottle: false,
build_from_source_formulae: [],
Expand All @@ -42,7 +43,7 @@ def upgrade_formulae(
end

formula_installers = formulae_to_install.map do |formula|
Migrator.migrate_if_needed(formula, force: force)
Migrator.migrate_if_needed(formula, force: force, dry_run: dry_run)
begin
fi = create_and_fetch_formula_installer(
formula,
Expand All @@ -57,7 +58,7 @@ def upgrade_formulae(
quiet: quiet,
verbose: verbose,
)
fi.fetch
fi.fetch unless dry_run
fi
rescue UnsatisfiedRequirements, DownloadError => e
ofail "#{formula}: #{e}"
Expand All @@ -66,8 +67,8 @@ def upgrade_formulae(
end.compact

formula_installers.each do |fi|
upgrade_formula(fi, verbose: verbose)
Cleanup.install_formula_clean!(fi.formula)
upgrade_formula(fi, dry_run: dry_run, verbose: verbose)
Cleanup.install_formula_clean!(fi.formula, dry_run: dry_run)
end
end

Expand All @@ -77,6 +78,22 @@ def outdated_kegs(formula)
.map { |k| Keg.new(k.resolved_path) }
end

def print_dry_run_dependencies(formula, fi_deps)
return if fi_deps.empty?

plural = "dependency".pluralize(fi_deps.count)
ohai "Would upgrade #{fi_deps.count} #{plural} for #{formula.full_specified_name}:"
formulae_upgrades = fi_deps.map(&:first).map(&:to_formula).map do |f|
name = f.full_specified_name
if f.optlinked?
"#{name} #{Keg.new(f.opt_prefix).version} -> #{f.pkg_version}"
else
"#{name} #{f.pkg_version}"
end
end
puts formulae_upgrades.join(", ")
end

def print_upgrade_message(formula, fi_options)
version_upgrade = if formula.optlinked?
"#{Keg.new(formula.opt_prefix).version} -> #{formula.pkg_version}"
Expand Down Expand Up @@ -139,13 +156,18 @@ def create_and_fetch_formula_installer(
end
private_class_method :create_and_fetch_formula_installer

def upgrade_formula(formula_installer, verbose: false)
def upgrade_formula(formula_installer, dry_run: false, verbose: false)
formula = formula_installer.formula

kegs = outdated_kegs(formula)
linked_kegs = kegs.select(&:linked?)

print_upgrade_message(formula, formula_installer.options)
if dry_run
print_dry_run_dependencies(formula, formula_installer.compute_dependencies)
return
else
print_upgrade_message(formula, formula_installer.options)
end

formula_installer.prelude

Expand Down
1 change: 1 addition & 0 deletions completions/bash/brew
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,7 @@ _brew_migrate() {
-*)
__brewcomp "
--debug
--dry-run
--force
--help
--quiet
Expand Down
1 change: 1 addition & 0 deletions completions/fish/brew.fish
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ __fish_brew_complete_arg 'man' -l verbose -d 'Make some output more verbose'

__fish_brew_complete_cmd 'migrate' 'Migrate renamed packages to new names, where formula are old names of packages'
__fish_brew_complete_arg 'migrate' -l debug -d 'Display any debugging information'
__fish_brew_complete_arg 'migrate' -l dry-run -d 'Show what would be migrated, but do not actually migrate anything'
__fish_brew_complete_arg 'migrate' -l force -d 'Treat installed formula and provided formula as if they are from the same taps and migrate them anyway'
__fish_brew_complete_arg 'migrate' -l help -d 'Show this message'
__fish_brew_complete_arg 'migrate' -l quiet -d 'Make some output more quiet'
Expand Down
1 change: 1 addition & 0 deletions completions/zsh/_brew
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,7 @@ _brew_man() {
_brew_migrate() {
_arguments \
'--debug[Display any debugging information]' \
'--dry-run[Show what would be migrated, but do not actually migrate anything]' \
'--force[Treat installed formula and provided formula as if they are from the same taps and migrate them anyway]' \
'--help[Show this message]' \
'--quiet[Make some output more quiet]' \
Expand Down
4 changes: 3 additions & 1 deletion docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,15 @@ if no formula is provided.
* `-n`, `--max-count`:
Print only a specified number of commits.

### `migrate` [*`--force`*] *`installed_formula`* [...]
### `migrate` [*`--force`*] [*`--dry-run`*] *`installed_formula`* [...]

Migrate renamed packages to new names, where *`formula`* are old names of
packages.

* `-f`, `--force`:
Treat installed *`formula`* and provided *`formula`* as if they are from the same taps and migrate them anyway.
* `-n`, `--dry-run`:
Show what would be migrated, but do not actually migrate anything.

### `missing` [*`--hide`*`=`] [*`formula`* ...]

Expand Down
6 changes: 5 additions & 1 deletion manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,17 @@ Print only one commit\.
\fB\-n\fR, \fB\-\-max\-count\fR
Print only a specified number of commits\.
.
.SS "\fBmigrate\fR [\fI\-\-force\fR] \fIinstalled_formula\fR [\.\.\.]"
.SS "\fBmigrate\fR [\fI\-\-force\fR] [\fI\-\-dry\-run\fR] \fIinstalled_formula\fR [\.\.\.]"
Migrate renamed packages to new names, where \fIformula\fR are old names of packages\.
.
.TP
\fB\-f\fR, \fB\-\-force\fR
Treat installed \fIformula\fR and provided \fIformula\fR as if they are from the same taps and migrate them anyway\.
.
.TP
\fB\-n\fR, \fB\-\-dry\-run\fR
Show what would be migrated, but do not actually migrate anything\.
.
.SS "\fBmissing\fR [\fI\-\-hide\fR\fB=\fR] [\fIformula\fR \.\.\.]"
Check the given \fIformula\fR kegs for missing dependencies\. If no \fIformula\fR are provided, check all kegs\. Will exit with a non\-zero status if any kegs are found to be missing dependencies\.
.
Expand Down