Merge pull request #4160 from MikeMcQuaid/reorder-hash
formula: improve to_hash output.
This commit is contained in:
commit
a3d639dc49
@ -251,11 +251,9 @@ module Homebrew
|
|||||||
problem "#{formula} is versioned but no #{unversioned_name} formula exists"
|
problem "#{formula} is versioned but no #{unversioned_name} formula exists"
|
||||||
end
|
end
|
||||||
elsif ARGV.build_stable? && formula.stable? &&
|
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/)
|
versioned_aliases = formula.aliases.grep(/.@\d/)
|
||||||
_, last_alias_version =
|
_, last_alias_version = versioned_formulae.map(&:name).last.split("@")
|
||||||
File.basename(versioned_formulae.sort.reverse.first)
|
|
||||||
.gsub(/\.rb$/, "").split("@")
|
|
||||||
major, minor, = formula.version.to_s.split(".")
|
major, minor, = formula.version.to_s.split(".")
|
||||||
alias_name_major = "#{formula.name}@#{major}"
|
alias_name_major = "#{formula.name}@#{major}"
|
||||||
alias_name_major_minor = "#{alias_name_major}.#{minor}"
|
alias_name_major_minor = "#{alias_name_major}.#{minor}"
|
||||||
|
|||||||
@ -370,6 +370,15 @@ class Formula
|
|||||||
name.include?("@")
|
name.include?("@")
|
||||||
end
|
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}.
|
# A named Resource for the currently active {SoftwareSpec}.
|
||||||
# Additional downloads can be defined as {#resource}s.
|
# Additional downloads can be defined as {#resource}s.
|
||||||
# {Resource#stage} will create a temporary directory and yield to a block.
|
# {Resource#stage} will create a temporary directory and yield to a block.
|
||||||
@ -1548,44 +1557,35 @@ class Formula
|
|||||||
hsh = {
|
hsh = {
|
||||||
"name" => name,
|
"name" => name,
|
||||||
"full_name" => full_name,
|
"full_name" => full_name,
|
||||||
"desc" => desc,
|
|
||||||
"homepage" => homepage,
|
|
||||||
"oldname" => oldname,
|
"oldname" => oldname,
|
||||||
"aliases" => aliases.sort,
|
"aliases" => aliases.sort,
|
||||||
|
"versioned_formulae" => versioned_formulae.map(&:name),
|
||||||
|
"desc" => desc,
|
||||||
|
"homepage" => homepage,
|
||||||
"versions" => {
|
"versions" => {
|
||||||
"stable" => stable&.version&.to_s,
|
"stable" => stable&.version&.to_s,
|
||||||
"bottle" => !bottle_specification.checksums.empty?,
|
|
||||||
"devel" => devel&.version&.to_s,
|
"devel" => devel&.version&.to_s,
|
||||||
"head" => head&.version&.to_s,
|
"head" => head&.version&.to_s,
|
||||||
|
"bottle" => !bottle_specification.checksums.empty?,
|
||||||
},
|
},
|
||||||
"revision" => revision,
|
"revision" => revision,
|
||||||
"version_scheme" => version_scheme,
|
"version_scheme" => version_scheme,
|
||||||
|
"bottle" => {},
|
||||||
|
"keg_only" => keg_only?,
|
||||||
|
"options" => [],
|
||||||
|
"build_dependencies" => dependencies.select(&:build?).map(&:name).uniq,
|
||||||
|
"dependencies" => dependencies.reject(&:optional?).reject(&:recommended?).reject(&:build?).map(&:name).uniq,
|
||||||
|
"recommended_dependencies" => dependencies.select(&:recommended?).map(&:name).uniq,
|
||||||
|
"optional_dependencies" => dependencies.select(&:optional?).map(&:name).uniq,
|
||||||
|
"requirements" => [],
|
||||||
|
"conflicts_with" => conflicts.map(&:name),
|
||||||
|
"caveats" => caveats,
|
||||||
"installed" => [],
|
"installed" => [],
|
||||||
"linked_keg" => linked_version&.to_s,
|
"linked_keg" => linked_version&.to_s,
|
||||||
"pinned" => pinned?,
|
"pinned" => pinned?,
|
||||||
"outdated" => outdated?,
|
"outdated" => outdated?,
|
||||||
"keg_only" => keg_only?,
|
|
||||||
"dependencies" => dependencies.map(&:name).uniq,
|
|
||||||
"recommended_dependencies" => dependencies.select(&:recommended?).map(&:name).uniq,
|
|
||||||
"optional_dependencies" => dependencies.select(&:optional?).map(&:name).uniq,
|
|
||||||
"build_dependencies" => dependencies.select(&:build?).map(&:name).uniq,
|
|
||||||
"conflicts_with" => conflicts.map(&:name),
|
|
||||||
"caveats" => caveats,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hsh["requirements"] = requirements.map do |req|
|
|
||||||
{
|
|
||||||
"name" => req.name,
|
|
||||||
"cask" => req.cask,
|
|
||||||
"download" => req.download,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
hsh["options"] = options.map do |opt|
|
|
||||||
{ "option" => opt.flag, "description" => opt.description }
|
|
||||||
end
|
|
||||||
|
|
||||||
hsh["bottle"] = {}
|
|
||||||
%w[stable devel].each do |spec_sym|
|
%w[stable devel].each do |spec_sym|
|
||||||
next unless spec = send(spec_sym)
|
next unless spec = send(spec_sym)
|
||||||
next unless spec.bottle_defined?
|
next unless spec.bottle_defined?
|
||||||
@ -1607,6 +1607,18 @@ class Formula
|
|||||||
hsh["bottle"][spec_sym] = bottle_info
|
hsh["bottle"][spec_sym] = bottle_info
|
||||||
end
|
end
|
||||||
|
|
||||||
|
hsh["options"] = options.map do |opt|
|
||||||
|
{ "option" => opt.flag, "description" => opt.description }
|
||||||
|
end
|
||||||
|
|
||||||
|
hsh["requirements"] = requirements.map do |req|
|
||||||
|
{
|
||||||
|
"name" => req.name,
|
||||||
|
"cask" => req.cask,
|
||||||
|
"download" => req.download,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
installed_kegs.each do |keg|
|
installed_kegs.each do |keg|
|
||||||
tab = Tab.for_keg keg
|
tab = Tab.for_keg keg
|
||||||
|
|
||||||
|
|||||||
@ -107,6 +107,56 @@ describe Formula do
|
|||||||
end
|
end
|
||||||
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
|
example "installed alias with core" do
|
||||||
f = formula do
|
f = formula do
|
||||||
url "foo-1.0"
|
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"])
|
expect(f3.runtime_dependencies.map(&:name)).to eq(["foo/bar/f1", "baz/qux/f2"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "includes non-declared direct dependencies", :focus do
|
it "includes non-declared direct dependencies" do
|
||||||
formula = Class.new(Testball).new
|
formula = Class.new(Testball).new
|
||||||
dependency = formula("dependency") { url "f-1.0" }
|
dependency = formula("dependency") { url "f-1.0" }
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user