2013-07-27 00:11:45 -07:00
|
|
|
require 'cxxstdlib'
|
2011-09-22 20:07:39 -07:00
|
|
|
require 'ostruct'
|
2013-01-23 00:26:23 -06:00
|
|
|
require 'options'
|
2013-06-22 16:51:08 -05:00
|
|
|
require 'utils/json'
|
2011-09-22 20:07:39 -07:00
|
|
|
|
|
|
|
# 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
|
2013-01-23 00:26:20 -06:00
|
|
|
# `Tab.create`.
|
2011-09-22 20:07:39 -07:00
|
|
|
class Tab < OpenStruct
|
2013-01-23 00:26:20 -06:00
|
|
|
FILENAME = 'INSTALL_RECEIPT.json'
|
|
|
|
|
2014-07-30 20:27:46 -05:00
|
|
|
def self.create(formula, compiler, stdlib, build)
|
2014-03-02 20:35:41 -06:00
|
|
|
Tab.new :used_options => build.used_options,
|
|
|
|
:unused_options => build.unused_options,
|
2014-07-30 20:27:46 -05:00
|
|
|
:tabfile => formula.prefix.join(FILENAME),
|
2013-01-23 00:26:20 -06:00
|
|
|
:built_as_bottle => !!ARGV.build_bottle?,
|
2013-03-15 00:28:18 +00:00
|
|
|
:poured_from_bottle => false,
|
2014-07-30 20:27:46 -05:00
|
|
|
:tapped_from => formula.tap,
|
2014-03-22 13:16:16 -05:00
|
|
|
:time => Time.now.to_i,
|
2014-06-30 19:15:03 -05:00
|
|
|
:HEAD => Homebrew.git_head,
|
2013-10-22 22:21:59 -07:00
|
|
|
:compiler => compiler,
|
|
|
|
:stdlib => stdlib
|
2011-09-22 20:07:39 -07:00
|
|
|
end
|
|
|
|
|
2011-09-23 08:36:40 -07:00
|
|
|
def self.from_file path
|
2014-06-29 23:15:13 -05:00
|
|
|
attributes = Utils::JSON.load(File.read(path))
|
|
|
|
attributes[:tabfile] = path
|
|
|
|
new(attributes)
|
2011-09-23 08:36:40 -07:00
|
|
|
end
|
|
|
|
|
2012-01-01 15:22:36 -06:00
|
|
|
def self.for_keg keg
|
2013-01-23 00:26:20 -06:00
|
|
|
path = keg.join(FILENAME)
|
2012-01-01 15:22:36 -06:00
|
|
|
|
|
|
|
if path.exist?
|
2014-06-29 22:26:14 -05:00
|
|
|
from_file(path)
|
2012-01-01 15:22:36 -06:00
|
|
|
else
|
2014-06-29 22:26:14 -05:00
|
|
|
dummy_tab
|
2012-01-01 15:22:36 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-26 10:37:09 -07:00
|
|
|
def self.for_name name
|
2014-06-22 15:00:15 -05:00
|
|
|
for_formula(Formulary.factory(name))
|
2013-06-26 10:37:09 -07:00
|
|
|
end
|
|
|
|
|
2011-09-23 08:36:40 -07:00
|
|
|
def self.for_formula f
|
2014-06-29 19:19:24 -05:00
|
|
|
paths = []
|
|
|
|
|
|
|
|
if f.opt_prefix.symlink? && f.opt_prefix.directory?
|
|
|
|
paths << f.opt_prefix.resolved_path
|
|
|
|
end
|
|
|
|
|
|
|
|
if f.linked_keg.symlink? && f.linked_keg.directory?
|
|
|
|
paths << f.linked_keg.resolved_path
|
|
|
|
end
|
2014-03-22 11:34:26 -05:00
|
|
|
|
|
|
|
if f.rack.directory? && (dirs = f.rack.subdirs).length == 1
|
|
|
|
paths << dirs.first
|
|
|
|
end
|
|
|
|
|
|
|
|
paths << f.prefix
|
|
|
|
|
|
|
|
path = paths.map { |pn| pn.join(FILENAME) }.find(&:file?)
|
|
|
|
|
|
|
|
if path
|
|
|
|
from_file(path)
|
|
|
|
else
|
|
|
|
dummy_tab(f)
|
|
|
|
end
|
2011-09-23 08:36:40 -07:00
|
|
|
end
|
|
|
|
|
2013-01-23 00:26:20 -06:00
|
|
|
def self.dummy_tab f=nil
|
2012-01-01 15:22:36 -06:00
|
|
|
Tab.new :used_options => [],
|
2013-01-23 00:26:20 -06:00
|
|
|
:unused_options => (f.build.as_flags rescue []),
|
2012-08-25 11:31:57 -07:00
|
|
|
:built_as_bottle => false,
|
2013-03-15 00:28:18 +00:00
|
|
|
:poured_from_bottle => false,
|
2012-08-10 16:06:51 -04:00
|
|
|
:tapped_from => "",
|
|
|
|
:time => nil,
|
2013-07-27 00:11:45 -07:00
|
|
|
:HEAD => nil,
|
2014-06-29 00:56:29 -05:00
|
|
|
:stdlib => nil,
|
2013-07-27 00:11:45 -07:00
|
|
|
:compiler => :clang
|
2012-01-01 15:22:36 -06:00
|
|
|
end
|
|
|
|
|
2013-01-23 00:26:24 -06:00
|
|
|
def with? name
|
|
|
|
if options.include? "with-#{name}"
|
|
|
|
used_options.include? "with-#{name}"
|
|
|
|
elsif options.include? "without-#{name}"
|
|
|
|
not used_options.include? "without-#{name}"
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-30 21:04:17 -05:00
|
|
|
def without? name
|
|
|
|
not with? name
|
|
|
|
end
|
|
|
|
|
2013-01-23 00:26:24 -06:00
|
|
|
def include? opt
|
2011-09-23 08:36:40 -07:00
|
|
|
used_options.include? opt
|
|
|
|
end
|
|
|
|
|
2013-01-23 00:26:24 -06:00
|
|
|
def universal?
|
|
|
|
used_options.include? "universal"
|
|
|
|
end
|
|
|
|
|
2013-01-23 00:26:23 -06:00
|
|
|
def used_options
|
2013-01-23 00:26:28 -06:00
|
|
|
Options.coerce(super)
|
2013-01-23 00:26:23 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def unused_options
|
2013-01-23 00:26:28 -06:00
|
|
|
Options.coerce(super)
|
2013-01-23 00:26:23 -06:00
|
|
|
end
|
|
|
|
|
2011-09-23 08:36:40 -07:00
|
|
|
def options
|
|
|
|
used_options + unused_options
|
|
|
|
end
|
|
|
|
|
2013-07-27 00:11:45 -07:00
|
|
|
def cxxstdlib
|
|
|
|
# Older tabs won't have these values, so provide sensible defaults
|
2013-10-07 00:25:26 -07:00
|
|
|
lib = stdlib.to_sym if stdlib
|
2013-07-27 00:11:45 -07:00
|
|
|
cc = compiler || MacOS.default_compiler
|
2014-08-02 19:29:59 -05:00
|
|
|
CxxStdlib.create(lib, cc.to_sym)
|
2013-07-27 00:11:45 -07:00
|
|
|
end
|
|
|
|
|
2011-09-22 20:07:39 -07:00
|
|
|
def to_json
|
2013-06-22 16:51:08 -05:00
|
|
|
Utils::JSON.dump({
|
2013-06-22 16:51:09 -05:00
|
|
|
:used_options => used_options.map(&:to_s),
|
|
|
|
:unused_options => unused_options.map(&:to_s),
|
2012-08-25 11:31:57 -07:00
|
|
|
:built_as_bottle => built_as_bottle,
|
2013-03-15 00:28:18 +00:00
|
|
|
:poured_from_bottle => poured_from_bottle,
|
2012-08-10 16:06:51 -04:00
|
|
|
:tapped_from => tapped_from,
|
|
|
|
:time => time,
|
2014-03-22 13:16:16 -05:00
|
|
|
:HEAD => self.HEAD,
|
2013-07-27 00:11:45 -07:00
|
|
|
:stdlib => (stdlib.to_s if stdlib),
|
|
|
|
:compiler => (compiler.to_s if compiler)})
|
2011-09-22 20:07:39 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def write
|
2014-03-22 11:13:33 -05:00
|
|
|
tabfile.atomic_write(to_json)
|
2011-09-22 20:07:39 -07:00
|
|
|
end
|
2013-03-27 23:07:25 -05:00
|
|
|
|
|
|
|
def to_s
|
|
|
|
s = []
|
|
|
|
case poured_from_bottle
|
|
|
|
when true then s << "Poured from bottle"
|
|
|
|
when false then s << "Built from source"
|
|
|
|
end
|
|
|
|
unless used_options.empty?
|
|
|
|
s << "Installed" if s.empty?
|
|
|
|
s << "with:"
|
|
|
|
s << used_options.to_a.join(", ")
|
|
|
|
end
|
|
|
|
s.join(" ")
|
|
|
|
end
|
2011-09-22 20:07:39 -07:00
|
|
|
end
|