Merge pull request #7702 from iMichka/resource

on_os blocks: resources, patches
This commit is contained in:
Michka Popoff 2020-06-11 11:42:41 +02:00 committed by GitHub
commit a81e1d1fa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 67 deletions

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
class Resource
undef on_linux
def on_linux(&_block)
yield
end
end

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
class Resource
undef on_macos
def on_macos(&_block)
yield
end
end

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
if OS.mac?
require "extend/os/mac/resource"
elsif OS.linux?
require "extend/os/linux/resource"
end

View File

@ -2474,13 +2474,13 @@ class Formula
specs.each { |spec| spec.uses_from_macos(dep, bounds) }
end
# Block executed only executed on macOS. No-op on Linux.
# Block only executed on macOS. No-op on Linux.
# <pre>on_macos do
# depends_on "mac_only_dep"
# end</pre>
def on_macos(&_block); end
# Block executed only executed on Linux. No-op on macOS.
# Block only executed on Linux. No-op on macOS.
# <pre>on_linux do
# depends_on "linux_only_dep"
# end</pre>

View File

@ -178,6 +178,18 @@ class Resource
patches << p
end
# Block only executed on macOS. No-op on Linux.
# <pre>on_macos do
# url "mac_only_url"
# end</pre>
def on_macos(&_block); end
# Block only executed on Linux. No-op on macOS.
# <pre>on_linux do
# url "linux_only_url"
# end</pre>
def on_linux(&_block); end
protected
def mktemp(prefix)
@ -252,3 +264,5 @@ class ResourceStageContext
"<#{self.class}: resource=#{resource} staging=#{staging}>"
end
end
require "extend/os/resource"

View File

@ -33,26 +33,6 @@ describe Formula do
end
end
describe "#on_linux" do
it "defines an url on Linux only" do
f = formula do
homepage "https://brew.sh"
on_macos do
url "https://brew.sh/test-macos-0.1.tbz"
sha256 TEST_SHA256
end
on_linux do
url "https://brew.sh/test-linux-0.1.tbz"
sha256 TEST_SHA256
end
end
expect(f.stable.url).to eq("https://brew.sh/test-linux-0.1.tbz")
end
end
describe "#on_linux" do
it "adds a dependency on Linux only" do
f = formula do
@ -87,27 +67,38 @@ describe Formula do
sha256 TEST_SHA256
patch do
url "patch_both"
end
on_macos do
patch do
url "patch_macos"
end
end
on_linux do
patch do
url "patch_linux"
end
end
end
expect(f.patchlist.length).to eq(2)
expect(f.patchlist.length).to eq(1)
expect(f.patchlist.first.strip).to eq(:p1)
expect(f.patchlist.first.url).to eq("patch_both")
expect(f.patchlist.second.strip).to eq(:p1)
expect(f.patchlist.second.url).to eq("patch_linux")
expect(f.patchlist.first.url).to eq("patch_linux")
end
end
describe "#on_linux" do
it "uses on_linux within a resource block" do
f = formula do
homepage "https://brew.sh"
url "https://brew.sh/test-0.1.tbz"
sha256 TEST_SHA256
resource "test_resource" do
on_linux do
url "on_linux"
end
end
end
expect(f.resources.length).to eq(1)
expect(f.resources.first.url).to eq("on_linux")
end
end
end

View File

@ -40,26 +40,6 @@ describe Formula do
end
end
describe "#on_macos" do
it "defines an url on macos only" do
f = formula do
homepage "https://brew.sh"
on_macos do
url "https://brew.sh/test-macos-0.1.tbz"
sha256 TEST_SHA256
end
on_linux do
url "https://brew.sh/test-linux-0.1.tbz"
sha256 TEST_SHA256
end
end
expect(f.stable.url).to eq("https://brew.sh/test-macos-0.1.tbz")
end
end
describe "#on_macos" do
it "adds a dependency on macos only" do
f = formula do
@ -86,7 +66,7 @@ describe Formula do
end
describe "#on_macos" do
it "adds a patch on macos only" do
it "adds a patch on Mac only" do
f = formula do
homepage "https://brew.sh"
@ -94,27 +74,38 @@ describe Formula do
sha256 TEST_SHA256
patch do
url "patch_both"
end
on_macos do
patch do
url "patch_macos"
end
end
on_linux do
patch do
url "patch_linux"
end
end
end
expect(f.patchlist.length).to eq(2)
expect(f.patchlist.length).to eq(1)
expect(f.patchlist.first.strip).to eq(:p1)
expect(f.patchlist.first.url).to eq("patch_both")
expect(f.patchlist.second.strip).to eq(:p1)
expect(f.patchlist.second.url).to eq("patch_macos")
expect(f.patchlist.first.url).to eq("patch_macos")
end
end
describe "#on_macos" do
it "uses on_macos within a resource block" do
f = formula do
homepage "https://brew.sh"
url "https://brew.sh/test-0.1.tbz"
sha256 TEST_SHA256
resource "test_resource" do
on_macos do
url "resource_macos"
end
end
end
expect(f.resources.length).to eq(1)
expect(f.resources.first.url).to eq("resource_macos")
end
end
end