aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharlie Sharpsteen2011-09-23 08:36:40 -0700
committerCharlie Sharpsteen2011-11-13 12:14:56 -0800
commitec1c7aaa38d7a41ac872f27bb67fc855721346d9 (patch)
treec6ee52e6fbc3bbecdcb642a07d56dcaff694a564
parent028104b861b2723a41bfeac011f6720ea7298179 (diff)
downloadbrew-ec1c7aaa38d7a41ac872f27bb67fc855721346d9.tar.bz2
metadata: Use options from previous installs
FormulaInstaller now loads the install recipt of a previous install and appends the `used_options` to ARGV before forking to build. This means `brew upgrade` will "remember" which options were invoked for the last install and re-use them. Fixes Homebrew/homebrew#5250.
-rw-r--r--Library/Homebrew/formula_installer.rb4
-rw-r--r--Library/Homebrew/tab.rb35
2 files changed, 38 insertions, 1 deletions
diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb
index e30b4f98a..537cbd317 100644
--- a/Library/Homebrew/formula_installer.rb
+++ b/Library/Homebrew/formula_installer.rb
@@ -248,9 +248,11 @@ class FormulaInstaller
# Did the user actually pass the formula this installer is considering on
# the command line?
def explicitly_requested?; ARGV.formulae.include? f end
+ previous_install = Tab.for_formula f
args = ARGV.clone
- args.uniq! # Just in case someone was playing around...
+ args.concat previous_install.used_options
+ args.uniq! # Just in case some dupes were added
%w[--HEAD --verbose -v --debug -d --interactive -i].each {|f| args.delete f} unless explicitly_requested?
diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb
index 15f8522c1..9eb9a34a9 100644
--- a/Library/Homebrew/tab.rb
+++ b/Library/Homebrew/tab.rb
@@ -20,6 +20,41 @@ class Tab < OpenStruct
:tabfile => f.prefix + 'INSTALL_RECEIPT.json'
end
+ def self.from_file path
+ tab = Tab.new MultiJson.decode(open(path).read)
+ tab.tabfile = path
+
+ return tab
+ end
+
+ def self.for_formula f
+ f = Formula.factory f unless f.kind_of? Formula
+ path = HOMEBREW_REPOSITORY + 'Library' + 'LinkedKegs' + f.name + 'INSTALL_RECEIPT.json'
+
+ if path.exist?
+ self.from_file path
+ else
+ # Really should bail out with an error if a formula was not installed
+ # with a Tab. However, there will be lots of legacy installs that have no
+ # receipt---so we fabricate one that claims the formula was installed with
+ # no options.
+ #
+ # TODO:
+ # This isn't the best behavior---perhaps a future version of Homebrew can
+ # treat missing Tabs as errors.
+ Tab.new :used_options => [],
+ :unused_options => f.options.map { |o, _| o}
+ end
+ end
+
+ def installed_with? opt
+ used_options.include? opt
+ end
+
+ def options
+ used_options + unused_options
+ end
+
def to_json
MultiJson.encode({
:used_options => used_options,