From 3d559fa79641735193636cbf6240c082e6ca171c Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 14 Sep 2016 23:18:55 +0100 Subject: [PATCH] Add Formula#installed_alias_path --- Library/Homebrew/formula.rb | 16 ++++++++++++---- Library/Homebrew/test/test_formula.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 599b493920..f2da6fbc86 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 7c09e765f2..2eb64ebb67 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"