Merge pull request #8084 from reitermarkus/cli-parser

Refactor usage of global `Homebrew.args`.
This commit is contained in:
Markus Reiter 2020-07-30 11:44:12 +02:00 committed by GitHub
commit 8d97029b03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 299 additions and 277 deletions

View File

@ -35,13 +35,6 @@ rescue MissingEnvironmentVariables => e
exec ENV["HOMEBREW_BREW_FILE"], *ARGV
end
def output_unsupported_error
$stderr.puts <<~EOS
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC.
EOS
end
begin
trap("INT", std_trap) # restore default CTRL-C handler
@ -150,7 +143,12 @@ rescue BuildError => e
Utils::Analytics.report_build_error(e)
e.dump
output_unsupported_error if e.formula.head? || e.formula.deprecated? || e.formula.disabled?
if e.formula.head? || e.formula.deprecated? || e.formula.disabled?
$stderr.puts <<~EOS
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC.
EOS
end
exit 1
rescue RuntimeError, SystemCallError => e
@ -159,8 +157,6 @@ rescue RuntimeError, SystemCallError => e
onoe e
$stderr.puts e.backtrace if Homebrew.args.debug?
output_unsupported_error if Homebrew.args.HEAD?
exit 1
rescue MethodDeprecatedError => e
onoe e

View File

@ -97,7 +97,11 @@ class Build
bottle_arch: args.bottle_arch,
)
post_superenv_hacks
reqs.each { |req| req.modify_build_environment(args: args) }
reqs.each do |req|
req.modify_build_environment(
env: args.env, cc: args.cc, build_bottle: args.build_bottle?, bottle_arch: args.bottle_arch,
)
end
deps.each(&:modify_build_environment)
else
ENV.setup_build_environment(
@ -106,7 +110,11 @@ class Build
build_bottle: args.build_bottle?,
bottle_arch: args.bottle_arch,
)
reqs.each { |req| req.modify_build_environment(args: args) }
reqs.each do |req|
req.modify_build_environment(
env: args.env, cc: args.cc, build_bottle: args.build_bottle?, bottle_arch: args.bottle_arch,
)
end
deps.each(&:modify_build_environment)
keg_only_deps.each do |dep|

View File

@ -70,24 +70,11 @@ module Homebrew
named.blank?
end
# If the user passes any flags that trigger building over installing from
# a bottle, they are collected here and returned as an Array for checking.
def collect_build_args
build_flags = []
build_flags << "--HEAD" if HEAD?
build_flags << "--universal" if build_universal?
build_flags << "--build-bottle" if build_bottle?
build_flags << "--build-from-source" if build_from_source?
build_flags
end
def formulae
require "formula"
@formulae ||= (downcased_unique_named - casks).map do |name|
Formulary.factory(name, spec)
Formulary.factory(name, spec, force_bottle: force_bottle?, flags: flags_only)
end.uniq(&:name).freeze
end
@ -113,7 +100,7 @@ module Homebrew
require "formula"
@resolved_formulae ||= (downcased_unique_named - casks).map do |name|
Formulary.resolve(name, spec: spec(nil))
Formulary.resolve(name, spec: spec(nil), force_bottle: force_bottle?, flags: flags_only)
end.uniq(&:name).freeze
end
@ -123,7 +110,8 @@ module Homebrew
casks = []
downcased_unique_named.each do |name|
resolved_formulae << Formulary.resolve(name, spec: spec(nil))
resolved_formulae << Formulary.resolve(name, spec: spec(nil),
force_bottle: force_bottle?, flags: flags_only)
rescue FormulaUnavailableError
begin
casks << Cask::CaskLoader.load(name)
@ -181,18 +169,20 @@ 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 }
def build_from_source_formulae
if build_from_source? || build_bottle?
formulae.map(&:full_name)
else
[]
end
end
def include_formula_test_deps?(f)
return false unless include_test?
formulae.any? { |args_f| args_f.full_name == f.full_name }
def include_test_formulae
if include_test?
formulae.map(&:full_name)
else
[]
end
end
def value(name)

View File

@ -360,7 +360,7 @@ module Homebrew
named_args.map do |arg|
next if arg.match?(HOMEBREW_CASK_TAP_CASK_REGEX)
Formulary.factory(arg, spec)
Formulary.factory(arg, spec, flags: @args.flags_only)
end.compact.uniq(&:name)
end
end

View File

@ -33,13 +33,13 @@ module Homebrew
end
def __cache
__cache_args.parse
args = __cache_args.parse
if args.no_named?
puts HOMEBREW_CACHE
elsif args.formula?
args.named.each do |name|
print_formula_cache name
print_formula_cache name, args: args
end
elsif args.cask?
args.named.each do |name|
@ -47,7 +47,7 @@ module Homebrew
end
else
args.named.each do |name|
print_formula_cache name
print_formula_cache name, args: args
rescue FormulaUnavailableError
begin
print_cask_cache name
@ -58,9 +58,9 @@ module Homebrew
end
end
def print_formula_cache(name)
formula = Formulary.factory name
if fetch_bottle?(formula)
def print_formula_cache(name, args:)
formula = Formulary.factory(name, force_bottle: args.force_bottle?, flags: args.flags_only)
if fetch_bottle?(formula, args: args)
puts formula.bottle.cached_download
else
puts formula.cached_download

View File

@ -46,7 +46,7 @@ module Homebrew
end
def fetch
fetch_args.parse
args = fetch_args.parse
if args.deps?
bucket = []
@ -64,7 +64,7 @@ module Homebrew
f.print_tap_action verb: "Fetching"
fetched_bottle = false
if fetch_bottle?(f)
if fetch_bottle?(f, args: args)
begin
fetch_formula(f.bottle)
rescue Interrupt

View File

@ -8,6 +8,8 @@ require "socket"
require "cli/parser"
module Homebrew
extend Install
module_function
def gist_logs_args

View File

@ -256,7 +256,7 @@ module Homebrew
def decorate_requirements(requirements)
req_status = requirements.map do |req|
req_s = req.display_s
req.satisfied?(args: args) ? pretty_installed(req_s) : pretty_uninstalled(req_s)
req.satisfied? ? pretty_installed(req_s) : pretty_uninstalled(req_s)
end
req_status.join(", ")
end

View File

