Merge pull request #6162 from gkpacker/add_uses_from_macos
Add uses from macos
This commit is contained in:
commit
7c5f71e5ac
26
Library/Homebrew/extend/os/mac/software_spec.rb
Normal file
26
Library/Homebrew/extend/os/mac/software_spec.rb
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class SoftwareSpec
|
||||||
|
undef uses_from_macos
|
||||||
|
|
||||||
|
def uses_from_macos(deps, **args)
|
||||||
|
if deps.is_a?(Hash)
|
||||||
|
args = deps
|
||||||
|
deps = Hash[*args.shift]
|
||||||
|
end
|
||||||
|
|
||||||
|
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]
|
||||||
|
|
||||||
|
args.present?
|
||||||
|
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,6 +2360,10 @@ class Formula
|
|||||||
specs.each { |spec| spec.depends_on(dep) }
|
specs.each { |spec| spec.depends_on(dep) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def uses_from_macos(dep, **args)
|
||||||
|
specs.each { |spec| spec.uses_from_macos(dep, args) }
|
||||||
|
end
|
||||||
|
|
||||||
# @!attribute [w] option
|
# @!attribute [w] option
|
||||||
# Options can be used as arguments to `brew install`.
|
# Options can be used as arguments to `brew install`.
|
||||||
# To switch features on/off: `"with-something"` or `"with-otherthing"`.
|
# To switch features on/off: `"with-something"` or `"with-otherthing"`.
|
||||||
|
|||||||
@ -170,6 +170,12 @@ class SoftwareSpec
|
|||||||
add_dep_option(dep) if dep
|
add_dep_option(dep) if dep
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def uses_from_macos(deps, **_args)
|
||||||
|
deps = Hash[*deps.shift] if deps.is_a?(Hash)
|
||||||
|
|
||||||
|
depends_on(deps)
|
||||||
|
end
|
||||||
|
|
||||||
def deps
|
def deps
|
||||||
dependency_collector.deps
|
dependency_collector.deps
|
||||||
end
|
end
|
||||||
|
|||||||
35
Library/Homebrew/test/os/linux/formula_spec.rb
Normal file
35
Library/Homebrew/test/os/linux/formula_spec.rb
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "formula"
|
||||||
|
|
||||||
|
describe Formula do
|
||||||
|
describe "#uses_from_macos" do
|
||||||
|
before do
|
||||||
|
allow(OS).to receive(:mac?).and_return(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "acts like #depends_on" do
|
||||||
|
f = formula "foo" do
|
||||||
|
url "foo-1.0"
|
||||||
|
|
||||||
|
uses_from_macos("foo")
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(f.class.stable.deps.first.name).to eq("foo")
|
||||||
|
expect(f.class.devel.deps.first.name).to eq("foo")
|
||||||
|
expect(f.class.head.deps.first.name).to eq("foo")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "ignores OS version specifications" do
|
||||||
|
f = formula "foo" do
|
||||||
|
url "foo-1.0"
|
||||||
|
|
||||||
|
uses_from_macos("foo", after: :mojave)
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(f.class.stable.deps.first.name).to eq("foo")
|
||||||
|
expect(f.class.devel.deps.first.name).to eq("foo")
|
||||||
|
expect(f.class.head.deps.first.name).to eq("foo")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
63
Library/Homebrew/test/os/mac/software_spec_spec.rb
Normal file
63
Library/Homebrew/test/os/mac/software_spec_spec.rb
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "software_spec"
|
||||||
|
|
||||||
|
describe SoftwareSpec do
|
||||||
|
subject(:spec) { described_class.new }
|
||||||
|
|
||||||
|
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 "allows specifying dependencies before certain version" do
|
||||||
|
spec.uses_from_macos("foo", before: :high_sierra)
|
||||||
|
|
||||||
|
expect(spec.deps.first.name).to eq("foo")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "allows specifying dependencies after certain version" do
|
||||||
|
spec.uses_from_macos("foo", after: :el_capitan)
|
||||||
|
|
||||||
|
expect(spec.deps.first.name).to eq("foo")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't adds a dependency if it doesn't meet OS version requirements" do
|
||||||
|
spec.uses_from_macos("foo", after: :high_sierra)
|
||||||
|
spec.uses_from_macos("bar", before: :el_capitan)
|
||||||
|
|
||||||
|
expect(spec.deps).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "works with tags" do
|
||||||
|
spec.uses_from_macos("foo" => :head, :after => :el_capitan)
|
||||||
|
|
||||||
|
dep = spec.deps.first
|
||||||
|
|
||||||
|
expect(dep.name).to eq("foo")
|
||||||
|
expect(dep.tags).to include(:head)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't adds the dependency without OS version requirements" do
|
||||||
|
spec.uses_from_macos("foo")
|
||||||
|
spec.uses_from_macos("bar" => :head)
|
||||||
|
|
||||||
|
expect(spec.deps).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "respects OS version requirements with tags" do
|
||||||
|
spec.uses_from_macos("foo" => :head, :after => :mojave)
|
||||||
|
|
||||||
|
expect(spec.deps).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "raises an error if passing invalid OS versions" do
|
||||||
|
expect {
|
||||||
|
spec.uses_from_macos("foo", after: "bar", before: :mojave)
|
||||||
|
}.to raise_error(ArgumentError, 'unknown version "bar"')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -132,6 +132,30 @@ describe SoftwareSpec do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#uses_from_macos" do
|
||||||
|
it "allows specifying dependencies", :needs_linux do
|
||||||
|
subject.uses_from_macos("foo")
|
||||||
|
|
||||||
|
expect(subject.deps.first.name).to eq("foo")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "works with tags", :needs_linux do
|
||||||
|
subject.uses_from_macos("foo" => :head, :after => :mojave)
|
||||||
|
|
||||||
|
expect(subject.deps.first.name).to eq("foo")
|
||||||
|
expect(subject.deps.first.tags).to include(:head)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "ignores OS version specifications", :needs_linux do
|
||||||
|
subject.uses_from_macos("foo", after: :mojave)
|
||||||
|
subject.uses_from_macos("bar" => :head, :after => :mojave)
|
||||||
|
|
||||||
|
expect(subject.deps.first.name).to eq("foo")
|
||||||
|
expect(subject.deps.last.name).to eq("bar")
|
||||||
|
expect(subject.deps.last.tags).to include(:head)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
specify "explicit options override defaupt depends_on option description" do
|
specify "explicit options override defaupt depends_on option description" do
|
||||||
subject.option("with-foo", "blah")
|
subject.option("with-foo", "blah")
|
||||||
subject.depends_on("foo" => :optional)
|
subject.depends_on("foo" => :optional)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user