From 028104b861b2723a41bfeac011f6720ea7298179 Mon Sep 17 00:00:00 2001 From: Charlie Sharpsteen Date: Thu, 22 Sep 2011 20:07:39 -0700 Subject: [PATCH] metadata: Record installation options Adds a new class called `Tab` that acts as a recipt for install options. A `Tab` can be serialized to a JSON file for future reference. --- Library/Homebrew/formula_installer.rb | 4 ++++ Library/Homebrew/tab.rb | 33 +++++++++++++++++++++++++++ bin/brew | 1 + 3 files changed, 38 insertions(+) create mode 100644 Library/Homebrew/tab.rb diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index d250f16d27..e30b4f98a8 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -2,6 +2,7 @@ require 'exceptions' require 'formula' require 'keg' require 'set' +require 'tab' class FormulaInstaller attr :f @@ -128,6 +129,9 @@ class FormulaInstaller data = read.read raise Marshal.load(data) unless data.nil? or data.empty? raise "Suspicious installation failure" unless $?.success? + + # Write an installation receipt (a Tab) to the prefix + Tab.for_install(f, args).write end end diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb new file mode 100644 index 0000000000..15f8522c1f --- /dev/null +++ b/Library/Homebrew/tab.rb @@ -0,0 +1,33 @@ +require 'ostruct' + +require 'formula' +require 'vendor/multi_json' + +# Inherit from OpenStruct to gain a generic initialization method that takes a +# hash and creates an attribute for each key and value. `Tab.new` probably +# should not be called directly, instead use one of the class methods like +# `Tab.for_install`. +class Tab < OpenStruct + def self.for_install f, args + # Retrieve option flags from command line. + arg_options = args.options_only + # Pick off the option flags from the formula's `options` array by + # discarding the descriptions. + formula_options = f.options.map { |o, _| o } + + Tab.new :used_options => formula_options & arg_options, + :unused_options => formula_options - arg_options, + :tabfile => f.prefix + 'INSTALL_RECEIPT.json' + end + + def to_json + MultiJson.encode({ + :used_options => used_options, + :unused_options => unused_options + }) + end + + def write + tabfile.write to_json + end +end diff --git a/bin/brew b/bin/brew index cc76f78f9b..e3539c4ae0 100755 --- a/bin/brew +++ b/bin/brew @@ -5,6 +5,7 @@ HOMEBREW_BREW_FILE = ENV['HOMEBREW_BREW_FILE'] = File.expand_path(__FILE__) require 'pathname' HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.dirname.parent.join("Library/Homebrew").to_s +$:.unshift(HOMEBREW_LIBRARY_PATH + '/vendor') $:.unshift(HOMEBREW_LIBRARY_PATH) require 'global'