@ -10,10 +10,10 @@ require "cli/parser"
require "upgrade"
module Homebrew
module_function
extend Search
module_function
def install_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
@ -115,13 +115,13 @@ module Homebrew
formulae = []
unless Homebrew.args.casks.empty?
unless args.casks.empty?
cask_args = []
cask_args << "--force" if args.force?
cask_args << "--debug" if args.debug?
cask_args << "--verbose" if args.verbose?
Homebrew.args.casks.each do |c|
args.casks.each do |c|
ohai "brew cask install #{c} #{cask_args.join " "}"
system("#{HOMEBREW_PREFIX}/bin/brew", "cask", "install", c, *cask_args)
end
@ -129,7 +129,7 @@ module Homebrew
# if the user's flags will prevent bottle only-installations when no
# developer tools are available, we need to stop them early on
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
FormulaInstaller.prevent_build_flags(args)
args.formulae.each do |f|
# head-only without --HEAD is an error
@ -255,17 +255,17 @@ module Homebrew
return if formulae.empty?
Install.perform_preinstall_checks
Install.perform_preinstall_checks(cc: args.cc)
formulae.each do |f|
Migrator.migrate_if_needed(f)
install_formula(f)
Migrator.migrate_if_needed(f, force: args.force?)
install_formula(f, args: args)
Cleanup.install_formula_clean!(f)
end
check_installed_dependents(args: args)
Homebrew.messages.display_messages
Homebrew.messages.display_messages(display_times: args.display_times?)
rescue FormulaUnreadableError, FormulaClassUnavailableError,
TapFormulaUnreadableError, TapFormulaClassUnavailableError => e
# Need to rescue before `FormulaUnavailableError` (superclass of this)
@ -319,12 +319,15 @@ module Homebrew
end
end
def install_formula(f)
def install_formula(f, args:)
f.print_tap_action
build_options = f.build
fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, include_test: args.include_test?,
build_from_source: args.build_from_source?)
fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?,
include_test: args.include_test?,
include_test_formulae: args.include_test_formulae,
build_from_source: args.build_from_source?,
build_from_source_formulae: args.build_from_source_formulae)
fi.options = build_options.used_options
fi.env = args.env
fi.force = args.force?

View File

@ -24,7 +24,7 @@ module Homebrew
end
def migrate
migrate_args.parse
args = migrate_args.parse
args.resolved_formulae.each do |f|
if f.oldname
@ -34,7 +34,7 @@ module Homebrew
raise "#{rack} is a symlink" if rack.symlink?
end
migrator = Migrator.new(f)
migrator = Migrator.new(f, force: args.force?)
migrator.migrate
end
end

View File

@ -3,6 +3,7 @@
require "formula_installer"
require "development_tools"
require "messages"
require "install"
require "reinstall"
require "cli/parser"
require "cleanup"
@ -56,7 +57,7 @@ module Homebrew
def reinstall
args = reinstall_args.parse
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
FormulaInstaller.prevent_build_flags(args)
Install.perform_preinstall_checks
@ -66,14 +67,14 @@ module Homebrew
onoe "#{f.full_name} is pinned. You must unpin it to reinstall."
next
end
Migrator.migrate_if_needed(f)
Migrator.migrate_if_needed(f, force: args.force?)
reinstall_formula(f, args: args)
Cleanup.install_formula_clean!(f)
end
check_installed_dependents(args: args)
Homebrew.messages.display_messages
Homebrew.messages.display_messages(display_times: args.display_times?)
return if casks.blank?

View File

@ -30,7 +30,7 @@ module Homebrew
end
def uninstall
uninstall_args.parse
args = uninstall_args.parse
if args.force?
casks = []
@ -54,7 +54,9 @@ module Homebrew
kegs_by_rack = all_kegs.group_by(&:rack)
end
handle_unsatisfied_dependents(kegs_by_rack)
handle_unsatisfied_dependents(kegs_by_rack,
ignore_dependencies: args.ignore_dependencies?,
named_args: args.named)
return if Homebrew.failed?
kegs_by_rack.each do |rack, kegs|
@ -142,40 +144,41 @@ module Homebrew
end
end
def handle_unsatisfied_dependents(kegs_by_rack)
return if args.ignore_dependencies?
def handle_unsatisfied_dependents(kegs_by_rack, ignore_dependencies: false, named_args: [])
return if ignore_dependencies
all_kegs = kegs_by_rack.values.flatten(1)
check_for_dependents all_kegs
check_for_dependents(all_kegs, named_args: named_args)
rescue MethodDeprecatedError
# Silently ignore deprecations when uninstalling.
nil
end
def check_for_dependents(kegs)
def check_for_dependents(kegs, named_args: [])
return false unless result = Keg.find_some_installed_dependents(kegs)
if Homebrew::EnvConfig.developer?
DeveloperDependentsMessage.new(*result).output
DeveloperDependentsMessage.new(*result, named_args: named_args).output
else
NondeveloperDependentsMessage.new(*result).output
NondeveloperDependentsMessage.new(*result, named_args: named_args).output
end
true
end
class DependentsMessage
attr_reader :reqs, :deps
attr_reader :reqs, :deps, :named_args
def initialize(requireds, dependents)
def initialize(requireds, dependents, named_args: [])
@reqs = requireds
@deps = dependents
@named_args = named_args
end
protected
def sample_command
"brew uninstall --ignore-dependencies #{Array(Homebrew.args.named).join(" ")}"
"brew uninstall --ignore-dependencies #{named_args.join(" ")}"
end
def are_required_by_deps

View File

@ -38,7 +38,7 @@ module Homebrew
end
def update_report
update_report_args.parse
args = update_report_args.parse
if !Utils::Analytics.messages_displayed? &&
!Utils::Analytics.disabled? &&
@ -104,7 +104,7 @@ module Homebrew
end
if reporter.updated?
updated_taps << tap.name
hub.add(reporter)
hub.add(reporter, preinstall: args.preinstall?)
end
end
@ -122,7 +122,7 @@ module Homebrew
else
hub.dump(updated_formula_report: !args.preinstall?)
hub.reporters.each(&:migrate_tap_migration)
hub.reporters.each(&:migrate_formula_rename)
hub.reporters.each { |r| r.migrate_formula_rename(force: args.force?) }
CacheStoreDatabase.use(:descriptions) do |db|
DescriptionCacheStore.new(db)
.update_from_report!(hub)
@ -186,7 +186,7 @@ class Reporter
raise ReporterRevisionUnsetError, current_revision_var if @current_revision.empty?
end
def report
def report(preinstall: false)
return @report if @report
@report = Hash.new { |h, k| h[k] = [] }
@ -223,7 +223,7 @@ class Reporter
name = tap.formula_file_to_name(src)
# Skip reporting updated formulae to speed up automatic updates.
if Homebrew.args.preinstall?
if preinstall
@report[:M] << name
next
end
@ -373,7 +373,7 @@ class Reporter
end
end
def migrate_formula_rename
def migrate_formula_rename(force:)
Formula.installed.each do |formula|
next unless Migrator.needs_migration?(formula)
@ -397,7 +397,7 @@ class Reporter
next
end
Migrator.migrate_if_needed(f)
Migrator.migrate_if_needed(f, force: force)
end
end
@ -425,9 +425,9 @@ class ReporterHub
@hash.fetch(key, [])
end
def add(reporter)
def add(reporter, preinstall: false)
@reporters << reporter
report = reporter.report.delete_if { |_k, v| v.empty? }
report = reporter.report(preinstall: preinstall).delete_if { |_k, v| v.empty? }
@hash.update(report) { |_key, oldval, newval| oldval.concat(newval) }
end

View File

@ -70,12 +70,12 @@ module Homebrew
named_formulae_specified = !formulae.empty? && casks.empty?
named_casks_specified = !casks.empty? && formulae.empty?
upgrade_outdated_formulae(formulae) unless named_casks_specified
upgrade_outdated_formulae(formulae, args: args) unless named_casks_specified
upgrade_outdated_casks(casks) unless named_formulae_specified
end
def upgrade_outdated_formulae(formulae)
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
def upgrade_outdated_formulae(formulae, args:)
FormulaInstaller.prevent_build_flags(args)
Install.perform_preinstall_checks
@ -129,7 +129,7 @@ module Homebrew
check_installed_dependents(args: args)
Homebrew.messages.display_messages
Homebrew.messages.display_messages(display_times: args.display_times?)
end
def upgrade_outdated_casks(casks)

