2022-06-23 17:18:58 -04:00
|
|
|
# typed: true
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Homebrew
|
2022-06-28 15:04:30 -04:00
|
|
|
# Helper module for simulating different system condfigurations.
|
2022-06-23 17:18:58 -04:00
|
|
|
#
|
|
|
|
# @api private
|
2022-06-28 15:04:30 -04:00
|
|
|
class SimulateSystem
|
2022-06-23 17:18:58 -04:00
|
|
|
class << self
|
|
|
|
extend T::Sig
|
|
|
|
|
|
|
|
attr_reader :os, :arch
|
|
|
|
|
|
|
|
sig { params(new_os: Symbol).void }
|
|
|
|
def os=(new_os)
|
2022-06-29 11:29:46 -04:00
|
|
|
os_options = [:macos, :linux, *MacOSVersions::SYMBOLS.keys]
|
2022-06-23 17:18:58 -04:00
|
|
|
raise "Unknown OS: #{new_os}" unless os_options.include?(new_os)
|
|
|
|
|
|
|
|
@os = new_os
|
|
|
|
end
|
|
|
|
|
|
|
|
sig { params(new_arch: Symbol).void }
|
|
|
|
def arch=(new_arch)
|
|
|
|
raise "New arch must be :arm or :intel" unless [:arm, :intel].include?(new_arch)
|
|
|
|
|
|
|
|
@arch = new_arch
|
|
|
|
end
|
|
|
|
|
|
|
|
sig { void }
|
|
|
|
def clear
|
|
|
|
@os = @arch = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
sig { returns(T::Boolean) }
|
2022-07-23 02:00:28 +02:00
|
|
|
def treat_as_macos?
|
|
|
|
return OS.mac? if @os.blank?
|
2022-06-23 17:18:58 -04:00
|
|
|
|
2022-06-29 11:29:46 -04:00
|
|
|
[:macos, *MacOSVersions::SYMBOLS.keys].include?(@os)
|
2022-06-23 17:18:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
sig { returns(T::Boolean) }
|
2022-07-23 02:00:28 +02:00
|
|
|
def treat_as_linux?
|
|
|
|
return OS.linux? if @os.blank?
|
|
|
|
|
2022-06-23 17:18:58 -04:00
|
|
|
@os == :linux
|
|
|
|
end
|
2022-07-23 02:00:28 +02:00
|
|
|
|
|
|
|
sig { returns(Symbol) }
|
|
|
|
def current_arch
|
|
|
|
@arch || Hardware::CPU.type
|
|
|
|
end
|
|
|
|
|
|
|
|
sig { returns(Symbol) }
|
|
|
|
def current_os
|
|
|
|
return @os if @os.present?
|
|
|
|
return :linux if OS.linux?
|
|
|
|
|
|
|
|
MacOS.version.to_sym
|
|
|
|
end
|
2022-06-23 17:18:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|