From ec1c7aaa38d7a41ac872f27bb67fc855721346d9 Mon Sep 17 00:00:00 2001 From: Charlie Sharpsteen Date: Fri, 23 Sep 2011 08:36:40 -0700 Subject: [PATCH] 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. --- Library/Homebrew/formula_installer.rb | 4 ++- Library/Homebrew/tab.rb | 35 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index e30b4f98a8..537cbd3176 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 15f8522c1f..9eb9a34a95 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,