From 2bdbca1280f0e602a05187f2c74d51f667ff8a36 Mon Sep 17 00:00:00 2001 From: Gautham G Date: Sat, 11 Apr 2020 18:50:24 +0530 Subject: [PATCH 1/3] Revert "Merge pull request #7289 from Homebrew/revert-7279-argv-cleanup-18" This reverts commit 64fd839c955b3c32855067d26fed7daf65183877, reversing changes made to 6f50801b37b7d829afc37da76d2ef0a1ac1c9f5f. --- Library/Homebrew/cli/args.rb | 8 ++++++++ Library/Homebrew/extend/ARGV.rb | 12 ------------ Library/Homebrew/fetch.rb | 2 +- Library/Homebrew/formula_installer.rb | 8 ++++---- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index dfb413f059..c8620a17e9 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -158,6 +158,14 @@ module Homebrew !(HEAD? || devel?) end + # Whether a given formula should be built from source during the current + # installation run. + def build_formula_from_source?(f) + return false if !build_from_source && !build_bottle + + formulae.any? { |args_f| args_f.full_name == f.full_name } + end + private def downcased_unique_named diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb index f2372e3c57..018c875058 100644 --- a/Library/Homebrew/extend/ARGV.rb +++ b/Library/Homebrew/extend/ARGV.rb @@ -40,18 +40,6 @@ module HomebrewArgvExtension arch&.to_sym end - def build_from_source? - switch?("s") || include?("--build-from-source") - end - - # Whether a given formula should be built from source during the current - # installation run. - def build_formula_from_source?(f) - return false if !build_from_source? && !build_bottle? - - formulae.any? { |argv_f| argv_f.full_name == f.full_name } - end - def force_bottle? include?("--force-bottle") end diff --git a/Library/Homebrew/fetch.rb b/Library/Homebrew/fetch.rb index 4d9a13719d..145a600974 100644 --- a/Library/Homebrew/fetch.rb +++ b/Library/Homebrew/fetch.rb @@ -7,7 +7,7 @@ module Homebrew def fetch_bottle?(f) return true if ARGV.force_bottle? && f.bottle return false unless f.bottle && f.pour_bottle? - return false if ARGV.build_formula_from_source?(f) + return false if Homebrew.args.build_formula_from_source?(f) return false unless f.bottle.compatible_cellar? true diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index b5ba33d8de..4853d1e7ce 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -49,7 +49,7 @@ class FormulaInstaller @show_header = false @ignore_deps = false @only_deps = false - @build_from_source = ARGV.build_from_source? + @build_from_source = Homebrew.args.build_from_source @build_bottle = false @force_bottle = ARGV.force_bottle? @include_test = ARGV.include?("--include-test") @@ -97,7 +97,7 @@ class FormulaInstaller return false if !formula.bottled? && !formula.local_bottle_path return true if force_bottle? - return false if build_from_source? || build_bottle? || interactive? + return false if Homebrew.args.build_from_source || build_bottle? || interactive? return false if ARGV.cc return false unless options.empty? return false if formula.bottle_disabled? @@ -128,7 +128,7 @@ class FormulaInstaller def install_bottle_for?(dep, build) return pour_bottle? if dep == formula - return false if ARGV.build_formula_from_source?(dep) + return false if Homebrew.args.build_formula_from_source?(dep) return false unless dep.bottle && dep.pour_bottle? return false unless build.used_options.empty? return false unless dep.bottle.compatible_cellar? @@ -591,7 +591,7 @@ class FormulaInstaller fi.options |= Tab.remap_deprecated_options(df.deprecated_options, dep.options) fi.options |= inherited_options fi.options &= df.options - fi.build_from_source = ARGV.build_formula_from_source?(df) + fi.build_from_source = Homebrew.args.build_formula_from_source?(df) fi.force_bottle = false fi.verbose = verbose? fi.quiet = quiet? From b05c72b98b4ce370ce9bd8763c931a8123511e2f Mon Sep 17 00:00:00 2001 From: Gautham G Date: Sun, 12 Apr 2020 19:12:16 +0530 Subject: [PATCH 2/3] cli/args: Make build_from_source public instance method --- Library/Homebrew/cli/args.rb | 13 +++++++------ Library/Homebrew/cli/parser.rb | 2 +- Library/Homebrew/global.rb | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index c8620a17e9..ff6afae43f 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -12,6 +12,7 @@ module Homebrew def initialize(argv:) super @argv = argv + @cmdline_args = argv @args_parsed = false @processed_options = [] end @@ -166,6 +167,12 @@ module Homebrew formulae.any? { |args_f| args_f.full_name == f.full_name } end + def build_from_source + return true if args_parsed && (build_from_source? || s?) + + cmdline_args.include?("--build-from-source") || cmdline_args.include?("-s") + end + private def downcased_unique_named @@ -208,12 +215,6 @@ module Homebrew cmdline_args.include?("--build-bottle") end - def build_from_source - return true if args_parsed && (build_from_source? || s?) - - cmdline_args.include?("--build-from-source") || cmdline_args.include?("-s") - end - def spec(default = :stable) if head :head diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index e3e59de199..07d05246f2 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -259,7 +259,7 @@ module Homebrew end def option_passed?(name) - @args.respond_to?(name) || @args.respond_to?("#{name}?") + @args[name.to_sym] || @args["#{name}?".to_sym] end def wrap_option_desc(desc) diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index bd8f745f03..78003daf96 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -86,7 +86,7 @@ module Homebrew end def args - @args ||= CLI::Args.new(argv: ARGV) + @args ||= CLI::Args.new(argv: ARGV_WITHOUT_MONKEY_PATCHING) end def messages From 8d868b739c0deee523fc0db90b9476af83f2a7e8 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 18 Apr 2020 21:14:35 +0100 Subject: [PATCH 3/3] cli/args: simplify initialisation. Move some logic from `CLI::Parser` to `CLI::Args` to simplify and make more consistent the initialisation process. --- Library/Homebrew/cli/args.rb | 10 +++++----- Library/Homebrew/cli/parser.rb | 7 +++---- Library/Homebrew/global.rb | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index ff6afae43f..1b00c1445b 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -9,10 +9,12 @@ module Homebrew # undefine tap to allow --tap argument undef tap - def initialize(argv:) + def initialize super - @argv = argv - @cmdline_args = argv + + self[:remaining] = [] + self[:cmdline_args] = ARGV_WITHOUT_MONKEY_PATCHING.dup + @args_parsed = false @processed_options = [] end @@ -60,8 +62,6 @@ module Homebrew end def named - return [] if remaining.nil? - remaining end diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 07d05246f2..b5d6941d30 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -37,11 +37,10 @@ module Homebrew } end - def initialize(args = ARGV, &block) + def initialize(&block) @parser = OptionParser.new - @args = Homebrew::CLI::Args.new(argv: ARGV_WITHOUT_MONKEY_PATCHING) - @args[:remaining] = [] - @args[:cmdline_args] = args.dup + @args = Homebrew::CLI::Args.new + @constraints = [] @conflicts = [] @switch_sources = {} diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 78003daf96..1fc0cb0a54 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -86,7 +86,7 @@ module Homebrew end def args - @args ||= CLI::Args.new(argv: ARGV_WITHOUT_MONKEY_PATCHING) + @args ||= CLI::Args.new end def messages