From e7e34c40f1f8135884b74b39c48971c4234fdb91 Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 5 Feb 2025 19:06:09 -0500 Subject: [PATCH 01/73] Adding the function ask to check if option is present --- Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi index 2bd0d91e02..c6967205e7 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi @@ -166,4 +166,7 @@ class Homebrew::Cmd::InstallCmd::Args < Homebrew::CLI::Args sig { returns(T::Boolean) } def zap?; end + + sig { returns(T::Boolean) } + def ask?; end end From 87492f8fbe7dca02b585d682d1fb7ad891d51d6e Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 5 Feb 2025 20:50:05 -0500 Subject: [PATCH 02/73] fetching dependencies and calculating bottle and install size --- Library/Homebrew/cmd/install.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index cd31c888be..471d63a48c 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -120,6 +120,9 @@ module Homebrew [:switch, "--overwrite", { description: "Delete files that already exist in the prefix while linking.", }], + [:switch, "--ask", { + description: "Ask for confirmation before downloading and installing software. Print bottles and dependencies download size and install size.", + }] ].each do |args| options = args.pop send(*args, **options) @@ -302,6 +305,35 @@ module Homebrew Install.perform_preinstall_checks_once Install.check_cc_argv(args.cc) + if args.ask? + ohai "Looking for dependencies..." + installed_formulae.each do |f| + if (bottle = f.bottle) + begin + package = [] + bottle.fetch_tab(quiet: !args.debug?) + bottle_size = bottle.bottle_size + installed_size = bottle.installed_size + package.push(f, f.recursive_dependencies) + unless f.deps.empty? + puts "Packages : #{package.join(", ")}\n\n" + f.recursive_dependencies.each do |dep| + bottle = dep.to_formula.bottle + bottle.fetch_tab(quiet: !args.debug?) + bottle_size += bottle.bottle_size if bottle.bottle_size + installed_size += bottle.installed_size if bottle.installed_size + end + puts "Bottle Size: #{disk_usage_readable(bottle_size)}" if bottle_size + puts "Installed Size: #{disk_usage_readable(installed_size)}" if installed_size + return + end + rescue RuntimeError => e + odebug e + end + end + end + end + Install.install_formulae( installed_formulae, build_bottle: args.build_bottle?, From e47bdd9ad056eb2c0d3715428e1faf6199f00f84 Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 5 Feb 2025 21:20:17 -0500 Subject: [PATCH 03/73] Getting input of user and proceeding the different output --- Library/Homebrew/cmd/install.rb | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 471d63a48c..23b647fcbe 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -305,6 +305,7 @@ module Homebrew Install.perform_preinstall_checks_once Install.check_cc_argv(args.cc) + # Showing dependencies and required size to install if args.ask? ohai "Looking for dependencies..." installed_formulae.each do |f| @@ -316,16 +317,28 @@ module Homebrew installed_size = bottle.installed_size package.push(f, f.recursive_dependencies) unless f.deps.empty? - puts "Packages : #{package.join(", ")}\n\n" f.recursive_dependencies.each do |dep| bottle = dep.to_formula.bottle bottle.fetch_tab(quiet: !args.debug?) bottle_size += bottle.bottle_size if bottle.bottle_size installed_size += bottle.installed_size if bottle.installed_size end - puts "Bottle Size: #{disk_usage_readable(bottle_size)}" if bottle_size - puts "Installed Size: #{disk_usage_readable(installed_size)}" if installed_size - return + end + puts "Packages : #{package.join(", ")}\n\n" + puts "Bottle Size: #{disk_usage_readable(bottle_size)}" if bottle_size + puts "Installed Size: #{disk_usage_readable(installed_size)}\n\n" if installed_size + ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" + loop do + result = STDIN.gets.chomp.strip.downcase + + if result == "y" || result == "yes" + puts "Proceeding with installation..." + break + elsif result == "n" + return + else + puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." + end end rescue RuntimeError => e odebug e From f989e9a67489a7b0fb083e8a888c6dd6388ede60 Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 5 Feb 2025 21:58:31 -0500 Subject: [PATCH 04/73] rearranging code to work with many formula and not only with last one --- Library/Homebrew/cmd/install.rb | 39 +++++++++++++++++---------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 23b647fcbe..1a083b93c9 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -308,13 +308,15 @@ module Homebrew # Showing dependencies and required size to install if args.ask? ohai "Looking for dependencies..." + package = [] + bottle_size = 0 + installed_size = 0 installed_formulae.each do |f| if (bottle = f.bottle) begin - package = [] bottle.fetch_tab(quiet: !args.debug?) - bottle_size = bottle.bottle_size - installed_size = bottle.installed_size + bottle_size += bottle.bottle_size if bottle.bottle_size + installed_size += bottle.installed_size if bottle.installed_size package.push(f, f.recursive_dependencies) unless f.deps.empty? f.recursive_dependencies.each do |dep| @@ -324,27 +326,26 @@ module Homebrew installed_size += bottle.installed_size if bottle.installed_size end end - puts "Packages : #{package.join(", ")}\n\n" - puts "Bottle Size: #{disk_usage_readable(bottle_size)}" if bottle_size - puts "Installed Size: #{disk_usage_readable(installed_size)}\n\n" if installed_size - ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" - loop do - result = STDIN.gets.chomp.strip.downcase - - if result == "y" || result == "yes" - puts "Proceeding with installation..." - break - elsif result == "n" - return - else - puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." - end - end rescue RuntimeError => e odebug e end end end + puts "Packages : #{package.join(", ")}\n\n" + puts "Bottle Size: #{disk_usage_readable(bottle_size)}" if bottle_size + puts "Installed Size: #{disk_usage_readable(installed_size)}\n\n" if installed_size + ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" + loop do + result = STDIN.gets.chomp.strip.downcase + if result == "y" || result == "yes" + puts "Proceeding with installation..." + break + elsif result == "n" + return + else + puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." + end + end end Install.install_formulae( From c8a9cfa4d0165348ad1b3c7e735cb97179a3be8f Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Feb 2025 09:07:55 -0500 Subject: [PATCH 05/73] Add support for the HOMEBREW_ASK environment variable --- Library/Homebrew/cmd/install.rb | 2 +- Library/Homebrew/env_config.rb | 4 ++++ Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 1a083b93c9..7649f52855 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -306,7 +306,7 @@ module Homebrew Install.check_cc_argv(args.cc) # Showing dependencies and required size to install - if args.ask? + if args.ask? || !Homebrew::EnvConfig.ask? ohai "Looking for dependencies..." package = [] bottle_size = 0 diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index 5a1e68207f..f91b3ac786 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -500,6 +500,10 @@ module Homebrew "of build provenance for bottles from homebrew-core.", boolean: true, }, + HOMEBREW_ASK: { + description: "If set, pass `--ask`to all formula install commands.", + boolean: true, + }, SUDO_ASKPASS: { description: "If set, pass the `-A` option when calling `sudo`(8).", }, diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi index bc71d5feb7..a6a0e07bc0 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi @@ -315,5 +315,8 @@ module Homebrew::EnvConfig sig { returns(T::Boolean) } def verify_attestations?; end + + sig { returns(T::Boolean) } + def ask?; end end end From 2c4d404cdbbef8dd3f2fb7a9e2ae97b309ccf6c8 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Feb 2025 09:26:52 -0500 Subject: [PATCH 06/73] Reordering by alphabetic order --- Library/Homebrew/env_config.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index f91b3ac786..4d4b8f5f79 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -48,6 +48,10 @@ module Homebrew "trying any other/default URLs.", boolean: true, }, + HOMEBREW_ASK: { + description: "If set, pass `--ask`to all formula install commands.", + boolean: true, + }, HOMEBREW_AUTO_UPDATE_SECS: { description: "Run `brew update` once every `$HOMEBREW_AUTO_UPDATE_SECS` seconds before some commands, " \ "e.g. `brew install`, `brew upgrade` and `brew tap`. Alternatively, " \ @@ -500,10 +504,6 @@ module Homebrew "of build provenance for bottles from homebrew-core.", boolean: true, }, - HOMEBREW_ASK: { - description: "If set, pass `--ask`to all formula install commands.", - boolean: true, - }, SUDO_ASKPASS: { description: "If set, pass the `-A` option when calling `sudo`(8).", }, From 0d2afcffe613dca3ff76890c8d93ed341e045c42 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Feb 2025 09:53:57 -0500 Subject: [PATCH 07/73] Erratum on environment variable if condition --- Library/Homebrew/cmd/install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 7649f52855..8a771e62f4 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -306,7 +306,7 @@ module Homebrew Install.check_cc_argv(args.cc) # Showing dependencies and required size to install - if args.ask? || !Homebrew::EnvConfig.ask? + if args.ask? || Homebrew::EnvConfig.ask? ohai "Looking for dependencies..." package = [] bottle_size = 0 From 0cc688f843bf8f1dacfef01c6941cd979f96d62e Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Feb 2025 12:37:19 -0500 Subject: [PATCH 08/73] resolving typecheck and final tests --- Library/Homebrew/cmd/install.rb | 43 ++++++++++++++++++--------------- Library/Homebrew/env_config.rb | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 8a771e62f4..d03615047b 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -121,8 +121,9 @@ module Homebrew description: "Delete files that already exist in the prefix while linking.", }], [:switch, "--ask", { - description: "Ask for confirmation before downloading and installing software. Print bottles and dependencies download size and install size.", - }] + description: "Ask for confirmation before downloading and installing software. " \ + "Print bottles and dependencies download size and install size.", + }], ].each do |args| options = args.pop send(*args, **options) @@ -312,35 +313,37 @@ module Homebrew bottle_size = 0 installed_size = 0 installed_formulae.each do |f| - if (bottle = f.bottle) - begin - bottle.fetch_tab(quiet: !args.debug?) - bottle_size += bottle.bottle_size if bottle.bottle_size - installed_size += bottle.installed_size if bottle.installed_size - package.push(f, f.recursive_dependencies) - unless f.deps.empty? - f.recursive_dependencies.each do |dep| - bottle = dep.to_formula.bottle - bottle.fetch_tab(quiet: !args.debug?) - bottle_size += bottle.bottle_size if bottle.bottle_size - installed_size += bottle.installed_size if bottle.installed_size - end + next unless (bottle = f.bottle) + + begin + bottle.fetch_tab(quiet: !args.debug?) + bottle_size += T.must(bottle.bottle_size) if bottle.bottle_size + installed_size += T.must(bottle.installed_size) if bottle.installed_size + package.push(f, f.recursive_dependencies) + unless f.deps.empty? + f.recursive_dependencies.each do |dep| + bottle_dep = dep.to_formula.bottle + bottle_dep.fetch_tab(quiet: !args.debug?) + bottle_size += bottle_dep.bottle_size if bottle_dep.bottle_size + installed_size += bottle_dep.installed_size if bottle_dep.installed_size end - rescue RuntimeError => e - odebug e end + rescue RuntimeError => e + odebug e end end puts "Packages : #{package.join(", ")}\n\n" puts "Bottle Size: #{disk_usage_readable(bottle_size)}" if bottle_size puts "Installed Size: #{disk_usage_readable(installed_size)}\n\n" if installed_size ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" + accepted_inputs = %w[y yes] + declined_inputs = %w[n no] loop do - result = STDIN.gets.chomp.strip.downcase - if result == "y" || result == "yes" + result = $stdin.gets.chomp.strip.downcase + if accepted_inputs.include?(result) puts "Proceeding with installation..." break - elsif result == "n" + elsif declined_inputs.include?(result) return else puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index 4d4b8f5f79..309f86bfa1 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -48,7 +48,7 @@ module Homebrew "trying any other/default URLs.", boolean: true, }, - HOMEBREW_ASK: { + HOMEBREW_ASK: { description: "If set, pass `--ask`to all formula install commands.", boolean: true, }, From bbd8aeb80f8904425ea67791da9d9fdc7d5cda35 Mon Sep 17 00:00:00 2001 From: thibhero Date: Fri, 7 Feb 2025 11:49:38 -0500 Subject: [PATCH 09/73] Applying the changes discussed --- Library/Homebrew/cmd/install.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index d03615047b..64b85daff1 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -121,8 +121,9 @@ module Homebrew description: "Delete files that already exist in the prefix while linking.", }], [:switch, "--ask", { - description: "Ask for confirmation before downloading and installing software. " \ + description: "Ask for confirmation before downloading and installing formulae. " \ "Print bottles and dependencies download size and install size.", + env: :install_ask, }], ].each do |args| options = args.pop @@ -308,10 +309,10 @@ module Homebrew # Showing dependencies and required size to install if args.ask? || Homebrew::EnvConfig.ask? - ohai "Looking for dependencies..." - package = [] - bottle_size = 0 - installed_size = 0 + ohai "Looking for bottle sizes..." + sized_formulae = [] + total_download_size = 0 + total_installed_size = 0 installed_formulae.each do |f| next unless (bottle = f.bottle) @@ -332,9 +333,9 @@ module Homebrew odebug e end end - puts "Packages : #{package.join(", ")}\n\n" - puts "Bottle Size: #{disk_usage_readable(bottle_size)}" if bottle_size - puts "Installed Size: #{disk_usage_readable(installed_size)}\n\n" if installed_size + puts "Formulae: #{sized_formulae(", ")}\n\n" + puts "Download Size: #{disk_usage_readable(total_download_size)}" if bottle_size + puts "Install Size: #{disk_usage_readable(total_installed_size)}\n" if installed_size ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" accepted_inputs = %w[y yes] declined_inputs = %w[n no] From f3c2d27cd04dc813c240c26cc8f819b1347963de Mon Sep 17 00:00:00 2001 From: thibhero Date: Fri, 7 Feb 2025 13:57:51 -0500 Subject: [PATCH 10/73] Updating env and option, now using --install-ask --- Library/Homebrew/env_config.rb | 4 ++-- Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index bdc89ed3da..b1049f7b24 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -48,8 +48,8 @@ module Homebrew "trying any other/default URLs.", boolean: true, }, - HOMEBREW_ASK: { - description: "If set, pass `--ask`to all formula install commands.", + HOMEBREW_INSTALL_ASK: { + description: "If set, pass `--install-ask`to all formula install commands.", boolean: true, }, HOMEBREW_AUTO_UPDATE_SECS: { diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi index a6a0e07bc0..071c6a8dbc 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi @@ -317,6 +317,6 @@ module Homebrew::EnvConfig def verify_attestations?; end sig { returns(T::Boolean) } - def ask?; end + def install_ask?; end end end From be1a4c03af5d7feed02e2719e0db5edb862ea240 Mon Sep 17 00:00:00 2001 From: thibhero Date: Fri, 7 Feb 2025 14:02:53 -0500 Subject: [PATCH 11/73] optimising the code, removing begin block --- Library/Homebrew/cmd/install.rb | 70 +++++++++++++++++---------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 64b85daff1..f309fdf980 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -120,7 +120,7 @@ module Homebrew [:switch, "--overwrite", { description: "Delete files that already exist in the prefix while linking.", }], - [:switch, "--ask", { + [:switch, "--install-ask", { description: "Ask for confirmation before downloading and installing formulae. " \ "Print bottles and dependencies download size and install size.", env: :install_ask, @@ -308,48 +308,31 @@ module Homebrew Install.check_cc_argv(args.cc) # Showing dependencies and required size to install - if args.ask? || Homebrew::EnvConfig.ask? + if args.install_ask? ohai "Looking for bottle sizes..." sized_formulae = [] total_download_size = 0 total_installed_size = 0 installed_formulae.each do |f| next unless (bottle = f.bottle) - - begin - bottle.fetch_tab(quiet: !args.debug?) - bottle_size += T.must(bottle.bottle_size) if bottle.bottle_size - installed_size += T.must(bottle.installed_size) if bottle.installed_size - package.push(f, f.recursive_dependencies) - unless f.deps.empty? - f.recursive_dependencies.each do |dep| - bottle_dep = dep.to_formula.bottle - bottle_dep.fetch_tab(quiet: !args.debug?) - bottle_size += bottle_dep.bottle_size if bottle_dep.bottle_size - installed_size += bottle_dep.installed_size if bottle_dep.installed_size - end + # keep it quiet as there could be a lot of json fetch, it’s not intuitive to show them all. + bottle.fetch_tab(quiet: !args.debug?) + total_download_size += T.must(bottle.bottle_size) if bottle.bottle_size + total_installed_size += T.must(bottle.installed_size) if bottle.installed_size + sized_formulae.push(f, f.recursive_dependencies) + unless f.deps.empty? + f.recursive_dependencies.each do |dep| + bottle_dep = dep.to_formula.bottle + bottle_dep.fetch_tab(quiet: !args.debug?) + total_download_size += bottle_dep.bottle_size if bottle_dep.bottle_size + total_installed_size += bottle_dep.installed_size if bottle_dep.installed_size end - rescue RuntimeError => e - odebug e - end - end - puts "Formulae: #{sized_formulae(", ")}\n\n" - puts "Download Size: #{disk_usage_readable(total_download_size)}" if bottle_size - puts "Install Size: #{disk_usage_readable(total_installed_size)}\n" if installed_size - ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" - accepted_inputs = %w[y yes] - declined_inputs = %w[n no] - loop do - result = $stdin.gets.chomp.strip.downcase - if accepted_inputs.include?(result) - puts "Proceeding with installation..." - break - elsif declined_inputs.include?(result) - return - else - puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." end end + puts "Formulae: #{sized_formulae.join(", ")}\n\n" + puts "Download Size: #{disk_usage_readable(total_download_size)}" if total_download_size + puts "Install Size: #{disk_usage_readable(total_installed_size)}\n" if total_installed_size + ask_input end Install.install_formulae( @@ -466,6 +449,25 @@ module Homebrew odie "No #{package_types.join(" or ")} found for #{name}." end + + private + + def ask_input + ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" + accepted_inputs = %w[y yes] + declined_inputs = %w[n no] + loop do + result = $stdin.gets.chomp.strip.downcase + if accepted_inputs.include?(result) + puts "Proceeding with installation..." + break + elsif declined_inputs.include?(result) + return + else + puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." + end + end + end end end end From 73758398e1de8aeeb05cf0aa60c9b672f6bb5093 Mon Sep 17 00:00:00 2001 From: thibhero Date: Fri, 7 Feb 2025 14:14:52 -0500 Subject: [PATCH 12/73] resolving typecheck error --- Library/Homebrew/cmd/install.rb | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index f309fdf980..8abb00a84c 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -180,6 +180,25 @@ module Homebrew odisabled "brew install --env", "`env :std` in specific formula files" end + sig { returns(NilClass) } + + def ask_input + ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" + accepted_inputs = %w[y yes] + declined_inputs = %w[n no] + loop do + result = $stdin.gets.chomp.strip.downcase + if accepted_inputs.include?(result) + puts "Proceeding with installation..." + break + elsif declined_inputs.include?(result) + return + else + puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." + end + end + end + args.named.each do |name| if (tap_with_name = Tap.with_formula_name(name)) tap, = tap_with_name @@ -449,25 +468,6 @@ module Homebrew odie "No #{package_types.join(" or ")} found for #{name}." end - - private - - def ask_input - ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" - accepted_inputs = %w[y yes] - declined_inputs = %w[n no] - loop do - result = $stdin.gets.chomp.strip.downcase - if accepted_inputs.include?(result) - puts "Proceeding with installation..." - break - elsif declined_inputs.include?(result) - return - else - puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." - end - end - end end end end From 1992bb44b28300513a15da328fd8ef1e12d54c47 Mon Sep 17 00:00:00 2001 From: thibhero Date: Fri, 7 Feb 2025 14:15:41 -0500 Subject: [PATCH 13/73] moving `ask?` to `install_ask?` --- Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi index c6967205e7..86f722e56a 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi @@ -168,5 +168,5 @@ class Homebrew::Cmd::InstallCmd::Args < Homebrew::CLI::Args def zap?; end sig { returns(T::Boolean) } - def ask?; end + def install_ask?; end end From 354849895ac6621c2cf4a0cafae3e277c63b9077 Mon Sep 17 00:00:00 2001 From: thibhero Date: Fri, 7 Feb 2025 14:39:22 -0500 Subject: [PATCH 14/73] changing `ask_input` function to lambda --- Library/Homebrew/cmd/install.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 8abb00a84c..12dbc82b60 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -180,9 +180,7 @@ module Homebrew odisabled "brew install --env", "`env :std` in specific formula files" end - sig { returns(NilClass) } - - def ask_input + ask_input = lambda { ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" accepted_inputs = %w[y yes] declined_inputs = %w[n no] @@ -197,7 +195,7 @@ module Homebrew puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." end end - end + } args.named.each do |name| if (tap_with_name = Tap.with_formula_name(name)) @@ -351,7 +349,7 @@ module Homebrew puts "Formulae: #{sized_formulae.join(", ")}\n\n" puts "Download Size: #{disk_usage_readable(total_download_size)}" if total_download_size puts "Install Size: #{disk_usage_readable(total_installed_size)}\n" if total_installed_size - ask_input + ask_input.call end Install.install_formulae( From bebbd6274e07e7176897282cd6a6e4a1764fd33b Mon Sep 17 00:00:00 2001 From: thibhero Date: Fri, 7 Feb 2025 15:10:27 -0500 Subject: [PATCH 15/73] corrected version for brew style --- Library/Homebrew/cmd/install.rb | 17 +++++++++-------- Library/Homebrew/env_config.rb | 8 ++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 12dbc82b60..6ff3790946 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -123,7 +123,7 @@ module Homebrew [:switch, "--install-ask", { description: "Ask for confirmation before downloading and installing formulae. " \ "Print bottles and dependencies download size and install size.", - env: :install_ask, + env: :install_ask, }], ].each do |args| options = args.pop @@ -332,18 +332,19 @@ module Homebrew total_installed_size = 0 installed_formulae.each do |f| next unless (bottle = f.bottle) + # keep it quiet as there could be a lot of json fetch, it’s not intuitive to show them all. bottle.fetch_tab(quiet: !args.debug?) total_download_size += T.must(bottle.bottle_size) if bottle.bottle_size total_installed_size += T.must(bottle.installed_size) if bottle.installed_size sized_formulae.push(f, f.recursive_dependencies) - unless f.deps.empty? - f.recursive_dependencies.each do |dep| - bottle_dep = dep.to_formula.bottle - bottle_dep.fetch_tab(quiet: !args.debug?) - total_download_size += bottle_dep.bottle_size if bottle_dep.bottle_size - total_installed_size += bottle_dep.installed_size if bottle_dep.installed_size - end + next if f.deps.empty? + + f.recursive_dependencies.each do |dep| + bottle_dep = dep.to_formula.bottle + bottle_dep.fetch_tab(quiet: !args.debug?) + total_download_size += bottle_dep.bottle_size if bottle_dep.bottle_size + total_installed_size += bottle_dep.installed_size if bottle_dep.installed_size end end puts "Formulae: #{sized_formulae.join(", ")}\n\n" diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index b1049f7b24..8b906ec51c 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -48,10 +48,6 @@ module Homebrew "trying any other/default URLs.", boolean: true, }, - HOMEBREW_INSTALL_ASK: { - description: "If set, pass `--install-ask`to all formula install commands.", - boolean: true, - }, HOMEBREW_AUTO_UPDATE_SECS: { description: "Run `brew update` once every `$HOMEBREW_AUTO_UPDATE_SECS` seconds before some commands, " \ "e.g. `brew install`, `brew upgrade` and `brew tap`. Alternatively, " \ @@ -308,6 +304,10 @@ module Homebrew description: "Linux only: Set this value to a new enough `git` executable for Homebrew to use.", default: "git", }, + HOMEBREW_INSTALL_ASK: { + description: "If set, pass `--install-ask`to all formula install commands.", + boolean: true, + }, HOMEBREW_INSTALL_BADGE: { description: "Print this text before the installation summary of each successful build.", default_text: 'The "Beer Mug" emoji.', From 403887deb619213c429e5a1e8ad96e4314959a98 Mon Sep 17 00:00:00 2001 From: thibhero Date: Fri, 7 Feb 2025 15:23:36 -0500 Subject: [PATCH 16/73] moving back to `--ask` option --- Library/Homebrew/cmd/install.rb | 6 +++--- Library/Homebrew/env_config.rb | 8 ++++---- .../Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi | 2 +- Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 6ff3790946..91800deee6 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -120,10 +120,10 @@ module Homebrew [:switch, "--overwrite", { description: "Delete files that already exist in the prefix while linking.", }], - [:switch, "--install-ask", { + [:switch, "--ask", { description: "Ask for confirmation before downloading and installing formulae. " \ "Print bottles and dependencies download size and install size.", - env: :install_ask, + env: :ask, }], ].each do |args| options = args.pop @@ -325,7 +325,7 @@ module Homebrew Install.check_cc_argv(args.cc) # Showing dependencies and required size to install - if args.install_ask? + if args.ask? ohai "Looking for bottle sizes..." sized_formulae = [] total_download_size = 0 diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index 8b906ec51c..bdc89ed3da 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -48,6 +48,10 @@ module Homebrew "trying any other/default URLs.", boolean: true, }, + HOMEBREW_ASK: { + description: "If set, pass `--ask`to all formula install commands.", + boolean: true, + }, HOMEBREW_AUTO_UPDATE_SECS: { description: "Run `brew update` once every `$HOMEBREW_AUTO_UPDATE_SECS` seconds before some commands, " \ "e.g. `brew install`, `brew upgrade` and `brew tap`. Alternatively, " \ @@ -304,10 +308,6 @@ module Homebrew description: "Linux only: Set this value to a new enough `git` executable for Homebrew to use.", default: "git", }, - HOMEBREW_INSTALL_ASK: { - description: "If set, pass `--install-ask`to all formula install commands.", - boolean: true, - }, HOMEBREW_INSTALL_BADGE: { description: "Print this text before the installation summary of each successful build.", default_text: 'The "Beer Mug" emoji.', diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi index 86f722e56a..c6967205e7 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi @@ -168,5 +168,5 @@ class Homebrew::Cmd::InstallCmd::Args < Homebrew::CLI::Args def zap?; end sig { returns(T::Boolean) } - def install_ask?; end + def ask?; end end diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi index 071c6a8dbc..a6a0e07bc0 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi @@ -317,6 +317,6 @@ module Homebrew::EnvConfig def verify_attestations?; end sig { returns(T::Boolean) } - def install_ask?; end + def ask?; end end end From 92470e00284e0f8379752a2746dd82abb7e35795 Mon Sep 17 00:00:00 2001 From: thibhero Date: Sun, 9 Feb 2025 20:47:35 -0500 Subject: [PATCH 17/73] adding the `--ask` option for the upgrade command --- Library/Homebrew/cmd/upgrade.rb | 63 +++++++++++++++++++ Library/Homebrew/env_config.rb | 4 ++ .../rbi/dsl/homebrew/cmd/upgrade_cmd.rbi | 3 + .../sorbet/rbi/dsl/homebrew/env_config.rbi | 3 + 4 files changed, 73 insertions(+) diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 6ab70581ac..d716178060 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -71,6 +71,11 @@ module Homebrew [:switch, "--overwrite", { description: "Delete files that already exist in the prefix while linking.", }], + [:switch, "--ask", { + description: "Ask for confirmation before downloading and upgrading formulae. " \ + "Print bottles and dependencies download size, install and net install size.", + env: :ask, + }], ].each do |args| options = args.pop send(*args, **options) @@ -216,6 +221,64 @@ module Homebrew Install.perform_preinstall_checks_once + ask_input = lambda { + ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" + accepted_inputs = %w[y yes] + declined_inputs = %w[n no] + loop do + result = $stdin.gets.chomp.strip.downcase + if accepted_inputs.include?(result) + puts "Proceeding with installation..." + break + elsif declined_inputs.include?(result) + return + else + puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." + end + end + } + + # Showing dependencies and required size to install + if args.ask? + ohai "Looking for bottles..." + sized_formulae = [] + total_download_size = 0 + total_installed_size = 0 + total_net_size = 0 + formulae_to_install.each do |f| + next unless (bottle = f.bottle) + kegs_size = 0 + # keep it quiet as there could be a lot of json fetch, it’s not intuitive to show them all. + bottle.fetch_tab(quiet: !args.debug?) + total_download_size += T.must(bottle.bottle_size) if bottle.bottle_size + total_installed_size += T.must(bottle.installed_size) if bottle.installed_size + f.installed_kegs.each do |keg| + kegs_size += keg.disk_usage if keg.disk_usage + end + total_net_size += (bottle.installed_size - kegs_size) if bottle.installed_size + sized_formulae.push(f) + next if f.deps.empty? + + # f.recursive_dependencies.each do |dep| + # f_dep = dep.to_formula + # kegs_dep_size = 0 + # bottle_dep = f_dep.bottle + # bottle_dep.fetch_tab(quiet: !args.debug?) + # total_download_size += bottle_dep.bottle_size if bottle_dep.bottle_size + # total_installed_size += bottle_dep.installed_size if bottle_dep.installed_size + # f_dep.installed_kegs.each do |keg| + # kegs_dep_size += keg.disk_usage if keg.disk_usage + # end + # total_net_size += (bottle_dep.installed_size - kegs_dep_size) if bottle_dep.installed_size + # end + end + puts "Formulae: #{sized_formulae.join(", ")}\n\n" + puts "Download Size: #{disk_usage_readable(total_download_size)}" if total_download_size + puts "Install Size: #{disk_usage_readable(total_installed_size)}\n" if total_installed_size + puts "Net Install Size: #{disk_usage_readable(total_net_size)}\n" if total_net_size + ask_input.call + end + Upgrade.upgrade_formulae( formulae_to_install, flags: args.flags_only, diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index 1157ad0780..bdc89ed3da 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -48,6 +48,10 @@ module Homebrew "trying any other/default URLs.", boolean: true, }, + HOMEBREW_ASK: { + description: "If set, pass `--ask`to all formula install commands.", + boolean: true, + }, HOMEBREW_AUTO_UPDATE_SECS: { description: "Run `brew update` once every `$HOMEBREW_AUTO_UPDATE_SECS` seconds before some commands, " \ "e.g. `brew install`, `brew upgrade` and `brew tap`. Alternatively, " \ diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/upgrade_cmd.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/upgrade_cmd.rbi index bc2ba6224b..3eb336f954 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/upgrade_cmd.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/upgrade_cmd.rbi @@ -14,6 +14,9 @@ class Homebrew::Cmd::UpgradeCmd::Args < Homebrew::CLI::Args sig { returns(T.nilable(String)) } def appdir; end + sig { returns(T::Boolean) } + def ask?; end + sig { returns(T.nilable(String)) } def audio_unit_plugindir; end diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi index bc71d5feb7..0405588ab3 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi @@ -28,6 +28,9 @@ module Homebrew::EnvConfig sig { returns(T::Boolean) } def artifact_domain_no_fallback?; end + sig { returns(T::Boolean) } + def ask?; end + sig { returns(T.nilable(::String)) } def auto_update_secs; end From 3ed1d6ccfba92ce9ccde56a120e01b5c6235ce84 Mon Sep 17 00:00:00 2001 From: thibhero Date: Mon, 10 Feb 2025 20:56:58 -0500 Subject: [PATCH 18/73] option `--ask` implementation for formulae dependency and dependant --- Library/Homebrew/cmd/upgrade.rb | 59 +++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index d716178060..4af765a736 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -246,36 +246,47 @@ module Homebrew total_installed_size = 0 total_net_size = 0 formulae_to_install.each do |f| - next unless (bottle = f.bottle) - kegs_size = 0 - # keep it quiet as there could be a lot of json fetch, it’s not intuitive to show them all. - bottle.fetch_tab(quiet: !args.debug?) - total_download_size += T.must(bottle.bottle_size) if bottle.bottle_size - total_installed_size += T.must(bottle.installed_size) if bottle.installed_size - f.installed_kegs.each do |keg| - kegs_size += keg.disk_usage if keg.disk_usage - end - total_net_size += (bottle.installed_size - kegs_size) if bottle.installed_size sized_formulae.push(f) next if f.deps.empty? + outdated_dependents = f.recursive_dependencies{ |_, dep| + next :prune if dep.to_formula.deps.empty? + next :prune unless dep.to_formula.outdated? + next :prune unless dep.to_formula.bottled? + }.flatten + + sized_formulae.concat(outdated_dependents.flat_map { |dep| + dep.to_formula + }).flatten - # f.recursive_dependencies.each do |dep| - # f_dep = dep.to_formula - # kegs_dep_size = 0 - # bottle_dep = f_dep.bottle - # bottle_dep.fetch_tab(quiet: !args.debug?) - # total_download_size += bottle_dep.bottle_size if bottle_dep.bottle_size - # total_installed_size += bottle_dep.installed_size if bottle_dep.installed_size - # f_dep.installed_kegs.each do |keg| - # kegs_dep_size += keg.disk_usage if keg.disk_usage - # end - # total_net_size += (bottle_dep.installed_size - kegs_dep_size) if bottle_dep.installed_size - # end end + + # check if formulae are dependant of those formulae and add if outdated + unless Homebrew::EnvConfig.no_installed_dependents_check? + sized_formulae.concat(Formula.installed.select do |f| + f.deps.any? { |dep| + sized_formulae.include?(dep.to_formula) && f.outdated? + } + end) + end + sized_formulae = sized_formulae.uniq { |dep| + dep.to_s + } + sized_formulae.each do |f| + kegs_dep_size = 0 + next unless (bottle = f.bottle) + bottle.fetch_tab(quiet: !args.debug?) + total_download_size += bottle.bottle_size if bottle.bottle_size + total_installed_size += bottle.installed_size if bottle.installed_size + f.installed_kegs.each do |keg| + kegs_dep_size += keg.disk_usage if keg.disk_usage + end + total_net_size += (bottle.installed_size - kegs_dep_size) if bottle.installed_size + end + puts "Formulae: #{sized_formulae.join(", ")}\n\n" puts "Download Size: #{disk_usage_readable(total_download_size)}" if total_download_size - puts "Install Size: #{disk_usage_readable(total_installed_size)}\n" if total_installed_size - puts "Net Install Size: #{disk_usage_readable(total_net_size)}\n" if total_net_size + puts "Install Size: #{disk_usage_readable(total_installed_size)}" if total_installed_size + puts "Net Install Size: #{disk_usage_readable(total_net_size)}" if total_net_size ask_input.call end From d9846ceda55455207ba09d5a3c8965fb8c665dbc Mon Sep 17 00:00:00 2001 From: thibhero Date: Mon, 10 Feb 2025 20:59:27 -0500 Subject: [PATCH 19/73] refactoring the code to make it clearer --- Library/Homebrew/cmd/upgrade.rb | 116 ++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 44 deletions(-) diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 4af765a736..d947560485 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -238,55 +238,83 @@ module Homebrew end } - # Showing dependencies and required size to install + # Build a unique list of formulae to size by including: + # 1. The original formulae to install. + # 2. Their outdated dependents (subject to pruning criteria). + # 3. Optionally, any installed formula that depends on one of these and is outdated. + def compute_sized_formulae(formulae_to_install) + sized_formulae = formulae_to_install.flat_map do |formula| + # Always include the formula itself. + formula_list = [formula] + + # If there are dependencies, try to gather outdated, bottled ones. + if formula.deps.any? + outdated_dependents = formula.recursive_dependencies do |_, dep| + dep_formula = dep.to_formula + next :prune if dep_formula.deps.empty? + next :prune unless dep_formula.outdated? + next :prune unless dep_formula.bottled? + end.flatten + + # Convert each dependency to its formula. + formula_list.concat(outdated_dependents.flat_map { |dep| Array(dep.to_formula) }) + end + + formula_list + end + + # Add any installed formula that depends on one of the sized formulae and is outdated. + unless Homebrew::EnvConfig.no_installed_dependents_check? + installed_outdated = Formula.installed.select do |installed_formula| + installed_formula.outdated? && + installed_formula.deps.any? { |dep| sized_formulae.include?(dep.to_formula) } + end + sized_formulae.concat(installed_outdated) + end + + # Uniquify based on a string representation (or any unique identifier) + sized_formulae.uniq { |f| f.to_s } + end + + # Compute the total sizes (download, installed, and net) for the given formulae. + def compute_total_sizes(sized_formulae, debug: false) + total_download_size = 0 + total_installed_size = 0 + total_net_size = 0 + + sized_formulae.each do |formula| + next unless (bottle = formula.bottle) + + # Fetch additional bottle metadata (if necessary). + bottle.fetch_tab(quiet: !debug) + + total_download_size += bottle.bottle_size.to_i if bottle.bottle_size + total_installed_size += bottle.installed_size.to_i if bottle.installed_size + + # Sum disk usage for all installed kegs of the formula. + kegs_dep_size = formula.installed_kegs.sum { |keg| keg.disk_usage.to_i } + if bottle.installed_size + total_net_size += bottle.installed_size.to_i - kegs_dep_size + end + end + + { download: total_download_size, + installed: total_installed_size, + net: total_net_size } + end + + # Main block: if asking the user is enabled, show dependency and size information. if args.ask? ohai "Looking for bottles..." - sized_formulae = [] - total_download_size = 0 - total_installed_size = 0 - total_net_size = 0 - formulae_to_install.each do |f| - sized_formulae.push(f) - next if f.deps.empty? - outdated_dependents = f.recursive_dependencies{ |_, dep| - next :prune if dep.to_formula.deps.empty? - next :prune unless dep.to_formula.outdated? - next :prune unless dep.to_formula.bottled? - }.flatten - sized_formulae.concat(outdated_dependents.flat_map { |dep| - dep.to_formula - }).flatten - - end - - # check if formulae are dependant of those formulae and add if outdated - unless Homebrew::EnvConfig.no_installed_dependents_check? - sized_formulae.concat(Formula.installed.select do |f| - f.deps.any? { |dep| - sized_formulae.include?(dep.to_formula) && f.outdated? - } - end) - end - sized_formulae = sized_formulae.uniq { |dep| - dep.to_s - } - sized_formulae.each do |f| - kegs_dep_size = 0 - next unless (bottle = f.bottle) - bottle.fetch_tab(quiet: !args.debug?) - total_download_size += bottle.bottle_size if bottle.bottle_size - total_installed_size += bottle.installed_size if bottle.installed_size - f.installed_kegs.each do |keg| - kegs_dep_size += keg.disk_usage if keg.disk_usage - end - total_net_size += (bottle.installed_size - kegs_dep_size) if bottle.installed_size - end + sized_formulae = compute_sized_formulae(formulae_to_install) + sizes = compute_total_sizes(sized_formulae, debug: args.debug?) puts "Formulae: #{sized_formulae.join(", ")}\n\n" - puts "Download Size: #{disk_usage_readable(total_download_size)}" if total_download_size - puts "Install Size: #{disk_usage_readable(total_installed_size)}" if total_installed_size - puts "Net Install Size: #{disk_usage_readable(total_net_size)}" if total_net_size + puts "Download Size: #{disk_usage_readable(sizes[:download])}" if sizes[:download] > 0 + puts "Install Size: #{disk_usage_readable(sizes[:installed])}" if sizes[:installed] > 0 + puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] > 0 + ask_input.call end From 4854113cf9e23dbc72453022d8f385a0e32be9cc Mon Sep 17 00:00:00 2001 From: thibhero Date: Mon, 10 Feb 2025 23:17:24 -0500 Subject: [PATCH 20/73] Add parameter to unify function arguments with reinstall.rb --- Library/Homebrew/cmd/upgrade.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index d947560485..a6e5454d0e 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -242,13 +242,13 @@ module Homebrew # 1. The original formulae to install. # 2. Their outdated dependents (subject to pruning criteria). # 3. Optionally, any installed formula that depends on one of these and is outdated. - def compute_sized_formulae(formulae_to_install) + def compute_sized_formulae(formulae_to_install, check_dep: true) sized_formulae = formulae_to_install.flat_map do |formula| # Always include the formula itself. formula_list = [formula] # If there are dependencies, try to gather outdated, bottled ones. - if formula.deps.any? + if formula.deps.any? && check_dep outdated_dependents = formula.recursive_dependencies do |_, dep| dep_formula = dep.to_formula next :prune if dep_formula.deps.empty? @@ -264,7 +264,7 @@ module Homebrew end # Add any installed formula that depends on one of the sized formulae and is outdated. - unless Homebrew::EnvConfig.no_installed_dependents_check? + unless Homebrew::EnvConfig.no_installed_dependents_check? || !check_dep installed_outdated = Formula.installed.select do |installed_formula| installed_formula.outdated? && installed_formula.deps.any? { |dep| sized_formulae.include?(dep.to_formula) } @@ -292,9 +292,11 @@ module Homebrew total_installed_size += bottle.installed_size.to_i if bottle.installed_size # Sum disk usage for all installed kegs of the formula. - kegs_dep_size = formula.installed_kegs.sum { |keg| keg.disk_usage.to_i } - if bottle.installed_size - total_net_size += bottle.installed_size.to_i - kegs_dep_size + if formula.installed_kegs.any? + kegs_dep_size = formula.installed_kegs.sum { |keg| keg.disk_usage.to_i } + if bottle.installed_size + total_net_size += bottle.installed_size.to_i - kegs_dep_size + end end end @@ -304,6 +306,7 @@ module Homebrew end # Main block: if asking the user is enabled, show dependency and size information. + # This part should be if args.ask? ohai "Looking for bottles..." @@ -311,9 +314,9 @@ module Homebrew sizes = compute_total_sizes(sized_formulae, debug: args.debug?) puts "Formulae: #{sized_formulae.join(", ")}\n\n" - puts "Download Size: #{disk_usage_readable(sizes[:download])}" if sizes[:download] > 0 - puts "Install Size: #{disk_usage_readable(sizes[:installed])}" if sizes[:installed] > 0 - puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] > 0 + puts "Download Size: #{disk_usage_readable(sizes[:download])}" + puts "Install Size: #{disk_usage_readable(sizes[:installed])}" + puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 ask_input.call end From 478035ed901e40cb6d3f4f8b5c1e55653950a57a Mon Sep 17 00:00:00 2001 From: thibhero Date: Mon, 10 Feb 2025 23:18:47 -0500 Subject: [PATCH 21/73] Copying function from upgrade.rb and implementing with `check_dep: false` --- Library/Homebrew/cmd/reinstall.rb | 105 ++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index cadda01cbe..14bdaf57e2 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -63,6 +63,11 @@ module Homebrew [:switch, "-g", "--git", { description: "Create a Git repository, useful for creating patches to the software.", }], + [:switch, "--ask", { + description: "Ask for confirmation before downloading and upgrading formulae. " \ + "Print bottles and dependencies download size, install and net install size.", + env: :ask, + }], ].each do |args| options = args.pop send(*args, **options) @@ -126,6 +131,106 @@ module Homebrew unless formulae.empty? Install.perform_preinstall_checks_once + ask_input = lambda { + ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" + accepted_inputs = %w[y yes] + declined_inputs = %w[n no] + loop do + result = $stdin.gets.chomp.strip.downcase + if accepted_inputs.include?(result) + puts "Proceeding with installation..." + break + elsif declined_inputs.include?(result) + exit 0 + else + puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." + end + end + } + + # Build a unique list of formulae to size by including: + # 1. The original formulae to install. + # 2. Their outdated dependents (subject to pruning criteria). + # 3. Optionally, any installed formula that depends on one of these and is outdated. + def compute_sized_formulae(formulae_to_install, check_dep: true) + sized_formulae = formulae_to_install.flat_map do |formula| + # Always include the formula itself. + formula_list = [formula] + + # If there are dependencies, try to gather outdated, bottled ones. + if formula.deps.any? && check_dep + outdated_dependents = formula.recursive_dependencies do |_, dep| + dep_formula = dep.to_formula + next :prune if dep_formula.deps.empty? + next :prune unless dep_formula.outdated? + next :prune unless dep_formula.bottled? + end.flatten + + # Convert each dependency to its formula. + formula_list.concat(outdated_dependents.flat_map { |dep| Array(dep.to_formula) }) + end + + formula_list + end + + # Add any installed formula that depends on one of the sized formulae and is outdated. + unless Homebrew::EnvConfig.no_installed_dependents_check? || !check_dep + installed_outdated = Formula.installed.select do |installed_formula| + installed_formula.outdated? && + installed_formula.deps.any? { |dep| sized_formulae.include?(dep.to_formula) } + end + sized_formulae.concat(installed_outdated) + end + + # Uniquify based on a string representation (or any unique identifier) + sized_formulae.uniq { |f| f.to_s } + end + + # Compute the total sizes (download, installed, and net) for the given formulae. + def compute_total_sizes(sized_formulae, debug: false) + total_download_size = 0 + total_installed_size = 0 + total_net_size = 0 + + sized_formulae.each do |formula| + next unless (bottle = formula.bottle) + + # Fetch additional bottle metadata (if necessary). + bottle.fetch_tab(quiet: !debug) + + total_download_size += bottle.bottle_size.to_i if bottle.bottle_size + total_installed_size += bottle.installed_size.to_i if bottle.installed_size + + # Sum disk usage for all installed kegs of the formula. + if formula.installed_kegs.any? + kegs_dep_size = formula.installed_kegs.sum { |keg| keg.disk_usage.to_i } + if bottle.installed_size + total_net_size += bottle.installed_size.to_i - kegs_dep_size + end + end + end + + { download: total_download_size, + installed: total_installed_size, + net: total_net_size } + end + + # Main block: if asking the user is enabled, show dependency and size information. + # This part should be + if args.ask? + ohai "Looking for bottles..." + + sized_formulae = compute_sized_formulae(formulae, check_dep: false) + sizes = compute_total_sizes(sized_formulae, debug: args.debug?) + + puts "Formulae: #{sized_formulae.join(", ")}\n\n" + puts "Download Size: #{disk_usage_readable(sizes[:download])}" + puts "Install Size: #{disk_usage_readable(sizes[:installed])}" + puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 + + ask_input.call + end + formulae.each do |formula| if formula.pinned? onoe "#{formula.full_name} is pinned. You must unpin it to reinstall." From db10b644ad93f2154043be7e8075a540d5151228 Mon Sep 17 00:00:00 2001 From: thibhero Date: Mon, 10 Feb 2025 23:18:56 -0500 Subject: [PATCH 22/73] updating typecheck --- Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/reinstall.rbi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/reinstall.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/reinstall.rbi index 10f9c8fb8f..beee25bbbe 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/reinstall.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/reinstall.rbi @@ -17,6 +17,9 @@ class Homebrew::Cmd::Reinstall::Args < Homebrew::CLI::Args sig { returns(T.nilable(String)) } def appdir; end + sig { returns(T::Boolean) } + def ask?; end + sig { returns(T.nilable(String)) } def audio_unit_plugindir; end From a1111396823989cf31c4211acd3d472b4ee01ce8 Mon Sep 17 00:00:00 2001 From: thibhero Date: Tue, 11 Feb 2025 11:06:16 -0500 Subject: [PATCH 23/73] moving to lambda expressions to respect `brew style` --- Library/Homebrew/cmd/reinstall.rb | 12 ++++++------ Library/Homebrew/cmd/upgrade.rb | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 14bdaf57e2..d336233313 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -152,7 +152,7 @@ module Homebrew # 1. The original formulae to install. # 2. Their outdated dependents (subject to pruning criteria). # 3. Optionally, any installed formula that depends on one of these and is outdated. - def compute_sized_formulae(formulae_to_install, check_dep: true) + compute_sized_formulae = lambda { |formulae_to_install, check_dep: true| sized_formulae = formulae_to_install.flat_map do |formula| # Always include the formula itself. formula_list = [formula] @@ -184,10 +184,10 @@ module Homebrew # Uniquify based on a string representation (or any unique identifier) sized_formulae.uniq { |f| f.to_s } - end + } # Compute the total sizes (download, installed, and net) for the given formulae. - def compute_total_sizes(sized_formulae, debug: false) + compute_total_sizes = lambda { |sized_formulae, debug: false| total_download_size = 0 total_installed_size = 0 total_net_size = 0 @@ -213,15 +213,15 @@ module Homebrew { download: total_download_size, installed: total_installed_size, net: total_net_size } - end + } # Main block: if asking the user is enabled, show dependency and size information. # This part should be if args.ask? ohai "Looking for bottles..." - sized_formulae = compute_sized_formulae(formulae, check_dep: false) - sizes = compute_total_sizes(sized_formulae, debug: args.debug?) + sized_formulae = compute_sized_formulae.call(formulae, check_dep: false) + sizes = compute_total_sizes.call(sized_formulae, debug: args.debug?) puts "Formulae: #{sized_formulae.join(", ")}\n\n" puts "Download Size: #{disk_usage_readable(sizes[:download])}" diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index a6e5454d0e..54893ad18a 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -242,7 +242,7 @@ module Homebrew # 1. The original formulae to install. # 2. Their outdated dependents (subject to pruning criteria). # 3. Optionally, any installed formula that depends on one of these and is outdated. - def compute_sized_formulae(formulae_to_install, check_dep: true) + compute_sized_formulae = lambda { |formulae_to_install, check_dep: true| sized_formulae = formulae_to_install.flat_map do |formula| # Always include the formula itself. formula_list = [formula] @@ -274,10 +274,10 @@ module Homebrew # Uniquify based on a string representation (or any unique identifier) sized_formulae.uniq { |f| f.to_s } - end + } # Compute the total sizes (download, installed, and net) for the given formulae. - def compute_total_sizes(sized_formulae, debug: false) + compute_total_sizes = lambda { |sized_formulae, debug: false| total_download_size = 0 total_installed_size = 0 total_net_size = 0 @@ -303,7 +303,7 @@ module Homebrew { download: total_download_size, installed: total_installed_size, net: total_net_size } - end + } # Main block: if asking the user is enabled, show dependency and size information. # This part should be From 9891653aa8db5a8f02532116f2edfd39f7eec24a Mon Sep 17 00:00:00 2001 From: thibhero Date: Tue, 11 Feb 2025 18:53:10 -0500 Subject: [PATCH 24/73] corrected code with `brew typecheck` --- Library/Homebrew/cmd/reinstall.rb | 20 +++++++++----------- Library/Homebrew/cmd/upgrade.rb | 28 +++++++++++++--------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index d336233313..a546389b38 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -65,7 +65,7 @@ module Homebrew }], [:switch, "--ask", { description: "Ask for confirmation before downloading and upgrading formulae. " \ - "Print bottles and dependencies download size, install and net install size.", + "Print bottles and dependencies download size, install and net install size.", env: :ask, }], ].each do |args| @@ -174,7 +174,7 @@ module Homebrew end # Add any installed formula that depends on one of the sized formulae and is outdated. - unless Homebrew::EnvConfig.no_installed_dependents_check? || !check_dep + if !Homebrew::EnvConfig.no_installed_dependents_check? && check_dep installed_outdated = Formula.installed.select do |installed_formula| installed_formula.outdated? && installed_formula.deps.any? { |dep| sized_formulae.include?(dep.to_formula) } @@ -183,7 +183,7 @@ module Homebrew end # Uniquify based on a string representation (or any unique identifier) - sized_formulae.uniq { |f| f.to_s } + sized_formulae.uniq(&:to_s) } # Compute the total sizes (download, installed, and net) for the given formulae. @@ -202,17 +202,15 @@ module Homebrew total_installed_size += bottle.installed_size.to_i if bottle.installed_size # Sum disk usage for all installed kegs of the formula. - if formula.installed_kegs.any? - kegs_dep_size = formula.installed_kegs.sum { |keg| keg.disk_usage.to_i } - if bottle.installed_size - total_net_size += bottle.installed_size.to_i - kegs_dep_size - end - end + next if formula.installed_kegs.none? + + kegs_dep_size = formula.installed_kegs.sum { |keg| keg.disk_usage.to_i } + total_net_size += bottle.installed_size.to_i - kegs_dep_size if bottle.installed_size end - { download: total_download_size, + { download: total_download_size, installed: total_installed_size, - net: total_net_size } + net: total_net_size } } # Main block: if asking the user is enabled, show dependency and size information. diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 54893ad18a..01391ea3d5 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -73,7 +73,7 @@ module Homebrew }], [:switch, "--ask", { description: "Ask for confirmation before downloading and upgrading formulae. " \ - "Print bottles and dependencies download size, install and net install size.", + "Print bottles and dependencies download size, install and net install size.", env: :ask, }], ].each do |args| @@ -242,8 +242,8 @@ module Homebrew # 1. The original formulae to install. # 2. Their outdated dependents (subject to pruning criteria). # 3. Optionally, any installed formula that depends on one of these and is outdated. - compute_sized_formulae = lambda { |formulae_to_install, check_dep: true| - sized_formulae = formulae_to_install.flat_map do |formula| + compute_sized_formulae = lambda { |f, check_dep: true| + sized_formulae = f.flat_map do |formula| # Always include the formula itself. formula_list = [formula] @@ -264,7 +264,7 @@ module Homebrew end # Add any installed formula that depends on one of the sized formulae and is outdated. - unless Homebrew::EnvConfig.no_installed_dependents_check? || !check_dep + if !Homebrew::EnvConfig.no_installed_dependents_check? && check_dep installed_outdated = Formula.installed.select do |installed_formula| installed_formula.outdated? && installed_formula.deps.any? { |dep| sized_formulae.include?(dep.to_formula) } @@ -273,7 +273,7 @@ module Homebrew end # Uniquify based on a string representation (or any unique identifier) - sized_formulae.uniq { |f| f.to_s } + sized_formulae.uniq(&:to_s) } # Compute the total sizes (download, installed, and net) for the given formulae. @@ -292,17 +292,15 @@ module Homebrew total_installed_size += bottle.installed_size.to_i if bottle.installed_size # Sum disk usage for all installed kegs of the formula. - if formula.installed_kegs.any? - kegs_dep_size = formula.installed_kegs.sum { |keg| keg.disk_usage.to_i } - if bottle.installed_size - total_net_size += bottle.installed_size.to_i - kegs_dep_size - end - end + next if formula.installed_kegs.none? + + kegs_dep_size = formula.installed_kegs.sum { |keg| keg.disk_usage.to_i } + total_net_size += bottle.installed_size.to_i - kegs_dep_size if bottle.installed_size end - { download: total_download_size, + { download: total_download_size, installed: total_installed_size, - net: total_net_size } + net: total_net_size } } # Main block: if asking the user is enabled, show dependency and size information. @@ -310,8 +308,8 @@ module Homebrew if args.ask? ohai "Looking for bottles..." - sized_formulae = compute_sized_formulae(formulae_to_install) - sizes = compute_total_sizes(sized_formulae, debug: args.debug?) + sized_formulae = compute_sized_formulae.call(formulae_to_install) + sizes = compute_total_sizes.call(sized_formulae, debug: args.debug?) puts "Formulae: #{sized_formulae.join(", ")}\n\n" puts "Download Size: #{disk_usage_readable(sizes[:download])}" From 081db50196a56b664600f313a9702bb3b34525b3 Mon Sep 17 00:00:00 2001 From: thibhero Date: Tue, 11 Feb 2025 19:46:38 -0500 Subject: [PATCH 25/73] Copying function from branch `upgrade-reinstall-size` into install.rb and adding parameter --- Library/Homebrew/cmd/install.rb | 132 ++++++++++++++++++++++---------- 1 file changed, 92 insertions(+), 40 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 91800deee6..fb3d5f3c6d 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -180,23 +180,6 @@ module Homebrew odisabled "brew install --env", "`env :std` in specific formula files" end - ask_input = lambda { - ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" - accepted_inputs = %w[y yes] - declined_inputs = %w[n no] - loop do - result = $stdin.gets.chomp.strip.downcase - if accepted_inputs.include?(result) - puts "Proceeding with installation..." - break - elsif declined_inputs.include?(result) - return - else - puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." - end - end - } - args.named.each do |name| if (tap_with_name = Tap.with_formula_name(name)) tap, = tap_with_name @@ -324,32 +307,101 @@ module Homebrew Install.perform_preinstall_checks_once Install.check_cc_argv(args.cc) - # Showing dependencies and required size to install - if args.ask? - ohai "Looking for bottle sizes..." - sized_formulae = [] - total_download_size = 0 - total_installed_size = 0 - installed_formulae.each do |f| - next unless (bottle = f.bottle) - - # keep it quiet as there could be a lot of json fetch, it’s not intuitive to show them all. - bottle.fetch_tab(quiet: !args.debug?) - total_download_size += T.must(bottle.bottle_size) if bottle.bottle_size - total_installed_size += T.must(bottle.installed_size) if bottle.installed_size - sized_formulae.push(f, f.recursive_dependencies) - next if f.deps.empty? - - f.recursive_dependencies.each do |dep| - bottle_dep = dep.to_formula.bottle - bottle_dep.fetch_tab(quiet: !args.debug?) - total_download_size += bottle_dep.bottle_size if bottle_dep.bottle_size - total_installed_size += bottle_dep.installed_size if bottle_dep.installed_size + ask_input = lambda { + ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" + accepted_inputs = %w[y yes] + declined_inputs = %w[n no] + loop do + result = $stdin.gets.chomp.strip.downcase + if accepted_inputs.include?(result) + puts "Proceeding with installation..." + break + elsif declined_inputs.include?(result) + return + else + puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." end end + } + + # Build a unique list of formulae to size by including: + # 1. The original formulae to install. + # 2. Their outdated dependents (subject to pruning criteria). + # 3. Optionally, any installed formula that depends on one of these and is outdated. + compute_sized_formulae = lambda { |f, check_dep: true, upgrade: true| + sized_formulae = f.flat_map do |formula| + # Always include the formula itself. + formula_list = [formula] + + # If there are dependencies, try to gather outdated, bottled ones. + if formula.deps.any? && check_dep + outdated_dependents = formula.recursive_dependencies do |_, dep| + dep_formula = dep.to_formula + next :prune if dep_formula.deps.empty? + next :prune if !upgrade || !dep_formula.outdated? + next :prune unless dep_formula.bottled? + end.flatten + + # Convert each dependency to its formula. + formula_list.concat(outdated_dependents.flat_map { |dep| Array(dep.to_formula) }) + end + + formula_list + end + + # Add any installed formula that depends on one of the sized formulae and is outdated. + if !Homebrew::EnvConfig.no_installed_dependents_check? && check_dep + installed_outdated = Formula.installed.select do |installed_formula| + installed_formula.outdated? && + installed_formula.deps.any? { |dep| sized_formulae.include?(dep.to_formula) } + end + sized_formulae.concat(installed_outdated) + end + + # Uniquify based on a string representation (or any unique identifier) + sized_formulae.uniq(&:to_s) + } + + # Compute the total sizes (download, installed, and net) for the given formulae. + compute_total_sizes = lambda { |sized_formulae, debug: false| + total_download_size = 0 + total_installed_size = 0 + total_net_size = 0 + + sized_formulae.each do |formula| + next unless (bottle = formula.bottle) + + # Fetch additional bottle metadata (if necessary). + bottle.fetch_tab(quiet: !debug) + + total_download_size += bottle.bottle_size.to_i if bottle.bottle_size + total_installed_size += bottle.installed_size.to_i if bottle.installed_size + + # Sum disk usage for all installed kegs of the formula. + next if formula.installed_kegs.none? + + kegs_dep_size = formula.installed_kegs.sum { |keg| keg.disk_usage.to_i } + total_net_size += bottle.installed_size.to_i - kegs_dep_size if bottle.installed_size + end + + { download: total_download_size, + installed: total_installed_size, + net: total_net_size } + } + + # Main block: if asking the user is enabled, show dependency and size information. + # This part should be + if args.ask? + ohai "Looking for bottles..." + + sized_formulae = compute_sized_formulae.call(formulae_to_install, check_dep: true, upgrade: false) + sizes = compute_total_sizes.call(sized_formulae, debug: args.debug?) + puts "Formulae: #{sized_formulae.join(", ")}\n\n" - puts "Download Size: #{disk_usage_readable(total_download_size)}" if total_download_size - puts "Install Size: #{disk_usage_readable(total_installed_size)}\n" if total_installed_size + puts "Download Size: #{disk_usage_readable(sizes[:download])}" + puts "Install Size: #{disk_usage_readable(sizes[:installed])}" + puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 + ask_input.call end From 1ba3f32026e6f0a772f5ce6a2a2d85c8a4c9f837 Mon Sep 17 00:00:00 2001 From: thibhero Date: Tue, 11 Feb 2025 20:15:19 -0500 Subject: [PATCH 26/73] Adding upgrade arguments in lambda --- Library/Homebrew/cmd/reinstall.rb | 6 +++--- Library/Homebrew/cmd/upgrade.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index a546389b38..122d73bd26 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -152,7 +152,7 @@ module Homebrew # 1. The original formulae to install. # 2. Their outdated dependents (subject to pruning criteria). # 3. Optionally, any installed formula that depends on one of these and is outdated. - compute_sized_formulae = lambda { |formulae_to_install, check_dep: true| + compute_sized_formulae = lambda { |formulae_to_install, check_dep: true, upgrade: true| sized_formulae = formulae_to_install.flat_map do |formula| # Always include the formula itself. formula_list = [formula] @@ -162,7 +162,7 @@ module Homebrew outdated_dependents = formula.recursive_dependencies do |_, dep| dep_formula = dep.to_formula next :prune if dep_formula.deps.empty? - next :prune unless dep_formula.outdated? + next :prune if !upgrade || !dep_formula.outdated? next :prune unless dep_formula.bottled? end.flatten @@ -218,7 +218,7 @@ module Homebrew if args.ask? ohai "Looking for bottles..." - sized_formulae = compute_sized_formulae.call(formulae, check_dep: false) + sized_formulae = compute_sized_formulae.call(formulae, check_dep: false, upgrade: false) sizes = compute_total_sizes.call(sized_formulae, debug: args.debug?) puts "Formulae: #{sized_formulae.join(", ")}\n\n" diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 01391ea3d5..fc8d1a2cef 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -242,7 +242,7 @@ module Homebrew # 1. The original formulae to install. # 2. Their outdated dependents (subject to pruning criteria). # 3. Optionally, any installed formula that depends on one of these and is outdated. - compute_sized_formulae = lambda { |f, check_dep: true| + compute_sized_formulae = lambda { |f, check_dep: true, upgrade: true| sized_formulae = f.flat_map do |formula| # Always include the formula itself. formula_list = [formula] @@ -252,7 +252,7 @@ module Homebrew outdated_dependents = formula.recursive_dependencies do |_, dep| dep_formula = dep.to_formula next :prune if dep_formula.deps.empty? - next :prune unless dep_formula.outdated? + next :prune if !upgrade || !dep_formula.outdated? next :prune unless dep_formula.bottled? end.flatten From cb947b9cf4de04dcb7974580cc74b5f7e11b3064 Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 12 Feb 2025 15:57:12 -0500 Subject: [PATCH 27/73] erratum on variable --- Library/Homebrew/cmd/install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index fb3d5f3c6d..64bcee9a80 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -394,7 +394,7 @@ module Homebrew if args.ask? ohai "Looking for bottles..." - sized_formulae = compute_sized_formulae.call(formulae_to_install, check_dep: true, upgrade: false) + sized_formulae = compute_sized_formulae.call(installed_formulae, check_dep: true, upgrade: false) sizes = compute_total_sizes.call(sized_formulae, debug: args.debug?) puts "Formulae: #{sized_formulae.join(", ")}\n\n" From f1906c1682a7eb49245b282721452f20e0b29e93 Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 12 Feb 2025 15:59:35 -0500 Subject: [PATCH 28/73] adding exit status if declined --- Library/Homebrew/cmd/install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 64bcee9a80..9d866b1952 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -317,7 +317,7 @@ module Homebrew puts "Proceeding with installation..." break elsif declined_inputs.include?(result) - return + exit 0 else puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." end From 97678708dba0affa4ab116e0d3473d6a17572790 Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 12 Feb 2025 16:05:11 -0500 Subject: [PATCH 29/73] removing useless statements --- Library/Homebrew/cmd/install.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 9d866b1952..089db1c1fa 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -314,7 +314,6 @@ module Homebrew loop do result = $stdin.gets.chomp.strip.downcase if accepted_inputs.include?(result) - puts "Proceeding with installation..." break elsif declined_inputs.include?(result) exit 0 From 5886b51df72a207c5fa3ebed0048fc17abe5c9e4 Mon Sep 17 00:00:00 2001 From: thibhero Date: Sat, 15 Feb 2025 23:00:35 -0500 Subject: [PATCH 30/73] refactoring and updating functions to correctly print formula to upgrade --- Library/Homebrew/cmd/upgrade.rb | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index fc8d1a2cef..03fb307a09 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -228,7 +228,6 @@ module Homebrew loop do result = $stdin.gets.chomp.strip.downcase if accepted_inputs.include?(result) - puts "Proceeding with installation..." break elsif declined_inputs.include?(result) return @@ -238,44 +237,36 @@ module Homebrew end } - # Build a unique list of formulae to size by including: - # 1. The original formulae to install. - # 2. Their outdated dependents (subject to pruning criteria). - # 3. Optionally, any installed formula that depends on one of these and is outdated. compute_sized_formulae = lambda { |f, check_dep: true, upgrade: true| sized_formulae = f.flat_map do |formula| # Always include the formula itself. formula_list = [formula] - + next unless upgrade + deps = args.build_from_source? ? formula.deps.build : formula.deps.required # If there are dependencies, try to gather outdated, bottled ones. - if formula.deps.any? && check_dep - outdated_dependents = formula.recursive_dependencies do |_, dep| - dep_formula = dep.to_formula - next :prune if dep_formula.deps.empty? - next :prune if !upgrade || !dep_formula.outdated? - next :prune unless dep_formula.bottled? - end.flatten + if deps.any? && check_dep + outdated_dependents = deps.map(&:to_formula).reject(&:pinned?).select do |dep| + dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) + end - # Convert each dependency to its formula. - formula_list.concat(outdated_dependents.flat_map { |dep| Array(dep.to_formula) }) + formula_list.concat(outdated_dependents) end formula_list end # Add any installed formula that depends on one of the sized formulae and is outdated. - if !Homebrew::EnvConfig.no_installed_dependents_check? && check_dep - installed_outdated = Formula.installed.select do |installed_formula| + if check_dep && !Homebrew::EnvConfig.no_installed_dependents_check? + sized_formulae.concat(Formula.installed.select do |installed_formula| installed_formula.outdated? && - installed_formula.deps.any? { |dep| sized_formulae.include?(dep.to_formula) } - end - sized_formulae.concat(installed_outdated) + installed_formula.deps.required.any? { |dep| sized_formulae.include?(dep.to_formula) } + end) end - # Uniquify based on a string representation (or any unique identifier) sized_formulae.uniq(&:to_s) } + # Compute the total sizes (download, installed, and net) for the given formulae. compute_total_sizes = lambda { |sized_formulae, debug: false| total_download_size = 0 From b821446b6f42e10f7167c5a828262056b776985b Mon Sep 17 00:00:00 2001 From: thibhero Date: Sat, 15 Feb 2025 23:01:53 -0500 Subject: [PATCH 31/73] description of lambda --- Library/Homebrew/cmd/upgrade.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 03fb307a09..89561c82b5 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -237,6 +237,10 @@ module Homebrew end } + # Build a unique list of formulae to size by including: + # 1. The original formulae to install. + # 2. Their outdated dependents (subject to pruning criteria). + # 3. Optionally, any installed formula that depends on one of these and is outdated. compute_sized_formulae = lambda { |f, check_dep: true, upgrade: true| sized_formulae = f.flat_map do |formula| # Always include the formula itself. From 624e960cd5d2aff9cf57bbe9c63cac0a7420c880 Mon Sep 17 00:00:00 2001 From: thibhero Date: Sat, 15 Feb 2025 23:02:14 -0500 Subject: [PATCH 32/73] refactoring lambda as upgrade.RB --- Library/Homebrew/cmd/reinstall.rb | 32 +++++++++++++------------------ 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 122d73bd26..f5440407ec 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -138,7 +138,6 @@ module Homebrew loop do result = $stdin.gets.chomp.strip.downcase if accepted_inputs.include?(result) - puts "Proceeding with installation..." break elsif declined_inputs.include?(result) exit 0 @@ -152,37 +151,32 @@ module Homebrew # 1. The original formulae to install. # 2. Their outdated dependents (subject to pruning criteria). # 3. Optionally, any installed formula that depends on one of these and is outdated. - compute_sized_formulae = lambda { |formulae_to_install, check_dep: true, upgrade: true| - sized_formulae = formulae_to_install.flat_map do |formula| + compute_sized_formulae = lambda { |f, check_dep: true, upgrade: true| + sized_formulae = f.flat_map do |formula| # Always include the formula itself. formula_list = [formula] - + next unless upgrade + deps = args.build_from_source? ? formula.deps.build : formula.deps.required # If there are dependencies, try to gather outdated, bottled ones. - if formula.deps.any? && check_dep - outdated_dependents = formula.recursive_dependencies do |_, dep| - dep_formula = dep.to_formula - next :prune if dep_formula.deps.empty? - next :prune if !upgrade || !dep_formula.outdated? - next :prune unless dep_formula.bottled? - end.flatten + if deps.any? && check_dep + outdated_dependents = deps.map(&:to_formula).reject(&:pinned?).select do |dep| + dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) + end - # Convert each dependency to its formula. - formula_list.concat(outdated_dependents.flat_map { |dep| Array(dep.to_formula) }) + formula_list.concat(outdated_dependents) end formula_list end # Add any installed formula that depends on one of the sized formulae and is outdated. - if !Homebrew::EnvConfig.no_installed_dependents_check? && check_dep - installed_outdated = Formula.installed.select do |installed_formula| + if check_dep && !Homebrew::EnvConfig.no_installed_dependents_check? + sized_formulae.concat(Formula.installed.select do |installed_formula| installed_formula.outdated? && - installed_formula.deps.any? { |dep| sized_formulae.include?(dep.to_formula) } - end - sized_formulae.concat(installed_outdated) + installed_formula.deps.required.any? { |dep| sized_formulae.include?(dep.to_formula) } + end) end - # Uniquify based on a string representation (or any unique identifier) sized_formulae.uniq(&:to_s) } From 5c2bbe59112f04aba7e020e41dfd04e8349c8d55 Mon Sep 17 00:00:00 2001 From: thibhero Date: Sat, 15 Feb 2025 23:20:07 -0500 Subject: [PATCH 33/73] pass `brew typecheck`, `brew style` and `brew tests` --- Library/Homebrew/cmd/reinstall.rb | 1 + Library/Homebrew/cmd/upgrade.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index f5440407ec..eec494b47b 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -156,6 +156,7 @@ module Homebrew # Always include the formula itself. formula_list = [formula] next unless upgrade + deps = args.build_from_source? ? formula.deps.build : formula.deps.required # If there are dependencies, try to gather outdated, bottled ones. if deps.any? && check_dep diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 89561c82b5..0a6cc0e710 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -230,7 +230,7 @@ module Homebrew if accepted_inputs.include?(result) break elsif declined_inputs.include?(result) - return + exit 0 else puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." end @@ -246,6 +246,7 @@ module Homebrew # Always include the formula itself. formula_list = [formula] next unless upgrade + deps = args.build_from_source? ? formula.deps.build : formula.deps.required # If there are dependencies, try to gather outdated, bottled ones. if deps.any? && check_dep @@ -270,7 +271,6 @@ module Homebrew sized_formulae.uniq(&:to_s) } - # Compute the total sizes (download, installed, and net) for the given formulae. compute_total_sizes = lambda { |sized_formulae, debug: false| total_download_size = 0 From 8299c5980117720b69fcad3660edfb9ef34b0bf8 Mon Sep 17 00:00:00 2001 From: thibhero Date: Sun, 16 Feb 2025 00:06:23 -0500 Subject: [PATCH 34/73] pass `brew typecheck`, `brew style` and `brew tests` --- Library/Homebrew/cmd/install.rb | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 089db1c1fa..ec4adb3c73 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -331,33 +331,29 @@ module Homebrew sized_formulae = f.flat_map do |formula| # Always include the formula itself. formula_list = [formula] + next unless upgrade + deps = args.build_from_source? ? formula.deps.build : formula.deps.required # If there are dependencies, try to gather outdated, bottled ones. - if formula.deps.any? && check_dep - outdated_dependents = formula.recursive_dependencies do |_, dep| - dep_formula = dep.to_formula - next :prune if dep_formula.deps.empty? - next :prune if !upgrade || !dep_formula.outdated? - next :prune unless dep_formula.bottled? - end.flatten + if deps.any? && check_dep + outdated_dependents = deps.map(&:to_formula).reject(&:pinned?).select do |dep| + dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) + end - # Convert each dependency to its formula. - formula_list.concat(outdated_dependents.flat_map { |dep| Array(dep.to_formula) }) + formula_list.concat(outdated_dependents) end formula_list end # Add any installed formula that depends on one of the sized formulae and is outdated. - if !Homebrew::EnvConfig.no_installed_dependents_check? && check_dep - installed_outdated = Formula.installed.select do |installed_formula| + if check_dep && !Homebrew::EnvConfig.no_installed_dependents_check? + sized_formulae.concat(Formula.installed.select do |installed_formula| installed_formula.outdated? && - installed_formula.deps.any? { |dep| sized_formulae.include?(dep.to_formula) } - end - sized_formulae.concat(installed_outdated) + installed_formula.deps.required.any? { |dep| sized_formulae.include?(dep.to_formula) } + end) end - # Uniquify based on a string representation (or any unique identifier) sized_formulae.uniq(&:to_s) } @@ -389,11 +385,10 @@ module Homebrew } # Main block: if asking the user is enabled, show dependency and size information. - # This part should be if args.ask? ohai "Looking for bottles..." - sized_formulae = compute_sized_formulae.call(installed_formulae, check_dep: true, upgrade: false) + sized_formulae = compute_sized_formulae.call(formulae, check_dep: false, upgrade: false) sizes = compute_total_sizes.call(sized_formulae, debug: args.debug?) puts "Formulae: #{sized_formulae.join(", ")}\n\n" From bb7dcc9384b99ff46556bd3e091ed4e878fa845a Mon Sep 17 00:00:00 2001 From: thibhero Date: Sun, 16 Feb 2025 00:06:57 -0500 Subject: [PATCH 35/73] updating comments --- Library/Homebrew/cmd/reinstall.rb | 1 - Library/Homebrew/cmd/upgrade.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index eec494b47b..54e74af6b9 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -209,7 +209,6 @@ module Homebrew } # Main block: if asking the user is enabled, show dependency and size information. - # This part should be if args.ask? ohai "Looking for bottles..." diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 0a6cc0e710..38eaf18f90 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -299,7 +299,6 @@ module Homebrew } # Main block: if asking the user is enabled, show dependency and size information. - # This part should be if args.ask? ohai "Looking for bottles..." From 1a43a9d258ed791e6bcf05569e855bcc70af3d84 Mon Sep 17 00:00:00 2001 From: thibhero Date: Tue, 18 Feb 2025 22:41:40 -0500 Subject: [PATCH 36/73] extracting method to Homebrew/install.rb --- Library/Homebrew/cmd/install.rb | 83 ++----------------------------- Library/Homebrew/cmd/reinstall.rb | 83 ++----------------------------- Library/Homebrew/cmd/upgrade.rb | 83 ++----------------------------- Library/Homebrew/install.rb | 76 ++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 240 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index ec4adb3c73..d14a50def1 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -307,96 +307,19 @@ module Homebrew Install.perform_preinstall_checks_once Install.check_cc_argv(args.cc) - ask_input = lambda { - ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" - accepted_inputs = %w[y yes] - declined_inputs = %w[n no] - loop do - result = $stdin.gets.chomp.strip.downcase - if accepted_inputs.include?(result) - break - elsif declined_inputs.include?(result) - exit 0 - else - puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." - end - end - } - - # Build a unique list of formulae to size by including: - # 1. The original formulae to install. - # 2. Their outdated dependents (subject to pruning criteria). - # 3. Optionally, any installed formula that depends on one of these and is outdated. - compute_sized_formulae = lambda { |f, check_dep: true, upgrade: true| - sized_formulae = f.flat_map do |formula| - # Always include the formula itself. - formula_list = [formula] - next unless upgrade - - deps = args.build_from_source? ? formula.deps.build : formula.deps.required - # If there are dependencies, try to gather outdated, bottled ones. - if deps.any? && check_dep - outdated_dependents = deps.map(&:to_formula).reject(&:pinned?).select do |dep| - dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) - end - - formula_list.concat(outdated_dependents) - end - - formula_list - end - - # Add any installed formula that depends on one of the sized formulae and is outdated. - if check_dep && !Homebrew::EnvConfig.no_installed_dependents_check? - sized_formulae.concat(Formula.installed.select do |installed_formula| - installed_formula.outdated? && - installed_formula.deps.required.any? { |dep| sized_formulae.include?(dep.to_formula) } - end) - end - - sized_formulae.uniq(&:to_s) - } - - # Compute the total sizes (download, installed, and net) for the given formulae. - compute_total_sizes = lambda { |sized_formulae, debug: false| - total_download_size = 0 - total_installed_size = 0 - total_net_size = 0 - - sized_formulae.each do |formula| - next unless (bottle = formula.bottle) - - # Fetch additional bottle metadata (if necessary). - bottle.fetch_tab(quiet: !debug) - - total_download_size += bottle.bottle_size.to_i if bottle.bottle_size - total_installed_size += bottle.installed_size.to_i if bottle.installed_size - - # Sum disk usage for all installed kegs of the formula. - next if formula.installed_kegs.none? - - kegs_dep_size = formula.installed_kegs.sum { |keg| keg.disk_usage.to_i } - total_net_size += bottle.installed_size.to_i - kegs_dep_size if bottle.installed_size - end - - { download: total_download_size, - installed: total_installed_size, - net: total_net_size } - } - # Main block: if asking the user is enabled, show dependency and size information. if args.ask? ohai "Looking for bottles..." - sized_formulae = compute_sized_formulae.call(formulae, check_dep: false, upgrade: false) - sizes = compute_total_sizes.call(sized_formulae, debug: args.debug?) + sized_formulae = Install.compute_sized_formulae(formulae, args: args) + sizes = Install.compute_total_sizes(sized_formulae, debug: args.debug?) puts "Formulae: #{sized_formulae.join(", ")}\n\n" puts "Download Size: #{disk_usage_readable(sizes[:download])}" puts "Install Size: #{disk_usage_readable(sizes[:installed])}" puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 - ask_input.call + Install.ask_input end Install.install_formulae( diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 54e74af6b9..9c67de6062 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -131,96 +131,19 @@ module Homebrew unless formulae.empty? Install.perform_preinstall_checks_once - ask_input = lambda { - ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" - accepted_inputs = %w[y yes] - declined_inputs = %w[n no] - loop do - result = $stdin.gets.chomp.strip.downcase - if accepted_inputs.include?(result) - break - elsif declined_inputs.include?(result) - exit 0 - else - puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." - end - end - } - - # Build a unique list of formulae to size by including: - # 1. The original formulae to install. - # 2. Their outdated dependents (subject to pruning criteria). - # 3. Optionally, any installed formula that depends on one of these and is outdated. - compute_sized_formulae = lambda { |f, check_dep: true, upgrade: true| - sized_formulae = f.flat_map do |formula| - # Always include the formula itself. - formula_list = [formula] - next unless upgrade - - deps = args.build_from_source? ? formula.deps.build : formula.deps.required - # If there are dependencies, try to gather outdated, bottled ones. - if deps.any? && check_dep - outdated_dependents = deps.map(&:to_formula).reject(&:pinned?).select do |dep| - dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) - end - - formula_list.concat(outdated_dependents) - end - - formula_list - end - - # Add any installed formula that depends on one of the sized formulae and is outdated. - if check_dep && !Homebrew::EnvConfig.no_installed_dependents_check? - sized_formulae.concat(Formula.installed.select do |installed_formula| - installed_formula.outdated? && - installed_formula.deps.required.any? { |dep| sized_formulae.include?(dep.to_formula) } - end) - end - - sized_formulae.uniq(&:to_s) - } - - # Compute the total sizes (download, installed, and net) for the given formulae. - compute_total_sizes = lambda { |sized_formulae, debug: false| - total_download_size = 0 - total_installed_size = 0 - total_net_size = 0 - - sized_formulae.each do |formula| - next unless (bottle = formula.bottle) - - # Fetch additional bottle metadata (if necessary). - bottle.fetch_tab(quiet: !debug) - - total_download_size += bottle.bottle_size.to_i if bottle.bottle_size - total_installed_size += bottle.installed_size.to_i if bottle.installed_size - - # Sum disk usage for all installed kegs of the formula. - next if formula.installed_kegs.none? - - kegs_dep_size = formula.installed_kegs.sum { |keg| keg.disk_usage.to_i } - total_net_size += bottle.installed_size.to_i - kegs_dep_size if bottle.installed_size - end - - { download: total_download_size, - installed: total_installed_size, - net: total_net_size } - } - # Main block: if asking the user is enabled, show dependency and size information. if args.ask? ohai "Looking for bottles..." - sized_formulae = compute_sized_formulae.call(formulae, check_dep: false, upgrade: false) - sizes = compute_total_sizes.call(sized_formulae, debug: args.debug?) + sized_formulae = Install.compute_sized_formulae(formulae, args: args) + sizes = Install.compute_total_sizes(sized_formulae, debug: args.debug?) puts "Formulae: #{sized_formulae.join(", ")}\n\n" puts "Download Size: #{disk_usage_readable(sizes[:download])}" puts "Install Size: #{disk_usage_readable(sizes[:installed])}" puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 - ask_input.call + Install.ask_input end formulae.each do |formula| diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 38eaf18f90..a65d96e9ba 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -221,96 +221,19 @@ module Homebrew Install.perform_preinstall_checks_once - ask_input = lambda { - ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" - accepted_inputs = %w[y yes] - declined_inputs = %w[n no] - loop do - result = $stdin.gets.chomp.strip.downcase - if accepted_inputs.include?(result) - break - elsif declined_inputs.include?(result) - exit 0 - else - puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." - end - end - } - - # Build a unique list of formulae to size by including: - # 1. The original formulae to install. - # 2. Their outdated dependents (subject to pruning criteria). - # 3. Optionally, any installed formula that depends on one of these and is outdated. - compute_sized_formulae = lambda { |f, check_dep: true, upgrade: true| - sized_formulae = f.flat_map do |formula| - # Always include the formula itself. - formula_list = [formula] - next unless upgrade - - deps = args.build_from_source? ? formula.deps.build : formula.deps.required - # If there are dependencies, try to gather outdated, bottled ones. - if deps.any? && check_dep - outdated_dependents = deps.map(&:to_formula).reject(&:pinned?).select do |dep| - dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) - end - - formula_list.concat(outdated_dependents) - end - - formula_list - end - - # Add any installed formula that depends on one of the sized formulae and is outdated. - if check_dep && !Homebrew::EnvConfig.no_installed_dependents_check? - sized_formulae.concat(Formula.installed.select do |installed_formula| - installed_formula.outdated? && - installed_formula.deps.required.any? { |dep| sized_formulae.include?(dep.to_formula) } - end) - end - - sized_formulae.uniq(&:to_s) - } - - # Compute the total sizes (download, installed, and net) for the given formulae. - compute_total_sizes = lambda { |sized_formulae, debug: false| - total_download_size = 0 - total_installed_size = 0 - total_net_size = 0 - - sized_formulae.each do |formula| - next unless (bottle = formula.bottle) - - # Fetch additional bottle metadata (if necessary). - bottle.fetch_tab(quiet: !debug) - - total_download_size += bottle.bottle_size.to_i if bottle.bottle_size - total_installed_size += bottle.installed_size.to_i if bottle.installed_size - - # Sum disk usage for all installed kegs of the formula. - next if formula.installed_kegs.none? - - kegs_dep_size = formula.installed_kegs.sum { |keg| keg.disk_usage.to_i } - total_net_size += bottle.installed_size.to_i - kegs_dep_size if bottle.installed_size - end - - { download: total_download_size, - installed: total_installed_size, - net: total_net_size } - } - # Main block: if asking the user is enabled, show dependency and size information. if args.ask? ohai "Looking for bottles..." - sized_formulae = compute_sized_formulae.call(formulae_to_install) - sizes = compute_total_sizes.call(sized_formulae, debug: args.debug?) + sized_formulae = Install.compute_sized_formulae(formulae, args: args) + sizes = Install.compute_total_sizes(sized_formulae, debug: args.debug?) puts "Formulae: #{sized_formulae.join(", ")}\n\n" puts "Download Size: #{disk_usage_readable(sizes[:download])}" puts "Install Size: #{disk_usage_readable(sizes[:installed])}" puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 - ask_input.call + Install.ask_input end Upgrade.upgrade_formulae( diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 80c3c54069..bb2cffdfc7 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -327,6 +327,82 @@ module Homebrew puts formula_names.join(" ") end + def ask_input + ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" + accepted_inputs = %w[y yes] + declined_inputs = %w[n no] + loop do + result = $stdin.gets.chomp.strip.downcase + if accepted_inputs.include?(result) + break + elsif declined_inputs.include?(result) + exit 0 + else + puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." + end + end + end + + # Build a unique list of formulae to size by including: + # 1. The original formulae to install. + # 2. Their outdated dependents (subject to pruning criteria). + # 3. Optionally, any installed formula that depends on one of these and is outdated. + def compute_sized_formulae(formulae, args:) + sized_formulae = formulae.flat_map do |formula| + # Always include the formula itself. + formula_list = [formula] + + deps = args.build_from_source? ? formula.deps.build : formula.deps.required + # If there are dependencies, try to gather outdated, bottled ones. + if deps.any? + outdated_dependents = deps.map(&:to_formula).reject(&:pinned?).select do |dep| + dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) + end + + formula_list.concat(outdated_dependents) + end + + formula_list + end + + # Add any installed formula that depends on one of the sized formulae and is outdated. + unless Homebrew::EnvConfig.no_installed_dependents_check? + sized_formulae.concat(Formula.installed.select do |installed_formula| + installed_formula.outdated? && + installed_formula.deps.required.any? { |dep| sized_formulae.include?(dep.to_formula) } + end) + end + + sized_formulae.uniq(&:to_s).compact + end + + # Compute the total sizes (download, installed, and net) for the given formulae. + def compute_total_sizes(sized_formulae, debug: false) + total_download_size = 0 + total_installed_size = 0 + total_net_size = 0 + + sized_formulae.each do |formula| + next unless (bottle = formula.bottle) + + # Fetch additional bottle metadata (if necessary). + bottle.fetch_tab(quiet: !debug) + + total_download_size += bottle.bottle_size.to_i if bottle.bottle_size + total_installed_size += bottle.installed_size.to_i if bottle.installed_size + + # Sum disk usage for all installed kegs of the formula. + next if formula.installed_kegs.none? + + kegs_dep_size = formula.installed_kegs.sum { |keg| keg.disk_usage.to_i } + total_net_size += bottle.installed_size.to_i - kegs_dep_size if bottle.installed_size + end + + { download: total_download_size, + installed: total_installed_size, + net: total_net_size } + end + private def perform_preinstall_checks(all_fatal: false) From 63f94708b07e34dc68af669af7b910c1f00a0799 Mon Sep 17 00:00:00 2001 From: thibhero Date: Tue, 18 Feb 2025 22:42:08 -0500 Subject: [PATCH 37/73] running `brew typecheck --update` --- .../Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi | 6 +++--- Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi index c6967205e7..164120bae8 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi @@ -20,6 +20,9 @@ class Homebrew::Cmd::InstallCmd::Args < Homebrew::CLI::Args sig { returns(T.nilable(String)) } def appdir; end + sig { returns(T::Boolean) } + def ask?; end + sig { returns(T.nilable(String)) } def audio_unit_plugindir; end @@ -166,7 +169,4 @@ class Homebrew::Cmd::InstallCmd::Args < Homebrew::CLI::Args sig { returns(T::Boolean) } def zap?; end - - sig { returns(T::Boolean) } - def ask?; end end diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi index f915406f5b..0405588ab3 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi @@ -318,8 +318,5 @@ module Homebrew::EnvConfig sig { returns(T::Boolean) } def verify_attestations?; end - - sig { returns(T::Boolean) } - def ask?; end end end From 7b3e469650eab97837a5d3b3954d33ffa281dfd6 Mon Sep 17 00:00:00 2001 From: thibhero Date: Tue, 25 Feb 2025 14:28:44 -0500 Subject: [PATCH 38/73] wrong array of formulae in compute sized --- Library/Homebrew/cmd/upgrade.rb | 2 +- Library/Homebrew/install.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index a65d96e9ba..4e1fac7a03 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -225,7 +225,7 @@ module Homebrew if args.ask? ohai "Looking for bottles..." - sized_formulae = Install.compute_sized_formulae(formulae, args: args) + sized_formulae = Install.compute_sized_formulae(formulae_to_install, args: args) sizes = Install.compute_total_sizes(sized_formulae, debug: args.debug?) puts "Formulae: #{sized_formulae.join(", ")}\n\n" diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index bb2cffdfc7..ab443e0e7c 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -368,7 +368,7 @@ module Homebrew # Add any installed formula that depends on one of the sized formulae and is outdated. unless Homebrew::EnvConfig.no_installed_dependents_check? sized_formulae.concat(Formula.installed.select do |installed_formula| - installed_formula.outdated? && + installed_formula.bottled? && installed_formula.outdated? && installed_formula.deps.required.any? { |dep| sized_formulae.include?(dep.to_formula) } end) end From c5d80271f44b1358479b3a8d16986dc93df3f40e Mon Sep 17 00:00:00 2001 From: thibhero Date: Sun, 2 Mar 2025 20:03:39 -0500 Subject: [PATCH 39/73] dont ask input if gets doesnt exist because of test --- Library/Homebrew/install.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index ab443e0e7c..558d722737 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -329,6 +329,7 @@ module Homebrew def ask_input ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" + return unless $stdin.gets != nil accepted_inputs = %w[y yes] declined_inputs = %w[n no] loop do From b7a298e1ecf8abf33771307630579b8351dc99f0 Mon Sep 17 00:00:00 2001 From: thibhero Date: Sun, 2 Mar 2025 20:04:02 -0500 Subject: [PATCH 40/73] first test to check option `--ask` --- Library/Homebrew/test/cmd/install_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Library/Homebrew/test/cmd/install_spec.rb b/Library/Homebrew/test/cmd/install_spec.rb index 4772947bf0..11eb405c78 100644 --- a/Library/Homebrew/test/cmd/install_spec.rb +++ b/Library/Homebrew/test/cmd/install_spec.rb @@ -84,4 +84,15 @@ RSpec.describe Homebrew::Cmd::InstallCmd do expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test.dSYM/Contents/Resources/DWARF/test").to be_a_file if OS.mac? expect(HOMEBREW_CACHE/"Sources/testball1").to be_a_directory end + + it "installs with asking for user prompts without installed dependent checks", :integration_test do + setup_test_formula "testball1" + + expect { + brew "install", "--ask", "testball1" + }.to output(/Formulae:\s*testball1/).to_stdout.and not_to_output.to_stderr + + expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file + end + end From 49007fbccde0a6b17874ba46f2f9f884b579e417 Mon Sep 17 00:00:00 2001 From: thibhero Date: Tue, 4 Mar 2025 20:01:07 -0500 Subject: [PATCH 41/73] modifying kernel.rb to accept negative value for disk_usage_readable --- Library/Homebrew/extend/kernel.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/extend/kernel.rb b/Library/Homebrew/extend/kernel.rb index 94bcf520c0..7d21851fd0 100644 --- a/Library/Homebrew/extend/kernel.rb +++ b/Library/Homebrew/extend/kernel.rb @@ -459,13 +459,13 @@ module Kernel end def disk_usage_readable(size_in_bytes) - if size_in_bytes >= 1_073_741_824 + if size_in_bytes.abs >= 1_073_741_824 size = size_in_bytes.to_f / 1_073_741_824 unit = "GB" - elsif size_in_bytes >= 1_048_576 + elsif size_in_bytes.abs >= 1_048_576 size = size_in_bytes.to_f / 1_048_576 unit = "MB" - elsif size_in_bytes >= 1_024 + elsif size_in_bytes.abs >= 1_024 size = size_in_bytes.to_f / 1_024 unit = "KB" else From 01bcf2e5bee2ed6bf86b989f119bd46a9418c236 Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 5 Mar 2025 13:05:14 -0500 Subject: [PATCH 42/73] brew vendor-gems: commit updates. --- .../Homebrew/vendor/bundle/bundler/setup.rb | 76 +------------------ 1 file changed, 1 insertion(+), 75 deletions(-) diff --git a/Library/Homebrew/vendor/bundle/bundler/setup.rb b/Library/Homebrew/vendor/bundle/bundler/setup.rb index 697e52ed5c..5de4adde5a 100644 --- a/Library/Homebrew/vendor/bundle/bundler/setup.rb +++ b/Library/Homebrew/vendor/bundle/bundler/setup.rb @@ -36,86 +36,12 @@ else end $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/public_suffix-6.0.1/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/addressable-2.8.7/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ast-2.4.2/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/base64-0.2.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/benchmark-0.4.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/arm64-darwin-20/#{Gem.extension_api_version}/bigdecimal-3.1.9") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/bigdecimal-3.1.9/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/bindata-2.5.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/coderay-1.1.3/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/concurrent-ruby-1.3.5/lib/concurrent-ruby") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/diff-lcs-1.5.1/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/docile-1.4.1/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/elftools-1.3.1/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/erubi-1.13.1/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/hana-1.3.7/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/arm64-darwin-20/#{Gem.extension_api_version}/json-2.9.1") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/json-2.9.1/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/regexp_parser-2.10.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/simpleidn-0.2.3/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/json_schemer-2.4.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rexml-3.4.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/kramdown-2.5.1/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/language_server-protocol-3.17.0.4/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/logger-1.6.5/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/method_source-1.1.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/minitest-5.25.4/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/netrc-0.11.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/parallel-1.26.3/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/parallel_tests-4.9.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/arm64-darwin-20/#{Gem.extension_api_version}/racc-1.8.1") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/racc-1.8.1/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/parser-3.3.7.1/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/patchelf-1.5.1/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/plist-3.7.2/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/arm64-darwin-20/#{Gem.extension_api_version}/prism-1.3.0") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/prism-1.3.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/pry-0.15.2/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/arm64-darwin-20/#{Gem.extension_api_version}/pycall-1.5.2") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/pycall-1.5.2/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rainbow-3.1.1/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/sorbet-runtime-0.5.11812/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rbi-0.2.4/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/arm64-darwin-20/#{Gem.extension_api_version}/rbs-3.8.1") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rbs-3.8.1/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/arm64-darwin-20/#{Gem.extension_api_version}/redcarpet-3.6.0") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/redcarpet-3.6.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rspec-support-3.13.2/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rspec-core-3.13.3/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rspec-expectations-3.13.3/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rspec-mocks-3.13.2/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rspec-3.13.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rspec-github-3.0.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rspec-retry-0.6.2/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rspec-sorbet-1.9.2/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rspec_junit_formatter-0.6.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-ast-1.38.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-progressbar-1.13.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/unicode-emoji-4.0.4/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/unicode-display_width-3.1.4/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-1.71.2/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-md-1.2.4/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-performance-1.23.1/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rspec-3.4.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-sorbet-0.8.7/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-lsp-0.23.9/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-macho-4.1.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/arm64-darwin-20/#{Gem.extension_api_version}/ruby-prof-1.7.1") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-prof-1.7.1/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/simplecov-html-0.13.1/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/simplecov_json_formatter-0.1.4/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/simplecov-0.22.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/simplecov-cobertura-2.1.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/sorbet-static-0.5.11812-universal-darwin/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/sorbet-0.5.11812/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/sorbet-static-and-runtime-0.5.11812/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/thor-1.3.2/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/spoom-1.5.3/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/arm64-darwin-20/#{Gem.extension_api_version}/stackprof-0.2.27") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/stackprof-0.2.27/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/yard-0.9.37/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/yard-sorbet-0.9.0/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/tapioca-0.16.9/lib") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/arm64-darwin-20/#{Gem.extension_api_version}/vernier-1.5.0") -$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/vernier-1.5.0/lib") +$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/sorbet-runtime-0.5.11812/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/warning-1.5.0/lib") From 817c40d2618e0e4aee902a7ef2e1e42520cab7a1 Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 5 Mar 2025 17:37:25 -0500 Subject: [PATCH 43/73] test for upgrade_spec.rb --- Library/Homebrew/test/cmd/upgrade_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index 4e7953ee74..0bd3453644 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -15,4 +15,17 @@ RSpec.describe Homebrew::Cmd::UpgradeCmd do expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist end + + it "upgrades with asking for user prompts", :integration_test do + setup_test_formula "testball" + (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath + + expect { + brew "upgrade", "--ask" + }.to output(/.*Formula\s*\(1\):\s*testball.*/ + ).to_stdout.and not_to_output.to_stderr + + expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory + expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist + end end From 0b53e54bfaea8f993dcfffd5d26db65d8231b73b Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 5 Mar 2025 17:38:18 -0500 Subject: [PATCH 44/73] Moving ask input to Install.ask --- Library/Homebrew/cmd/install.rb | 13 +--- Library/Homebrew/cmd/reinstall.rb | 12 +--- Library/Homebrew/cmd/upgrade.rb | 14 +--- Library/Homebrew/install.rb | 106 ++++++++++++++++++------------ 4 files changed, 69 insertions(+), 76 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index d14a50def1..b93b0f6397 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -307,19 +307,8 @@ module Homebrew Install.perform_preinstall_checks_once Install.check_cc_argv(args.cc) - # Main block: if asking the user is enabled, show dependency and size information. if args.ask? - ohai "Looking for bottles..." - - sized_formulae = Install.compute_sized_formulae(formulae, args: args) - sizes = Install.compute_total_sizes(sized_formulae, debug: args.debug?) - - puts "Formulae: #{sized_formulae.join(", ")}\n\n" - puts "Download Size: #{disk_usage_readable(sizes[:download])}" - puts "Install Size: #{disk_usage_readable(sizes[:installed])}" - puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 - - Install.ask_input + Install.ask(formulae, args: args) end Install.install_formulae( diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 9c67de6062..094936dd3f 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -133,17 +133,7 @@ module Homebrew # Main block: if asking the user is enabled, show dependency and size information. if args.ask? - ohai "Looking for bottles..." - - sized_formulae = Install.compute_sized_formulae(formulae, args: args) - sizes = Install.compute_total_sizes(sized_formulae, debug: args.debug?) - - puts "Formulae: #{sized_formulae.join(", ")}\n\n" - puts "Download Size: #{disk_usage_readable(sizes[:download])}" - puts "Install Size: #{disk_usage_readable(sizes[:installed])}" - puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 - - Install.ask_input + Install.ask(formulae, args: args) end formulae.each do |formula| diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 4e1fac7a03..c33c7c7bf4 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -216,24 +216,14 @@ module Homebrew "#{f.full_specified_name} #{f.pkg_version}" end end - puts formulae_upgrades.join("\n") + puts formulae_upgrades.join("\n") unless args.ask? end Install.perform_preinstall_checks_once # Main block: if asking the user is enabled, show dependency and size information. if args.ask? - ohai "Looking for bottles..." - - sized_formulae = Install.compute_sized_formulae(formulae_to_install, args: args) - sizes = Install.compute_total_sizes(sized_formulae, debug: args.debug?) - - puts "Formulae: #{sized_formulae.join(", ")}\n\n" - puts "Download Size: #{disk_usage_readable(sizes[:download])}" - puts "Install Size: #{disk_usage_readable(sizes[:installed])}" - puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 - - Install.ask_input + Install.ask(formulae_to_install, args: args) end Upgrade.upgrade_formulae( diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 558d722737..37a42ccd3b 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -327,17 +327,74 @@ module Homebrew puts formula_names.join(" ") end + + # Main block: if asking the user is enabled, show dependency and size information. + def ask(formulae, args:) + ohai "Looking for bottles..." + + sized_formulae = compute_sized_formulae(formulae, args: args) + sizes = compute_total_sizes(sized_formulae, debug: args.debug?) + + puts "#{::Utils.pluralize("Formul", sized_formulae.count, plural: "ae", + singular: "a")} (#{sized_formulae.count}): #{sized_formulae.join(", ")}\n\n" + puts "Download Size: #{disk_usage_readable(sizes[:download])}" + puts "Install Size: #{disk_usage_readable(sizes[:installed])}" + puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 + + ask_input + end + + private + + def perform_preinstall_checks(all_fatal: false) + check_prefix + check_cpu + attempt_directory_creation + Diagnostic.checks(:supported_configuration_checks, fatal: all_fatal) + Diagnostic.checks(:fatal_preinstall_checks) + end + alias generic_perform_preinstall_checks perform_preinstall_checks + + def attempt_directory_creation + Keg.must_exist_directories.each do |dir| + FileUtils.mkdir_p(dir) unless dir.exist? + rescue + nil + end + end + + def check_cpu + return unless Hardware::CPU.ppc? + + odie <<~EOS + Sorry, Homebrew does not support your computer's CPU architecture! + For PowerPC Mac (PPC32/PPC64BE) support, see: + #{Formatter.url("https://github.com/mistydemeo/tigerbrew")} + EOS + end + + def install_formula(formula_installer) + formula = formula_installer.formula + + upgrade = formula.linked? && formula.outdated? && !formula.head? && !Homebrew::EnvConfig.no_install_upgrade? + + Upgrade.install_formula(formula_installer, upgrade:) + end + + def ask_input ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" - return unless $stdin.gets != nil accepted_inputs = %w[y yes] declined_inputs = %w[n no] loop do - result = $stdin.gets.chomp.strip.downcase + result = $stdin.gets + return unless result + + result = result.chomp.strip.downcase if accepted_inputs.include?(result) break elsif declined_inputs.include?(result) - exit 0 + exit 1 else puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." end @@ -359,7 +416,11 @@ module Homebrew outdated_dependents = deps.map(&:to_formula).reject(&:pinned?).select do |dep| dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) end - + deps.map(&:to_formula).each do |f| + outdated_dependents.concat(f.recursive_dependencies.map(&:to_formula).reject(&:pinned?).select do |dep| + dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) + end) + end formula_list.concat(outdated_dependents) end @@ -403,43 +464,6 @@ module Homebrew installed: total_installed_size, net: total_net_size } end - - private - - def perform_preinstall_checks(all_fatal: false) - check_prefix - check_cpu - attempt_directory_creation - Diagnostic.checks(:supported_configuration_checks, fatal: all_fatal) - Diagnostic.checks(:fatal_preinstall_checks) - end - alias generic_perform_preinstall_checks perform_preinstall_checks - - def attempt_directory_creation - Keg.must_exist_directories.each do |dir| - FileUtils.mkdir_p(dir) unless dir.exist? - rescue - nil - end - end - - def check_cpu - return unless Hardware::CPU.ppc? - - odie <<~EOS - Sorry, Homebrew does not support your computer's CPU architecture! - For PowerPC Mac (PPC32/PPC64BE) support, see: - #{Formatter.url("https://github.com/mistydemeo/tigerbrew")} - EOS - end - - def install_formula(formula_installer) - formula = formula_installer.formula - - upgrade = formula.linked? && formula.outdated? && !formula.head? && !Homebrew::EnvConfig.no_install_upgrade? - - Upgrade.install_formula(formula_installer, upgrade:) - end end end end From 665fbc382d22be139d83355b55a835d611e35255 Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 5 Mar 2025 17:38:55 -0500 Subject: [PATCH 45/73] second test for install with dependencies --- Library/Homebrew/test/cmd/install_spec.rb | 47 ++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/test/cmd/install_spec.rb b/Library/Homebrew/test/cmd/install_spec.rb index 11eb405c78..e9744e71d2 100644 --- a/Library/Homebrew/test/cmd/install_spec.rb +++ b/Library/Homebrew/test/cmd/install_spec.rb @@ -4,6 +4,7 @@ require "cmd/install" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::InstallCmd do + include FileUtils it_behaves_like "parseable arguments" it "installs formulae", :integration_test do @@ -90,9 +91,53 @@ RSpec.describe Homebrew::Cmd::InstallCmd do expect { brew "install", "--ask", "testball1" - }.to output(/Formulae:\s*testball1/).to_stdout.and not_to_output.to_stderr + }.to output(/.*Formula\s*\(1\):\s*testball1.*/ + ).to_stdout.and not_to_output.to_stderr expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file end + it "installs with asking for user prompts with installed dependent checks", :integration_test do + setup_test_formula "testball1", <<~RUBY + url "https://brew.sh/testball1-1.0" + depends_on "testball3" + depends_on "build" => :build + depends_on "installed" + RUBY + setup_test_formula "installed" + setup_test_formula "testball3", <<~RUBY + url "https://brew.sh/testball3-1.0" + depends_on "testball4" + RUBY + setup_test_formula "testball4", <<~RUBY + url "https://brew.sh/testball4-1.0" + RUBY + setup_test_formula "hiop" + setup_test_formula "build" + + expect { + brew "info", "testball1" + }.to be_a_failure + + expect { + brew "info", "testball4" + }.to be_a_failure + + # Mock `Formula#any_version_installed?` by creating the tab in a plausible keg directory + keg_dir = HOMEBREW_CELLAR/"installed"/"1.0" + keg_dir.mkpath + touch keg_dir/AbstractTab::FILENAME + # + # expect { brew "deps", "baz", "--include-test", "--missing", "--skip-recommended" } + # .to be_a_success + # .and output("bar\nfoo\ntest\n").to_stdout + # .and not_to_output.to_stderr + + expect { + brew "install", "--ask", "testball1" + }.to output(/.*Formula\s*\(3\):\s*testball1\s*,?\s*testball3\s*,?\s*testball4.*/ + ).to_stdout.and not_to_output.to_stderr + + expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file + end end From 0b9374b7acfc0d30c40bac261e78fe37ed4e157e Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 5 Mar 2025 21:29:02 -0500 Subject: [PATCH 46/73] modifying integration_test.rb to work with other dependencies --- .../spec/shared_context/integration_test.rb | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index 8c5c1740d2..4240f77abd 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -135,13 +135,43 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin case name when /^testball/ # Use a different tarball for testball2 to avoid lock errors when writing concurrency tests - prefix = (name == "testball2") ? "testball2" : "testball" - tarball = if OS.linux? - TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1-linux.tbz" + if name == "testball3" || name == "testball4" + tarball = if OS.linux? + TEST_FIXTURE_DIR/"tarballs/#{name}-0.1-linux.tbz" + else + TEST_FIXTURE_DIR/"tarballs/#{name}-0.1.tbz" + end + content = <<~RUBY + desc "Some test" + homepage "https://brew.sh/#{name}" + url "file://#{tarball}" + sha256 "#{tarball.sha256}" + + option "with-foo", "Build with foo" + #{bottle_block} + def install + STDERR.puts prefix + (prefix/"foo"/"#{name}").write("#{name}") if build.with? "foo" + prefix.install Dir["*"] + (buildpath/"#{name}.c").write \ + "#include \\nint main(){printf(\\"#{name}\\");return 0;}" + bin.mkpath + system ENV.cc, "#{name}.c", "-o", bin/"#{name}" + end + + #{content} + + # something here + RUBY else - TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1.tbz" - end - content = <<~RUBY + prefix = (name == "testball2") ? "testball2" : "testball" + tarball = if OS.linux? + TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1-linux.tbz" + else + TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1.tbz" + end + + content = <<~RUBY desc "Some test" homepage "https://brew.sh/#{name}" url "file://#{tarball}" @@ -161,7 +191,8 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin #{content} # something here - RUBY + RUBY + end when "bar" content = <<~RUBY url "https://brew.sh/#{name}-1.0" From 640c5175fb5a0ae1452a7fb4a35be48ff7053bc3 Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 5 Mar 2025 21:31:21 -0500 Subject: [PATCH 47/73] creating install test with dependencies --- Library/Homebrew/test/cmd/install_spec.rb | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/Library/Homebrew/test/cmd/install_spec.rb b/Library/Homebrew/test/cmd/install_spec.rb index e9744e71d2..6afb9a3267 100644 --- a/Library/Homebrew/test/cmd/install_spec.rb +++ b/Library/Homebrew/test/cmd/install_spec.rb @@ -99,45 +99,32 @@ RSpec.describe Homebrew::Cmd::InstallCmd do it "installs with asking for user prompts with installed dependent checks", :integration_test do setup_test_formula "testball1", <<~RUBY - url "https://brew.sh/testball1-1.0" depends_on "testball3" - depends_on "build" => :build + # should work as its not building but test doesnt pass if dependant + # depends_on "build" => :build depends_on "installed" RUBY setup_test_formula "installed" setup_test_formula "testball3", <<~RUBY - url "https://brew.sh/testball3-1.0" depends_on "testball4" RUBY setup_test_formula "testball4", <<~RUBY - url "https://brew.sh/testball4-1.0" RUBY setup_test_formula "hiop" setup_test_formula "build" - expect { - brew "info", "testball1" - }.to be_a_failure - - expect { - brew "info", "testball4" - }.to be_a_failure - # Mock `Formula#any_version_installed?` by creating the tab in a plausible keg directory keg_dir = HOMEBREW_CELLAR/"installed"/"1.0" keg_dir.mkpath touch keg_dir/AbstractTab::FILENAME - # - # expect { brew "deps", "baz", "--include-test", "--missing", "--skip-recommended" } - # .to be_a_success - # .and output("bar\nfoo\ntest\n").to_stdout - # .and not_to_output.to_stderr expect { brew "install", "--ask", "testball1" - }.to output(/.*Formula\s*\(3\):\s*testball1\s*,?\s*testball3\s*,?\s*testball4.*/ + }.to output(/.*Formulae\s*\(3\):\s*testball1\s*,?\s*testball3\s*,?\s*testball4.*/ ).to_stdout.and not_to_output.to_stderr expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file + expect(HOMEBREW_CELLAR/"testball4/0.1/bin/testball4").to be_a_file + expect(HOMEBREW_CELLAR/"testball3/0.1/bin/testball3").to be_a_file end end From 0f919e839754112b41319d0c3bc9c86ed00ff114 Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 5 Mar 2025 21:32:48 -0500 Subject: [PATCH 48/73] new files for integration_spec.rb for testball3 and 4 --- .../fixtures/tarballs/testball3-0.1-linux.tbz | Bin 0 -> 441 bytes .../support/fixtures/tarballs/testball3-0.1.tbz | Bin 0 -> 437 bytes .../fixtures/tarballs/testball4-0.1-linux.tbz | Bin 0 -> 442 bytes .../support/fixtures/tarballs/testball4-0.1.tbz | Bin 0 -> 432 bytes 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Library/Homebrew/test/support/fixtures/tarballs/testball3-0.1-linux.tbz create mode 100644 Library/Homebrew/test/support/fixtures/tarballs/testball3-0.1.tbz create mode 100644 Library/Homebrew/test/support/fixtures/tarballs/testball4-0.1-linux.tbz create mode 100644 Library/Homebrew/test/support/fixtures/tarballs/testball4-0.1.tbz diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testball3-0.1-linux.tbz b/Library/Homebrew/test/support/fixtures/tarballs/testball3-0.1-linux.tbz new file mode 100644 index 0000000000000000000000000000000000000000..29650d8089198f02e48b283b5d2a82daa7d452b7 GIT binary patch literal 441 zcmV;q0Y?5pT4*^jL0KkKS!chXs{jFe|F!kt{c`_j|3C;x4oCoi01*HP zFaeA+U^J$hnHm7l&;S4c00x=>X`lfJO${|P0000D000000031Yo~nM0Od6X>Jxn7_ z4H^vwntBk>14f3PrV(XE0AL2S6i>{|kP(VVN`zuZi`VS~0t+BOH$md5A^{ANLUKf0 zNfv5PG?5!xdtKUCAA)2?33z21f?a99y}7BAdShlsODL$uZbYxgw(7#$aL%4Drth+g zrehJ@<&9Rnd-LtZC2H{+XPB6bCg~x)pM#2pL`acY*NbBQw!BnEw)rygw>z?YQba-k zQ41JSoXnJaB7}Or7)b%}2Q_xRUtpT7meO4~*ek_ET({JxOlTBCl4kHU7p|069 zfQs1zvPwaPdwKA%mksM)I8*`D4hdXtHdBDox&GjC5#(?;*gFcqm@$VMYis8@3+lf` zFE6L>m*oO*q&%9IBfz=&aws*2dLXZdAUFz;$_xf?hc;LQz?c{<1_ffqpb7H>gsGc} z%dOKH9`*3a3v@v~po+OnWlse)5fiprTqumC4Z0FVGb2hYU<5d!jIt0w5t+&=z&-d; zW{w3aIj}T2V{jT3P7swq!aq#DxnVpytx?c%IB3Eh0s0PgGT0U$hYexDs&%JKNCBO5 zdlMNsR@JZg6$I6Tgn>r&21GE4yG75#iX*5mN((&^q(&-Iy(x f4Euuu^TNW#+BaJVVcK^R0sj|rML1B9!cJzwYBII{ literal 0 HcmV?d00001 diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testball4-0.1-linux.tbz b/Library/Homebrew/test/support/fixtures/tarballs/testball4-0.1-linux.tbz new file mode 100644 index 0000000000000000000000000000000000000000..3fd48d948dd45575b60fd8b3918f39cd464f0c72 GIT binary patch literal 442 zcmV;r0Y&~oT4*^jL0KkKS#=Y8O8^0T|F!kt{c`_j|3C;x4oCoi01*HP zFae6p+d(NcH8PJ=LmsHYGBBEHp@K4KGBouAMo&n{1d)|cZOe>N3Cuv&X49W| z5XNB+VJD0#D>}OgS+#1IPyyr)1gC9wRe)rLKI$mhoeBju2jRE_;l2{ln+b{mvk}hO zSq}5H%`%Z#z%;GKOD;OBRf(jgyCV$UB@upBBpenj@=Q);$R#8%3Xv{MUr&t_5nPa> zRhA|?=4mp579)C?f}Sbhp@11aq^azr+p6%Dh!cHA4rL;6K&a71^yr+y%eeY8h;>`$ zyKbI2Z?`#S{(nh@LKRywpl6G1wXiqd9ejrpgj0hcWe)^>BL^Oe8N)u^7`1AWVP-iu zB1UD1xgNg82|ghyK%`P0@pLB)3S_aux`J?Fg;dH#1wzZj_<&GNPqR2BiOEZY?#<7t ki_@% literal 0 HcmV?d00001 diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testball4-0.1.tbz b/Library/Homebrew/test/support/fixtures/tarballs/testball4-0.1.tbz new file mode 100644 index 0000000000000000000000000000000000000000..5c9ca1d2fefa9992f11b6677f172a696e4956b4c GIT binary patch literal 432 zcmV;h0Z;xyT4*^jL0KkKSv`NL6#xNq|F!!3BM=NGg8-Th113!wG8jN%BvVG35SgVt6HOX4 z^$drpiL?k}7@Jd1Q`15$D$or8-hyBES+YVHBTHE1jt}6r4hTju0O-%5xIhFjG6!Uo z!wXZ$`m807)wNtN0Cod{RyNx#AT;iGdR&D&t_I5ofoK#4xNWAbeIj4?tTx?w@cwdg zz_=GfYclelWzClQgIZDxP&YxqRt7*|I5@cSKsDkC!I4l^iEAt>a8YgmV2WnO8Hkst0$wD{@nI~j~&R`JDw4?-TuDdH%p2Jzj z7NzM52n3o8yQxG z+x!c`MgVY_BoYkju*{^E0K}lK1&NeY%JSB`q5*i9uRAzNP!1XZ@8Qv>C{|c;X$(u< a3rkms-RvF*iT)-7{x0N-aG@Z2|57Ta_qYZC literal 0 HcmV?d00001 From 885b7c6f4fc95a407f3994692094e6c3b1e5c5f3 Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 5 Mar 2025 23:57:58 -0500 Subject: [PATCH 49/73] checking other tests functions --- Library/Homebrew/test/cmd/install_spec.rb | 82 +++++++++---------- .../spec/shared_context/integration_test.rb | 44 ++-------- 2 files changed, 48 insertions(+), 78 deletions(-) diff --git a/Library/Homebrew/test/cmd/install_spec.rb b/Library/Homebrew/test/cmd/install_spec.rb index 6afb9a3267..a0a296115e 100644 --- a/Library/Homebrew/test/cmd/install_spec.rb +++ b/Library/Homebrew/test/cmd/install_spec.rb @@ -86,45 +86,45 @@ RSpec.describe Homebrew::Cmd::InstallCmd do expect(HOMEBREW_CACHE/"Sources/testball1").to be_a_directory end - it "installs with asking for user prompts without installed dependent checks", :integration_test do - setup_test_formula "testball1" - - expect { - brew "install", "--ask", "testball1" - }.to output(/.*Formula\s*\(1\):\s*testball1.*/ - ).to_stdout.and not_to_output.to_stderr - - expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file - end - - it "installs with asking for user prompts with installed dependent checks", :integration_test do - setup_test_formula "testball1", <<~RUBY - depends_on "testball3" - # should work as its not building but test doesnt pass if dependant - # depends_on "build" => :build - depends_on "installed" - RUBY - setup_test_formula "installed" - setup_test_formula "testball3", <<~RUBY - depends_on "testball4" - RUBY - setup_test_formula "testball4", <<~RUBY - RUBY - setup_test_formula "hiop" - setup_test_formula "build" - - # Mock `Formula#any_version_installed?` by creating the tab in a plausible keg directory - keg_dir = HOMEBREW_CELLAR/"installed"/"1.0" - keg_dir.mkpath - touch keg_dir/AbstractTab::FILENAME - - expect { - brew "install", "--ask", "testball1" - }.to output(/.*Formulae\s*\(3\):\s*testball1\s*,?\s*testball3\s*,?\s*testball4.*/ - ).to_stdout.and not_to_output.to_stderr - - expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file - expect(HOMEBREW_CELLAR/"testball4/0.1/bin/testball4").to be_a_file - expect(HOMEBREW_CELLAR/"testball3/0.1/bin/testball3").to be_a_file - end + # it "installs with asking for user prompts without installed dependent checks", :integration_test do + # setup_test_formula "testball1" + # + # expect { + # brew "install", "--ask", "testball1" + # }.to output(/.*Formula\s*\(1\):\s*testball1.*/ + # ).to_stdout.and not_to_output.to_stderr + # + # expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file + # end + # + # it "installs with asking for user prompts with installed dependent checks", :integration_test do + # setup_test_formula "testball1", <<~RUBY + # depends_on "testball5" + # # should work as its not building but test doesnt pass if dependant + # # depends_on "build" => :build + # depends_on "installed" + # RUBY + # setup_test_formula "installed" + # setup_test_formula "testball5", <<~RUBY + # depends_on "testball4" + # RUBY + # setup_test_formula "testball4", <<~RUBY + # RUBY + # setup_test_formula "hiop" + # setup_test_formula "build" + # + # # Mock `Formula#any_version_installed?` by creating the tab in a plausible keg directory + # keg_dir = HOMEBREW_CELLAR/"installed"/"1.0" + # keg_dir.mkpath + # touch keg_dir/AbstractTab::FILENAME + # + # expect { + # brew "install", "--ask", "testball1" + # }.to output(/.*Formulae\s*\(3\):\s*testball1\s*,?\s*testball5\s*,?\s*testball4.*/ + # ).to_stdout.and not_to_output.to_stderr + # + # expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file + # expect(HOMEBREW_CELLAR/"testball4/0.1/bin/testball4").to be_a_file + # expect(HOMEBREW_CELLAR/"testball5/0.1/bin/testball5").to be_a_file + # end end diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index 4240f77abd..1d8f6a03c6 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -135,43 +135,14 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin case name when /^testball/ # Use a different tarball for testball2 to avoid lock errors when writing concurrency tests - if name == "testball3" || name == "testball4" - tarball = if OS.linux? - TEST_FIXTURE_DIR/"tarballs/#{name}-0.1-linux.tbz" - else - TEST_FIXTURE_DIR/"tarballs/#{name}-0.1.tbz" - end - content = <<~RUBY - desc "Some test" - homepage "https://brew.sh/#{name}" - url "file://#{tarball}" - sha256 "#{tarball.sha256}" + prefix = (name == "testball2") ? "testball2" : "testball" + tarball = if OS.linux? + TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1-linux.tbz" + else + TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1.tbz" + end - option "with-foo", "Build with foo" - #{bottle_block} - def install - STDERR.puts prefix - (prefix/"foo"/"#{name}").write("#{name}") if build.with? "foo" - prefix.install Dir["*"] - (buildpath/"#{name}.c").write \ - "#include \\nint main(){printf(\\"#{name}\\");return 0;}" - bin.mkpath - system ENV.cc, "#{name}.c", "-o", bin/"#{name}" - end - - #{content} - - # something here - RUBY - else - prefix = (name == "testball2") ? "testball2" : "testball" - tarball = if OS.linux? - TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1-linux.tbz" - else - TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1.tbz" - end - - content = <<~RUBY + content = <<~RUBY desc "Some test" homepage "https://brew.sh/#{name}" url "file://#{tarball}" @@ -192,7 +163,6 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin # something here RUBY - end when "bar" content = <<~RUBY url "https://brew.sh/#{name}-1.0" From 4e90aa527d90ddcb7ae5464154656a31764f9092 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 19:34:25 -0500 Subject: [PATCH 50/73] moving testball3 to testball5 --- ...tball3-0.1-linux.tbz => testball5-0.1-linux.tbz} | Bin .../{testball3-0.1.tbz => testball5-0.1.tbz} | Bin 2 files changed, 0 insertions(+), 0 deletions(-) rename Library/Homebrew/test/support/fixtures/tarballs/{testball3-0.1-linux.tbz => testball5-0.1-linux.tbz} (100%) rename Library/Homebrew/test/support/fixtures/tarballs/{testball3-0.1.tbz => testball5-0.1.tbz} (100%) diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testball3-0.1-linux.tbz b/Library/Homebrew/test/support/fixtures/tarballs/testball5-0.1-linux.tbz similarity index 100% rename from Library/Homebrew/test/support/fixtures/tarballs/testball3-0.1-linux.tbz rename to Library/Homebrew/test/support/fixtures/tarballs/testball5-0.1-linux.tbz diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testball3-0.1.tbz b/Library/Homebrew/test/support/fixtures/tarballs/testball5-0.1.tbz similarity index 100% rename from Library/Homebrew/test/support/fixtures/tarballs/testball3-0.1.tbz rename to Library/Homebrew/test/support/fixtures/tarballs/testball5-0.1.tbz From 16599b6e050764f5b96516552c15c52381eea24d Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 19:34:46 -0500 Subject: [PATCH 51/73] tests for install_spec.rb --- Library/Homebrew/test/cmd/install_spec.rb | 82 +++++++++---------- .../spec/shared_context/integration_test.rb | 46 +++++++++-- 2 files changed, 79 insertions(+), 49 deletions(-) diff --git a/Library/Homebrew/test/cmd/install_spec.rb b/Library/Homebrew/test/cmd/install_spec.rb index a0a296115e..5cea09d32b 100644 --- a/Library/Homebrew/test/cmd/install_spec.rb +++ b/Library/Homebrew/test/cmd/install_spec.rb @@ -86,45 +86,45 @@ RSpec.describe Homebrew::Cmd::InstallCmd do expect(HOMEBREW_CACHE/"Sources/testball1").to be_a_directory end - # it "installs with asking for user prompts without installed dependent checks", :integration_test do - # setup_test_formula "testball1" - # - # expect { - # brew "install", "--ask", "testball1" - # }.to output(/.*Formula\s*\(1\):\s*testball1.*/ - # ).to_stdout.and not_to_output.to_stderr - # - # expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file - # end - # - # it "installs with asking for user prompts with installed dependent checks", :integration_test do - # setup_test_formula "testball1", <<~RUBY - # depends_on "testball5" - # # should work as its not building but test doesnt pass if dependant - # # depends_on "build" => :build - # depends_on "installed" - # RUBY - # setup_test_formula "installed" - # setup_test_formula "testball5", <<~RUBY - # depends_on "testball4" - # RUBY - # setup_test_formula "testball4", <<~RUBY - # RUBY - # setup_test_formula "hiop" - # setup_test_formula "build" - # - # # Mock `Formula#any_version_installed?` by creating the tab in a plausible keg directory - # keg_dir = HOMEBREW_CELLAR/"installed"/"1.0" - # keg_dir.mkpath - # touch keg_dir/AbstractTab::FILENAME - # - # expect { - # brew "install", "--ask", "testball1" - # }.to output(/.*Formulae\s*\(3\):\s*testball1\s*,?\s*testball5\s*,?\s*testball4.*/ - # ).to_stdout.and not_to_output.to_stderr - # - # expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file - # expect(HOMEBREW_CELLAR/"testball4/0.1/bin/testball4").to be_a_file - # expect(HOMEBREW_CELLAR/"testball5/0.1/bin/testball5").to be_a_file - # end + it "installs with asking for user prompts without installed dependent checks", :integration_test do + setup_test_formula "testball1" + + expect { + brew "install", "--ask", "testball1" + }.to output(/.*Formula\s*\(1\):\s*testball1.*/ + ).to_stdout.and not_to_output.to_stderr + + expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file + end + + it "installs with asking for user prompts with installed dependent checks", :integration_test do + setup_test_formula "testball1", <<~RUBY + depends_on "testball5" + # should work as its not building but test doesnt pass if dependant + # depends_on "build" => :build + depends_on "installed" + RUBY + setup_test_formula "installed" + setup_test_formula "testball5", <<~RUBY + depends_on "testball4" + RUBY + setup_test_formula "testball4", <<~RUBY + RUBY + setup_test_formula "hiop" + setup_test_formula "build" + + # Mock `Formula#any_version_installed?` by creating the tab in a plausible keg directory + keg_dir = HOMEBREW_CELLAR/"installed"/"1.0" + keg_dir.mkpath + touch keg_dir/AbstractTab::FILENAME + + expect { + brew "install", "--ask", "testball1" + }.to output(/.*Formulae\s*\(3\):\s*testball1\s*,?\s*testball5\s*,?\s*testball4.*/ + ).to_stdout.and not_to_output.to_stderr + + expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file + expect(HOMEBREW_CELLAR/"testball4/0.1/bin/testball4").to be_a_file + expect(HOMEBREW_CELLAR/"testball5/0.1/bin/testball5").to be_a_file + end end diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index 1d8f6a03c6..1465b0124d 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -134,15 +134,44 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin bottle_block: nil, tab_attributes: nil) case name when /^testball/ - # Use a different tarball for testball2 to avoid lock errors when writing concurrency tests - prefix = (name == "testball2") ? "testball2" : "testball" - tarball = if OS.linux? - TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1-linux.tbz" - else - TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1.tbz" - end + if name == "testball5" || name == "testball4" + tarball = if OS.linux? + TEST_FIXTURE_DIR/"tarballs/#{name}-0.1-linux.tbz" + else + TEST_FIXTURE_DIR/"tarballs/#{name}-0.1.tbz" + end + content = <<~RUBY + desc "Some test" + homepage "https://brew.sh/#{name}" + url "file://#{tarball}" + sha256 "#{tarball.sha256}" - content = <<~RUBY + option "with-foo", "Build with foo" + #{bottle_block} + def install + STDERR.puts prefix + (prefix/"foo"/"#{name}").write("#{name}") if build.with? "foo" + prefix.install Dir["*"] + (buildpath/"#{name}.c").write \ + "#include \\nint main(){printf(\\"#{name}\\");return 0;}" + bin.mkpath + system ENV.cc, "#{name}.c", "-o", bin/"#{name}" + end + + #{content} + + # something here + RUBY + else + # Use a different tarball for testball2 to avoid lock errors when writing concurrency tests + prefix = (name == "testball2") ? "testball2" : "testball" + tarball = if OS.linux? + TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1-linux.tbz" + else + TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1.tbz" + end + + content = <<~RUBY desc "Some test" homepage "https://brew.sh/#{name}" url "file://#{tarball}" @@ -163,6 +192,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin # something here RUBY + end when "bar" content = <<~RUBY url "https://brew.sh/#{name}-1.0" From 4651b961faa70073430cd233a17482740cef2759 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 19:57:44 -0500 Subject: [PATCH 52/73] removing attributes from macOS --- .../fixtures/tarballs/testball4-0.1-linux.tbz | Bin 442 -> 190 bytes .../support/fixtures/tarballs/testball4-0.1.tbz | Bin 432 -> 186 bytes .../fixtures/tarballs/testball5-0.1-linux.tbz | Bin 441 -> 188 bytes .../support/fixtures/tarballs/testball5-0.1.tbz | Bin 437 -> 135 bytes 4 files changed, 0 insertions(+), 0 deletions(-) diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testball4-0.1-linux.tbz b/Library/Homebrew/test/support/fixtures/tarballs/testball4-0.1-linux.tbz index 3fd48d948dd45575b60fd8b3918f39cd464f0c72..72957a4c136c5006830afd1f370975d4a9ea384c 100644 GIT binary patch literal 190 zcmV;v073skT4*^jL0KkKSrGmy%m4s~eUQ+A1b{#T|9}Amc4wYI1V8`?FaWu%HBA`} zGzKFe88c97pQ4XZpa1{>1ym-cnKaPTA)si}L(9vpms@AzH3I%L4@sb<2%AYNVHwJ; z$|zo?qhyfe!6F*iB6P+{t%)R6F_qe_Q1&2(22(hsvcieLE@06hgoTZPE7ZE%G5I2&|x45mIzE(8Yui-$rRy2KtuSaFb%IxE&u=k literal 442 zcmV;r0Y&~oT4*^jL0KkKS#=Y8O8^0T|F!kt{c`_j|3C;x4oCoi01*HP zFae6p+d(NcH8PJ=LmsHYGBBEHp@K4KGBouAMo&n{1d)|cZOe>N3Cuv&X49W| z5XNB+VJD0#D>}OgS+#1IPyyr)1gC9wRe)rLKI$mhoeBju2jRE_;l2{ln+b{mvk}hO zSq}5H%`%Z#z%;GKOD;OBRf(jgyCV$UB@upBBpenj@=Q);$R#8%3Xv{MUr&t_5nPa> zRhA|?=4mp579)C?f}Sbhp@11aq^azr+p6%Dh!cHA4rL;6K&a71^yr+y%eeY8h;>`$ zyKbI2Z?`#S{(nh@LKRywpl6G1wXiqd9ejrpgj0hcWe)^>BL^Oe8N)u^7`1AWVP-iu zB1UD1xgNg82|ghyK%`P0@pLB)3S_aux`J?Fg;dH#1wzZj_<&GNPqR2BiOEZY?#<7t ki_@% diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testball4-0.1.tbz b/Library/Homebrew/test/support/fixtures/tarballs/testball4-0.1.tbz index 5c9ca1d2fefa9992f11b6677f172a696e4956b4c..c7c57aee5f2c729db393dba428cf85dd098feca9 100644 GIT binary patch literal 186 zcmV;r07d^oT4*^jL0KkKS^F(o&W?u00=MuyCH@~ z1k(a!F*IN$G=o!7pfo)}pa4}wnrZ4ZG}A!P^)hMdO*S^)!rBp#F27L8S_=?~ys0J; zu3auALZu5h+zf{XsgQ$}+{S}An*$5&#)Cq*h)G7GyB=gu!70#CcAi;hs6QtVL3`3mL*mH79FCS`?+~IidVr$rRy2L+rfls1&(OZ2$lO literal 432 zcmV;h0Z;xyT4*^jL0KkKSv`NL6#xNq|F!!3BM=NGg8-Th113!wG8jN%BvVG35SgVt6HOX4 z^$drpiL?k}7@Jd1Q`15$D$or8-hyBES+YVHBTHE1jt}6r4hTju0O-%5xIhFjG6!Uo z!wXZ$`m807)wNtN0Cod{RyNx#AT;iGdR&D&t_I5ofoK#4xNWAbeIj4?tTx?w@cwdg zz_=GfYclelWzClQgIZDxP&YxqRt7*|I5@cSKsDkC!I4l^iEAt>a8YgmV2WnO8Hkst0$wD{@nI~j~&R`JDw4?-TuDdH%p2Jzj z7NzM52n3o8yQxG z+x!c`MgVY_BoYkju*{^E0K}lK1&NeY%JSB`q5*i9uRAzNP!1XZ@8Qv>C{|c;X$(u< a3rkms-RvF*iT)-7{x0N-aG@Z2|57Ta_qYZC diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testball5-0.1-linux.tbz b/Library/Homebrew/test/support/fixtures/tarballs/testball5-0.1-linux.tbz index 29650d8089198f02e48b283b5d2a82daa7d452b7..4d35e20d2b6e98b55beb4be565c208e48bda91aa 100644 GIT binary patch literal 188 zcmV;t07L&mT4*^jL0KkKS$VhjegFW6eUQ+A1b{#T|9}Amc4wYI1V8`?FaWu%HBA`} zGzKFe88c97pQO~$kN^Mx1ys^%WHb#JfDHq?yPdadxA7Ule)@-%5>}KNiL%ELbK=#t1m_nu$UdF1u|t#F&B_45o2ODAkt{c`_j|3C;x4oCoi01*HP zFaeA+U^J$hnHm7l&;S4c00x=>X`lfJO${|P0000D000000031Yo~nM0Od6X>Jxn7_ z4H^vwntBk>14f3PrV(XE0AL2S6i>{|kP(VVN`zuZi`VS~0t+BOH$md5A^{ANLUKf0 zNfv5PG?5!xdtKUCAA)2?33z21f?a99y}7BAdShlsODL$uZbYxgw(7#$aL%4Drth+g zrehJ@<&9Rnd-LtZC2H{+XPB6bCg~x)pM#2pL`acY*NbBQw!BnEw)rygw>z?YQba-k zQ41JSoND~=yU4W+6GY$X% literal 437 zcmV;m0ZRTtT4*^jL0KkKS;9_c!TXnJaB7}Or7)b%}2Q_xRUtpT7meO4~*ek_ET({JxOlTBCl4kHU7p|069 zfQs1zvPwaPdwKA%mksM)I8*`D4hdXtHdBDox&GjC5#(?;*gFcqm@$VMYis8@3+lf` zFE6L>m*oO*q&%9IBfz=&aws*2dLXZdAUFz;$_xf?hc;LQz?c{<1_ffqpb7H>gsGc} z%dOKH9`*3a3v@v~po+OnWlse)5fiprTqumC4Z0FVGb2hYU<5d!jIt0w5t+&=z&-d; zW{w3aIj}T2V{jT3P7swq!aq#DxnVpytx?c%IB3Eh0s0PgGT0U$hYexDs&%JKNCBO5 zdlMNsR@JZg6$I6Tgn>r&21GE4yG75#iX*5mN((&^q(&-Iy(x f4Euuu^TNW#+BaJVVcK^R0sj|rML1B9!cJzwYBII{ From e5e647d950adeb9feeab1fce4e604bd38a860204 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 19:58:32 -0500 Subject: [PATCH 53/73] refactoring testball --- .../spec/shared_context/integration_test.rb | 86 +++++++------------ 1 file changed, 29 insertions(+), 57 deletions(-) diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index 1465b0124d..f585f3ee96 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -134,65 +134,37 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin bottle_block: nil, tab_attributes: nil) case name when /^testball/ - if name == "testball5" || name == "testball4" - tarball = if OS.linux? - TEST_FIXTURE_DIR/"tarballs/#{name}-0.1-linux.tbz" - else - TEST_FIXTURE_DIR/"tarballs/#{name}-0.1.tbz" - end - content = <<~RUBY - desc "Some test" - homepage "https://brew.sh/#{name}" - url "file://#{tarball}" - sha256 "#{tarball.sha256}" - - option "with-foo", "Build with foo" - #{bottle_block} - def install - STDERR.puts prefix - (prefix/"foo"/"#{name}").write("#{name}") if build.with? "foo" - prefix.install Dir["*"] - (buildpath/"#{name}.c").write \ - "#include \\nint main(){printf(\\"#{name}\\");return 0;}" - bin.mkpath - system ENV.cc, "#{name}.c", "-o", bin/"#{name}" - end - - #{content} - - # something here - RUBY + case name + when "testball4", "testball5", "testball2" + prefix = name else - # Use a different tarball for testball2 to avoid lock errors when writing concurrency tests - prefix = (name == "testball2") ? "testball2" : "testball" - tarball = if OS.linux? - TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1-linux.tbz" - else - TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1.tbz" - end - - content = <<~RUBY - desc "Some test" - homepage "https://brew.sh/#{name}" - url "file://#{tarball}" - sha256 "#{tarball.sha256}" - - option "with-foo", "Build with foo" - #{bottle_block} - def install - (prefix/"foo"/"test").write("test") if build.with? "foo" - prefix.install Dir["*"] - (buildpath/"test.c").write \ - "#include \\nint main(){printf(\\"test\\");return 0;}" - bin.mkpath - system ENV.cc, "test.c", "-o", bin/"test" - end - - #{content} - - # something here - RUBY + prefix = "testball" end + tarball_name = "#{prefix}-0.1#{'-linux' if OS.linux?}.tbz" + tarball = TEST_FIXTURE_DIR/"tarballs/#{tarball_name}" + + content = <<~RUBY + desc "Some test" + homepage "https://brew.sh/#{name}" + url "file://#{tarball}" + sha256 "#{tarball.sha256}" + + option "with-foo", "Build with foo" + #{bottle_block} + + def install + (prefix/"foo"/"#{prefix}").write("#{prefix}") if build.with? "foo" + prefix.install Dir["*"] + (buildpath/"#{prefix}.c").write \\ + "#include \\nint main(){printf(\\"#{prefix}\\");return 0;}" + bin.mkpath + system ENV.cc, "#{prefix}.c", "-o", bin/"#{prefix}" + end + + #{content} + + # something here + RUBY when "bar" content = <<~RUBY url "https://brew.sh/#{name}-1.0" From fa4e2bad6e269afe80a2f3bdad7a685cd5492c33 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 20:59:33 -0500 Subject: [PATCH 54/73] updating testball5-0.1.tbz to make it work --- .../support/fixtures/tarballs/testball5-0.1.tbz | Bin 135 -> 184 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testball5-0.1.tbz b/Library/Homebrew/test/support/fixtures/tarballs/testball5-0.1.tbz index 1dc6e1f40e38ccd998d850027e5b7de793543ecf..06def51fbd0e79fd5e65bb76a885fdaf0adf1251 100644 GIT binary patch literal 184 zcmV;p07w5qT4*^jL0KkKS%nYLQ2+pge~{3C1b{#T|9}7l5CC>(o&W?u00=Muxv)xz zG|&J5Xwy$nYMv1qX`lc!01Bz3(gvCgho~9=$&;nq@4N9D0lM1ND~=yU4W+6GY$X% From f4d93e19b872760e5fa8563af1f7b4ec269bcd72 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 20:59:56 -0500 Subject: [PATCH 55/73] refactoring testball case to make it more readable --- .../spec/shared_context/integration_test.rb | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index f585f3ee96..d205f2f005 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -135,36 +135,41 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin case name when /^testball/ case name - when "testball4", "testball5", "testball2" + when "testball4", "testball5" prefix = name + program_name = name + when "testball2" + prefix = name + program_name = "test" else prefix = "testball" + program_name = "test" end + tarball_name = "#{prefix}-0.1#{'-linux' if OS.linux?}.tbz" - tarball = TEST_FIXTURE_DIR/"tarballs/#{tarball_name}" + tarball = TEST_FIXTURE_DIR / "tarballs/#{tarball_name}" content = <<~RUBY - desc "Some test" - homepage "https://brew.sh/#{name}" - url "file://#{tarball}" - sha256 "#{tarball.sha256}" + desc "Some test" + homepage "https://brew.sh/#{name}" + url "file://#{tarball}" + sha256 "#{tarball.sha256}" - option "with-foo", "Build with foo" - #{bottle_block} + option "with-foo", "Build with foo" + #{bottle_block} + def install + (prefix/"foo"/"#{program_name}").write("#{program_name}") if build.with? "foo" + prefix.install Dir["*"] + (buildpath/"#{program_name}.c").write \ + "#include \\nint main(){printf(\\"#{program_name}\\");return 0;}" + bin.mkpath + system ENV.cc, "#{program_name}.c", "-o", bin/"#{program_name}" + end - def install - (prefix/"foo"/"#{prefix}").write("#{prefix}") if build.with? "foo" - prefix.install Dir["*"] - (buildpath/"#{prefix}.c").write \\ - "#include \\nint main(){printf(\\"#{prefix}\\");return 0;}" - bin.mkpath - system ENV.cc, "#{prefix}.c", "-o", bin/"#{prefix}" - end + #{content} - #{content} - - # something here - RUBY + # something here + RUBY when "bar" content = <<~RUBY url "https://brew.sh/#{name}-1.0" From 99fad7797cccc7b141389cda3f34c61d396044cb Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 21:27:13 -0500 Subject: [PATCH 56/73] modifying files with brew style --- Library/Homebrew/cmd/install.rb | 4 +-- Library/Homebrew/cmd/reinstall.rb | 4 +-- Library/Homebrew/cmd/upgrade.rb | 4 +-- Library/Homebrew/install.rb | 7 ++-- Library/Homebrew/test/cmd/install_spec.rb | 12 +++---- .../spec/shared_context/integration_test.rb | 34 +++++++++---------- 6 files changed, 28 insertions(+), 37 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index b93b0f6397..d6b29fea44 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -307,9 +307,7 @@ module Homebrew Install.perform_preinstall_checks_once Install.check_cc_argv(args.cc) - if args.ask? - Install.ask(formulae, args: args) - end + Install.ask(formulae, args: args) if args.ask? Install.install_formulae( installed_formulae, diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 094936dd3f..4556222e1c 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -132,9 +132,7 @@ module Homebrew Install.perform_preinstall_checks_once # Main block: if asking the user is enabled, show dependency and size information. - if args.ask? - Install.ask(formulae, args: args) - end + Install.ask(formulae, args: args) if args.ask? formulae.each do |formula| if formula.pinned? diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index c33c7c7bf4..b48ace323d 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -222,9 +222,7 @@ module Homebrew Install.perform_preinstall_checks_once # Main block: if asking the user is enabled, show dependency and size information. - if args.ask? - Install.ask(formulae_to_install, args: args) - end + Install.ask(formulae_to_install, args: args) if args.ask? Upgrade.upgrade_formulae( formulae_to_install, diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 37a42ccd3b..c7a0b41aff 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -327,7 +327,6 @@ module Homebrew puts formula_names.join(" ") end - # Main block: if asking the user is enabled, show dependency and size information. def ask(formulae, args:) ohai "Looking for bottles..." @@ -335,8 +334,9 @@ module Homebrew sized_formulae = compute_sized_formulae(formulae, args: args) sizes = compute_total_sizes(sized_formulae, debug: args.debug?) - puts "#{::Utils.pluralize("Formul", sized_formulae.count, plural: "ae", - singular: "a")} (#{sized_formulae.count}): #{sized_formulae.join(", ")}\n\n" + puts "#{::Utils.pluralize("Formul", sized_formulae.count, plural: "ae", + singular: "a")} (#{sized_formulae.count}): \ + #{sized_formulae.join(", ")}\n\n" puts "Download Size: #{disk_usage_readable(sizes[:download])}" puts "Install Size: #{disk_usage_readable(sizes[:installed])}" puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 @@ -381,7 +381,6 @@ module Homebrew Upgrade.install_formula(formula_installer, upgrade:) end - def ask_input ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" accepted_inputs = %w[y yes] diff --git a/Library/Homebrew/test/cmd/install_spec.rb b/Library/Homebrew/test/cmd/install_spec.rb index 5cea09d32b..460c465c76 100644 --- a/Library/Homebrew/test/cmd/install_spec.rb +++ b/Library/Homebrew/test/cmd/install_spec.rb @@ -89,10 +89,9 @@ RSpec.describe Homebrew::Cmd::InstallCmd do it "installs with asking for user prompts without installed dependent checks", :integration_test do setup_test_formula "testball1" - expect { + expect do brew "install", "--ask", "testball1" - }.to output(/.*Formula\s*\(1\):\s*testball1.*/ - ).to_stdout.and not_to_output.to_stderr + end.to output(/.*Formula\s*\(1\):\s*testball1.*/).to_stdout.and not_to_output.to_stderr expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file end @@ -108,8 +107,7 @@ RSpec.describe Homebrew::Cmd::InstallCmd do setup_test_formula "testball5", <<~RUBY depends_on "testball4" RUBY - setup_test_formula "testball4", <<~RUBY - RUBY + setup_test_formula "testball4", "" setup_test_formula "hiop" setup_test_formula "build" @@ -120,8 +118,8 @@ RSpec.describe Homebrew::Cmd::InstallCmd do expect { brew "install", "--ask", "testball1" - }.to output(/.*Formulae\s*\(3\):\s*testball1\s*,?\s*testball5\s*,?\s*testball4.*/ - ).to_stdout.and not_to_output.to_stderr + }.to output(/.*Formulae\s*\(3\):\s*testball1\s*,?\s*testball5\s*,?\s*testball4.*/).to_stdout + .and not_to_output.to_stderr expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file expect(HOMEBREW_CELLAR/"testball4/0.1/bin/testball4").to be_a_file diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index d205f2f005..f8f3b0f60a 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -146,29 +146,29 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin program_name = "test" end - tarball_name = "#{prefix}-0.1#{'-linux' if OS.linux?}.tbz" + tarball_name = "#{prefix}-0.1#{"-linux" if OS.linux?}.tbz" tarball = TEST_FIXTURE_DIR / "tarballs/#{tarball_name}" content = <<~RUBY - desc "Some test" - homepage "https://brew.sh/#{name}" - url "file://#{tarball}" - sha256 "#{tarball.sha256}" + desc "Some test" + homepage "https://brew.sh/#{name}" + url "file://#{tarball}" + sha256 "#{tarball.sha256}" - option "with-foo", "Build with foo" - #{bottle_block} - def install - (prefix/"foo"/"#{program_name}").write("#{program_name}") if build.with? "foo" - prefix.install Dir["*"] - (buildpath/"#{program_name}.c").write \ - "#include \\nint main(){printf(\\"#{program_name}\\");return 0;}" - bin.mkpath - system ENV.cc, "#{program_name}.c", "-o", bin/"#{program_name}" - end + option "with-foo", "Build with foo" + #{bottle_block} + def install + (prefix/"foo"/"#{program_name}").write("#{program_name}") if build.with? "foo" + prefix.install Dir["*"] + (buildpath/"#{program_name}.c").write \ + "#include \\nint main(){printf(\\"#{program_name}\\");return 0;}" + bin.mkpath + system ENV.cc, "#{program_name}.c", "-o", bin/"#{program_name}" + end - #{content} + #{content} - # something here + # something here RUBY when "bar" content = <<~RUBY From c5b8dd91f18c259f21270c5c3f646e7567d14a8c Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 21:27:25 -0500 Subject: [PATCH 57/73] test for upgrade --- Library/Homebrew/test/cmd/upgrade_spec.rb | 37 +++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index 0bd3453644..3075df4f6f 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -20,12 +20,43 @@ RSpec.describe Homebrew::Cmd::UpgradeCmd do setup_test_formula "testball" (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath - expect { + expect do brew "upgrade", "--ask" - }.to output(/.*Formula\s*\(1\):\s*testball.*/ - ).to_stdout.and not_to_output.to_stderr + end.to output(/.*Formula\s*\(1\):\s*testball.*/).to_stdout.and not_to_output.to_stderr expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist end + + it "upgrades with asking for user prompts with dependants checks", :integration_test do + setup_test_formula "testball1", <<~RUBY + depends_on "testball5" + # should work as its not building but test doesnt pass if dependant + # depends_on "build" => :build + depends_on "installed" + RUBY + setup_test_formula "installed" + setup_test_formula "testball5", <<~RUBY + depends_on "testball4" + RUBY + setup_test_formula "testball4" + setup_test_formula "hiop" + setup_test_formula "build" + + (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath + (HOMEBREW_CELLAR/"testball5/0.0.1/foo").mkpath + (HOMEBREW_CELLAR/"testball4/0.0.1/foo").mkpath + + expect { + brew "upgrade", "--ask" + }.to output(/.*Formulae\s*\(3\):\s*testball1\s*,?\s*testball5\s*,?\s*testball4.*/) + .to_stdout.and not_to_output.to_stderr + + expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory + expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist + expect(HOMEBREW_CELLAR/"testball5/0.1").to be_a_directory + expect(HOMEBREW_CELLAR/"testball5/0.0.1").not_to exist + expect(HOMEBREW_CELLAR/"testball4/0.1").to be_a_directory + expect(HOMEBREW_CELLAR/"testball4/0.0.1").not_to exist + end end From 0ebbd118e4450ff3126277127e98148e69ad098f Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 21:27:35 -0500 Subject: [PATCH 58/73] test for reinstall --- Library/Homebrew/test/cmd/reinstall_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Library/Homebrew/test/cmd/reinstall_spec.rb b/Library/Homebrew/test/cmd/reinstall_spec.rb index fd5690de26..9452e9b1cb 100644 --- a/Library/Homebrew/test/cmd/reinstall_spec.rb +++ b/Library/Homebrew/test/cmd/reinstall_spec.rb @@ -20,4 +20,18 @@ RSpec.describe Homebrew::Cmd::Reinstall do expect(foo_dir).to exist end + + it "reinstalls a Formula with ask input", :integration_test do + install_test_formula "testball" + foo_dir = HOMEBREW_CELLAR/"testball/0.1/bin" + expect(foo_dir).to exist + FileUtils.rm_r(foo_dir) + + expect { brew "reinstall", "--ask", "testball" } + .to output(/.*Formula\s*\(1\):\s*testball.*/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect(foo_dir).to exist + end end From 2edc42e905d89a13a333df924716c699e133c533 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 21:43:24 -0500 Subject: [PATCH 59/73] erratum testball and not testball1 --- Library/Homebrew/test/cmd/upgrade_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index 3075df4f6f..f74f573e66 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -29,7 +29,7 @@ RSpec.describe Homebrew::Cmd::UpgradeCmd do end it "upgrades with asking for user prompts with dependants checks", :integration_test do - setup_test_formula "testball1", <<~RUBY + setup_test_formula "testball", <<~RUBY depends_on "testball5" # should work as its not building but test doesnt pass if dependant # depends_on "build" => :build @@ -49,7 +49,7 @@ RSpec.describe Homebrew::Cmd::UpgradeCmd do expect { brew "upgrade", "--ask" - }.to output(/.*Formulae\s*\(3\):\s*testball1\s*,?\s*testball5\s*,?\s*testball4.*/) + }.to output(/.*Formulae\s*\(3\):\s*testball\s*,?\s*testball5\s*,?\s*testball4.*/) .to_stdout.and not_to_output.to_stderr expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory From 483aa26aaa5525d9045f91fd129a675f041a8f61 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 22:02:45 -0500 Subject: [PATCH 60/73] checking also the formula itself --- Library/Homebrew/install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index c7a0b41aff..6250ea91df 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -407,7 +407,7 @@ module Homebrew def compute_sized_formulae(formulae, args:) sized_formulae = formulae.flat_map do |formula| # Always include the formula itself. - formula_list = [formula] + formula_list = formula.installed_kegs.empty? || (formula.bottled? && formula.outdated?) ? [formula] : [] deps = args.build_from_source? ? formula.deps.build : formula.deps.required # If there are dependencies, try to gather outdated, bottled ones. From e6d02658b218a2ae18bcf0605304422fa5039659 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 22:03:15 -0500 Subject: [PATCH 61/73] adding installed up-to-date --- Library/Homebrew/test/cmd/upgrade_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index f74f573e66..04429e7e40 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -47,9 +47,13 @@ RSpec.describe Homebrew::Cmd::UpgradeCmd do (HOMEBREW_CELLAR/"testball5/0.0.1/foo").mkpath (HOMEBREW_CELLAR/"testball4/0.0.1/foo").mkpath + keg_dir = HOMEBREW_CELLAR/"installed"/"1.0" + keg_dir.mkpath + touch keg_dir/AbstractTab::FILENAME + expect { brew "upgrade", "--ask" - }.to output(/.*Formulae\s*\(3\):\s*testball\s*,?\s*testball5\s*,?\s*testball4.*/) + }.to output(/.*Formulae\s*\(3\):\s*testball4\s*,?\s*testball5\s*,?\s*testball5.*/) .to_stdout.and not_to_output.to_stderr expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory From 8506f1901a4d87a36d5bff9840d9c8e10aea8e20 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 22:20:52 -0500 Subject: [PATCH 62/73] check only if formula is bottled for first formula --- Library/Homebrew/install.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 6250ea91df..97734f232e 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -406,8 +406,8 @@ module Homebrew # 3. Optionally, any installed formula that depends on one of these and is outdated. def compute_sized_formulae(formulae, args:) sized_formulae = formulae.flat_map do |formula| - # Always include the formula itself. - formula_list = formula.installed_kegs.empty? || (formula.bottled? && formula.outdated?) ? [formula] : [] + # Always include the formula itself if bottled. + formula_list = formula.bottled? ? [formula] : [] deps = args.build_from_source? ? formula.deps.build : formula.deps.required # If there are dependencies, try to gather outdated, bottled ones. From 0b302dc3ad84d2f9f72325015d145ebd8a677893 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 22:32:51 -0500 Subject: [PATCH 63/73] always include --- Library/Homebrew/install.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 97734f232e..c7a0b41aff 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -406,8 +406,8 @@ module Homebrew # 3. Optionally, any installed formula that depends on one of these and is outdated. def compute_sized_formulae(formulae, args:) sized_formulae = formulae.flat_map do |formula| - # Always include the formula itself if bottled. - formula_list = formula.bottled? ? [formula] : [] + # Always include the formula itself. + formula_list = [formula] deps = args.build_from_source? ? formula.deps.build : formula.deps.required # If there are dependencies, try to gather outdated, bottled ones. From 459741f683cf7b059464631188a9c20abfd7e9d1 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 22:59:58 -0500 Subject: [PATCH 64/73] include FileUtils for touch --- Library/Homebrew/test/cmd/upgrade_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index 04429e7e40..0b3679ecfd 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -4,6 +4,7 @@ require "cmd/shared_examples/args_parse" require "cmd/upgrade" RSpec.describe Homebrew::Cmd::UpgradeCmd do + include FileUtils it_behaves_like "parseable arguments" it "upgrades a Formula and cleans up old versions", :integration_test do @@ -53,7 +54,7 @@ RSpec.describe Homebrew::Cmd::UpgradeCmd do expect { brew "upgrade", "--ask" - }.to output(/.*Formulae\s*\(3\):\s*testball4\s*,?\s*testball5\s*,?\s*testball5.*/) + }.to output(/.*Formulae\s*\(3\):\s*testball4\s*,?\s*testball5\s*,?\s*testball.*/) .to_stdout.and not_to_output.to_stderr expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory From 909f2afd16ccf6197e7798fbf208fabd89d6588f Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 23:02:17 -0500 Subject: [PATCH 65/73] brew style --fix --- Library/Homebrew/test/cmd/install_spec.rb | 6 +++--- Library/Homebrew/test/cmd/reinstall_spec.rb | 4 ++-- Library/Homebrew/test/cmd/upgrade_spec.rb | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/test/cmd/install_spec.rb b/Library/Homebrew/test/cmd/install_spec.rb index 460c465c76..ef74f06cc3 100644 --- a/Library/Homebrew/test/cmd/install_spec.rb +++ b/Library/Homebrew/test/cmd/install_spec.rb @@ -116,10 +116,10 @@ RSpec.describe Homebrew::Cmd::InstallCmd do keg_dir.mkpath touch keg_dir/AbstractTab::FILENAME - expect { + expect do brew "install", "--ask", "testball1" - }.to output(/.*Formulae\s*\(3\):\s*testball1\s*,?\s*testball5\s*,?\s*testball4.*/).to_stdout - .and not_to_output.to_stderr + end.to output(/.*Formulae\s*\(3\):\s*testball1\s*,?\s*testball5\s*,?\s*testball4.*/).to_stdout + .and not_to_output.to_stderr expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file expect(HOMEBREW_CELLAR/"testball4/0.1/bin/testball4").to be_a_file diff --git a/Library/Homebrew/test/cmd/reinstall_spec.rb b/Library/Homebrew/test/cmd/reinstall_spec.rb index 9452e9b1cb..77e55c994c 100644 --- a/Library/Homebrew/test/cmd/reinstall_spec.rb +++ b/Library/Homebrew/test/cmd/reinstall_spec.rb @@ -29,8 +29,8 @@ RSpec.describe Homebrew::Cmd::Reinstall do expect { brew "reinstall", "--ask", "testball" } .to output(/.*Formula\s*\(1\):\s*testball.*/).to_stdout - .and not_to_output.to_stderr - .and be_a_success + .and not_to_output.to_stderr + .and be_a_success expect(foo_dir).to exist end diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index 0b3679ecfd..0dbac25f7f 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -52,10 +52,10 @@ RSpec.describe Homebrew::Cmd::UpgradeCmd do keg_dir.mkpath touch keg_dir/AbstractTab::FILENAME - expect { + expect do brew "upgrade", "--ask" - }.to output(/.*Formulae\s*\(3\):\s*testball4\s*,?\s*testball5\s*,?\s*testball.*/) - .to_stdout.and not_to_output.to_stderr + end.to output(/.*Formulae\s*\(3\):\s*testball4\s*,?\s*testball5\s*,?\s*testball.*/) + .to_stdout.and not_to_output.to_stderr expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist From 9874f2bbb913e4e0e1e39b1baf575a6dd180afc6 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 23:30:22 -0500 Subject: [PATCH 66/73] check for formula in any order --- Library/Homebrew/test/cmd/upgrade_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index 0dbac25f7f..1fc6f65c4d 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -54,7 +54,8 @@ RSpec.describe Homebrew::Cmd::UpgradeCmd do expect do brew "upgrade", "--ask" - end.to output(/.*Formulae\s*\(3\):\s*testball4\s*,?\s*testball5\s*,?\s*testball.*/) + end.to output(/.*Formulae\s*\(3\):\s*(?:testball|testball5|testball4)\s*,?\s*(?:testball|testball5|testball4)\s*,? +\s*(?:testball|testball5|testball4).*/) .to_stdout.and not_to_output.to_stderr expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory From 640556df39e7898ea6eae5359057be67a6686778 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 23:52:12 -0500 Subject: [PATCH 67/73] correcting big space while displaying --- Library/Homebrew/install.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index c7a0b41aff..eea3f6fa9d 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -335,8 +335,8 @@ module Homebrew sizes = compute_total_sizes(sized_formulae, debug: args.debug?) puts "#{::Utils.pluralize("Formul", sized_formulae.count, plural: "ae", - singular: "a")} (#{sized_formulae.count}): \ - #{sized_formulae.join(", ")}\n\n" + singular: "a")} \ +(#{sized_formulae.count}): #{sized_formulae.join(", ")}\n\n" puts "Download Size: #{disk_usage_readable(sizes[:download])}" puts "Install Size: #{disk_usage_readable(sizes[:installed])}" puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 From 692174305d55640472286bfa1db00863333f2ee2 Mon Sep 17 00:00:00 2001 From: thibhero Date: Thu, 6 Mar 2025 23:54:19 -0500 Subject: [PATCH 68/73] correcting regex to match in any order and only once --- Library/Homebrew/test/cmd/upgrade_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index 1fc6f65c4d..436b513cb7 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -54,8 +54,7 @@ RSpec.describe Homebrew::Cmd::UpgradeCmd do expect do brew "upgrade", "--ask" - end.to output(/.*Formulae\s*\(3\):\s*(?:testball|testball5|testball4)\s*,?\s*(?:testball|testball5|testball4)\s*,? -\s*(?:testball|testball5|testball4).*/) + end.to output(/Formulae\s*\(3\):\s*(testball|testball5|testball4)\s*,\s*(?!(\1))(testball|testball5|testball4)\s*,\s*(?!(\1|\3))(testball|testball5|testball4)/) .to_stdout.and not_to_output.to_stderr expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory From 6d3ca98207973e55a4c678c9c8cfe4bd44161aa1 Mon Sep 17 00:00:00 2001 From: thibhero Date: Fri, 7 Mar 2025 00:38:02 -0500 Subject: [PATCH 69/73] correcting regex to match in any order and only once --- Library/Homebrew/test/cmd/upgrade_spec.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index 436b513cb7..27b9fc7891 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -52,9 +52,25 @@ RSpec.describe Homebrew::Cmd::UpgradeCmd do keg_dir.mkpath touch keg_dir/AbstractTab::FILENAME + regex = / + Formulae\s*\(3\):\s* + ( + testball|testball5|testball4 + ) + \s*,\s* + (?!\1) + ( + testball|testball5|testball4 + ) + \s*,\s* + (?!\1|\2) + ( + testball|testball5|testball4 + ) + /x expect do brew "upgrade", "--ask" - end.to output(/Formulae\s*\(3\):\s*(testball|testball5|testball4)\s*,\s*(?!(\1))(testball|testball5|testball4)\s*,\s*(?!(\1|\3))(testball|testball5|testball4)/) + end.to output(regex) .to_stdout.and not_to_output.to_stderr expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory From 548d87c9e840e227c7c34b449ec9fc60f806f651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibaut=20H=C3=A9rault?= <78233978+tyuwags@users.noreply.github.com> Date: Fri, 7 Mar 2025 11:26:52 -0500 Subject: [PATCH 70/73] Update Library/Homebrew/cmd/reinstall.rb comment Co-authored-by: Mike McQuaid --- Library/Homebrew/cmd/reinstall.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 4556222e1c..3c767f0619 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -131,7 +131,7 @@ module Homebrew unless formulae.empty? Install.perform_preinstall_checks_once - # Main block: if asking the user is enabled, show dependency and size information. + # If asking the user is enabled, show dependency and size information. Install.ask(formulae, args: args) if args.ask? formulae.each do |formula| From d7723fa6ed163594e64d577b1a876c358a195494 Mon Sep 17 00:00:00 2001 From: thibhero Date: Fri, 7 Mar 2025 11:32:34 -0500 Subject: [PATCH 71/73] resolving conversations from pull request --- Library/Homebrew/env_config.rb | 3 ++- Library/Homebrew/install.rb | 28 ++++++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index 5ccf2326ce..213a0fdae8 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -49,7 +49,8 @@ module Homebrew boolean: true, }, HOMEBREW_ASK: { - description: "If set, pass `--ask`to all formula install commands.", + description: "If set, pass `--ask`to all formulae `brew install`, `brew upgrade` and `brew reinstall` " \ + "commands.", boolean: true, }, HOMEBREW_AUTO_UPDATE_SECS: { diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index eea3f6fa9d..db240ee171 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -327,7 +327,7 @@ module Homebrew puts formula_names.join(" ") end - # Main block: if asking the user is enabled, show dependency and size information. + # If asking the user is enabled, show dependency and size information. def ask(formulae, args:) ohai "Looking for bottles..." @@ -410,18 +410,16 @@ module Homebrew formula_list = [formula] deps = args.build_from_source? ? formula.deps.build : formula.deps.required - # If there are dependencies, try to gather outdated, bottled ones. - if deps.any? - outdated_dependents = deps.map(&:to_formula).reject(&:pinned?).select do |dep| - dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) - end - deps.map(&:to_formula).each do |f| - outdated_dependents.concat(f.recursive_dependencies.map(&:to_formula).reject(&:pinned?).select do |dep| - dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) - end) - end - formula_list.concat(outdated_dependents) + + outdated_dependents = deps.map(&:to_formula).reject(&:pinned?).select do |dep| + dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) end + deps.map(&:to_formula).each do |f| + outdated_dependents.concat(f.recursive_dependencies.map(&:to_formula).reject(&:pinned?).select do |dep| + dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) + end) + end + formula_list.concat(outdated_dependents) formula_list end @@ -430,7 +428,7 @@ module Homebrew unless Homebrew::EnvConfig.no_installed_dependents_check? sized_formulae.concat(Formula.installed.select do |installed_formula| installed_formula.bottled? && installed_formula.outdated? && - installed_formula.deps.required.any? { |dep| sized_formulae.include?(dep.to_formula) } + installed_formula.deps.required.map(&:to_formula).intersect?(sized_formulae) end) end @@ -443,9 +441,7 @@ module Homebrew total_installed_size = 0 total_net_size = 0 - sized_formulae.each do |formula| - next unless (bottle = formula.bottle) - + sized_formulae.select(&:bottle).each do |formula| # Fetch additional bottle metadata (if necessary). bottle.fetch_tab(quiet: !debug) From c1d80ecf540901a94382b7a96b94755f60ceb090 Mon Sep 17 00:00:00 2001 From: thibhero Date: Fri, 7 Mar 2025 16:18:17 -0500 Subject: [PATCH 72/73] resolving conversations from pull request --- Library/Homebrew/install.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index db240ee171..40503f6783 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -334,8 +334,7 @@ module Homebrew sized_formulae = compute_sized_formulae(formulae, args: args) sizes = compute_total_sizes(sized_formulae, debug: args.debug?) - puts "#{::Utils.pluralize("Formul", sized_formulae.count, plural: "ae", - singular: "a")} \ + puts "#{::Utils.pluralize("Formul", sized_formulae.count, plural: "ae")} \ (#{sized_formulae.count}): #{sized_formulae.join(", ")}\n\n" puts "Download Size: #{disk_usage_readable(sizes[:download])}" puts "Install Size: #{disk_usage_readable(sizes[:installed])}" @@ -442,6 +441,7 @@ module Homebrew total_net_size = 0 sized_formulae.select(&:bottle).each do |formula| + bottle = formula.bottle # Fetch additional bottle metadata (if necessary). bottle.fetch_tab(quiet: !debug) From 96983ee4efe211497a34d3eb78f96c3eb16fda6a Mon Sep 17 00:00:00 2001 From: thibhero Date: Fri, 7 Mar 2025 16:21:05 -0500 Subject: [PATCH 73/73] Specifying the plural of formula --- Library/Homebrew/install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 40503f6783..1f14cbd211 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -334,7 +334,7 @@ module Homebrew sized_formulae = compute_sized_formulae(formulae, args: args) sizes = compute_total_sizes(sized_formulae, debug: args.debug?) - puts "#{::Utils.pluralize("Formul", sized_formulae.count, plural: "ae")} \ + puts "#{::Utils.pluralize("Formula", sized_formulae.count, plural: "e")} \ (#{sized_formulae.count}): #{sized_formulae.join(", ")}\n\n" puts "Download Size: #{disk_usage_readable(sizes[:download])}" puts "Install Size: #{disk_usage_readable(sizes[:installed])}"