View File

@ -127,6 +127,7 @@ module Homebrew
}
options[:style_offenses] = style_results.file_offenses(f.path) if style_results
options[:display_cop_names] = args.display_cop_names?
options[:build_stable] = args.build_stable?
fa = FormulaAuditor.new(f, options)
fa.audit
@ -207,6 +208,7 @@ module Homebrew
@new_formula = options[:new_formula] && !@versioned_formula
@strict = options[:strict]
@online = options[:online]
@build_stable = options[:build_stable]
@git = options[:git]
@display_cop_names = options[:display_cop_names]
@only = options[:only]
@ -248,7 +250,7 @@ module Homebrew
unversioned_name = unversioned_formula.basename(".rb")
problem "#{formula} is versioned but no #{unversioned_name} formula exists"
end
elsif Homebrew.args.build_stable? && formula.stable? &&
elsif @build_stable && formula.stable? &&
!(versioned_formulae = formula.versioned_formulae).empty?
versioned_aliases = formula.aliases.grep(/.@\d/)
_, last_alias_version = versioned_formulae.map(&:name).last.split("@")

View File

@ -31,12 +31,12 @@ module Homebrew
end
def man
man_args.parse
args = man_args.parse
odie "`brew man --link` is now done automatically by `brew update`." if args.link?
Commands.rebuild_internal_commands_completion_list
regenerate_man_pages
regenerate_man_pages(args: args)
if system "git", "-C", HOMEBREW_REPOSITORY, "diff", "--quiet", "docs/Manpage.md", "manpages", "completions"
puts "No changes to manpage or completions output detected."
@ -45,15 +45,15 @@ module Homebrew
end
end
def regenerate_man_pages
def regenerate_man_pages(args:)
Homebrew.install_bundler_gems!
markup = build_man_page
convert_man_page(markup, TARGET_DOC_PATH/"Manpage.md")
convert_man_page(markup, TARGET_MAN_PATH/"brew.1")
convert_man_page(markup, TARGET_DOC_PATH/"Manpage.md", args: args)
convert_man_page(markup, TARGET_MAN_PATH/"brew.1", args: args)
cask_markup = (SOURCE_PATH/"brew-cask.1.md").read
convert_man_page(cask_markup, TARGET_MAN_PATH/"brew-cask.1")
convert_man_page(cask_markup, TARGET_MAN_PATH/"brew-cask.1", args: args)
end
def build_man_page
@ -94,7 +94,7 @@ module Homebrew
path.basename.to_s.sub(/\.(rb|sh)$/, "").sub(/^--/, "~~")
end
def convert_man_page(markup, target)
def convert_man_page(markup, target, args:)
manual = target.basename(".1")
organisation = "Homebrew"
@ -148,7 +148,7 @@ module Homebrew
def generate_cmd_manpages(cmd_paths)
man_page_lines = []
man_args = Homebrew.args
# preserve existing manpage order
cmd_paths.sort_by(&method(:sort_key_for_path))
.each do |cmd_path|
@ -162,7 +162,7 @@ module Homebrew
man_page_lines << cmd_man_page_lines
end
Homebrew.args = man_args
man_page_lines.compact.join("\n")
end

View File

@ -32,15 +32,15 @@ module Homebrew
end
def pr_automerge
pr_automerge_args.parse
args = pr_automerge_args.parse
without_labels = Homebrew.args.without_labels || ["do not merge", "new formula"]
tap = Tap.fetch(Homebrew.args.tap || CoreTap.instance.name)
without_labels = args.without_labels || ["do not merge", "new formula"]
tap = Tap.fetch(args.tap || CoreTap.instance.name)
query = "is:pr is:open repo:#{tap.full_name}"
query += Homebrew.args.ignore_failures? ? " -status:pending" : " status:success"
query += " review:approved" unless Homebrew.args.without_approval?
query += " label:\"#{args.with_label}\"" if Homebrew.args.with_label
query += args.ignore_failures? ? " -status:pending" : " status:success"
query += " review:approved" unless args.without_approval?
query += " label:\"#{args.with_label}\"" if args.with_label
without_labels&.each { |label| query += " -label:\"#{label}\"" }
odebug "Searching: #{query}"

View File

@ -51,7 +51,7 @@ module Homebrew
only_cops = args.only_cops
except_cops = args.except_cops
options = { fix: args.fix? }
options = { fix: args.fix?, display_cop_names: args.display_cop_names? }
if only_cops
options[:only_cops] = only_cops
elsif except_cops

View File

@ -43,8 +43,8 @@ module Homebrew
FileUtils.ln_sf ld_so, brew_ld_so
end
def perform_preinstall_checks(all_fatal: false)
generic_perform_preinstall_checks(all_fatal: all_fatal)
def perform_preinstall_checks(all_fatal: false, cc: nil)
generic_perform_preinstall_checks(all_fatal: all_fatal, cc: cc)
symlink_ld_so
end
end

View File

@ -2,10 +2,10 @@
module Homebrew
module Fetch
def fetch_bottle?(f)
def fetch_bottle?(f, args:)
return true if args.force_bottle? && f.bottle
return false unless f.bottle && f.pour_bottle?
return false if args.build_formula_from_source?(f)
return false if args.build_from_source_formulae.include?(f.full_name)
return false unless f.bottle.compatible_cellar?
true

View File

@ -101,6 +101,10 @@ class Formula
# @private
attr_reader :tap
# Whether or not to force the use of a bottle.
# @private
attr_reader :force_bottle
# The stable (and default) {SoftwareSpec} for this {Formula}
# This contains all the attributes (e.g. URL, checksum) that apply to the
# stable version of this formula.
@ -181,7 +185,7 @@ class Formula
alias follow_installed_alias? follow_installed_alias
# @private
def initialize(name, path, spec, alias_path: nil)
def initialize(name, path, spec, alias_path: nil, force_bottle: false)
@name = name
@path = path
@alias_path = alias_path
@ -189,6 +193,8 @@ class Formula
@revision = self.class.revision || 0
@version_scheme = self.class.version_scheme || 0
@force_bottle = force_bottle
@tap = if path == Formulary.core_path(name)
CoreTap.instance
else
@ -2372,6 +2378,16 @@ class Formula
stable.build
end
# Get the `BUILD_FLAGS` from the formula's namespace set in `Formulary::load_formula`.
# @private
def build_flags
namespace = to_s.split("::")[0..-2].join("::")
return [] if namespace.empty?
mod = const_get(namespace)
mod.const_get(:BUILD_FLAGS)
end
# @!attribute [w] stable
# Allows adding {.depends_on} and {Patch}es just to the {.stable} {SoftwareSpec}.
# This is required instead of using a conditional.
@ -2385,7 +2401,7 @@ class Formula
# depends_on "libffi"
# end</pre>
def stable(&block)
@stable ||= SoftwareSpec.new
@stable ||= SoftwareSpec.new(flags: build_flags)
return @stable unless block_given?
@stable.instance_eval(&block)
@ -2405,7 +2421,7 @@ class Formula
# end</pre>
# @private
def devel(&block)
@devel ||= SoftwareSpec.new
@devel ||= SoftwareSpec.new(flags: build_flags)
return @devel unless block_given?
odeprecated "'devel' blocks in formulae", "'head' blocks or @-versioned formulae"
@ -2425,7 +2441,7 @@ class Formula
# or (if autodetect fails):
# <pre>head "https://hg.is.awesome.but.git.has.won.example.com/", :using => :hg</pre>
def head(val = nil, specs = {}, &block)
@head ||= HeadSoftwareSpec.new
@head ||= HeadSoftwareSpec.new(flags: build_flags)
if block_given?
@head.instance_eval(&block)
elsif val

