formula: add versioned formulae method.

This commit is contained in:
Mike McQuaid 2018-05-12 14:35:50 -04:00
parent 524379e897
commit 840c97c1cc
3 changed files with 62 additions and 5 deletions

View File

@ -251,11 +251,9 @@ module Homebrew
problem "#{formula} is versioned but no #{unversioned_name} formula exists"
end
elsif ARGV.build_stable? && formula.stable? &&
!(versioned_formulae = Dir[formula.path.to_s.gsub(/\.rb$/, "@*.rb")]).empty?
!(versioned_formulae = formula.versioned_formulae).empty?
versioned_aliases = formula.aliases.grep(/.@\d/)
_, last_alias_version =
File.basename(versioned_formulae.sort.reverse.first)
.gsub(/\.rb$/, "").split("@")
_, last_alias_version = versioned_formulae.map(&:name).last.split("@")
major, minor, = formula.version.to_s.split(".")
alias_name_major = "#{formula.name}@#{major}"
alias_name_major_minor = "#{alias_name_major}.#{minor}"

View File

@ -370,6 +370,15 @@ class Formula
name.include?("@")
end
# Returns any `@`-versioned formulae for an non-`@`-versioned formula.
def versioned_formulae
return [] if versioned_formula?
Pathname.glob(path.to_s.gsub(/\.rb$/, "@*.rb")).map do |path|
Formula[path.basename(".rb").to_s]
end.sort
end
# A named Resource for the currently active {SoftwareSpec}.
# Additional downloads can be defined as {#resource}s.
# {Resource#stage} will create a temporary directory and yield to a block.

View File

@ -107,6 +107,56 @@ describe Formula do
end
end
describe "#versioned_formula?" do
let(:f) do
formula "foo" do
url "foo-1.0"
end
end
let(:f2) do
formula "foo@2.0" do
url "foo-2.0"
end
end
it "returns true for @-versioned formulae" do
expect(f2.versioned_formula?).to be true
end
it "returns false for non-@-versioned formulae" do
expect(f.versioned_formula?).to be false
end
end
describe "#versioned_formulae" do
let(:f) do
formula "foo" do
url "foo-1.0"
end
end
let(:f2) do
formula "foo@2.0" do
url "foo-2.0"
end
end
it "returns true by default" do
FileUtils.touch f.path
FileUtils.touch f2.path
allow(Formulary).to receive(:load_formula_from_path).with(f2.name, f2.path).and_return(f2)
allow(Formulary).to receive(:factory).with(f2.name).and_return(f2)
expect(f.versioned_formulae).to eq [f2]
end
it "returns empty array for non-@-versioned formulae" do
FileUtils.touch f.path
FileUtils.touch f2.path
expect(f2.versioned_formulae).to be_empty
end
end
example "installed alias with core" do
f = formula do
url "foo-1.0"
@ -708,7 +758,7 @@ describe Formula do
expect(f3.runtime_dependencies.map(&:name)).to eq(["foo/bar/f1", "baz/qux/f2"])
end
it "includes non-declared direct dependencies", :focus do
it "includes non-declared direct dependencies" do
formula = Class.new(Testball).new
dependency = formula("dependency") { url "f-1.0" }