From 0ef3e1e0dcbcd5aa55408fe81d23613e1c2c5e79 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sat, 3 Sep 2016 21:10:44 +0100 Subject: [PATCH 1/9] Preserve alias when installing formulae Part of #567 --- Library/Homebrew/formula.rb | 23 ++++++++++++++++++++- Library/Homebrew/formula_installer.rb | 2 +- Library/Homebrew/formulary.rb | 6 +++++- Library/Homebrew/tab.rb | 3 +++ Library/Homebrew/test/fixtures/receipt.json | 1 + Library/Homebrew/test/test_formula.rb | 19 ++++++++++++++++- Library/Homebrew/test/test_formulary.rb | 4 +++- Library/Homebrew/test/test_tab.rb | 3 +++ Library/Homebrew/test/testball.rb | 2 +- Library/Homebrew/test/testball_bottle.rb | 2 +- 10 files changed, 58 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 9e7bd21cab..479798829f 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -58,6 +58,11 @@ class Formula # e.g. `this-formula` attr_reader :name + # The name specified when installing this {Formula}. + # Could be the name of the {Formula}, or an alias. + # e.g. `another-name-for-this-formula` + attr_reader :install_name + # The fully-qualified name of this {Formula}. # For core formula it's the same as {#name}. # e.g. `homebrew/tap-name/this-formula` @@ -143,9 +148,10 @@ class Formula attr_accessor :build # @private - def initialize(name, path, spec) + def initialize(name, path, spec, install_name: name) @name = name @path = path + @install_name = install_name @revision = self.class.revision || 0 @version_scheme = self.class.version_scheme || 0 @@ -502,6 +508,21 @@ class Formula installed_prefixes.map { |dir| Keg.new(dir) } end + # Formula reference to use to get an identical installation of the formula. + # + # Usually, the formula's path is a good canonical identifier for the formula. + # Just using whatever was passed to `brew install` isn't a good idea, because + # if it was e.g. a URL, it could end up being downloaded twice. + # + # However, if the formula was installed with an alias (i.e. `install_name` is + # different from `name`), that should be used instead so that information is + # preserved. Aliases are looked up in repositories that have already been + # tapped, so we don't have to worry about doing extra HTTP requests, or other + # expensive operations, when looking them up again. + def install_ref + install_name == name ? path : install_name + end + # The directory where the formula's binaries should be installed. # This is symlinked into `HOMEBREW_PREFIX` after installation or with # `brew link` for formulae that are not keg-only. diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index cf595cf71f..b9b72812e0 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -589,7 +589,7 @@ class FormulaInstaller -I #{HOMEBREW_LOAD_PATH} -- #{HOMEBREW_LIBRARY_PATH}/build.rb - #{formula.path} + #{formula.install_ref} ].concat(build_argv) Sandbox.print_sandbox_message if Sandbox.formula?(formula) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 261a54fefb..095d5f883f 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -68,15 +68,18 @@ class Formulary attr_reader :name # The formula's ruby file's path or filename attr_reader :path + # The name used to install the formula + attr_reader :install_name def initialize(name, path) @name = name @path = path.resolved_path + @install_name = name end # Gets the formula instance. def get_formula(spec) - klass.new(name, path, spec) + klass.new(name, path, spec, install_name: install_name) end def klass @@ -118,6 +121,7 @@ class Formulary path = alias_path.resolved_path name = path.basename(".rb").to_s super name, path + @install_name = alias_path.basename.to_s end end diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index cf398fcbfa..0b26116c54 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -27,6 +27,7 @@ class Tab < OpenStruct "time" => Time.now.to_i, "source_modified_time" => formula.source_modified_time.to_i, "HEAD" => HOMEBREW_REPOSITORY.git_head, + "install_name" => formula.install_name, "compiler" => compiler, "stdlib" => stdlib, "source" => { @@ -161,6 +162,7 @@ class Tab < OpenStruct "time" => nil, "source_modified_time" => 0, "HEAD" => nil, + "install_name" => nil, "stdlib" => nil, "compiler" => DevelopmentTools.default_compiler, "source" => { @@ -292,6 +294,7 @@ class Tab < OpenStruct "time" => time, "source_modified_time" => source_modified_time.to_i, "HEAD" => self.HEAD, + "install_name" => install_name, "stdlib" => (stdlib.to_s if stdlib), "compiler" => (compiler.to_s if compiler), "source" => source diff --git a/Library/Homebrew/test/fixtures/receipt.json b/Library/Homebrew/test/fixtures/receipt.json index 4a829788ea..cf93f932d3 100644 --- a/Library/Homebrew/test/fixtures/receipt.json +++ b/Library/Homebrew/test/fixtures/receipt.json @@ -11,6 +11,7 @@ "poured_from_bottle": true, "time": 1403827774, "HEAD": "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", + "install_name": "test-formula", "stdlib": "libcxx", "compiler": "clang", "source": { diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb index 7ebb178841..1ea1ff1853 100644 --- a/Library/Homebrew/test/test_formula.rb +++ b/Library/Homebrew/test/test_formula.rb @@ -8,13 +8,30 @@ class FormulaTests < Homebrew::TestCase name = "formula_name" path = Formulary.core_path(name) spec = :stable + install_name = "formula_alias" - f = klass.new(name, path, spec) + f = klass.new(name, path, spec, install_name: install_name) assert_equal name, f.name assert_equal path, f.path + assert_equal install_name, f.install_name assert_raises(ArgumentError) { klass.new } end + def test_install_ref_with_alias + name = "formula_name" + path = Formulary.core_path(name) + spec = :stable + install_name = "formula_alias" + + f = Testball.new(name, path, spec, install_name: install_name) + assert_equal f.install_name, f.install_ref + end + + def test_install_ref_with_non_alias + f = Testball.new + assert_equal f.path, f.install_ref + end + def test_prefix f = Testball.new assert_equal HOMEBREW_CELLAR/f.name/"0.1", f.prefix diff --git a/Library/Homebrew/test/test_formulary.rb b/Library/Homebrew/test/test_formulary.rb index abc034e14b..0d34132ec2 100644 --- a/Library/Homebrew/test/test_formulary.rb +++ b/Library/Homebrew/test/test_formulary.rb @@ -86,7 +86,9 @@ class FormularyFactoryTest < Homebrew::TestCase alias_dir = CoreTap.instance.alias_dir alias_dir.mkpath FileUtils.ln_s @path, alias_dir/"foo" - assert_kind_of Formula, Formulary.factory("foo") + result = Formulary.factory("foo") + assert_kind_of Formula, result + assert_equal "foo", result.install_name ensure alias_dir.rmtree end diff --git a/Library/Homebrew/test/test_tab.rb b/Library/Homebrew/test/test_tab.rb index 8a261a46a4..dd61fd57b9 100644 --- a/Library/Homebrew/test/test_tab.rb +++ b/Library/Homebrew/test/test_tab.rb @@ -43,6 +43,7 @@ class TabTests < Homebrew::TestCase assert_nil tab.stable_version assert_nil tab.devel_version assert_nil tab.head_version + assert_nil tab.install_name assert_equal DevelopmentTools.default_compiler, tab.cxxstdlib.compiler assert_nil tab.cxxstdlib.type end @@ -116,6 +117,7 @@ class TabTests < Homebrew::TestCase assert_equal "2.14", tab.stable_version.to_s assert_equal "2.15", tab.devel_version.to_s assert_equal "HEAD-0000000", tab.head_version.to_s + assert_equal "test-formula", tab.install_name end def test_to_json @@ -133,6 +135,7 @@ class TabTests < Homebrew::TestCase assert_equal @tab.stable_version, tab.stable_version assert_equal @tab.devel_version, tab.devel_version assert_equal @tab.head_version, tab.head_version + assert_equal @tab.install_name, tab.install_name end def test_remap_deprecated_options diff --git a/Library/Homebrew/test/testball.rb b/Library/Homebrew/test/testball.rb index c1b09111b9..c13c73adb8 100644 --- a/Library/Homebrew/test/testball.rb +++ b/Library/Homebrew/test/testball.rb @@ -1,5 +1,5 @@ class Testball < Formula - def initialize(name = "testball", path = Pathname.new(__FILE__).expand_path, spec = :stable) + def initialize(name = "testball", path = Pathname.new(__FILE__).expand_path, spec = :stable, install_name: name) self.class.instance_eval do stable.url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz" stable.sha256 TESTBALL_SHA256 diff --git a/Library/Homebrew/test/testball_bottle.rb b/Library/Homebrew/test/testball_bottle.rb index 5aa582fa8a..584478afd7 100644 --- a/Library/Homebrew/test/testball_bottle.rb +++ b/Library/Homebrew/test/testball_bottle.rb @@ -1,5 +1,5 @@ class TestballBottle < Formula - def initialize(name = "testball_bottle", path = Pathname.new(__FILE__).expand_path, spec = :stable) + def initialize(name = "testball_bottle", path = Pathname.new(__FILE__).expand_path, spec = :stable, install_name: name) self.class.instance_eval do stable.url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz" stable.sha256 TESTBALL_SHA256 From c17664b124a84c7b6f8373337b3623003ca30772 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 4 Sep 2016 20:48:15 +0100 Subject: [PATCH 2/9] Switch to hash rockets --- Library/Homebrew/formulary.rb | 2 +- Library/Homebrew/test/test_formula.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 095d5f883f..f95f9c51a2 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -79,7 +79,7 @@ class Formulary # Gets the formula instance. def get_formula(spec) - klass.new(name, path, spec, install_name: install_name) + klass.new(name, path, spec, :install_name => install_name) end def klass diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb index 1ea1ff1853..b70ecbb6fc 100644 --- a/Library/Homebrew/test/test_formula.rb +++ b/Library/Homebrew/test/test_formula.rb @@ -10,7 +10,7 @@ class FormulaTests < Homebrew::TestCase spec = :stable install_name = "formula_alias" - f = klass.new(name, path, spec, install_name: install_name) + f = klass.new(name, path, spec, :install_name => install_name) assert_equal name, f.name assert_equal path, f.path assert_equal install_name, f.install_name @@ -23,7 +23,7 @@ class FormulaTests < Homebrew::TestCase spec = :stable install_name = "formula_alias" - f = Testball.new(name, path, spec, install_name: install_name) + f = Testball.new(name, path, spec, :install_name => install_name) assert_equal f.install_name, f.install_ref end From 65ee5408c3d000393c1b73bfe8fb731a651ee281 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Mon, 5 Sep 2016 01:11:36 +0100 Subject: [PATCH 3/9] Replace install_name/install_ref with alias_path --- Library/Homebrew/formula.rb | 21 +++------------------ Library/Homebrew/formula_installer.rb | 2 +- Library/Homebrew/formulary.rb | 7 +++---- Library/Homebrew/tab.rb | 6 +++--- Library/Homebrew/test/fixtures/receipt.json | 2 +- Library/Homebrew/test/test_formula.rb | 21 +++------------------ Library/Homebrew/test/test_formulary.rb | 5 +++-- Library/Homebrew/test/test_tab.rb | 6 +++--- Library/Homebrew/test/testball.rb | 2 +- Library/Homebrew/test/testball_bottle.rb | 2 +- 10 files changed, 22 insertions(+), 52 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 479798829f..90e6b22122 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -61,7 +61,7 @@ class Formula # The name specified when installing this {Formula}. # Could be the name of the {Formula}, or an alias. # e.g. `another-name-for-this-formula` - attr_reader :install_name + attr_reader :alias_path # The fully-qualified name of this {Formula}. # For core formula it's the same as {#name}. @@ -148,10 +148,10 @@ class Formula attr_accessor :build # @private - def initialize(name, path, spec, install_name: name) + def initialize(name, path, spec, alias_path: nil) @name = name @path = path - @install_name = install_name + @alias_path = alias_path @revision = self.class.revision || 0 @version_scheme = self.class.version_scheme || 0 @@ -508,21 +508,6 @@ class Formula installed_prefixes.map { |dir| Keg.new(dir) } end - # Formula reference to use to get an identical installation of the formula. - # - # Usually, the formula's path is a good canonical identifier for the formula. - # Just using whatever was passed to `brew install` isn't a good idea, because - # if it was e.g. a URL, it could end up being downloaded twice. - # - # However, if the formula was installed with an alias (i.e. `install_name` is - # different from `name`), that should be used instead so that information is - # preserved. Aliases are looked up in repositories that have already been - # tapped, so we don't have to worry about doing extra HTTP requests, or other - # expensive operations, when looking them up again. - def install_ref - install_name == name ? path : install_name - end - # The directory where the formula's binaries should be installed. # This is symlinked into `HOMEBREW_PREFIX` after installation or with # `brew link` for formulae that are not keg-only. diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index b9b72812e0..ebcc3d4dab 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -589,7 +589,7 @@ class FormulaInstaller -I #{HOMEBREW_LOAD_PATH} -- #{HOMEBREW_LIBRARY_PATH}/build.rb - #{formula.install_ref} + #{formula.alias_path || formula.path} ].concat(build_argv) Sandbox.print_sandbox_message if Sandbox.formula?(formula) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index f95f9c51a2..cbad28fc78 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -69,17 +69,16 @@ class Formulary # The formula's ruby file's path or filename attr_reader :path # The name used to install the formula - attr_reader :install_name + attr_reader :alias_path def initialize(name, path) @name = name @path = path.resolved_path - @install_name = name end # Gets the formula instance. def get_formula(spec) - klass.new(name, path, spec, :install_name => install_name) + klass.new(name, path, spec, :alias_path => alias_path) end def klass @@ -121,7 +120,7 @@ class Formulary path = alias_path.resolved_path name = path.basename(".rb").to_s super name, path - @install_name = alias_path.basename.to_s + @alias_path = alias_path end end diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index 0b26116c54..ec8cbe2353 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -27,7 +27,7 @@ class Tab < OpenStruct "time" => Time.now.to_i, "source_modified_time" => formula.source_modified_time.to_i, "HEAD" => HOMEBREW_REPOSITORY.git_head, - "install_name" => formula.install_name, + "alias_path" => formula.alias_path.to_s, "compiler" => compiler, "stdlib" => stdlib, "source" => { @@ -162,7 +162,7 @@ class Tab < OpenStruct "time" => nil, "source_modified_time" => 0, "HEAD" => nil, - "install_name" => nil, + "alias_path" => nil, "stdlib" => nil, "compiler" => DevelopmentTools.default_compiler, "source" => { @@ -294,7 +294,7 @@ class Tab < OpenStruct "time" => time, "source_modified_time" => source_modified_time.to_i, "HEAD" => self.HEAD, - "install_name" => install_name, + "alias_path" => alias_path, "stdlib" => (stdlib.to_s if stdlib), "compiler" => (compiler.to_s if compiler), "source" => source diff --git a/Library/Homebrew/test/fixtures/receipt.json b/Library/Homebrew/test/fixtures/receipt.json index cf93f932d3..39dcaea079 100644 --- a/Library/Homebrew/test/fixtures/receipt.json +++ b/Library/Homebrew/test/fixtures/receipt.json @@ -11,7 +11,7 @@ "poured_from_bottle": true, "time": 1403827774, "HEAD": "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", - "install_name": "test-formula", + "alias_path": "test-formula", "stdlib": "libcxx", "compiler": "clang", "source": { diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb index b70ecbb6fc..ce1ac28b1a 100644 --- a/Library/Homebrew/test/test_formula.rb +++ b/Library/Homebrew/test/test_formula.rb @@ -8,30 +8,15 @@ class FormulaTests < Homebrew::TestCase name = "formula_name" path = Formulary.core_path(name) spec = :stable - install_name = "formula_alias" + alias_path = "formula_alias" - f = klass.new(name, path, spec, :install_name => install_name) + f = klass.new(name, path, spec, :alias_path => alias_path) assert_equal name, f.name assert_equal path, f.path - assert_equal install_name, f.install_name + assert_equal alias_path, f.alias_path assert_raises(ArgumentError) { klass.new } end - def test_install_ref_with_alias - name = "formula_name" - path = Formulary.core_path(name) - spec = :stable - install_name = "formula_alias" - - f = Testball.new(name, path, spec, :install_name => install_name) - assert_equal f.install_name, f.install_ref - end - - def test_install_ref_with_non_alias - f = Testball.new - assert_equal f.path, f.install_ref - end - def test_prefix f = Testball.new assert_equal HOMEBREW_CELLAR/f.name/"0.1", f.prefix diff --git a/Library/Homebrew/test/test_formulary.rb b/Library/Homebrew/test/test_formulary.rb index 0d34132ec2..8b3417dad9 100644 --- a/Library/Homebrew/test/test_formulary.rb +++ b/Library/Homebrew/test/test_formulary.rb @@ -85,10 +85,11 @@ class FormularyFactoryTest < Homebrew::TestCase def test_factory_from_alias alias_dir = CoreTap.instance.alias_dir alias_dir.mkpath - FileUtils.ln_s @path, alias_dir/"foo" + alias_path = alias_dir/"foo" + FileUtils.ln_s @path, alias_path result = Formulary.factory("foo") assert_kind_of Formula, result - assert_equal "foo", result.install_name + assert_equal alias_path, result.alias_path ensure alias_dir.rmtree end diff --git a/Library/Homebrew/test/test_tab.rb b/Library/Homebrew/test/test_tab.rb index dd61fd57b9..85fcf4d162 100644 --- a/Library/Homebrew/test/test_tab.rb +++ b/Library/Homebrew/test/test_tab.rb @@ -43,7 +43,7 @@ class TabTests < Homebrew::TestCase assert_nil tab.stable_version assert_nil tab.devel_version assert_nil tab.head_version - assert_nil tab.install_name + assert_nil tab.alias_path assert_equal DevelopmentTools.default_compiler, tab.cxxstdlib.compiler assert_nil tab.cxxstdlib.type end @@ -117,7 +117,7 @@ class TabTests < Homebrew::TestCase assert_equal "2.14", tab.stable_version.to_s assert_equal "2.15", tab.devel_version.to_s assert_equal "HEAD-0000000", tab.head_version.to_s - assert_equal "test-formula", tab.install_name + assert_equal "test-formula", tab.alias_path end def test_to_json @@ -135,7 +135,7 @@ class TabTests < Homebrew::TestCase assert_equal @tab.stable_version, tab.stable_version assert_equal @tab.devel_version, tab.devel_version assert_equal @tab.head_version, tab.head_version - assert_equal @tab.install_name, tab.install_name + assert_equal @tab.alias_path, tab.alias_path end def test_remap_deprecated_options diff --git a/Library/Homebrew/test/testball.rb b/Library/Homebrew/test/testball.rb index c13c73adb8..cce09738df 100644 --- a/Library/Homebrew/test/testball.rb +++ b/Library/Homebrew/test/testball.rb @@ -1,5 +1,5 @@ class Testball < Formula - def initialize(name = "testball", path = Pathname.new(__FILE__).expand_path, spec = :stable, install_name: name) + def initialize(name = "testball", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil) self.class.instance_eval do stable.url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz" stable.sha256 TESTBALL_SHA256 diff --git a/Library/Homebrew/test/testball_bottle.rb b/Library/Homebrew/test/testball_bottle.rb index 584478afd7..769f615aad 100644 --- a/Library/Homebrew/test/testball_bottle.rb +++ b/Library/Homebrew/test/testball_bottle.rb @@ -1,5 +1,5 @@ class TestballBottle < Formula - def initialize(name = "testball_bottle", path = Pathname.new(__FILE__).expand_path, spec = :stable, install_name: name) + def initialize(name = "testball_bottle", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil) self.class.instance_eval do stable.url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz" stable.sha256 TESTBALL_SHA256 From b90eba8ffd9549879bf4c911377d8d4cf9aa7b39 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Mon, 5 Sep 2016 14:21:00 +0100 Subject: [PATCH 4/9] Update Tap for alias_path --- Library/Homebrew/tab.rb | 6 +++++- Library/Homebrew/test/fixtures/receipt.json | 2 +- Library/Homebrew/test/test_tab.rb | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index ec8cbe2353..d84c643296 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -56,6 +56,10 @@ class Tab < OpenStruct attributes["source_modified_time"] ||= 0 attributes["source"] ||= {} + if alias_path = attributes["alias_path"] + attributes["alias_path"] = Pathname.new(alias_path) + end + tapped_from = attributes["tapped_from"] unless tapped_from.nil? || tapped_from == "path or URL" attributes["source"]["tap"] = attributes.delete("tapped_from") @@ -294,7 +298,7 @@ class Tab < OpenStruct "time" => time, "source_modified_time" => source_modified_time.to_i, "HEAD" => self.HEAD, - "alias_path" => alias_path, + "alias_path" => alias_path && alias_path.to_s, "stdlib" => (stdlib.to_s if stdlib), "compiler" => (compiler.to_s if compiler), "source" => source diff --git a/Library/Homebrew/test/fixtures/receipt.json b/Library/Homebrew/test/fixtures/receipt.json index 39dcaea079..585a4e27de 100644 --- a/Library/Homebrew/test/fixtures/receipt.json +++ b/Library/Homebrew/test/fixtures/receipt.json @@ -11,7 +11,7 @@ "poured_from_bottle": true, "time": 1403827774, "HEAD": "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", - "alias_path": "test-formula", + "alias_path": "/usr/local/Library/Taps/homebrew/homebrew-core/Aliases/test-formula", "stdlib": "libcxx", "compiler": "clang", "source": { diff --git a/Library/Homebrew/test/test_tab.rb b/Library/Homebrew/test/test_tab.rb index 85fcf4d162..be528390a8 100644 --- a/Library/Homebrew/test/test_tab.rb +++ b/Library/Homebrew/test/test_tab.rb @@ -100,6 +100,7 @@ class TabTests < Homebrew::TestCase def test_from_file path = Pathname.new(TEST_DIRECTORY).join("fixtures", "receipt.json") tab = Tab.from_file(path) + alias_path = Pathname.new("/usr/local/Library/Taps/homebrew/homebrew-core/Aliases/test-formula") assert_equal @used.sort, tab.used_options.sort assert_equal @unused.sort, tab.unused_options.sort @@ -117,7 +118,7 @@ class TabTests < Homebrew::TestCase assert_equal "2.14", tab.stable_version.to_s assert_equal "2.15", tab.devel_version.to_s assert_equal "HEAD-0000000", tab.head_version.to_s - assert_equal "test-formula", tab.alias_path + assert_equal alias_path, tab.alias_path end def test_to_json From ba10ce70bd36cbdc05a574f2227093da0ab7f470 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Mon, 5 Sep 2016 22:01:05 +0100 Subject: [PATCH 5/9] More consistent style --- Library/Homebrew/tab.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index d84c643296..cf15e4c7b3 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -298,7 +298,7 @@ class Tab < OpenStruct "time" => time, "source_modified_time" => source_modified_time.to_i, "HEAD" => self.HEAD, - "alias_path" => alias_path && alias_path.to_s, + "alias_path" => (alias_path.to_s if alias_path), "stdlib" => (stdlib.to_s if stdlib), "compiler" => (compiler.to_s if compiler), "source" => source From c58bbdc2138d2eb21ab7ea499beb6994a01891c4 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Mon, 5 Sep 2016 22:13:55 +0100 Subject: [PATCH 6/9] Formula#specified_path --- Library/Homebrew/formula.rb | 5 +++++ Library/Homebrew/formula_installer.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 90e6b22122..cc26a492e2 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -226,6 +226,11 @@ class Formula public + # The path that was specified to find/install this formula. + def specified_path + alias_path || path + end + # Is the currently active {SoftwareSpec} a {#stable} build? # @private def stable? diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index ebcc3d4dab..19c7838b35 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -589,7 +589,7 @@ class FormulaInstaller -I #{HOMEBREW_LOAD_PATH} -- #{HOMEBREW_LIBRARY_PATH}/build.rb - #{formula.alias_path || formula.path} + #{formula.specified_path} ].concat(build_argv) Sandbox.print_sandbox_message if Sandbox.formula?(formula) From 8bbcbfc0203cde999a0a6e10053ffc173ee73b06 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 7 Sep 2016 21:47:53 +0100 Subject: [PATCH 7/9] More realistic alias_path test --- Library/Homebrew/test/test_formula.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb index ce1ac28b1a..63cefe9fa9 100644 --- a/Library/Homebrew/test/test_formula.rb +++ b/Library/Homebrew/test/test_formula.rb @@ -8,7 +8,7 @@ class FormulaTests < Homebrew::TestCase name = "formula_name" path = Formulary.core_path(name) spec = :stable - alias_path = "formula_alias" + alias_path = CoreTap.instance.alias_dir/"formula_alias" f = klass.new(name, path, spec, :alias_path => alias_path) assert_equal name, f.name From f9e16ee2e04b7b23b273bfa683ab54a85ed40660 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 7 Sep 2016 22:48:52 +0100 Subject: [PATCH 8/9] Combine Tab alias_path with source.path --- Library/Homebrew/tab.rb | 11 ++--------- Library/Homebrew/test/test_tab.rb | 8 ++++---- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index cf15e4c7b3..13082a213a 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -27,11 +27,10 @@ class Tab < OpenStruct "time" => Time.now.to_i, "source_modified_time" => formula.source_modified_time.to_i, "HEAD" => HOMEBREW_REPOSITORY.git_head, - "alias_path" => formula.alias_path.to_s, "compiler" => compiler, "stdlib" => stdlib, "source" => { - "path" => formula.path.to_s, + "path" => formula.specified_path.to_s, "tap" => formula.tap ? formula.tap.name : nil, "spec" => formula.active_spec_sym.to_s, "versions" => { @@ -56,10 +55,6 @@ class Tab < OpenStruct attributes["source_modified_time"] ||= 0 attributes["source"] ||= {} - if alias_path = attributes["alias_path"] - attributes["alias_path"] = Pathname.new(alias_path) - end - tapped_from = attributes["tapped_from"] unless tapped_from.nil? || tapped_from == "path or URL" attributes["source"]["tap"] = attributes.delete("tapped_from") @@ -142,7 +137,7 @@ class Tab < OpenStruct tab = empty tab.unused_options = f.options.as_flags tab.source = { - "path" => f.path.to_s, + "path" => f.specified_path.to_s, "tap" => f.tap ? f.tap.name : f.tap, "spec" => f.active_spec_sym.to_s, "versions" => { @@ -166,7 +161,6 @@ class Tab < OpenStruct "time" => nil, "source_modified_time" => 0, "HEAD" => nil, - "alias_path" => nil, "stdlib" => nil, "compiler" => DevelopmentTools.default_compiler, "source" => { @@ -298,7 +292,6 @@ class Tab < OpenStruct "time" => time, "source_modified_time" => source_modified_time.to_i, "HEAD" => self.HEAD, - "alias_path" => (alias_path.to_s if alias_path), "stdlib" => (stdlib.to_s if stdlib), "compiler" => (compiler.to_s if compiler), "source" => source diff --git a/Library/Homebrew/test/test_tab.rb b/Library/Homebrew/test/test_tab.rb index be528390a8..a5d50d81da 100644 --- a/Library/Homebrew/test/test_tab.rb +++ b/Library/Homebrew/test/test_tab.rb @@ -43,9 +43,9 @@ class TabTests < Homebrew::TestCase assert_nil tab.stable_version assert_nil tab.devel_version assert_nil tab.head_version - assert_nil tab.alias_path assert_equal DevelopmentTools.default_compiler, tab.cxxstdlib.compiler assert_nil tab.cxxstdlib.type + assert_nil tab.source["path"] end def test_include? @@ -100,7 +100,7 @@ class TabTests < Homebrew::TestCase def test_from_file path = Pathname.new(TEST_DIRECTORY).join("fixtures", "receipt.json") tab = Tab.from_file(path) - alias_path = Pathname.new("/usr/local/Library/Taps/homebrew/homebrew-core/Aliases/test-formula") + source_path = "/usr/local/Library/Taps/hombrew/homebrew-core/Formula/foo.rb" assert_equal @used.sort, tab.used_options.sort assert_equal @unused.sort, tab.unused_options.sort @@ -118,7 +118,7 @@ class TabTests < Homebrew::TestCase assert_equal "2.14", tab.stable_version.to_s assert_equal "2.15", tab.devel_version.to_s assert_equal "HEAD-0000000", tab.head_version.to_s - assert_equal alias_path, tab.alias_path + assert_equal source_path, tab.source["path"] end def test_to_json @@ -136,7 +136,7 @@ class TabTests < Homebrew::TestCase assert_equal @tab.stable_version, tab.stable_version assert_equal @tab.devel_version, tab.devel_version assert_equal @tab.head_version, tab.head_version - assert_equal @tab.alias_path, tab.alias_path + assert_equal @tab.source["path"], tab.source["path"] end def test_remap_deprecated_options From 4f1d47bc156253ab0eabf6b7aba1fcfa46d80633 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 7 Sep 2016 22:52:25 +0100 Subject: [PATCH 9/9] Test source.path on Tab.create and .for_formula --- Library/Homebrew/test/test_tab.rb | 34 ++++++++++++++++++++++++++++ Library/Homebrew/test/testing_env.rb | 4 ++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/test_tab.rb b/Library/Homebrew/test/test_tab.rb index a5d50d81da..962bfc602c 100644 --- a/Library/Homebrew/test/test_tab.rb +++ b/Library/Homebrew/test/test_tab.rb @@ -121,6 +121,40 @@ class TabTests < Homebrew::TestCase assert_equal source_path, tab.source["path"] end + def test_create + f = formula { url "foo-1.0" } + compiler = DevelopmentTools.default_compiler + stdlib = :libcxx + tab = Tab.create(f, compiler, stdlib) + + assert_equal f.path.to_s, tab.source["path"] + end + + def test_create_from_alias + alias_path = CoreTap.instance.alias_dir/"bar" + f = formula(:alias_path => alias_path) { url "foo-1.0" } + compiler = DevelopmentTools.default_compiler + stdlib = :libcxx + tab = Tab.create(f, compiler, stdlib) + + assert_equal f.alias_path.to_s, tab.source["path"] + end + + def test_for_formula + f = formula { url "foo-1.0" } + tab = Tab.for_formula(f) + + assert_equal f.path.to_s, tab.source["path"] + end + + def test_for_formula_from_alias + alias_path = CoreTap.instance.alias_dir/"bar" + f = formula(:alias_path => alias_path) { url "foo-1.0" } + tab = Tab.for_formula(f) + + assert_equal alias_path.to_s, tab.source["path"] + end + def test_to_json tab = Tab.new(Utils::JSON.load(@tab.to_json)) assert_equal @tab.used_options.sort, tab.used_options.sort diff --git a/Library/Homebrew/test/testing_env.rb b/Library/Homebrew/test/testing_env.rb index 5d464b8cc8..bc25f8ef82 100644 --- a/Library/Homebrew/test/testing_env.rb +++ b/Library/Homebrew/test/testing_env.rb @@ -72,8 +72,8 @@ module Homebrew TEST_SHA1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze TEST_SHA256 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze - def formula(name = "formula_name", path = Formulary.core_path(name), spec = :stable, &block) - @_f = Class.new(Formula, &block).new(name, path, spec) + def formula(name = "formula_name", path = Formulary.core_path(name), spec = :stable, alias_path: nil, &block) + @_f = Class.new(Formula, &block).new(name, path, spec, :alias_path => alias_path) end def mktmpdir(prefix_suffix = nil, &block)