View File

@ -21,6 +21,7 @@ require "cmd/install"
require "find"
class FormulaInstaller
include Homebrew::Install
include FormulaCellarChecks
extend Predicable
@ -39,14 +40,19 @@ class FormulaInstaller
attr_reader :formula
attr_accessor :cc, :env, :options, :build_bottle, :bottle_arch,
:installed_as_dependency, :installed_on_request, :link_keg
:build_from_source_formulae, :include_test_formulae,
:installed_as_dependency, :installed_on_request, :link_keg, :other_installers
mode_attr_accessor :show_summary_heading, :show_header
mode_attr_accessor :build_from_source, :force_bottle, :include_test
mode_attr_accessor :ignore_deps, :only_deps, :interactive, :git, :force, :keep_tmp
mode_attr_accessor :verbose, :debug, :quiet
def initialize(formula, force_bottle: false, include_test: false, build_from_source: false, cc: nil)
def initialize(formula,
force_bottle: false,
include_test: false, include_test_formulae: [],
build_from_source: false, build_from_source_formulae: [],
cc: nil)
@formula = formula
@env = nil
@force = false
@ -56,10 +62,12 @@ class FormulaInstaller
@ignore_deps = false
@only_deps = false
@build_from_source = build_from_source
@build_from_source_formulae = build_from_source_formulae
@build_bottle = false
@bottle_arch = nil
@force_bottle = force_bottle
@include_test = include_test
@include_test_formulae = include_test_formulae
@interactive = false
@git = false
@cc = cc
@ -93,12 +101,20 @@ class FormulaInstaller
# When no build tools are available and build flags are passed through ARGV,
# it's necessary to interrupt the user before any sort of installation
# can proceed. Only invoked when the user has no developer tools.
def self.prevent_build_flags
build_flags = Homebrew.args.collect_build_args
# can proceed. Only raises when the user has no developer tools.
def self.prevent_build_flags(args)
return if DevelopmentTools.installed?
build_flags = []
build_flags << "--HEAD" if args.HEAD?
build_flags << "--universal" if args.universal?
build_flags << "--build-bottle" if args.build_bottle?
build_flags << "--build-from-source" if args.build_from_source?
return if build_flags.empty?
all_bottled = Homebrew.args.formulae.all?(&:bottled?)
all_bottled = args.formulae.all?(&:bottled?)
raise BuildFlagsError.new(build_flags, bottled: all_bottled)
end
@ -144,7 +160,7 @@ class FormulaInstaller
def install_bottle_for?(dep, build)
return pour_bottle? if dep == formula
return false if Homebrew.args.build_formula_from_source?(dep)
return false if build_from_source_formulae.include?(dep.full_name)
return false unless dep.bottle && dep.pour_bottle?
return false unless build.used_options.empty?
return false unless dep.bottle.compatible_cellar?
@ -239,9 +255,7 @@ class FormulaInstaller
lock
start_time = Time.now
if !formula.bottle_unneeded? && !pour_bottle? && DevelopmentTools.installed?
Homebrew::Install.perform_build_from_source_checks
end
perform_build_from_source_checks if !formula.bottle_unneeded? && !pour_bottle? && DevelopmentTools.installed?
# not in initialize so upgrade can unlink the active keg before calling this
# function but after instantiating this class so that it can avoid having to
@ -475,7 +489,7 @@ class FormulaInstaller
if req.prune_from_option?(build)
Requirement.prune
elsif req.satisfied?(args: Homebrew.args)
elsif req.satisfied?(env: env, cc: cc, build_bottle: @build_bottle, bottle_arch: bottle_arch)
Requirement.prune
elsif (req.build? || req.test?) && !keep_build_test
Requirement.prune
@ -505,7 +519,7 @@ class FormulaInstaller
)
keep_build_test = false
keep_build_test ||= dep.test? && include_test? && Homebrew.args.include_formula_test_deps?(dependent)
keep_build_test ||= dep.test? && include_test? && include_test_formulae.include?(dependent.full_name)
keep_build_test ||= dep.build? && !install_bottle_for?(dependent, build) && !dependent.latest_version_installed?
if dep.prune_from_option?(build)
@ -583,8 +597,8 @@ class FormulaInstaller
def fetch_dependency(dep)
df = dep.to_formula
fi = FormulaInstaller.new(df, force_bottle: false,
include_test: Homebrew.args.include_formula_test_deps?(df),
build_from_source: Homebrew.args.build_formula_from_source?(df))
include_test: include_test_formulae.include?(df.full_name),
build_from_source: build_from_source_formulae.include?(df.full_name))
fi.force = force?
fi.keep_tmp = keep_tmp?
@ -624,8 +638,8 @@ class FormulaInstaller
end
fi = FormulaInstaller.new(df, force_bottle: false,
include_test: Homebrew.args.include_formula_test_deps?(df),
build_from_source: Homebrew.args.build_formula_from_source?(df))
include_test: include_test_formulae.include?(df.full_name),
build_from_source: build_from_source_formulae.include?(df.full_name))
fi.options |= tab.used_options
fi.options |= Tab.remap_deprecated_options(df.deprecated_options, dep.options)
@ -763,12 +777,6 @@ class FormulaInstaller
args << "--devel"
end
formula.options.each do |opt|
name = opt.name[/^([^=]+)=$/, 1]
value = Homebrew.args.value(name) if name
args << "--#{name}=#{value}" if value
end
args
end

View File

