Keg no longer inherits from Pathname

This commit is contained in:
Jack Nagel 2014-06-26 19:06:31 -05:00
parent 62b29e7686
commit de81350b42
2 changed files with 77 additions and 36 deletions

View File

@ -3,7 +3,7 @@ require "keg_fix_install_names"
require "formula_lock"
require "ostruct"
class Keg < Pathname
class Keg
class AlreadyLinkedError < RuntimeError
def initialize(keg)
super <<-EOS.undent
@ -88,13 +88,14 @@ class Keg < Pathname
raise NotAKegError, "#{path} is not inside a keg"
end
attr_reader :name, :linked_keg_record
attr_reader :path, :name, :linked_keg_record
protected :path
def initialize path
super path
raise "#{to_s} is not a valid keg" unless parent.parent.realpath == HOMEBREW_CELLAR.realpath
raise "#{to_s} is not a directory" unless directory?
@name = parent.basename.to_s
raise "#{path} is not a valid keg" unless path.parent.parent.realpath == HOMEBREW_CELLAR.realpath
raise "#{path} is not a directory" unless path.directory?
@path = path
@name = path.parent.basename.to_s
@linked_keg_record = HOMEBREW_LIBRARY.join("LinkedKegs", name)
end
@ -103,12 +104,55 @@ class Keg < Pathname
name
end
def to_s
path.to_s
end
if Pathname.method_defined?(:to_path)
alias_method :to_path, :to_s
else
alias_method :to_str, :to_s
end
def inspect
"#<#{self.class.name}:#{path}>"
end
def ==(other)
instance_of?(other.class) && path == other.path
end
alias_method :eql?, :==
def hash
path.hash
end
def abv
path.abv
end
def exist?
path.exist?
end
def /(other)
path / other
end
def join(*args)
path.join(*args)
end
def rename(*args)
path.rename(*args)
end
def uninstall
rmtree
parent.rmdir_if_possible
path.rmtree
path.parent.rmdir_if_possible
opt = HOMEBREW_PREFIX.join("opt", name)
if opt.symlink? && self == opt.resolved_path
if opt.symlink? && path == opt.resolved_path
opt.unlink
opt.parent.rmdir_if_possible
end
@ -119,10 +163,10 @@ class Keg < Pathname
dirs = []
TOP_LEVEL_DIRECTORIES.map{ |d| self/d }.each do |dir|
TOP_LEVEL_DIRECTORIES.map{ |d| path.join(d) }.each do |dir|
next unless dir.exist?
dir.find do |src|
dst = HOMEBREW_PREFIX + src.relative_path_from(self)
dst = HOMEBREW_PREFIX + src.relative_path_from(path)
dst.extend(ObserverPathnameExtension)
dirs << dst if dst.directory? && !dst.symlink?
@ -153,41 +197,36 @@ class Keg < Pathname
def linked?
linked_keg_record.symlink? &&
linked_keg_record.directory? &&
self == linked_keg_record.resolved_path
path == linked_keg_record.resolved_path
end
def completion_installed? shell
dir = case shell
when :bash then self/'etc/bash_completion.d'
when :zsh then self/'share/zsh/site-functions'
when :bash then path.join("etc", "bash_completion.d")
when :zsh then path.join("share", "zsh", "site-functions")
end
return if dir.nil?
dir.directory? and not dir.children.length.zero?
dir && dir.directory? && dir.children.any?
end
def plist_installed?
Dir["#{self}/*.plist"].any?
Dir["#{path}/*.plist"].any?
end
def python_site_packages_installed?
(self/'lib/python2.7/site-packages').directory?
path.join("lib", "python2.7", "site-packages").directory?
end
def app_installed?
Dir["#{self}/{,libexec/}*.app"].any?
Dir["#{path}/{,libexec/}*.app"].any?
end
def version
require 'pkg_version'
PkgVersion.parse(basename.to_s)
end
def basename
Pathname.new(self).basename
PkgVersion.parse(path.basename.to_s)
end
def find(*args, &block)
Pathname.new(self).find(*args, &block)
path.find(*args, &block)
end
def link mode=OpenStruct.new
@ -250,7 +289,7 @@ class Keg < Pathname
end
unless mode.dry_run
make_relative_symlink(linked_keg_record, self, mode)
make_relative_symlink(linked_keg_record, path, mode)
optlink
end
rescue LinkError
@ -269,7 +308,7 @@ class Keg < Pathname
elsif from.exist?
from.delete
end
make_relative_symlink(from, self)
make_relative_symlink(from, path)
end
def delete_pyc_files!
@ -332,13 +371,13 @@ class Keg < Pathname
protected
# symlinks the contents of self+relative_dir recursively into #{HOMEBREW_PREFIX}/relative_dir
# symlinks the contents of path+relative_dir recursively into #{HOMEBREW_PREFIX}/relative_dir
def link_dir relative_dir, mode
root = self+relative_dir
root = path+relative_dir
return unless root.exist?
root.find do |src|
next if src == root
dst = HOMEBREW_PREFIX+src.relative_path_from(self)
dst = HOMEBREW_PREFIX + src.relative_path_from(path)
dst.extend ObserverPathnameExtension
if src.file?

View File

@ -1,4 +1,4 @@
class Keg < Pathname
class Keg
PREFIX_PLACEHOLDER = "@@HOMEBREW_PREFIX@@".freeze
CELLAR_PLACEHOLDER = "@@HOMEBREW_CELLAR@@".freeze
@ -121,7 +121,9 @@ class Keg < Pathname
end
end
def lib; join 'lib' end
def lib
path.join("lib")
end
def each_install_name_for file, &block
dylibs = file.dynamically_linked_libraries
@ -133,7 +135,7 @@ class Keg < Pathname
# The new dylib ID should have the same basename as the old dylib ID, not
# the basename of the file itself.
basename = File.basename(file.dylib_id)
relative_dirname = file.dirname.relative_path_from(self)
relative_dirname = file.dirname.relative_path_from(path)
shortpath = HOMEBREW_PREFIX.join(relative_dirname, basename)
if shortpath.exist? and not options[:keg_only]
@ -150,7 +152,7 @@ class Keg < Pathname
def mach_o_files
mach_o_files = []
dirs = %w{bin lib Frameworks}
dirs.map! { |dir| join(dir) }
dirs.map! { |dir| path.join(dir) }
dirs.reject! { |dir| not dir.directory? }
dirs.each do |dir|
@ -179,7 +181,7 @@ class Keg < Pathname
pkgconfig_files = []
%w[lib share].each do |dir|
pcdir = join(dir, "pkgconfig")
pcdir = path.join(dir, "pkgconfig")
pcdir.find do |pn|
next if pn.symlink? or pn.directory? or pn.extname != '.pc'