-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6162 from gkpacker/add_uses_from_macos
Add uses from macos
- Loading branch information
Showing
7 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters