diff --git a/Library/Homebrew/extend/os/linux/simulate_system.rb b/Library/Homebrew/extend/os/linux/simulate_system.rb new file mode 100644 index 0000000000..35ddeb8740 --- /dev/null +++ b/Library/Homebrew/extend/os/linux/simulate_system.rb @@ -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 diff --git a/Library/Homebrew/extend/os/mac/simulate_system.rb b/Library/Homebrew/extend/os/mac/simulate_system.rb new file mode 100644 index 0000000000..053d361869 --- /dev/null +++ b/Library/Homebrew/extend/os/mac/simulate_system.rb @@ -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 diff --git a/Library/Homebrew/extend/os/simulate_system.rb b/Library/Homebrew/extend/os/simulate_system.rb new file mode 100644 index 0000000000..5558a82de2 --- /dev/null +++ b/Library/Homebrew/extend/os/simulate_system.rb @@ -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 diff --git a/Library/Homebrew/simulate_system.rb b/Library/Homebrew/simulate_system.rb index 206e9a460f..51be4690a6 100644 --- a/Library/Homebrew/simulate_system.rb +++ b/Library/Homebrew/simulate_system.rb @@ -9,14 +9,7 @@ module Homebrew class << self extend T::Sig - attr_reader :arch - - sig { returns(T.nilable(Symbol)) } - def os - return :macos if @os.blank? && !OS.mac? && Homebrew::EnvConfig.simulate_macos_on_linux? - - @os - end + attr_reader :arch, :os sig { params(new_os: Symbol).void } def os=(new_os) @@ -40,15 +33,11 @@ module Homebrew sig { returns(T::Boolean) } def simulating_or_running_on_macos? - return OS.mac? if os.blank? - [:macos, *MacOSVersions::SYMBOLS.keys].include?(os) end sig { returns(T::Boolean) } def simulating_or_running_on_linux? - return OS.linux? if os.blank? - os == :linux end @@ -59,11 +48,10 @@ module Homebrew sig { returns(Symbol) } def current_os - return T.must(os) if os.present? - return :linux if OS.linux? - - MacOS.version.to_sym + os || :generic end end end end + +require "extend/os/simulate_system"