mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Merge pull request #7458 from Bo98/uses_since
software_spec: add uses_from_macos since bound
This commit is contained in:
commit
e6dffdd006
@ -3,8 +3,19 @@
|
|||||||
class SoftwareSpec
|
class SoftwareSpec
|
||||||
undef uses_from_macos
|
undef uses_from_macos
|
||||||
|
|
||||||
def uses_from_macos(deps)
|
def uses_from_macos(deps, bounds = {})
|
||||||
@uses_from_macos_elements ||= []
|
@uses_from_macos_elements ||= []
|
||||||
|
|
||||||
|
if deps.is_a?(Hash)
|
||||||
|
bounds = deps.dup
|
||||||
|
deps = Hash[*bounds.shift]
|
||||||
|
end
|
||||||
|
|
||||||
|
bounds.transform_values! { |v| MacOS::Version.from_symbol(v) }
|
||||||
|
if MacOS.version >= bounds[:since]
|
||||||
@uses_from_macos_elements << deps
|
@uses_from_macos_elements << deps
|
||||||
|
else
|
||||||
|
depends_on deps
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2431,8 +2431,8 @@ class Formula
|
|||||||
# Indicates use of dependencies provided by macOS.
|
# Indicates use of dependencies provided by macOS.
|
||||||
# On macOS this is a no-op (as we use the system libraries there).
|
# On macOS this is a no-op (as we use the system libraries there).
|
||||||
# On Linux this will act as `depends_on`.
|
# On Linux this will act as `depends_on`.
|
||||||
def uses_from_macos(dep)
|
def uses_from_macos(dep, bounds = {})
|
||||||
specs.each { |spec| spec.uses_from_macos(dep) }
|
specs.each { |spec| spec.uses_from_macos(dep, bounds) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Block executed only executed on macOS. No-op on Linux.
|
# Block executed only executed on macOS. No-op on Linux.
|
||||||
|
@ -126,7 +126,7 @@ module RuboCop
|
|||||||
|
|
||||||
# Node pattern method to extract `name` in `depends_on :name` or `uses_from_macos :name`
|
# Node pattern method to extract `name` in `depends_on :name` or `uses_from_macos :name`
|
||||||
def_node_search :dependency_name_node, <<~EOS
|
def_node_search :dependency_name_node, <<~EOS
|
||||||
{(send nil? {:depends_on :uses_from_macos} {(hash (pair $_ _)) $({str sym} _) $(const nil? _)})
|
{(send nil? {:depends_on :uses_from_macos} {(hash (pair $_ _) ...) $({str sym} _) $(const nil? _)} ...)
|
||||||
(if _ (send nil? :depends_on {(hash (pair $_ _)) $({str sym} _) $(const nil? _)}) nil?)}
|
(if _ (send nil? :depends_on {(hash (pair $_ _)) $({str sym} _) $(const nil? _)}) nil?)}
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
|
@ -171,7 +171,8 @@ class SoftwareSpec
|
|||||||
add_dep_option(dep) if dep
|
add_dep_option(dep) if dep
|
||||||
end
|
end
|
||||||
|
|
||||||
def uses_from_macos(spec)
|
def uses_from_macos(spec, _bounds = {})
|
||||||
|
spec = Hash[*spec.first] if spec.is_a?(Hash)
|
||||||
depends_on(spec)
|
depends_on(spec)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,6 +19,18 @@ describe Formula do
|
|||||||
expect(f.class.devel.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")
|
expect(f.class.head.deps.first.name).to eq("foo")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "ignores OS version specifications" do
|
||||||
|
f = formula "foo" do
|
||||||
|
url "foo-1.0"
|
||||||
|
|
||||||
|
uses_from_macos "foo", since: :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
|
||||||
|
|
||||||
describe "#on_linux" do
|
describe "#on_linux" do
|
||||||
|
@ -13,11 +13,40 @@ describe SoftwareSpec do
|
|||||||
allow(OS::Mac).to receive(:version).and_return(OS::Mac::Version.new(sierra_os_version))
|
allow(OS::Mac).to receive(:version).and_return(OS::Mac::Version.new(sierra_os_version))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't add a dependency" do
|
it "adds a macOS dependency if the OS version meets requirements" do
|
||||||
|
spec.uses_from_macos("foo", since: :el_capitan)
|
||||||
|
|
||||||
|
expect(spec.deps).to be_empty
|
||||||
|
expect(spec.uses_from_macos_elements.first).to eq("foo")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't add a macOS dependency if the OS version doesn't meet requirements" do
|
||||||
|
spec.uses_from_macos("foo", since: :high_sierra)
|
||||||
|
|
||||||
|
expect(spec.deps.first.name).to eq("foo")
|
||||||
|
expect(spec.uses_from_macos_elements).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "works with tags" do
|
||||||
|
spec.uses_from_macos("foo" => :build, :since => :high_sierra)
|
||||||
|
|
||||||
|
dep = spec.deps.first
|
||||||
|
|
||||||
|
expect(dep.name).to eq("foo")
|
||||||
|
expect(dep.tags).to include(:build)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't add a dependency if no OS version is specified" do
|
||||||
spec.uses_from_macos("foo")
|
spec.uses_from_macos("foo")
|
||||||
spec.uses_from_macos("bar" => :build)
|
spec.uses_from_macos("bar" => :build)
|
||||||
|
|
||||||
expect(spec.deps).to be_empty
|
expect(spec.deps).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "raises an error if passing invalid OS versions" do
|
||||||
|
expect {
|
||||||
|
spec.uses_from_macos("foo", since: :bar)
|
||||||
|
}.to raise_error(ArgumentError, "unknown version :bar")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -147,8 +147,8 @@ describe SoftwareSpec do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "ignores OS version specifications", :needs_linux do
|
it "ignores OS version specifications", :needs_linux do
|
||||||
subject.uses_from_macos("foo")
|
subject.uses_from_macos("foo", since: :mojave)
|
||||||
subject.uses_from_macos("bar" => :build)
|
subject.uses_from_macos("bar" => :build, :since => :mojave)
|
||||||
|
|
||||||
expect(subject.deps.first.name).to eq("foo")
|
expect(subject.deps.first.name).to eq("foo")
|
||||||
expect(subject.deps.last.name).to eq("bar")
|
expect(subject.deps.last.name).to eq("bar")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user