Introduce tag for implicit dependencies

This commit is contained in:
Bo Anderson 2023-06-19 06:06:15 +01:00
parent d1b923f314
commit 71d51faa55
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
9 changed files with 47 additions and 35 deletions

View File

@ -191,6 +191,7 @@ module Homebrew
str = "#{str} [test]" if dep.test? str = "#{str} [test]" if dep.test?
str = "#{str} [optional]" if dep.optional? str = "#{str} [optional]" if dep.optional?
str = "#{str} [recommended]" if dep.recommended? str = "#{str} [recommended]" if dep.recommended?
str = "#{str} [implicit]" if dep.implicit?
end end
str str

View File

@ -9,7 +9,7 @@ require "options"
module Dependable module Dependable
# `:run` and `:linked` are no longer used but keep them here to avoid their # `:run` and `:linked` are no longer used but keep them here to avoid their
# misuse in future. # misuse in future.
RESERVED_TAGS = [:build, :optional, :recommended, :run, :test, :linked].freeze RESERVED_TAGS = [:build, :optional, :recommended, :run, :test, :linked, :implicit].freeze
attr_reader :tags attr_reader :tags
@ -29,6 +29,10 @@ module Dependable
tags.include? :test tags.include? :test
end end
def implicit?
tags.include? :implicit
end
def required? def required?
!build? && !test? && !optional? && !recommended? !build? && !test? && !optional? && !recommended?
end end

View File

@ -180,9 +180,14 @@ class Dependency
option_names = deps.flat_map(&:option_names).uniq option_names = deps.flat_map(&:option_names).uniq
kwargs = {} kwargs = {}
kwargs[:bounds] = dep.bounds if dep.uses_from_macos? kwargs[:bounds] = dep.bounds if dep.uses_from_macos?
# TODO: simpify to just **kwargs when we require Ruby >= 2.7
if kwargs.empty?
dep.class.new(name, tags, dep.env_proc, option_names)
else
dep.class.new(name, tags, dep.env_proc, option_names, **kwargs) dep.class.new(name, tags, dep.env_proc, option_names, **kwargs)
end end
end end
end
private private
@ -208,10 +213,10 @@ class Dependency
end end
def merge_temporality(deps) def merge_temporality(deps)
# Means both build and runtime dependency. new_tags = []
return [] unless deps.all?(&:build?) new_tags << :build if deps.all?(&:build?)
new_tags << :implicit if deps.all?(&:implicit?)
[:build] new_tags
end end
end end
end end

View File

