Clean up Tab creation
This commit is contained in:
parent
a3daca1b13
commit
d8a83073ff
@ -243,7 +243,7 @@ class FormulaInstaller
|
|||||||
|
|
||||||
raise "Empty installation" if Dir["#{f.prefix}/*"].empty?
|
raise "Empty installation" if Dir["#{f.prefix}/*"].empty?
|
||||||
|
|
||||||
Tab.for_install(f, args).write # INSTALL_RECEIPT.json
|
Tab.create(f, args).write # INSTALL_RECEIPT.json
|
||||||
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
ignore_interrupts do
|
ignore_interrupts do
|
||||||
|
|||||||
@ -1,18 +1,22 @@
|
|||||||
require 'ostruct'
|
require 'ostruct'
|
||||||
|
|
||||||
require 'formula'
|
require 'formula'
|
||||||
require 'vendor/multi_json'
|
require 'vendor/multi_json'
|
||||||
|
|
||||||
# Inherit from OpenStruct to gain a generic initialization method that takes a
|
# 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
|
# 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
|
# should not be called directly, instead use one of the class methods like
|
||||||
# `Tab.for_install`.
|
# `Tab.create`.
|
||||||
class Tab < OpenStruct
|
class Tab < OpenStruct
|
||||||
def self.for_install f, args
|
FILENAME = 'INSTALL_RECEIPT.json'
|
||||||
sha = `cd '#{HOMEBREW_REPOSITORY}' && git rev-parse --verify -q HEAD 2>/dev/null`.chuzzle
|
|
||||||
|
def self.create f, args
|
||||||
|
sha = HOMEBREW_REPOSITORY.cd do
|
||||||
|
`git rev-parse --verify -q HEAD 2>/dev/null`.chuzzle
|
||||||
|
end
|
||||||
|
|
||||||
Tab.new :used_options => args.used_options(f),
|
Tab.new :used_options => args.used_options(f),
|
||||||
:unused_options => args.unused_options(f),
|
:unused_options => args.unused_options(f),
|
||||||
:tabfile => f.prefix + "INSTALL_RECEIPT.json",
|
:tabfile => f.prefix.join(FILENAME),
|
||||||
:built_as_bottle => !!args.build_bottle?,
|
:built_as_bottle => !!args.build_bottle?,
|
||||||
:tapped_from => f.tap,
|
:tapped_from => f.tap,
|
||||||
:time => Time.now.to_i, # to_s would be better but Ruby has no from_s function :P
|
:time => Time.now.to_i, # to_s would be better but Ruby has no from_s function :P
|
||||||
@ -22,50 +26,29 @@ class Tab < OpenStruct
|
|||||||
def self.from_file path
|
def self.from_file path
|
||||||
tab = Tab.new MultiJson.decode(open(path).read)
|
tab = Tab.new MultiJson.decode(open(path).read)
|
||||||
tab.tabfile = path
|
tab.tabfile = path
|
||||||
return tab
|
tab
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.for_keg keg
|
def self.for_keg keg
|
||||||
path = keg+'INSTALL_RECEIPT.json'
|
path = keg.join(FILENAME)
|
||||||
|
|
||||||
if path.exist?
|
if path.exist?
|
||||||
self.from_file path
|
self.from_file(path)
|
||||||
else
|
else
|
||||||
begin
|
self.dummy_tab
|
||||||
self.dummy_tab Formula.factory(keg.parent.basename)
|
|
||||||
rescue FormulaUnavailableError
|
|
||||||
Tab.new :used_options => [],
|
|
||||||
:unused_options => [],
|
|
||||||
:built_as_bottle => false,
|
|
||||||
:tapped_from => "",
|
|
||||||
:time => nil,
|
|
||||||
:HEAD => nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.for_formula f
|
def self.for_formula f
|
||||||
f = Formula.factory f unless f.kind_of? Formula
|
f = Formula.factory(f)
|
||||||
path = f.linked_keg/'INSTALL_RECEIPT.json'
|
path = [f.opt_prefix, f.linked_keg].map{ |pn| pn.join(FILENAME) }.find{ |pn| pn.exist? }
|
||||||
|
# Legacy kegs may lack a receipt. If it doesn't exist, fake one
|
||||||
if path.exist?
|
if path.nil? then self.dummy_tab(f) else self.from_file(path) end
|
||||||
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.
|
|
||||||
self.dummy_tab f
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.dummy_tab f
|
def self.dummy_tab f=nil
|
||||||
Tab.new :used_options => [],
|
Tab.new :used_options => [],
|
||||||
:unused_options => f.build.as_flags,
|
:unused_options => (f.build.as_flags rescue []),
|
||||||
:built_as_bottle => false,
|
:built_as_bottle => false,
|
||||||
:tapped_from => "",
|
:tapped_from => "",
|
||||||
:time => nil,
|
:time => nil,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user