aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/build_options.rb
diff options
context:
space:
mode:
authorSamuel John2013-06-13 15:52:23 +0200
committerSamuel John2013-09-05 15:26:57 +0200
commit59a0c1e1b5604ab198e9694df030cd855b5ccbd6 (patch)
treee2d9642f20b4d0c3557877b822202402da6921fe /Library/Homebrew/build_options.rb
parent6ae2e872d3154815de5137844d284a009c411d5b (diff)
downloadbrew-59a0c1e1b5604ab198e9694df030cd855b5ccbd6.tar.bz2
Improve python tests for brew bots
Allow `build.with?` and similar methods to be used during the test phase. The BuildOptions (`build`) are initialized with the `Tab.used_options` unless explicitly overwritten on the command line. So basically `build.with?` works in `def install` and in `test do` as one would naively expect. (For the test, gramatically it should be `built.with?` but who cares) If a formula was installed `--with-python`, now the tests are also run `--with-python`. This enables us to use the `python do ... end` in a meaningful manner. Using `python do ... end` blocks for the tests, because the bot.brew.sh has system python per default and we need to set the PYTHONPATH for the test. Potentially to different values for Python 2.x and 3.x.
Diffstat (limited to 'Library/Homebrew/build_options.rb')
-rw-r--r--Library/Homebrew/build_options.rb25
1 files changed, 19 insertions, 6 deletions
diff --git a/Library/Homebrew/build_options.rb b/Library/Homebrew/build_options.rb
index 0cd3a5a46..441a81bc2 100644
--- a/Library/Homebrew/build_options.rb
+++ b/Library/Homebrew/build_options.rb
@@ -100,13 +100,26 @@ class BuildOptions
# implicit_options are needed because `depends_on 'spam' => 'with-stuff'`
# complains if 'spam' has stuff as default and only defines `--without-stuff`.
def implicit_options
- implicit = unused_options.map do |o|
- if o.name =~ /^with-(.+)$/ && without?($1)
- Option.new("without-#{$1}") # we lose the description, but that's ok
- elsif o.name =~ /^without-(.+)$/ && with?($1)
- Option.new("with-#{$1}")
- end
+ implicit = unused_options.map do |option|
+ opposite_of option unless has_opposite_of? option
end.compact
Options.new(implicit)
end
+
+ def has_opposite_of? option
+ true if args.include? opposite_of option
+ end
+
+ def opposite_of option
+ option = Option.new option
+ if option.name =~ /^with-(.+)$/
+ Option.new("without-#{$1}")
+ elsif option.name =~ /^without-(.+)$/
+ Option.new("with-#{$1}")
+ elsif option.name =~ /^enable-(.+)$/
+ Option.new("disable-#{$1}")
+ elsif option.name =~ /^disable-(.+)$/
+ Option.new("enable-#{$1}")
+ end
+ end
end