Move SimulateSystem check to extend/os

This commit is contained in:
apainintheneck 2022-11-21 21:04:22 -08:00
parent 1db5d967c3
commit 2eee1e7c2a
4 changed files with 62 additions and 16 deletions

View File

@ -0,0 +1,29 @@
# typed: true
# frozen_string_literal: true
module Homebrew
class SimulateSystem
class << self
undef os
undef simulating_or_running_on_linux?
undef current_os
sig { returns(T.nilable(Symbol)) }
def os
return :macos if @os.blank? && Homebrew::EnvConfig.simulate_macos_on_linux?
@os
end
sig { returns(T::Boolean) }
def simulating_or_running_on_linux?
os.blank? || os == :linux
end
sig { returns(Symbol) }
def current_os
os || :linux
end
end
end
end

View File

@ -0,0 +1,21 @@
# typed: true
# frozen_string_literal: true
module Homebrew
class SimulateSystem
class << self
undef simulating_or_running_on_macos?
undef current_os
sig { returns(T::Boolean) }
def simulating_or_running_on_macos?
os.blank? || [:macos, *MacOSVersions::SYMBOLS.keys].include?(os)
end
sig { returns(Symbol) }
def current_os
os || MacOS.version.to_sym
end
end
end
end

View File

@ -0,0 +1,8 @@
# typed: strict
# frozen_string_literal: true
if OS.mac?
require "extend/os/mac/simulate_system"
elsif OS.linux?
require "extend/os/linux/simulate_system"
end

View File

@ -9,14 +9,7 @@ module Homebrew
class << self class << self
extend T::Sig extend T::Sig
attr_reader :arch attr_reader :arch, :os
sig { returns(T.nilable(Symbol)) }
def os
return :macos if @os.blank? && !OS.mac? && Homebrew::EnvConfig.simulate_macos_on_linux?
@os
end
sig { params(new_os: Symbol).void } sig { params(new_os: Symbol).void }
def os=(new_os) def os=(new_os)
@ -40,15 +33,11 @@ module Homebrew
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def simulating_or_running_on_macos? def simulating_or_running_on_macos?
return OS.mac? if os.blank?
[:macos, *MacOSVersions::SYMBOLS.keys].include?(os) [:macos, *MacOSVersions::SYMBOLS.keys].include?(os)
end end
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def simulating_or_running_on_linux? def simulating_or_running_on_linux?
return OS.linux? if os.blank?
os == :linux os == :linux
end end
@ -59,11 +48,10 @@ module Homebrew
sig { returns(Symbol) } sig { returns(Symbol) }
def current_os def current_os
return T.must(os) if os.present? os || :generic
return :linux if OS.linux? end
end
end
end
MacOS.version.to_sym require "extend/os/simulate_system"
end
end
end
end