Merge pull request #1217 from MatzFan/invalid_build_option_warnings
Invalid build option warnings - supersedes #1088
This commit is contained in:
commit
2a53d14b51
@ -101,6 +101,16 @@ class BuildOptions
|
|||||||
@options - @args
|
@options - @args
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @private
|
||||||
|
def invalid_options
|
||||||
|
@args - @options
|
||||||
|
end
|
||||||
|
|
||||||
|
# @private
|
||||||
|
def invalid_option_names
|
||||||
|
invalid_options.map(&:flag).sort
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def option_defined?(name)
|
def option_defined?(name)
|
||||||
|
|||||||
@ -249,9 +249,11 @@ module Homebrew
|
|||||||
|
|
||||||
def install_formula(f)
|
def install_formula(f)
|
||||||
f.print_tap_action
|
f.print_tap_action
|
||||||
|
build_options = f.build
|
||||||
|
|
||||||
fi = FormulaInstaller.new(f)
|
fi = FormulaInstaller.new(f)
|
||||||
fi.options = f.build.used_options
|
fi.options = build_options.used_options
|
||||||
|
fi.invalid_option_names = build_options.invalid_option_names
|
||||||
fi.ignore_deps = ARGV.ignore_deps?
|
fi.ignore_deps = ARGV.ignore_deps?
|
||||||
fi.only_deps = ARGV.only_deps?
|
fi.only_deps = ARGV.only_deps?
|
||||||
fi.build_bottle = ARGV.build_bottle?
|
fi.build_bottle = ARGV.build_bottle?
|
||||||
|
|||||||
@ -31,7 +31,7 @@ class FormulaInstaller
|
|||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :formula
|
attr_reader :formula
|
||||||
attr_accessor :options, :build_bottle
|
attr_accessor :options, :build_bottle, :invalid_option_names
|
||||||
mode_attr_accessor :show_summary_heading, :show_header
|
mode_attr_accessor :show_summary_heading, :show_header
|
||||||
mode_attr_accessor :build_from_source, :force_bottle
|
mode_attr_accessor :build_from_source, :force_bottle
|
||||||
mode_attr_accessor :ignore_deps, :only_deps, :interactive, :git
|
mode_attr_accessor :ignore_deps, :only_deps, :interactive, :git
|
||||||
@ -51,6 +51,7 @@ class FormulaInstaller
|
|||||||
@quieter = false
|
@quieter = false
|
||||||
@debug = false
|
@debug = false
|
||||||
@options = Options.new
|
@options = Options.new
|
||||||
|
@invalid_option_names = []
|
||||||
|
|
||||||
@@attempted ||= Set.new
|
@@attempted ||= Set.new
|
||||||
|
|
||||||
@ -213,6 +214,10 @@ class FormulaInstaller
|
|||||||
opoo "#{formula.full_name}: #{old_flag} was deprecated; using #{new_flag} instead!"
|
opoo "#{formula.full_name}: #{old_flag} was deprecated; using #{new_flag} instead!"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
invalid_option_names.each do |option|
|
||||||
|
opoo "#{formula.full_name}: this formula has no #{option} option so it will be ignored!"
|
||||||
|
end
|
||||||
|
|
||||||
oh1 "Installing #{Formatter.identifier(formula.full_name)}" if show_header?
|
oh1 "Installing #{Formatter.identifier(formula.full_name)}" if show_header?
|
||||||
|
|
||||||
if formula.tap && !formula.tap.private?
|
if formula.tap && !formula.tap.private?
|
||||||
|
|||||||
@ -7,6 +7,8 @@ class BuildOptionsTests < Homebrew::TestCase
|
|||||||
args = Options.create(%w[--with-foo --with-bar --without-qux])
|
args = Options.create(%w[--with-foo --with-bar --without-qux])
|
||||||
opts = Options.create(%w[--with-foo --with-bar --without-baz --without-qux])
|
opts = Options.create(%w[--with-foo --with-bar --without-baz --without-qux])
|
||||||
@build = BuildOptions.new(args, opts)
|
@build = BuildOptions.new(args, opts)
|
||||||
|
bad_args = Options.create(%w[--with-foo --with-bar --without-bas --without-qux --without-abc])
|
||||||
|
@bad_build = BuildOptions.new(bad_args, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_include
|
def test_include
|
||||||
@ -31,4 +33,17 @@ class BuildOptionsTests < Homebrew::TestCase
|
|||||||
def test_unused_options
|
def test_unused_options
|
||||||
assert_includes @build.unused_options, "--without-baz"
|
assert_includes @build.unused_options, "--without-baz"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_invalid_options
|
||||||
|
assert_empty @build.invalid_options
|
||||||
|
assert_includes @bad_build.invalid_options, "--without-bas"
|
||||||
|
assert_includes @bad_build.invalid_options, "--without-abc"
|
||||||
|
refute_includes @bad_build.invalid_options, "--with-foo"
|
||||||
|
refute_includes @bad_build.invalid_options, "--with-baz"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_invalid_option_names
|
||||||
|
assert_empty @build.invalid_option_names
|
||||||
|
assert_equal @bad_build.invalid_option_names, %w[--without-abc --without-bas]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -37,6 +37,7 @@ class InstallTests < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_a_basic_install
|
def test_a_basic_install
|
||||||
|
ARGV << "--with-invalid_flag" # added to ensure it doesn't fail install
|
||||||
temporary_install(Testball.new) do |f|
|
temporary_install(Testball.new) do |f|
|
||||||
# Test that things made it into the Keg
|
# Test that things made it into the Keg
|
||||||
assert_predicate f.prefix+"readme", :exist?
|
assert_predicate f.prefix+"readme", :exist?
|
||||||
|
|||||||
@ -21,4 +21,10 @@ class IntegrationCommandTestInstall < IntegrationCommandTestCase
|
|||||||
assert_match "testball1 already installed, it's just not migrated",
|
assert_match "testball1 already installed, it's just not migrated",
|
||||||
cmd("install", "testball2")
|
cmd("install", "testball2")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_install_with_invalid_option
|
||||||
|
setup_test_formula "testball1"
|
||||||
|
assert_match "testball1: this formula has no --with-fo option so it will be ignored!",
|
||||||
|
cmd("install", "testball1", "--with-fo")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user