diff options
| author | Charlie Sharpsteen | 2011-09-22 20:07:39 -0700 |
|---|---|---|
| committer | Charlie Sharpsteen | 2011-11-13 12:14:56 -0800 |
| commit | 9e773c334469bf64cb9379b1f5dbc018d2d19364 (patch) | |
| tree | 9d3c2903fcb33e80c2dc2c6b3ba4b345fcb8ee78 /Library | |
| parent | 605dedb816f0ed2f7e3d49138b869686c8401e6d (diff) | |
| download | homebrew-9e773c334469bf64cb9379b1f5dbc018d2d19364.tar.bz2 | |
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.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/formula_installer.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/tab.rb | 33 |
2 files changed, 37 insertions, 0 deletions
diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index d250f16d2..e30b4f98a 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 000000000..15f8522c1 --- /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 |