@ -84,37 +84,37 @@ class DependencyCollector
def git_dep_if_needed(tags) def git_dep_if_needed(tags)
return if Utils::Git.available? return if Utils::Git.available?
Dependency.new("git", tags) Dependency.new("git", [*tags, :implicit])
end end
def curl_dep_if_needed(tags) def curl_dep_if_needed(tags)
Dependency.new("curl", tags) Dependency.new("curl", [*tags, :implicit])
end end
def subversion_dep_if_needed(tags) def subversion_dep_if_needed(tags)
return if Utils::Svn.available? return if Utils::Svn.available?
Dependency.new("subversion", tags) Dependency.new("subversion", [*tags, :implicit])
end end
def cvs_dep_if_needed(tags) def cvs_dep_if_needed(tags)
Dependency.new("cvs", tags) unless which("cvs") Dependency.new("cvs", [*tags, :implicit]) unless which("cvs")
end end
def xz_dep_if_needed(tags) def xz_dep_if_needed(tags)
Dependency.new("xz", tags) unless which("xz") Dependency.new("xz", [*tags, :implicit]) unless which("xz")
end end
def zstd_dep_if_needed(tags) def zstd_dep_if_needed(tags)
Dependency.new("zstd", tags) unless which("zstd") Dependency.new("zstd", [*tags, :implicit]) unless which("zstd")
end end
def unzip_dep_if_needed(tags) def unzip_dep_if_needed(tags)
Dependency.new("unzip", tags) unless which("unzip") Dependency.new("unzip", [*tags, :implicit]) unless which("unzip")
end end
def bzip2_dep_if_needed(tags) def bzip2_dep_if_needed(tags)
Dependency.new("bzip2", tags) unless which("bzip2") Dependency.new("bzip2", [*tags, :implicit]) unless which("bzip2")
end end
def self.tar_needs_xz_dependency? def self.tar_needs_xz_dependency?
@ -127,6 +127,8 @@ class DependencyCollector
def init_global_dep_tree_if_needed!; end def init_global_dep_tree_if_needed!; end
def parse_spec(spec, tags) def parse_spec(spec, tags)
raise ArgumentError, "Implicit dependencies cannot be manually specified" if tags.include?(:implicit)
case spec case spec
when String when String
parse_string_spec(spec, tags) parse_string_spec(spec, tags)
@ -184,11 +186,11 @@ class DependencyCollector
elsif strategy <= SubversionDownloadStrategy elsif strategy <= SubversionDownloadStrategy
subversion_dep_if_needed(tags) subversion_dep_if_needed(tags)
elsif strategy <= MercurialDownloadStrategy elsif strategy <= MercurialDownloadStrategy
Dependency.new("mercurial", tags) Dependency.new("mercurial", [*tags, :implicit])
elsif strategy <= FossilDownloadStrategy elsif strategy <= FossilDownloadStrategy
Dependency.new("fossil", tags) Dependency.new("fossil", [*tags, :implicit])
elsif strategy <= BazaarDownloadStrategy elsif strategy <= BazaarDownloadStrategy
Dependency.new("breezy", tags) Dependency.new("breezy", [*tags, :implicit])
elsif strategy <= CVSDownloadStrategy elsif strategy <= CVSDownloadStrategy
cvs_dep_if_needed(tags) cvs_dep_if_needed(tags)
elsif strategy < AbstractDownloadStrategy elsif strategy < AbstractDownloadStrategy
@ -204,10 +206,10 @@ class DependencyCollector
when ".zst" then zstd_dep_if_needed(tags) when ".zst" then zstd_dep_if_needed(tags)
when ".zip" then unzip_dep_if_needed(tags) when ".zip" then unzip_dep_if_needed(tags)
when ".bz2" then bzip2_dep_if_needed(tags) when ".bz2" then bzip2_dep_if_needed(tags)
when ".lha", ".lzh" then Dependency.new("lha", tags) when ".lha", ".lzh" then Dependency.new("lha", [*tags, :implicit])
when ".lz" then Dependency.new("lzip", tags) when ".lz" then Dependency.new("lzip", [*tags, :implicit])
when ".rar" then Dependency.new("libarchive", tags) when ".rar" then Dependency.new("libarchive", [*tags, :implicit])
when ".7z" then Dependency.new("p7zip", tags) when ".7z" then Dependency.new("p7zip", [*tags, :implicit])
end end
end end
end end

View File

@ -17,7 +17,7 @@ class DependencyCollector
return if global_dep_tree[GCC]&.intersect?(related_formula_names) return if global_dep_tree[GCC]&.intersect?(related_formula_names)
return unless formula_for(GCC) return unless formula_for(GCC)
Dependency.new(GCC) Dependency.new(GCC, [:implicit])
end end
sig { params(related_formula_names: T::Set[String]).returns(T.nilable(Dependency)) } sig { params(related_formula_names: T::Set[String]).returns(T.nilable(Dependency)) }
@ -28,7 +28,7 @@ class DependencyCollector
return if global_dep_tree[GLIBC]&.intersect?(related_formula_names) return if global_dep_tree[GLIBC]&.intersect?(related_formula_names)
return unless formula_for(GLIBC) return unless formula_for(GLIBC)
Dependency.new(GLIBC) Dependency.new(GLIBC, [:implicit])
end end
private private

View File

@ -8,11 +8,11 @@ class DependencyCollector
def git_dep_if_needed(tags); end def git_dep_if_needed(tags); end
def subversion_dep_if_needed(tags) def subversion_dep_if_needed(tags)
Dependency.new("subversion", tags) Dependency.new("subversion", [*tags, :implicit])
end end
def cvs_dep_if_needed(tags) def cvs_dep_if_needed(tags)
Dependency.new("cvs", tags) Dependency.new("cvs", [*tags, :implicit])
end end
def xz_dep_if_needed(tags); end def xz_dep_if_needed(tags); end

View File

