Rename Override module to SimulateSystem
This commit is contained in:
parent
d96a8fd35e
commit
5ec19adf58
@ -255,8 +255,8 @@ module Cask
|
|||||||
# Big Sur is the first version of macOS that supports arm
|
# Big Sur is the first version of macOS that supports arm
|
||||||
next if arch == :arm && MacOS::Version.from_symbol(os_name) < MacOS::Version.from_symbol(:big_sur)
|
next if arch == :arm && MacOS::Version.from_symbol(os_name) < MacOS::Version.from_symbol(:big_sur)
|
||||||
|
|
||||||
Homebrew::Override.os = os_name
|
Homebrew::SimulateSystem.os = os_name
|
||||||
Homebrew::Override.arch = arch
|
Homebrew::SimulateSystem.arch = arch
|
||||||
|
|
||||||
refresh
|
refresh
|
||||||
|
|
||||||
@ -272,7 +272,7 @@ module Cask
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Homebrew::Override.clear
|
Homebrew::SimulateSystem.clear
|
||||||
refresh
|
refresh
|
||||||
|
|
||||||
hash["variations"] = variations
|
hash["variations"] = variations
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
require "locale"
|
require "locale"
|
||||||
require "lazy_object"
|
require "lazy_object"
|
||||||
require "livecheck"
|
require "livecheck"
|
||||||
require "override"
|
|
||||||
|
|
||||||
require "cask/artifact"
|
require "cask/artifact"
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
# typed: false
|
# typed: false
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "override"
|
require "simulate_system"
|
||||||
|
|
||||||
module OnSystem
|
module OnSystem
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
@ -13,9 +13,9 @@ module OnSystem
|
|||||||
|
|
||||||
sig { params(arch: Symbol).returns(T::Boolean) }
|
sig { params(arch: Symbol).returns(T::Boolean) }
|
||||||
def arch_condition_met?(arch)
|
def arch_condition_met?(arch)
|
||||||
raise ArgumentError, "Invalid arch condition: #{arch.inspect}" unless ARCH_OPTIONS.include?(arch)
|
raise ArgumentError, "Invalid arch condition: #{arch.inspect}" if ARCH_OPTIONS.exclude?(arch)
|
||||||
|
|
||||||
current_arch = Homebrew::Override.arch || Hardware::CPU.type
|
current_arch = Homebrew::SimulateSystem.arch || Hardware::CPU.type
|
||||||
arch == current_arch
|
arch == current_arch
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -27,12 +27,12 @@ module OnSystem
|
|||||||
end
|
end
|
||||||
|
|
||||||
if BASE_OS_OPTIONS.include?(os_name)
|
if BASE_OS_OPTIONS.include?(os_name)
|
||||||
if Homebrew::Override.none?
|
if Homebrew::SimulateSystem.none?
|
||||||
return OS.linux? if os_name == :linux
|
return OS.linux? if os_name == :linux
|
||||||
return OS.mac? if os_name == :macos
|
return OS.mac? if os_name == :macos
|
||||||
end
|
end
|
||||||
|
|
||||||
return Homebrew::Override.send("#{os_name}?")
|
return Homebrew::SimulateSystem.send("#{os_name}?")
|
||||||
end
|
end
|
||||||
|
|
||||||
raise ArgumentError, "Invalid OS condition: #{os_name.inspect}" unless MacOS::Version::SYMBOLS.key?(os_name)
|
raise ArgumentError, "Invalid OS condition: #{os_name.inspect}" unless MacOS::Version::SYMBOLS.key?(os_name)
|
||||||
@ -42,7 +42,7 @@ module OnSystem
|
|||||||
end
|
end
|
||||||
|
|
||||||
base_os = MacOS::Version.from_symbol(os_name)
|
base_os = MacOS::Version.from_symbol(os_name)
|
||||||
current_os = MacOS::Version.from_symbol(Homebrew::Override.os || MacOS.version.to_sym)
|
current_os = MacOS::Version.from_symbol(Homebrew::SimulateSystem.os || MacOS.version.to_sym)
|
||||||
|
|
||||||
return current_os >= base_os if or_condition == :or_newer
|
return current_os >= base_os if or_condition == :or_newer
|
||||||
return current_os <= base_os if or_condition == :or_older
|
return current_os <= base_os if or_condition == :or_older
|
||||||
|
|||||||
@ -2,16 +2,13 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
# Helper module for overriding machine-specific methods.
|
# Helper module for simulating different system condfigurations.
|
||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
class Override
|
class SimulateSystem
|
||||||
class << self
|
class << self
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
ARCH_OPTIONS = [:intel, :arm64].freeze
|
|
||||||
OS_OPTIONS = [:macos, :linux].freeze
|
|
||||||
|
|
||||||
attr_reader :os, :arch
|
attr_reader :os, :arch
|
||||||
|
|
||||||
sig { params(new_os: Symbol).void }
|
sig { params(new_os: Symbol).void }
|
||||||
@ -1583,11 +1583,11 @@ describe Formula do
|
|||||||
|
|
||||||
describe "on_{os_version} blocks", :needs_macos do
|
describe "on_{os_version} blocks", :needs_macos do
|
||||||
before do
|
before do
|
||||||
Homebrew::Override.os = :monterey
|
Homebrew::SimulateSystem.os = :monterey
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
Homebrew::Override.clear
|
Homebrew::SimulateSystem.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:f) do
|
let(:f) do
|
||||||
@ -1610,31 +1610,31 @@ describe Formula do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "only calls code within `on_monterey`" do
|
it "only calls code within `on_monterey`" do
|
||||||
Homebrew::Override.os = :monterey
|
Homebrew::SimulateSystem.os = :monterey
|
||||||
f.brew { f.install }
|
f.brew { f.install }
|
||||||
expect(f.test).to eq(1)
|
expect(f.test).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "only calls code within `on_monterey :or_newer`" do
|
it "only calls code within `on_monterey :or_newer`" do
|
||||||
Homebrew::Override.os = :ventura
|
Homebrew::SimulateSystem.os = :ventura
|
||||||
f.brew { f.install }
|
f.brew { f.install }
|
||||||
expect(f.test).to eq(1)
|
expect(f.test).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "only calls code within `on_big_sur`" do
|
it "only calls code within `on_big_sur`" do
|
||||||
Homebrew::Override.os = :big_sur
|
Homebrew::SimulateSystem.os = :big_sur
|
||||||
f.brew { f.install }
|
f.brew { f.install }
|
||||||
expect(f.test).to eq(2)
|
expect(f.test).to eq(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "only calls code within `on_catalina`" do
|
it "only calls code within `on_catalina`" do
|
||||||
Homebrew::Override.os = :catalina
|
Homebrew::SimulateSystem.os = :catalina
|
||||||
f.brew { f.install }
|
f.brew { f.install }
|
||||||
expect(f.test).to eq(3)
|
expect(f.test).to eq(3)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "only calls code within `on_catalina :or_older`" do
|
it "only calls code within `on_catalina :or_older`" do
|
||||||
Homebrew::Override.os = :mojave
|
Homebrew::SimulateSystem.os = :mojave
|
||||||
f.brew { f.install }
|
f.brew { f.install }
|
||||||
expect(f.test).to eq(3)
|
expect(f.test).to eq(3)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user