@ -27,12 +27,16 @@ module Formulary
cache.fetch(path)
end
def self.load_formula(name, path, contents, namespace)
def self.load_formula(name, path, contents, namespace, flags:)
raise "Formula loading disabled by HOMEBREW_DISABLE_LOAD_FORMULA!" if Homebrew::EnvConfig.disable_load_formula?
mod = Module.new
const_set(namespace, mod)
begin
# Set `BUILD_FLAGS` in the formula's namespace so we can
# access them from within the formula's class scope.
mod.const_set(:BUILD_FLAGS, flags)
mod.module_eval(contents, path)
rescue NameError, ArgumentError, ScriptError => e
$stderr.puts e.backtrace if Homebrew::EnvConfig.developer?
@ -51,16 +55,16 @@ module Formulary
end
end
def self.load_formula_from_path(name, path)
def self.load_formula_from_path(name, path, flags:)
contents = path.open("r") { |f| ensure_utf8_encoding(f).read }
namespace = "FormulaNamespace#{Digest::MD5.hexdigest(path.to_s)}"
klass = load_formula(name, path, contents, namespace)
klass = load_formula(name, path, contents, namespace, flags: flags)
cache[path] = klass
end
def self.resolve(name, spec: nil)
def self.resolve(name, spec: nil, force_bottle: false, flags: [])
if name.include?("/") || File.exist?(name)
f = factory(name, *spec)
f = factory(name, *spec, force_bottle: force_bottle, flags: flags)
if f.any_version_installed?
tab = Tab.for_formula(f)
resolved_spec = spec || tab.spec
@ -73,8 +77,8 @@ module Formulary
end
else
rack = to_rack(name)
alias_path = factory(name).alias_path
f = from_rack(rack, *spec, alias_path: alias_path)
alias_path = factory(name, force_bottle: force_bottle, flags: flags).alias_path
f = from_rack(rack, *spec, alias_path: alias_path, force_bottle: force_bottle, flags: flags)
end
# If this formula was installed with an alias that has since changed,
@ -121,22 +125,23 @@ module Formulary
#
# `alias_path` can be overridden here in case an alias was used to refer to
# a formula that was loaded in another way.
def get_formula(spec, alias_path: nil)
klass.new(name, path, spec, alias_path: alias_path || self.alias_path)
def get_formula(spec, alias_path: nil, force_bottle: false, flags: [])
alias_path ||= self.alias_path
klass(flags: flags).new(name, path, spec, alias_path: alias_path, force_bottle: force_bottle)
end
def klass
load_file unless Formulary.formula_class_defined?(path)
def klass(flags:)
load_file(flags: flags) unless Formulary.formula_class_defined?(path)
Formulary.formula_class_get(path)
end
private
def load_file
def load_file(flags:)
$stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if Homebrew.args.debug?
raise FormulaUnavailableError, name unless path.file?
Formulary.load_formula_from_path(name, path)
Formulary.load_formula_from_path(name, path, flags: flags)
end
end
@ -161,10 +166,10 @@ module Formulary
super name, Formulary.path(full_name)
end
def get_formula(spec, **)
def get_formula(spec, force_bottle: false, flags: [], **)
contents = Utils::Bottles.formula_contents @bottle_filename, name: name
formula = begin
Formulary.from_contents name, @bottle_filename, contents, spec
Formulary.from_contents(name, @bottle_filename, contents, spec, force_bottle: force_bottle, flags: flags)
rescue FormulaUnreadableError => e
opoo <<~EOS
Unreadable formula in #{@bottle_filename}:
@ -205,7 +210,7 @@ module Formulary
super formula, HOMEBREW_CACHE_FORMULA/File.basename(uri.path)
end
def load_file
def load_file(flags:)
if url =~ %r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(/Formula)?/([\w+-.@]+).rb}
formula_name = Regexp.last_match(2)
odeprecated "Installation of #{formula_name} from a GitHub commit URL",
@ -270,7 +275,7 @@ module Formulary
[name, path]
end
def get_formula(spec, alias_path: nil)
def get_formula(spec, alias_path: nil, force_bottle: false, flags: [])
super
rescue FormulaUnreadableError => e
raise TapFormulaUnreadableError.new(tap, name, e.formula_error), "", e.backtrace
@ -280,7 +285,7 @@ module Formulary
raise TapFormulaUnavailableError.new(tap, name), "", e.backtrace
end
def load_file
def load_file(flags:)
super
rescue MethodDeprecatedError => e
e.issues_url = tap.issues_url || tap.to_s
@ -308,10 +313,10 @@ module Formulary
super name, path
end
def klass
def klass(flags:)
$stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if Homebrew.args.debug?
namespace = "FormulaNamespace#{Digest::MD5.hexdigest(contents)}"
Formulary.load_formula(name, path, contents, namespace)
namespace = "FormulaNamespace#{Digest::MD5.hexdigest(contents.to_s)}"
Formulary.load_formula(name, path, contents, namespace, flags: flags)
end
end
@ -322,7 +327,7 @@ module Formulary
# * a formula pathname
# * a formula URL
# * a local bottle reference
def self.factory(ref, spec = :stable, alias_path: nil, from: nil)
def self.factory(ref, spec = :stable, alias_path: nil, from: nil, force_bottle: false, flags: [])
raise ArgumentError, "Formulae must have a ref!" unless ref
cache_key = "#{ref}-#{spec}-#{alias_path}-#{from}"
@ -331,7 +336,8 @@ module Formulary
return cache[:formulary_factory][cache_key]
end
formula = loader_for(ref, from: from).get_formula(spec, alias_path: alias_path)
formula = loader_for(ref, from: from).get_formula(spec, alias_path: alias_path,
force_bottle: force_bottle, flags: flags)
if factory_cached?
cache[:formulary_factory] ||= {}
cache[:formulary_factory][cache_key] ||= formula
@ -345,14 +351,15 @@ module Formulary
# The :alias_path option will be used if the formula is found not to be
# installed, and discarded if it is installed because the alias_path used
# to install the formula will be set instead.
def self.from_rack(rack, spec = nil, alias_path: nil)
def self.from_rack(rack, spec = nil, alias_path: nil, force_bottle: false, flags: [])
kegs = rack.directory? ? rack.subdirs.map { |d| Keg.new(d) } : []
keg = kegs.find(&:linked?) || kegs.find(&:optlinked?) || kegs.max_by(&:version)
if keg
from_keg(keg, spec, alias_path: alias_path)
else
factory(rack.basename.to_s, spec || :stable, alias_path: alias_path, from: :rack)
factory(rack.basename.to_s, spec || :stable, alias_path: alias_path, from: :rack,
force_bottle: force_bottle, flags: flags)
end
end
@ -365,19 +372,22 @@ module Formulary
# Return a Formula instance for the given keg.
# It will auto resolve formula's spec when requested spec is nil
def self.from_keg(keg, spec = nil, alias_path: nil)
def self.from_keg(keg, spec = nil, alias_path: nil, force_bottle: false, flags: [])
tab = Tab.for_keg(keg)
tap = tab.tap
spec ||= tab.spec
f = if tap.nil?
factory(keg.rack.basename.to_s, spec, alias_path: alias_path, from: :keg)
factory(keg.rack.basename.to_s, spec, alias_path: alias_path, from: :keg,
force_bottle: force_bottle, flags: flags)
else
begin
factory("#{tap}/#{keg.rack.basename}", spec, alias_path: alias_path, from: :keg)
factory("#{tap}/#{keg.rack.basename}", spec, alias_path: alias_path, from: :keg,
force_bottle: force_bottle, flags: flags)
rescue FormulaUnavailableError
# formula may be migrated to different tap. Try to search in core and all taps.
factory(keg.rack.basename.to_s, spec, alias_path: alias_path, from: :keg)
factory(keg.rack.basename.to_s, spec, alias_path: alias_path, from: :keg,
force_bottle: force_bottle, flags: flags)
end
end
f.build = tab
@ -387,8 +397,9 @@ module Formulary
end
# Return a Formula instance directly from contents
def self.from_contents(name, path, contents, spec = :stable)
FormulaContentsLoader.new(name, path, contents).get_formula(spec)
def self.from_contents(name, path, contents, spec = :stable, alias_path: nil, force_bottle: false, flags: [])
FormulaContentsLoader.new(name, path, contents)
.get_formula(spec, alias_path: alias_path, force_bottle: force_bottle, flags: flags)
end
def self.to_rack(ref)

