aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorAlyssa Ross2016-09-14 23:18:55 +0100
committerAlyssa Ross2016-09-18 19:45:52 +0100
commit3d559fa79641735193636cbf6240c082e6ca171c (patch)
treeffe3bb75f9c9bafa9dede1c568aec57dcc038b5d /Library
parentf4a8d28819f1fee73fcc63d08e70cb36eecdfb20 (diff)
downloadbrew-3d559fa79641735193636cbf6240c082e6ca171c.tar.bz2
Add Formula#installed_alias_path
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/formula.rb16
-rw-r--r--Library/Homebrew/test/test_formula.rb26
2 files changed, 38 insertions, 4 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 599b49392..f2da6fbc8 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -60,7 +60,7 @@ class Formula
# e.g. `this-formula`
attr_reader :name
- # The name specified when installing this {Formula}.
+ # The name that was used to identify this {Formula}.
# Could be the name of the {Formula}, or an alias.
# e.g. `another-name-for-this-formula`
attr_reader :alias_path
@@ -228,7 +228,15 @@ class Formula
public
- # The path that was specified to find/install this formula.
+ # The alias path that was used to install this formula, if present.
+ # Can differ from alias_path, which is the alias used to find the formula,
+ # and is specified to this instance.
+ def installed_alias_path
+ path = build.source["path"] if build.is_a?(Tab)
+ path if path =~ %r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases}
+ end
+
+ # The path that was specified to find this formula.
def specified_path
alias_path || path
end
@@ -503,13 +511,13 @@ class Formula
prefix.parent
end
- # All of current installed prefix directories.
+ # All currently installed prefix directories.
# @private
def installed_prefixes
rack.directory? ? rack.subdirs : []
end
- # All of current installed kegs.
+ # All currently installed kegs.
# @private
def installed_kegs
installed_prefixes.map { |dir| Keg.new(dir) }
diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb
index 7c09e765f..2eb64ebb6 100644
--- a/Library/Homebrew/test/test_formula.rb
+++ b/Library/Homebrew/test/test_formula.rb
@@ -248,6 +248,32 @@ class FormulaTests < Homebrew::TestCase
assert_nil Testball.new <=> Object.new
end
+ def test_alias_paths_with_build_options
+ alias_path = CoreTap.instance.alias_dir/"another_name"
+ f = formula(:alias_path => alias_path) { url "foo-1.0" }
+ f.build = BuildOptions.new({}, {})
+ assert_equal alias_path, f.alias_path
+ assert_nil f.installed_alias_path
+ end
+
+ def test_alias_paths_with_tab_with_non_alias_source_path
+ alias_path = CoreTap.instance.alias_dir/"another_name"
+ source_path = CoreTap.instance.formula_dir/"another_other_name"
+ f = formula(:alias_path => alias_path) { url "foo-1.0" }
+ f.build = Tab.new(:source => { "path" => source_path.to_s })
+ assert_equal alias_path, f.alias_path
+ assert_nil f.installed_alias_path
+ end
+
+ def test_alias_paths_with_tab_with_alias_source_path
+ alias_path = CoreTap.instance.alias_dir/"another_name"
+ source_path = CoreTap.instance.alias_dir/"another_other_name"
+ f = formula(:alias_path => alias_path) { url "foo-1.0" }
+ f.build = Tab.new(:source => { "path" => source_path.to_s })
+ assert_equal alias_path, f.alias_path
+ assert_equal source_path.to_s, f.installed_alias_path
+ end
+
def test_formula_spec_integration
f = formula do
homepage "http://example.com"