Skip to content
Snippets Groups Projects
Commit a571965d authored by Mike McQuaid's avatar Mike McQuaid
Browse files

formula: make prefix usually return opt_prefix.

Return `opt_prefix` if it exists and `prefix` is not called from within
the same formula's `install` or `post_install` methods. Otherwise, fall
back to the existing functionality.

This avoids the need to use `opt_prefix` etc. everywhere and generally
means we don't expose an implementation detail (i.e. the full Cellar
path) to dependents that have a habit of hard-coding it.
parent b1e27d68
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ module Homebrew
if ARGV.named.empty?
puts HOMEBREW_PREFIX
else
puts ARGV.resolved_formulae.map { |f| f.opt_prefix.exist? ? f.opt_prefix : f.installed_prefix }
puts ARGV.resolved_formulae.map(&:installed_prefix)
end
end
end
......@@ -198,6 +198,7 @@ class Formula
@build = active_spec.build
@pin = FormulaPin.new(self)
@follow_installed_alias = true
@versioned_prefix = false
end
# @private
......@@ -548,9 +549,16 @@ class Formula
end
# The directory in the cellar that the formula is installed to.
# This directory contains the formula's name and version.
# This directory points to {#opt_prefix} if it exists and if #{prefix} is not
# called from within the same formula's {#install} or {#post_install} methods.
# Otherwise, return the full path to the formula's versioned cellar.
def prefix(v = pkg_version)
Pathname.new("#{HOMEBREW_CELLAR}/#{name}/#{v}")
prefix = rack/v
if !@versioned_prefix && prefix.directory? && Keg.new(prefix).optlinked?
opt_prefix
else
prefix
end
end
# Is the formula linked?
......@@ -579,7 +587,7 @@ class Formula
# installed versions of this software
# @private
def rack
prefix.parent
Pathname.new("#{HOMEBREW_CELLAR}/#{name}")
end
# All currently installed prefix directories.
......@@ -994,6 +1002,7 @@ class Formula
# @private
def run_post_install
@versioned_prefix = true
build = self.build
self.build = Tab.for_formula(self)
old_tmpdir = ENV["TMPDIR"]
......@@ -1008,6 +1017,7 @@ class Formula
ENV["TMPDIR"] = old_tmpdir
ENV["TEMP"] = old_temp
ENV["TMP"] = old_tmp
@versioned_prefix = false
end
# Tell the user about any caveats regarding this package.
......@@ -1110,6 +1120,7 @@ class Formula
# where staging is a Mktemp staging context
# @private
def brew
@versioned_prefix = true
stage do |staging|
staging.retain! if ARGV.keep_tmp?
prepare_patches
......@@ -1123,6 +1134,8 @@ class Formula
cp Dir["config.log", "CMakeCache.txt"], logs
end
end
ensure
@versioned_prefix = false
end
# @private
......@@ -1624,6 +1637,7 @@ class Formula
# @private
def run_test
@versioned_prefix = true
old_home = ENV["HOME"]
old_curl_home = ENV["CURL_HOME"]
old_tmpdir = ENV["TMPDIR"]
......@@ -1655,6 +1669,7 @@ class Formula
ENV["TEMP"] = old_temp
ENV["TMP"] = old_tmp
ENV["TERM"] = old_term
@versioned_prefix = false
end
# @private
......
......@@ -546,7 +546,7 @@ class FormulaInstaller
def summary
s = ""
s << "#{Emoji.install_badge} " if Emoji.enabled?
s << "#{formula.prefix}: #{formula.prefix.abv}"
s << "#{formula.prefix.resolved_path}: #{formula.prefix.abv}"
s << ", built in #{pretty_duration build_time}" if build_time
s
end
......
......@@ -147,6 +147,7 @@ class Keg
protected :path
def initialize(path)
path = path.resolved_path if path.to_s.start_with?("#{HOMEBREW_PREFIX}/opt/")
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment