Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Invalid build option warnings - supersedes #1088 #1217

Merged
merged 5 commits into from
Nov 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Library/Homebrew/build_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ def unused_options
@options - @args
end

# @private
def invalid_options
@args - @options
end

# @private
def invalid_option_names
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this @private too, thanks!

invalid_options.map(&:flag).sort
end

private

def option_defined?(name)
Expand Down
24 changes: 13 additions & 11 deletions Library/Homebrew/cmd/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,21 @@ def perform_preinstall_checks

def install_formula(f)
f.print_tap_action
build_options = f.build

fi = FormulaInstaller.new(f)
fi.options = f.build.used_options
fi.ignore_deps = ARGV.ignore_deps?
fi.only_deps = ARGV.only_deps?
fi.build_bottle = ARGV.build_bottle?
fi.build_from_source = ARGV.build_from_source? || ARGV.build_all_from_source?
fi.force_bottle = ARGV.force_bottle?
fi.interactive = ARGV.interactive?
fi.git = ARGV.git?
fi.verbose = ARGV.verbose?
fi.quieter = ARGV.quieter?
fi.debug = ARGV.debug?
fi.options = build_options.used_options
fi.invalid_option_names = build_options.invalid_option_names
fi.ignore_deps = ARGV.ignore_deps?
fi.only_deps = ARGV.only_deps?
fi.build_bottle = ARGV.build_bottle?
fi.build_from_source = ARGV.build_from_source? || ARGV.build_all_from_source?
fi.force_bottle = ARGV.force_bottle?
fi.interactive = ARGV.interactive?
fi.git = ARGV.git?
fi.verbose = ARGV.verbose?
fi.quieter = ARGV.quieter?
fi.debug = ARGV.debug?
fi.prelude
fi.install
fi.finish
Expand Down
7 changes: 6 additions & 1 deletion Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def self.mode_attr_accessor(*names)
end

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 :build_from_source, :force_bottle
mode_attr_accessor :ignore_deps, :only_deps, :interactive, :git
Expand All @@ -52,6 +52,7 @@ def initialize(formula)
@quieter = false
@debug = false
@options = Options.new
@invalid_option_names = []

@@attempted ||= Set.new

Expand Down Expand Up @@ -214,6 +215,10 @@ def install
opoo "#{formula.full_name}: #{old_flag} was deprecated; using #{new_flag} instead!"
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?

if formula.tap && !formula.tap.private?
Expand Down
15 changes: 15 additions & 0 deletions Library/Homebrew/test/test_build_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def setup
args = Options.create(%w[--with-foo --with-bar --without-qux])
opts = Options.create(%w[--with-foo --with-bar --without-baz --without-qux])
@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

def test_include
Expand All @@ -31,4 +33,17 @@ def test_used_options
def test_unused_options
assert_includes @build.unused_options, "--without-baz"
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
1 change: 1 addition & 0 deletions Library/Homebrew/test/test_formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def temporary_install(formula)
end

def test_a_basic_install
ARGV << "--with-invalid_flag" # added to ensure it doesn't fail install
temporary_install(Testball.new) do |f|
# Test that things made it into the Keg
assert_predicate f.prefix+"readme", :exist?
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/test/test_install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ def test_install
assert_match "testball1 already installed, it's just not migrated",
cmd("install", "testball2")
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