Keg no longer inherits from Pathname
This commit is contained in:
parent
62b29e7686
commit
de81350b42
@ -3,7 +3,7 @@ require "keg_fix_install_names"
|
|||||||
require "formula_lock"
|
require "formula_lock"
|
||||||
require "ostruct"
|
require "ostruct"
|
||||||
|
|
||||||
class Keg < Pathname
|
class Keg
|
||||||
class AlreadyLinkedError < RuntimeError
|
class AlreadyLinkedError < RuntimeError
|
||||||
def initialize(keg)
|
def initialize(keg)
|
||||||
super <<-EOS.undent
|
super <<-EOS.undent
|
||||||
@ -88,13 +88,14 @@ class Keg < Pathname
|
|||||||
raise NotAKegError, "#{path} is not inside a keg"
|
raise NotAKegError, "#{path} is not inside a keg"
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :name, :linked_keg_record
|
attr_reader :path, :name, :linked_keg_record
|
||||||
|
protected :path
|
||||||
|
|
||||||
def initialize path
|
def initialize path
|
||||||
super path
|
raise "#{path} is not a valid keg" unless path.parent.parent.realpath == HOMEBREW_CELLAR.realpath
|
||||||
raise "#{to_s} is not a valid keg" unless parent.parent.realpath == HOMEBREW_CELLAR.realpath
|
raise "#{path} is not a directory" unless path.directory?
|
||||||
raise "#{to_s} is not a directory" unless directory?
|
@path = path
|
||||||
@name = parent.basename.to_s
|
@name = path.parent.basename.to_s
|
||||||
@linked_keg_record = HOMEBREW_LIBRARY.join("LinkedKegs", name)
|
@linked_keg_record = HOMEBREW_LIBRARY.join("LinkedKegs", name)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -103,12 +104,55 @@ class Keg < Pathname
|
|||||||
name
|
name
|
||||||
end
|
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
|
def uninstall
|
||||||
rmtree
|
path.rmtree
|
||||||
parent.rmdir_if_possible
|
path.parent.rmdir_if_possible
|
||||||
|
|
||||||
opt = HOMEBREW_PREFIX.join("opt", name)
|
opt = HOMEBREW_PREFIX.join("opt", name)
|
||||||
if opt.symlink? && self == opt.resolved_path
|
if opt.symlink? && path == opt.resolved_path
|
||||||
opt.unlink
|
opt.unlink
|
||||||
opt.parent.rmdir_if_possible
|
opt.parent.rmdir_if_possible
|
||||||
end
|
end
|
||||||
@ -119,10 +163,10 @@ class Keg < Pathname
|
|||||||
|
|
||||||
dirs = []
|
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?
|
next unless dir.exist?
|
||||||
dir.find do |src|
|
dir.find do |src|
|
||||||
dst = HOMEBREW_PREFIX + src.relative_path_from(self)
|
dst = HOMEBREW_PREFIX + src.relative_path_from(path)
|
||||||
dst.extend(ObserverPathnameExtension)
|
dst.extend(ObserverPathnameExtension)
|
||||||
|
|
||||||
dirs << dst if dst.directory? && !dst.symlink?
|
dirs << dst if dst.directory? && !dst.symlink?
|
||||||
@ -153,41 +197,36 @@ class Keg < Pathname
|
|||||||
def linked?
|
def linked?
|
||||||
linked_keg_record.symlink? &&
|
linked_keg_record.symlink? &&
|
||||||
linked_keg_record.directory? &&
|
linked_keg_record.directory? &&
|
||||||
self == linked_keg_record.resolved_path
|
path == linked_keg_record.resolved_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def completion_installed? shell
|
def completion_installed? shell
|
||||||
dir = case shell
|
dir = case shell
|
||||||
when :bash then self/'etc/bash_completion.d'
|
when :bash then path.join("etc", "bash_completion.d")
|
||||||
when :zsh then self/'share/zsh/site-functions'
|
when :zsh then path.join("share", "zsh", "site-functions")
|
||||||
end
|
end
|
||||||
return if dir.nil?
|
dir && dir.directory? && dir.children.any?
|
||||||
dir.directory? and not dir.children.length.zero?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def plist_installed?
|
def plist_installed?
|
||||||
Dir["#{self}/*.plist"].any?
|
Dir["#{path}/*.plist"].any?
|
||||||
end
|
end
|
||||||
|
|
||||||
def python_site_packages_installed?
|
def python_site_packages_installed?
|
||||||
(self/'lib/python2.7/site-packages').directory?
|
path.join("lib", "python2.7", "site-packages").directory?
|
||||||
end
|
end
|
||||||
|
|
||||||
def app_installed?
|
def app_installed?
|
||||||
Dir["#{self}/{,libexec/}*.app"].any?
|
Dir["#{path}/{,libexec/}*.app"].any?
|
||||||
end
|
end
|
||||||
|
|
||||||
def version
|
def version
|
||||||
require 'pkg_version'
|
require 'pkg_version'
|
||||||
PkgVersion.parse(basename.to_s)
|
PkgVersion.parse(path.basename.to_s)
|
||||||
end
|
|
||||||
|
|
||||||
def basename
|
|
||||||
Pathname.new(self).basename
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def find(*args, &block)
|
def find(*args, &block)
|
||||||
Pathname.new(self).find(*args, &block)
|
path.find(*args, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def link mode=OpenStruct.new
|
def link mode=OpenStruct.new
|
||||||
@ -250,7 +289,7 @@ class Keg < Pathname
|
|||||||
end
|
end
|
||||||
|
|
||||||
unless mode.dry_run
|
unless mode.dry_run
|
||||||
make_relative_symlink(linked_keg_record, self, mode)
|
make_relative_symlink(linked_keg_record, path, mode)
|
||||||
optlink
|
optlink
|
||||||
end
|
end
|
||||||
rescue LinkError
|
rescue LinkError
|
||||||
@ -269,7 +308,7 @@ class Keg < Pathname
|
|||||||
elsif from.exist?
|
elsif from.exist?
|
||||||
from.delete
|
from.delete
|
||||||
end
|
end
|
||||||
make_relative_symlink(from, self)
|
make_relative_symlink(from, path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_pyc_files!
|
def delete_pyc_files!
|
||||||
@ -332,13 +371,13 @@ class Keg < Pathname
|
|||||||
|
|
||||||
protected
|
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
|
def link_dir relative_dir, mode
|
||||||
root = self+relative_dir
|
root = path+relative_dir
|
||||||
return unless root.exist?
|
return unless root.exist?
|
||||||
root.find do |src|
|
root.find do |src|
|
||||||
next if src == root
|
next if src == root
|
||||||
dst = HOMEBREW_PREFIX+src.relative_path_from(self)
|
dst = HOMEBREW_PREFIX + src.relative_path_from(path)
|
||||||
dst.extend ObserverPathnameExtension
|
dst.extend ObserverPathnameExtension
|
||||||
|
|
||||||
if src.file?
|
if src.file?
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
class Keg < Pathname
|
class Keg
|
||||||
PREFIX_PLACEHOLDER = "@@HOMEBREW_PREFIX@@".freeze
|
PREFIX_PLACEHOLDER = "@@HOMEBREW_PREFIX@@".freeze
|
||||||
CELLAR_PLACEHOLDER = "@@HOMEBREW_CELLAR@@".freeze
|
CELLAR_PLACEHOLDER = "@@HOMEBREW_CELLAR@@".freeze
|
||||||
|
|
||||||
@ -121,7 +121,9 @@ class Keg < Pathname
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def lib; join 'lib' end
|
def lib
|
||||||
|
path.join("lib")
|
||||||
|
end
|
||||||
|
|
||||||
def each_install_name_for file, &block
|
def each_install_name_for file, &block
|
||||||
dylibs = file.dynamically_linked_libraries
|
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 new dylib ID should have the same basename as the old dylib ID, not
|
||||||
# the basename of the file itself.
|
# the basename of the file itself.
|
||||||
basename = File.basename(file.dylib_id)
|
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)
|
shortpath = HOMEBREW_PREFIX.join(relative_dirname, basename)
|
||||||
|
|
||||||
if shortpath.exist? and not options[:keg_only]
|
if shortpath.exist? and not options[:keg_only]
|
||||||
@ -150,7 +152,7 @@ class Keg < Pathname
|
|||||||
def mach_o_files
|
def mach_o_files
|
||||||
mach_o_files = []
|
mach_o_files = []
|
||||||
dirs = %w{bin lib Frameworks}
|
dirs = %w{bin lib Frameworks}
|
||||||
dirs.map! { |dir| join(dir) }
|
dirs.map! { |dir| path.join(dir) }
|
||||||
dirs.reject! { |dir| not dir.directory? }
|
dirs.reject! { |dir| not dir.directory? }
|
||||||
|
|
||||||
dirs.each do |dir|
|
dirs.each do |dir|
|
||||||
@ -179,7 +181,7 @@ class Keg < Pathname
|
|||||||
pkgconfig_files = []
|
pkgconfig_files = []
|
||||||
|
|
||||||
%w[lib share].each do |dir|
|
%w[lib share].each do |dir|
|
||||||
pcdir = join(dir, "pkgconfig")
|
pcdir = path.join(dir, "pkgconfig")
|
||||||
|
|
||||||
pcdir.find do |pn|
|
pcdir.find do |pn|
|
||||||
next if pn.symlink? or pn.directory? or pn.extname != '.pc'
|
next if pn.symlink? or pn.directory? or pn.extname != '.pc'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user