View File

@ -39,20 +39,20 @@ module Homebrew
end
end
def check_cc_argv
return unless Homebrew.args.cc
def check_cc_argv(cc)
return unless cc
@checks ||= Diagnostic::Checks.new
opoo <<~EOS
You passed `--cc=#{Homebrew.args.cc}`.
You passed `--cc=#{cc}`.
#{@checks.please_create_pull_requests}
EOS
end
def perform_preinstall_checks(all_fatal: false)
def perform_preinstall_checks(all_fatal: false, cc: nil)
check_cpu
attempt_directory_creation
check_cc_argv
check_cc_argv(cc)
diagnostic_checks(:supported_configuration_checks, fatal: all_fatal)
diagnostic_checks(:fatal_preinstall_checks)
end

View File

@ -20,9 +20,9 @@ class Messages
@install_times.push(formula: f.name, time: elapsed_time)
end
def display_messages
def display_messages(display_times: false)
display_caveats
display_install_times if Homebrew.args.display_times?
display_install_times if display_times
end
def display_caveats

View File

@ -97,18 +97,18 @@ class Migrator
true
end
def self.migrate_if_needed(formula)
def self.migrate_if_needed(formula, force:)
return unless Migrator.needs_migration?(formula)
begin
migrator = Migrator.new(formula)
migrator = Migrator.new(formula, force: force)
migrator.migrate
rescue => e
onoe e
end
end
def initialize(formula, force: Homebrew.args.force?)
def initialize(formula, force: false)
@oldname = formula.oldname
@newname = formula.name
raise MigratorNoOldnameError, formula unless oldname

View File

@ -159,6 +159,10 @@ class ExternalPatch
end
end
end
rescue ErrorDuringExecution => e
f = resource.owner.owner
cmd, *args = e.cmd
raise BuildError.new(f, cmd, args, ENV.to_hash)
end
def inspect

View File

@ -10,13 +10,13 @@ require "cli/parser"
require "cmd/postinstall"
begin
Homebrew.postinstall_args.parse
args = Homebrew.postinstall_args.parse
error_pipe = UNIXSocket.open(ENV["HOMEBREW_ERROR_PIPE"], &:recv_io)
error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
trap("INT", old_trap)
formula = Homebrew.args.resolved_formulae.first
formula = args.resolved_formulae.first
formula.extend(Debrew::Formula) if Homebrew.args.debug?
formula.run_post_install
rescue Exception => e # rubocop:disable Lint/RescueException

View File

@ -18,13 +18,14 @@ module Homebrew
backup keg
end
build_options = BuildOptions.new(Options.create(Homebrew.args.flags_only), f.options)
build_options = BuildOptions.new(Options.create(args.flags_only), f.options)
options = build_options.used_options
options |= f.build.used_options
options &= f.options
fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, include_test: args.include_test?,
build_from_source: args.build_from_source?)
fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?,
build_from_source: args.build_from_source?,
build_from_source_formulae: args.build_from_source_formulae)
fi.options = options
fi.force = args.force?
fi.keep_tmp = args.keep_tmp?

View File

@ -53,11 +53,14 @@ class Requirement
# Overriding {#satisfied?} is unsupported.
# Pass a block or boolean to the satisfy DSL method instead.
def satisfied?(args: nil)
def satisfied?(env: nil, cc: nil, build_bottle: false, bottle_arch: nil)
satisfy = self.class.satisfy
return true unless satisfy
@satisfied_result = satisfy.yielder(args: args) { |p| instance_eval(&p) }
@satisfied_result =
satisfy.yielder(env: env, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch) do |p|
instance_eval(&p)
end
return false unless @satisfied_result
true
@ -81,8 +84,8 @@ class Requirement
# Overriding {#modify_build_environment} is unsupported.
# Pass a block to the env DSL method instead.
def modify_build_environment(args:)
satisfied?(args: args)
def modify_build_environment(env: nil, cc: nil, build_bottle: false, bottle_arch: nil)
satisfied?(env: env, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch)
instance_eval(&env_proc) if env_proc
# XXX If the satisfy block returns a Pathname, then make sure that it
@ -185,13 +188,13 @@ class Requirement
@proc = block
end
def yielder(args:)
def yielder(env: nil, cc: nil, build_bottle: false, bottle_arch: nil)
if instance_variable_defined?(:@satisfied)
@satisfied
elsif @options[:build_env]
require "extend/ENV"
ENV.with_build_environment(
env: args.env, cc: args.cc, build_bottle: args.build_bottle?, bottle_arch: args.bottle_arch,
env: env, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch,
) do
yield @proc
end

View File

@ -28,14 +28,14 @@ class SoftwareSpec
:cached_download, :clear_cache, :checksum, :mirrors, :specs, :using, :version, :mirror,
:downloader, *Checksum::TYPES
def initialize
def initialize(flags: [])
@resource = Resource.new
@resources = {}
@dependency_collector = DependencyCollector.new
@bottle_specification = BottleSpecification.new
@patches = []
@options = Options.new
@flags = Homebrew.args.flags_only
@flags = flags
@deprecated_flags = []
@deprecated_options = []
@build = BuildOptions.new(Options.create(@flags), options)
@ -87,7 +87,7 @@ class SoftwareSpec
def bottled?
bottle_specification.tag?(Utils::Bottles.tag) && \
(bottle_specification.compatible_cellar? || Homebrew.args.force_bottle?)
(bottle_specification.compatible_cellar? || owner.force_bottle)
end
def bottle(disable_type = nil, disable_reason = nil, &block)
@ -234,7 +234,7 @@ class SoftwareSpec
end
class HeadSoftwareSpec < SoftwareSpec
def initialize
def initialize(flags: [])
super
@resource.version = Version.create("HEAD")
end

View File

@ -16,7 +16,7 @@ module Homebrew
check_style_impl(files, :json, **options)
end
def check_style_impl(files, output_type, fix: false, except_cops: nil, only_cops: nil)
def check_style_impl(files, output_type, fix: false, except_cops: nil, only_cops: nil, display_cop_names: false)
Homebrew.install_bundler_gems!
require "rubocop"
require "rubocops"
@ -78,7 +78,7 @@ module Homebrew
case output_type
when :print
args << "--debug" if Homebrew.args.debug?
args << "--display-cop-names" if Homebrew.args.display_cop_names?
args << "--display-cop-names" if display_cop_names
args << "--format" << "simple" if files.present?
system(cache_env, "rubocop", *args)
rubocop_success = $CHILD_STATUS.success?

View File

