Merge pull request #863 from penman/preserve_alias

Save aliases in INSTALL_RECEIPT
This commit is contained in:
Mike McQuaid 2016-09-09 07:47:05 +01:00 committed by GitHub
commit 1d66cdd3ad
11 changed files with 70 additions and 12 deletions

View File

@ -60,6 +60,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 :alias_path
# The fully-qualified name of this {Formula}.
# For core formula it's the same as {#name}.
# e.g. `homebrew/tap-name/this-formula`
@ -145,9 +150,10 @@ class Formula
attr_accessor :build
# @private
def initialize(name, path, spec)
def initialize(name, path, spec, alias_path: nil)
@name = name
@path = path
@alias_path = alias_path
@revision = self.class.revision || 0
@version_scheme = self.class.version_scheme || 0
@ -222,6 +228,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?

View File

@ -599,7 +599,7 @@ class FormulaInstaller
-I #{HOMEBREW_LOAD_PATH}
--
#{HOMEBREW_LIBRARY_PATH}/build.rb
#{formula.path}
#{formula.specified_path}
].concat(build_argv)
Sandbox.print_sandbox_message if Sandbox.formula?(formula)

View File

@ -68,6 +68,8 @@ 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 :alias_path
def initialize(name, path)
@name = name
@ -76,7 +78,7 @@ class Formulary
# Gets the formula instance.
def get_formula(spec)
klass.new(name, path, spec)
klass.new(name, path, spec, :alias_path => alias_path)
end
def klass
@ -118,6 +120,7 @@ class Formulary
path = alias_path.resolved_path
name = path.basename(".rb").to_s
super name, path
@alias_path = alias_path
end
end

View File

@ -31,7 +31,7 @@ class Tab < OpenStruct
"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" => {
@ -146,7 +146,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" => {

View File

@ -11,6 +11,7 @@
"poured_from_bottle": true,
"time": 1403827774,
"HEAD": "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"alias_path": "/usr/local/Library/Taps/homebrew/homebrew-core/Aliases/test-formula",
"stdlib": "libcxx",
"compiler": "clang",
"source": {

View File

@ -8,10 +8,12 @@ class FormulaTests < Homebrew::TestCase
name = "formula_name"
path = Formulary.core_path(name)
spec = :stable
alias_path = CoreTap.instance.alias_dir/"formula_alias"
f = klass.new(name, path, spec)
f = klass.new(name, path, spec, :alias_path => alias_path)
assert_equal name, f.name
assert_equal path, f.path
assert_equal alias_path, f.alias_path
assert_raises(ArgumentError) { klass.new }
end

View File

@ -85,8 +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"
assert_kind_of Formula, Formulary.factory("foo")
alias_path = alias_dir/"foo"
FileUtils.ln_s @path, alias_path
result = Formulary.factory("foo")
assert_kind_of Formula, result
assert_equal alias_path, result.alias_path
ensure
alias_dir.rmtree
end

View File

@ -45,6 +45,7 @@ class TabTests < Homebrew::TestCase
assert_nil tab.head_version
assert_equal DevelopmentTools.default_compiler, tab.cxxstdlib.compiler
assert_nil tab.cxxstdlib.type
assert_nil tab.source["path"]
end
def test_include?
@ -99,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)
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
@ -116,6 +118,41 @@ 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 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
@ -133,6 +170,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.source["path"], tab.source["path"]
end
def test_remap_deprecated_options

View File

@ -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, alias_path: nil)
self.class.instance_eval do
stable.url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
stable.sha256 TESTBALL_SHA256

View File

@ -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, alias_path: nil)
self.class.instance_eval do
stable.url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
stable.sha256 TESTBALL_SHA256

View File

@ -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)