Extends SoftwareSpec with #uses_from_macos
This commit is contained in:
parent
412f7d964f
commit
aafe87524d
19
Library/Homebrew/extend/os/mac/software_spec.rb
Normal file
19
Library/Homebrew/extend/os/mac/software_spec.rb
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class SoftwareSpec
|
||||||
|
def uses_from_macos(deps, **args)
|
||||||
|
depends_on(deps) if add_mac_dependency?(args)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def add_mac_dependency?(args)
|
||||||
|
args.each { |key, version| args[key] = OS::Mac::Version.from_symbol(version) }
|
||||||
|
|
||||||
|
return false if args[:after] && OS::Mac.version < args[:after]
|
||||||
|
|
||||||
|
return false if args[:before] && OS::Mac.version >= args[:before]
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,3 +1,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "extend/os/linux/software_spec" if OS.linux?
|
if OS.linux?
|
||||||
|
require "extend/os/linux/software_spec"
|
||||||
|
elsif OS.mac?
|
||||||
|
require "extend/os/mac/software_spec"
|
||||||
|
end
|
||||||
|
|||||||
@ -2360,8 +2360,8 @@ class Formula
|
|||||||
specs.each { |spec| spec.depends_on(dep) }
|
specs.each { |spec| spec.depends_on(dep) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def uses_from_macos(dep, **_args)
|
def uses_from_macos(dep, **args)
|
||||||
depends_on(dep)
|
specs.each { |spec| spec.uses_from_macos(dep, args) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# @!attribute [w] option
|
# @!attribute [w] option
|
||||||
|
|||||||
@ -170,6 +170,10 @@ class SoftwareSpec
|
|||||||
add_dep_option(dep) if dep
|
add_dep_option(dep) if dep
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def uses_from_macos(spec, **_args)
|
||||||
|
depends_on(spec)
|
||||||
|
end
|
||||||
|
|
||||||
def deps
|
def deps
|
||||||
dependency_collector.deps
|
dependency_collector.deps
|
||||||
end
|
end
|
||||||
|
|||||||
48
Library/Homebrew/test/os/mac/software_spec_spec.rb
Normal file
48
Library/Homebrew/test/os/mac/software_spec_spec.rb
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "software_spec"
|
||||||
|
|
||||||
|
describe SoftwareSpec do
|
||||||
|
describe "#uses_from_macos" do
|
||||||
|
before do
|
||||||
|
sierra_os_version = OS::Mac::Version.from_symbol(:sierra)
|
||||||
|
|
||||||
|
allow(OS).to receive(:mac?).and_return(true)
|
||||||
|
allow(OS::Mac).to receive(:version).and_return(OS::Mac::Version.new(sierra_os_version))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't adds a dependency if it doesn't meet OS version requirements" do
|
||||||
|
subject.uses_from_macos("foo", after: :high_sierra)
|
||||||
|
subject.uses_from_macos("bar", before: :el_capitan)
|
||||||
|
|
||||||
|
expect(subject.deps).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "allows specifying dependencies after certain version" do
|
||||||
|
subject.uses_from_macos("foo", after: :el_capitan)
|
||||||
|
|
||||||
|
expect(subject.deps.first.name).to eq("foo")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "works with tags" do
|
||||||
|
subject.uses_from_macos("foo" => :head, after: :el_capitan)
|
||||||
|
|
||||||
|
dep = subject.deps.first
|
||||||
|
|
||||||
|
expect(dep.name).to eq("foo")
|
||||||
|
expect(dep.tags).to include(:head)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "allows specifying dependencies before certain version" do
|
||||||
|
subject.uses_from_macos("foo", before: :high_sierra)
|
||||||
|
|
||||||
|
expect(subject.deps.first.name).to eq("foo")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "raises an error if passing invalid OS versions" do
|
||||||
|
expect {
|
||||||
|
subject.uses_from_macos("foo", after: "bar", before: :mojave)
|
||||||
|
}.to raise_error(ArgumentError, 'unknown version "bar"')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user