@ -28,7 +28,7 @@ describe Homebrew do
end
end
let(:opts) { { dependency.rack => [Keg.new(dependency.installed_prefix)] } }
let(:kegs_by_rack) { { dependency.rack => [Keg.new(dependency.installed_prefix)] } }
before do
[dependency, dependent].each do |f|
@ -53,7 +53,7 @@ describe Homebrew do
ENV["HOMEBREW_DEVELOPER"] = "1"
expect {
described_class.handle_unsatisfied_dependents(opts)
described_class.handle_unsatisfied_dependents(kegs_by_rack)
}.to output(/Warning/).to_stderr
expect(described_class).not_to have_failed
@ -61,19 +61,15 @@ describe Homebrew do
specify "when not developer" do
expect {
described_class.handle_unsatisfied_dependents(opts)
described_class.handle_unsatisfied_dependents(kegs_by_rack)
}.to output(/Error/).to_stderr
expect(described_class).to have_failed
end
specify "when not developer and --ignore-dependencies is specified" do
described_class.args = described_class.args.dup if described_class.args.frozen?
expect(described_class.args).to receive(:ignore_dependencies?).and_return(true)
described_class.args.freeze
specify "when not developer and `ignore_dependencies` is true" do
expect {
described_class.handle_unsatisfied_dependents(opts)
described_class.handle_unsatisfied_dependents(kegs_by_rack, ignore_dependencies: true)
}.not_to output.to_stderr
expect(described_class).not_to have_failed

View File

@ -16,7 +16,7 @@ describe Formulary do
bottle do
cellar :any_skip_relocation
root_url "file://#{bottle_dir}"
sha256 "d48bbbe583dcfbfa608579724fc6f0328b3cd316935c6ea22f134610aaf2952f" => :#{Utils::Bottles.tag}
sha256 "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" => :#{Utils::Bottles.tag}
end
def install

View File

@ -41,16 +41,14 @@ describe JavaRequirement do
describe "#satisfied?" do
subject { described_class.new(%w[1.8]) }
let(:args) { Homebrew::CLI::Args.new }
it "returns false if no `java` executable can be found" do
allow(File).to receive(:executable?).and_return(false)
expect(subject).not_to be_satisfied(args: args)
expect(subject).not_to be_satisfied
end
it "returns true if #preferred_java returns a path" do
allow(subject).to receive(:preferred_java).and_return(Pathname.new("/usr/bin/java"))
expect(subject).to be_satisfied(args: args)
expect(subject).to be_satisfied
end
context "when #possible_javas contains paths" do
@ -74,17 +72,17 @@ describe JavaRequirement do
it "returns false if all are lower" do
setup_java_with_version "1.6.0_5"
expect(subject).not_to be_satisfied(args: args)
expect(subject).not_to be_satisfied
end
it "returns true if one is equal" do
setup_java_with_version "1.7.0_5"
expect(subject).to be_satisfied(args: args)
expect(subject).to be_satisfied
end
it "returns false if all are higher" do
setup_java_with_version "1.8.0_5"
expect(subject).not_to be_satisfied(args: args)
expect(subject).not_to be_satisfied
end
end
@ -93,17 +91,17 @@ describe JavaRequirement do
it "returns false if all are lower" do
setup_java_with_version "1.6.0_5"
expect(subject).not_to be_satisfied(args: args)
expect(subject).not_to be_satisfied
end
it "returns true if one is equal" do
setup_java_with_version "1.7.0_5"
expect(subject).to be_satisfied(args: args)
expect(subject).to be_satisfied
end
it "returns true if one is higher" do
setup_java_with_version "1.8.0_5"
expect(subject).to be_satisfied(args: args)
expect(subject).to be_satisfied
end
end
end

View File

@ -72,27 +72,20 @@ describe Messages do
end
end
# Homebrew.args OpenStruct usage cannot use verified doubles.
# rubocop:disable RSpec/VerifiedDoubles
context "when the --display-times argument is present" do
before do
allow(Homebrew).to receive(:args).and_return \
double(display_times?: true, flags_only: ["--display-times"])
end
context "when install_times is empty" do
it "doesn't print any output" do
expect { messages.display_messages }.not_to output.to_stdout
context "when the `display_times` argument is true" do
context "when `install_times` is empty" do
it "doesn't print anything" do
expect { messages.display_messages(display_times: true) }.not_to output.to_stdout
end
end
context "when install_times is present" do
context "when `install_times` is present" do
before do
messages.formula_installed(test_formula, elapsed_time)
end
it "prints installation times" do
expect { messages.display_messages }.to output(
expect { messages.display_messages(display_times: true) }.to output(
<<~EOS,
==> Installation times
foo 1.100 s
@ -102,15 +95,10 @@ describe Messages do
end
end
context "when the --display-times argument isn't present" do
before do
allow(Homebrew).to receive(:args).and_return(double(display_times?: false))
end
context "when the `display_times` argument isn't specified" do
it "doesn't print installation times" do
expect { messages.display_messages }.not_to output.to_stdout
end
end
# rubocop:enable RSpec/VerifiedDoubles
end
end

View File

@ -9,8 +9,6 @@ describe JavaRequirement do
let(:java_home) { mktmpdir }
let(:args) { Homebrew::CLI::Args.new }
before do
FileUtils.mkdir java_home/"bin"
FileUtils.touch java_home/"bin/java"
@ -18,23 +16,23 @@ describe JavaRequirement do
end
specify "Apple Java environment" do
expect(subject).to be_satisfied(args: args)
expect(subject).to be_satisfied
expect(ENV).to receive(:prepend_path)
expect(ENV).to receive(:append_to_cflags)
subject.modify_build_environment(args: args)
subject.modify_build_environment
expect(ENV["JAVA_HOME"]).to eq(java_home.to_s)
end
specify "Oracle Java environment" do
expect(subject).to be_satisfied(args: args)
expect(subject).to be_satisfied
FileUtils.mkdir java_home/"include"
expect(ENV).to receive(:prepend_path)
expect(ENV).to receive(:append_to_cflags).twice
subject.modify_build_environment(args: args)
subject.modify_build_environment
expect(ENV["JAVA_HOME"]).to eq(java_home.to_s)
end
end

View File

@ -149,7 +149,7 @@ describe "patching" do
end
f.brew { |formula, _staging| formula.patch }
}.to raise_error(ErrorDuringExecution)
}.to raise_error(BuildError)
end
specify "single_patch_dsl_with_incorrect_strip_with_apply" do
@ -163,7 +163,7 @@ describe "patching" do
end
f.brew { |formula, _staging| formula.patch }
}.to raise_error(ErrorDuringExecution)
}.to raise_error(BuildError)
end
specify "patch_p0_dsl" do
@ -219,7 +219,7 @@ describe "patching" do
end
f.brew { |formula, _staging| formula.patch }
}.to raise_error(ErrorDuringExecution)
}.to raise_error(BuildError)
end
end

View File

