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.
This commit is contained in:
parent
1d1cd374b3
commit
028104b861
@ -2,6 +2,7 @@ require 'exceptions'
|
|||||||
require 'formula'
|
require 'formula'
|
||||||
require 'keg'
|
require 'keg'
|
||||||
require 'set'
|
require 'set'
|
||||||
|
require 'tab'
|
||||||
|
|
||||||
class FormulaInstaller
|
class FormulaInstaller
|
||||||
attr :f
|
attr :f
|
||||||
@ -128,6 +129,9 @@ class FormulaInstaller
|
|||||||
data = read.read
|
data = read.read
|
||||||
raise Marshal.load(data) unless data.nil? or data.empty?
|
raise Marshal.load(data) unless data.nil? or data.empty?
|
||||||
raise "Suspicious installation failure" unless $?.success?
|
raise "Suspicious installation failure" unless $?.success?
|
||||||
|
|
||||||
|
# Write an installation receipt (a Tab) to the prefix
|
||||||
|
Tab.for_install(f, args).write
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
33
Library/Homebrew/tab.rb
Normal file
33
Library/Homebrew/tab.rb
Normal file
@ -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
|
||||||
1
bin/brew
1
bin/brew
@ -5,6 +5,7 @@ HOMEBREW_BREW_FILE = ENV['HOMEBREW_BREW_FILE'] = File.expand_path(__FILE__)
|
|||||||
|
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.dirname.parent.join("Library/Homebrew").to_s
|
HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.dirname.parent.join("Library/Homebrew").to_s
|
||||||
|
$:.unshift(HOMEBREW_LIBRARY_PATH + '/vendor')
|
||||||
$:.unshift(HOMEBREW_LIBRARY_PATH)
|
$:.unshift(HOMEBREW_LIBRARY_PATH)
|
||||||
require 'global'
|
require 'global'
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user