@ -52,13 +52,13 @@ describe DependencyCollector do
it "creates a resource dependency from a CVS URL" do it "creates a resource dependency from a CVS URL" do
resource = Resource.new resource = Resource.new
resource.url(":pserver:anonymous:@brew.sh:/cvsroot/foo/bar", using: :cvs) resource.url(":pserver:anonymous:@brew.sh:/cvsroot/foo/bar", using: :cvs)
expect(collector.add(resource)).to eq(Dependency.new("cvs", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("cvs", [:build, :test, :implicit]))
end end
it "creates a resource dependency from a '.7z' URL" do it "creates a resource dependency from a '.7z' URL" do
resource = Resource.new resource = Resource.new
resource.url("https://brew.sh/foo.7z") resource.url("https://brew.sh/foo.7z")
expect(collector.add(resource)).to eq(Dependency.new("p7zip", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("p7zip", [:build, :test, :implicit]))
end end
it "creates a resource dependency from a '.gz' URL" do it "creates a resource dependency from a '.gz' URL" do
@ -70,25 +70,25 @@ describe DependencyCollector do
it "creates a resource dependency from a '.lz' URL" do it "creates a resource dependency from a '.lz' URL" do
resource = Resource.new resource = Resource.new
resource.url("https://brew.sh/foo.lz") resource.url("https://brew.sh/foo.lz")
expect(collector.add(resource)).to eq(Dependency.new("lzip", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("lzip", [:build, :test, :implicit]))
end end
it "creates a resource dependency from a '.lha' URL" do it "creates a resource dependency from a '.lha' URL" do
resource = Resource.new resource = Resource.new
resource.url("https://brew.sh/foo.lha") resource.url("https://brew.sh/foo.lha")
expect(collector.add(resource)).to eq(Dependency.new("lha", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("lha", [:build, :test, :implicit]))
end end
it "creates a resource dependency from a '.lzh' URL" do it "creates a resource dependency from a '.lzh' URL" do
resource = Resource.new resource = Resource.new
resource.url("https://brew.sh/foo.lzh") resource.url("https://brew.sh/foo.lzh")
expect(collector.add(resource)).to eq(Dependency.new("lha", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("lha", [:build, :test, :implicit]))
end end
it "creates a resource dependency from a '.rar' URL" do it "creates a resource dependency from a '.rar' URL" do
resource = Resource.new resource = Resource.new
resource.url("https://brew.sh/foo.rar") resource.url("https://brew.sh/foo.rar")
expect(collector.add(resource)).to eq(Dependency.new("libarchive", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("libarchive", [:build, :test, :implicit]))
end end
it "raises a TypeError for unknown classes" do it "raises a TypeError for unknown classes" do

View File

@ -14,19 +14,19 @@ describe DependencyCollector do
it "creates a resource dependency from a '.xz' URL" do it "creates a resource dependency from a '.xz' URL" do
resource.url("https://brew.sh/foo.xz") resource.url("https://brew.sh/foo.xz")
allow_any_instance_of(Object).to receive(:which).with("xz") allow_any_instance_of(Object).to receive(:which).with("xz")
expect(collector.add(resource)).to eq(Dependency.new("xz", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("xz", [:build, :test, :implicit]))
end end
it "creates a resource dependency from a '.zip' URL" do it "creates a resource dependency from a '.zip' URL" do
resource.url("https://brew.sh/foo.zip") resource.url("https://brew.sh/foo.zip")
allow_any_instance_of(Object).to receive(:which).with("unzip") allow_any_instance_of(Object).to receive(:which).with("unzip")
expect(collector.add(resource)).to eq(Dependency.new("unzip", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("unzip", [:build, :test, :implicit]))
end end
it "creates a resource dependency from a '.bz2' URL" do it "creates a resource dependency from a '.bz2' URL" do
resource.url("https://brew.sh/foo.tar.bz2") resource.url("https://brew.sh/foo.tar.bz2")
allow_any_instance_of(Object).to receive(:which).with("bzip2") allow_any_instance_of(Object).to receive(:which).with("bzip2")
expect(collector.add(resource)).to eq(Dependency.new("bzip2", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("bzip2", [:build, :test, :implicit]))
end end
end end

View File

@ -34,6 +34,6 @@ describe DependencyCollector do
specify "Resource dependency from a Subversion URL" do specify "Resource dependency from a Subversion URL" do
resource = Resource.new resource = Resource.new
resource.url("svn://brew.sh/foo/bar") resource.url("svn://brew.sh/foo/bar")
expect(collector.add(resource)).to eq(Dependency.new("subversion", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("subversion", [:build, :test, :implicit]))
end end
end end