@ -11,8 +11,6 @@ describe Requirement do
let(:klass) { Class.new(described_class) }
let(:args) { Homebrew::CLI::Args.new }
describe "#tags" do
subject { described_class.new(tags) }
@ -67,7 +65,7 @@ describe Requirement do
end
end
it { is_expected.to be_satisfied(args: args) }
it { is_expected.to be_satisfied }
end
describe "#satisfy with block and build_env returns false" do
@ -79,7 +77,7 @@ describe Requirement do
end
end
it { is_expected.not_to be_satisfied(args: args) }
it { is_expected.not_to be_satisfied }
end
describe "#satisfy returns true" do
@ -89,7 +87,7 @@ describe Requirement do
end
end
it { is_expected.to be_satisfied(args: args) }
it { is_expected.to be_satisfied }
end
describe "#satisfy returns false" do
@ -99,7 +97,7 @@ describe Requirement do
end
end
it { is_expected.not_to be_satisfied(args: args) }
it { is_expected.not_to be_satisfied }
end
describe "#satisfy with block returning true and without :build_env" do
@ -113,7 +111,7 @@ describe Requirement do
it "sets up build environment" do
expect(ENV).to receive(:with_build_environment).and_call_original
subject.satisfied?(args: args)
subject.satisfied?
end
end
@ -128,7 +126,7 @@ describe Requirement do
it "skips setting up build environment" do
expect(ENV).not_to receive(:with_build_environment)
subject.satisfied?(args: args)
subject.satisfied?
end
end
@ -143,8 +141,8 @@ describe Requirement do
it "infers path from #satisfy result" do
expect(ENV).to receive(:prepend_path).with("PATH", Pathname.new("/foo/bar"))
subject.satisfied?(args: args)
subject.modify_build_environment(args: args)
subject.satisfied?
subject.modify_build_environment
end
end
end
@ -182,7 +180,7 @@ describe Requirement do
let(:klass) { Class.new(described_class) }
it "returns nil" do
expect(subject.modify_build_environment(args: args)).to be nil
expect(subject.modify_build_environment).to be nil
end
end
end

View File

@ -7,10 +7,8 @@ describe LinuxRequirement do
subject(:requirement) { described_class.new }
describe "#satisfied?" do
let(:args) { Homebrew::CLI::Args.new }
it "returns true on Linux" do
expect(requirement.satisfied?(args: args)).to eq(OS.linux?)
expect(requirement.satisfied?).to eq(OS.linux?)
end
end
end

View File

@ -7,20 +7,18 @@ describe MacOSRequirement do
subject(:requirement) { described_class.new }
describe "#satisfied?" do
let(:args) { Homebrew::CLI::Args.new }
it "returns true on macOS" do
expect(requirement.satisfied?(args: args)).to eq OS.mac?
expect(requirement.satisfied?).to eq OS.mac?
end
it "supports version symbols", :needs_macos do
requirement = described_class.new([MacOS.version.to_sym])
expect(requirement).to be_satisfied(args: args)
expect(requirement).to be_satisfied
end
it "supports maximum versions", :needs_macos do
requirement = described_class.new([:catalina], comparator: "<=")
expect(requirement.satisfied?(args: args)).to eq MacOS.version <= :catalina
expect(requirement.satisfied?).to eq MacOS.version <= :catalina
end
end
end

View File

@ -22,23 +22,21 @@ describe OsxfuseRequirement do
end
describe "#modify_build_environment", :needs_macos do
let(:args) { Homebrew::CLI::Args.new }
it "adds the fuse directories to PKG_CONFIG_PATH" do
allow(ENV).to receive(:append_path)
requirement.modify_build_environment(args: args)
requirement.modify_build_environment
expect(ENV).to have_received(:append_path).with("PKG_CONFIG_PATH", any_args)
end
it "adds the fuse directories to HOMEBREW_LIBRARY_PATHS" do
allow(ENV).to receive(:append_path)
requirement.modify_build_environment(args: args)
requirement.modify_build_environment
expect(ENV).to have_received(:append_path).with("HOMEBREW_LIBRARY_PATHS", any_args)
end
it "adds the fuse directories to HOMEBREW_INCLUDE_PATHS" do
allow(ENV).to receive(:append_path)
requirement.modify_build_environment(args: args)
requirement.modify_build_environment
expect(ENV).to have_received(:append_path).with("HOMEBREW_INCLUDE_PATHS", any_args)
end
end

View File

@ -13,7 +13,8 @@ describe "RuboCop" do
end
it "loads all Formula cops without errors" do
_, _, status = Open3.capture3("rubocop", TEST_FIXTURE_DIR/"testball.rb")
stdout, _, status = Open3.capture3("rubocop", TEST_FIXTURE_DIR/"testball.rb")
expect(stdout).to include("no offenses detected")
expect(status).to be_a_success
end
end

View File

@ -1,7 +1,8 @@
# frozen_string_literal: true
class Failball < Formula
def initialize(name = "failball", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil)
def initialize(name = "failball", path = Pathname.new(__FILE__).expand_path, spec = :stable,
alias_path: nil, force_bottle: false)
self.class.instance_eval do
stable.url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
stable.sha256 TESTBALL_SHA256

View File

@ -1,7 +1,8 @@
# frozen_string_literal: true
class Testball < Formula
def initialize(name = "testball", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil)
def initialize(name = "testball", path = Pathname.new(__FILE__).expand_path, spec = :stable,
alias_path: nil, force_bottle: false)
self.class.instance_eval do
stable.url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
stable.sha256 TESTBALL_SHA256

View File

@ -1,14 +1,15 @@
# frozen_string_literal: true
class TestballBottle < Formula
def initialize(name = "testball_bottle", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil)
def initialize(name = "testball_bottle", path = Pathname.new(__FILE__).expand_path, spec = :stable,
alias_path: nil, force_bottle: false)
self.class.instance_eval do
stable.url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
stable.sha256 TESTBALL_SHA256
stable.bottle do
cellar :any_skip_relocation
root_url "file://#{TEST_FIXTURE_DIR}/bottles"
sha256 "d48bbbe583dcfbfa608579724fc6f0328b3cd316935c6ea22f134610aaf2952f" => Utils::Bottles.tag
sha256 "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" => Utils::Bottles.tag
end
cxxstdlib_check :skip
end

View File

@ -6,8 +6,6 @@ require "requirements/x11_requirement"
describe X11Requirement do
let(:default_name) { "x11" }
let(:args) { Homebrew::CLI::Args.new }
describe "#name" do
it "defaults to x11" do
expect(subject.name).to eq(default_name)
@ -25,7 +23,7 @@ describe X11Requirement do
it "calls ENV#x11" do
allow(subject).to receive(:satisfied?).and_return(true)
expect(ENV).to receive(:x11)
subject.modify_build_environment(args: args)
subject.modify_build_environment
end
end
@ -33,12 +31,12 @@ describe X11Requirement do
it "returns true if X11 is installed" do
expect(MacOS::XQuartz).to receive(:version).and_return("2.7.5")
expect(MacOS::XQuartz).to receive(:installed?).and_return(true)
expect(subject).to be_satisfied(args: args)
expect(subject).to be_satisfied
end
it "returns false if X11 is not installed" do
expect(MacOS::XQuartz).to receive(:installed?).and_return(false)
expect(subject).not_to be_satisfied(args: args)
expect(subject).not_to be_satisfied
end
end
end

View File

@ -26,7 +26,7 @@ module Homebrew
end
formulae_to_install.each do |f|
Migrator.migrate_if_needed(f)
Migrator.migrate_if_needed(f, force: args.force?)
begin
upgrade_formula(f, args: args)
Cleanup.install_formula_clean!(f)