mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Move HOMEBREW_SIMULATE_MACOS_ON_LINUX
handling to SimulateSystem
This commit is contained in:
parent
ef929a7c28
commit
ea1f2098ac
@ -1,10 +1,12 @@
|
|||||||
# typed: true
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "simulate_system"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
DEFAULT_PREFIX, DEFAULT_REPOSITORY = if OS.mac? && Hardware::CPU.arm?
|
DEFAULT_PREFIX, DEFAULT_REPOSITORY = if OS.mac? && Hardware::CPU.arm?
|
||||||
[HOMEBREW_MACOS_ARM_DEFAULT_PREFIX, HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY]
|
[HOMEBREW_MACOS_ARM_DEFAULT_PREFIX, HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY]
|
||||||
elsif OS.linux? && !EnvConfig.simulate_macos_on_linux?
|
elsif Homebrew::SimulateSystem.simulating_or_running_on_linux?
|
||||||
[HOMEBREW_LINUX_DEFAULT_PREFIX, HOMEBREW_LINUX_DEFAULT_REPOSITORY]
|
[HOMEBREW_LINUX_DEFAULT_PREFIX, HOMEBREW_LINUX_DEFAULT_REPOSITORY]
|
||||||
else
|
else
|
||||||
[HOMEBREW_DEFAULT_PREFIX, HOMEBREW_DEFAULT_REPOSITORY]
|
[HOMEBREW_DEFAULT_PREFIX, HOMEBREW_DEFAULT_REPOSITORY]
|
||||||
|
@ -20,11 +20,6 @@ module OnSystem
|
|||||||
|
|
||||||
sig { params(os_name: Symbol, or_condition: T.nilable(Symbol)).returns(T::Boolean) }
|
sig { params(os_name: Symbol, or_condition: T.nilable(Symbol)).returns(T::Boolean) }
|
||||||
def os_condition_met?(os_name, or_condition = nil)
|
def os_condition_met?(os_name, or_condition = nil)
|
||||||
if Homebrew::EnvConfig.simulate_macos_on_linux?
|
|
||||||
return false if os_name == :linux
|
|
||||||
return true if [:macos, *MacOSVersions::SYMBOLS.keys].include?(os_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
return Homebrew::SimulateSystem.send("simulating_or_running_on_#{os_name}?") if BASE_OS_OPTIONS.include?(os_name)
|
return Homebrew::SimulateSystem.send("simulating_or_running_on_#{os_name}?") if BASE_OS_OPTIONS.include?(os_name)
|
||||||
|
|
||||||
raise ArgumentError, "Invalid OS condition: #{os_name.inspect}" unless MacOSVersions::SYMBOLS.key?(os_name)
|
raise ArgumentError, "Invalid OS condition: #{os_name.inspect}" unless MacOSVersions::SYMBOLS.key?(os_name)
|
||||||
|
@ -80,16 +80,4 @@ class Keg
|
|||||||
end
|
end
|
||||||
elf_files
|
elf_files
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.bottle_dependencies
|
|
||||||
@bottle_dependencies ||= begin
|
|
||||||
formulae = []
|
|
||||||
gcc = Formulary.factory(CompilerSelector.preferred_gcc)
|
|
||||||
if !Homebrew::EnvConfig.simulate_macos_on_linux? &&
|
|
||||||
DevelopmentTools.non_apple_gcc_version("gcc") < gcc.version.to_i
|
|
||||||
formulae << gcc
|
|
||||||
end
|
|
||||||
formulae
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -329,7 +329,7 @@ module Homebrew
|
|||||||
|
|
||||||
# The number of conflicts on Linux is absurd.
|
# The number of conflicts on Linux is absurd.
|
||||||
# TODO: remove this and check these there too.
|
# TODO: remove this and check these there too.
|
||||||
return if OS.linux? && !Homebrew::EnvConfig.simulate_macos_on_linux?
|
return if Homebrew::SimulateSystem.simulating_or_running_on_linux?
|
||||||
|
|
||||||
recursive_runtime_formulae = formula.runtime_formula_dependencies(undeclared: false)
|
recursive_runtime_formulae = formula.runtime_formula_dependencies(undeclared: false)
|
||||||
version_hash = {}
|
version_hash = {}
|
||||||
|
@ -368,7 +368,14 @@ class Keg
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.bottle_dependencies
|
def self.bottle_dependencies
|
||||||
[]
|
return [] unless Homebrew::SimulateSystem.simulating_or_running_on_linux?
|
||||||
|
|
||||||
|
@bottle_dependencies ||= begin
|
||||||
|
formulae = []
|
||||||
|
gcc = Formulary.factory(CompilerSelector.preferred_gcc)
|
||||||
|
formulae << gcc if DevelopmentTools.non_apple_gcc_version("gcc") < gcc.version.to_i
|
||||||
|
formulae
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ module Homebrew
|
|||||||
# Ideally `ca-certificates` would not be excluded here, but sourcing a HTTP mirror was tricky.
|
# Ideally `ca-certificates` would not be excluded here, but sourcing a HTTP mirror was tricky.
|
||||||
# Instead, we have logic elsewhere to pass `--insecure` to curl when downloading the certs.
|
# Instead, we have logic elsewhere to pass `--insecure` to curl when downloading the certs.
|
||||||
# TODO: try remove the OS/env conditional
|
# TODO: try remove the OS/env conditional
|
||||||
if (OS.mac? || Homebrew::EnvConfig.simulate_macos_on_linux?) && spec_name == :stable &&
|
if Homebrew::SimulateSystem.simulating_or_running_on_macos? && spec_name == :stable &&
|
||||||
owner.name != "ca-certificates" && curl_dep && !urls.find { |u| u.start_with?("http://") }
|
owner.name != "ca-certificates" && curl_dep && !urls.find { |u| u.start_with?("http://") }
|
||||||
problem "should always include at least one HTTP mirror"
|
problem "should always include at least one HTTP mirror"
|
||||||
end
|
end
|
||||||
|
@ -9,7 +9,14 @@ module Homebrew
|
|||||||
class << self
|
class << self
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
attr_reader :os, :arch
|
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
|
||||||
|
|
||||||
sig { params(new_os: Symbol).void }
|
sig { params(new_os: Symbol).void }
|
||||||
def os=(new_os)
|
def os=(new_os)
|
||||||
@ -33,16 +40,16 @@ 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?
|
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?
|
return OS.linux? if os.blank?
|
||||||
|
|
||||||
@os == :linux
|
os == :linux
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(Symbol) }
|
sig { returns(Symbol) }
|
||||||
@ -52,7 +59,7 @@ module Homebrew
|
|||||||
|
|
||||||
sig { returns(Symbol) }
|
sig { returns(Symbol) }
|
||||||
def current_os
|
def current_os
|
||||||
return @os if @os.present?
|
return T.must(os) if os.present?
|
||||||
return :linux if OS.linux?
|
return :linux if OS.linux?
|
||||||
|
|
||||||
MacOS.version.to_sym
|
MacOS.version.to_sym
|
||||||
|
@ -170,14 +170,16 @@ class SoftwareSpec
|
|||||||
|
|
||||||
@uses_from_macos_elements << deps
|
@uses_from_macos_elements << deps
|
||||||
|
|
||||||
# Linux simulating macOS. Assume oldest macOS version.
|
# Check whether macOS is new enough for dependency to not be required.
|
||||||
return if Homebrew::EnvConfig.simulate_macos_on_linux? && !bounds.key?(:since)
|
|
||||||
|
|
||||||
# macOS new enough for dependency to not be required.
|
|
||||||
if Homebrew::SimulateSystem.simulating_or_running_on_macos?
|
if Homebrew::SimulateSystem.simulating_or_running_on_macos?
|
||||||
current_os = MacOS::Version.from_symbol(Homebrew::SimulateSystem.current_os)
|
# Assume the oldest macOS version when simulating a generic macOS version
|
||||||
since_os = MacOS::Version.from_symbol(bounds[:since]) if bounds.key?(:since)
|
return if Homebrew::SimulateSystem.current_os == :macos && !bounds.key?(:since)
|
||||||
return if current_os >= since_os
|
|
||||||
|
if Homebrew::SimulateSystem.current_os != :macos
|
||||||
|
current_os = MacOS::Version.from_symbol(Homebrew::SimulateSystem.current_os)
|
||||||
|
since_os = MacOS::Version.from_symbol(bounds[:since]) if bounds.key?(:since)
|
||||||
|
return if current_os >= since_os
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
depends_on deps
|
depends_on deps
|
||||||
|
@ -36,6 +36,12 @@ describe Homebrew::SimulateSystem do
|
|||||||
described_class.os = :monterey
|
described_class.os = :monterey
|
||||||
expect(described_class.simulating_or_running_on_macos?).to be true
|
expect(described_class.simulating_or_running_on_macos?).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns true on Linux with HOMEBREW_SIMULATE_MACOS_ON_LINUX", :needs_linux do
|
||||||
|
described_class.clear
|
||||||
|
ENV["HOMEBREW_SIMULATE_MACOS_ON_LINUX"] = "1"
|
||||||
|
expect(described_class.simulating_or_running_on_macos?).to be true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "::simulating_or_running_on_linux?" do
|
describe "::simulating_or_running_on_linux?" do
|
||||||
@ -66,6 +72,12 @@ describe Homebrew::SimulateSystem do
|
|||||||
described_class.os = :monterey
|
described_class.os = :monterey
|
||||||
expect(described_class.simulating_or_running_on_linux?).to be false
|
expect(described_class.simulating_or_running_on_linux?).to be false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns false on Linux with HOMEBREW_SIMULATE_MACOS_ON_LINUX", :needs_linux do
|
||||||
|
described_class.clear
|
||||||
|
ENV["HOMEBREW_SIMULATE_MACOS_ON_LINUX"] = "1"
|
||||||
|
expect(described_class.simulating_or_running_on_linux?).to be false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "::current_arch" do
|
describe "::current_arch" do
|
||||||
@ -114,5 +126,17 @@ describe Homebrew::SimulateSystem do
|
|||||||
described_class.os = :monterey
|
described_class.os = :monterey
|
||||||
expect(described_class.current_os).to eq :monterey
|
expect(described_class.current_os).to eq :monterey
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns the current macOS version on macOS with HOMEBREW_SIMULATE_MACOS_ON_LINUX", :needs_macos do
|
||||||
|
described_class.clear
|
||||||
|
ENV["HOMEBREW_SIMULATE_MACOS_ON_LINUX"] = "1"
|
||||||
|
expect(described_class.current_os).to eq MacOS.version.to_sym
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns `:macos` on Linux with HOMEBREW_SIMULATE_MACOS_ON_LINUX", :needs_linux do
|
||||||
|
described_class.clear
|
||||||
|
ENV["HOMEBREW_SIMULATE_MACOS_ON_LINUX"] = "1"
|
||||||
|
expect(described_class.current_os).to eq :macos
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -150,6 +150,20 @@ describe SoftwareSpec do
|
|||||||
expect(spec.deps.first.tags).to include(:build)
|
expect(spec.deps.first.tags).to include(:build)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "ignores dependencies with HOMEBREW_SIMULATE_MACOS_ON_LINUX" do
|
||||||
|
ENV["HOMEBREW_SIMULATE_MACOS_ON_LINUX"] = "1"
|
||||||
|
spec.uses_from_macos("foo")
|
||||||
|
|
||||||
|
expect(spec.deps).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "ignores dependencies with tags with HOMEBREW_SIMULATE_MACOS_ON_LINUX" do
|
||||||
|
ENV["HOMEBREW_SIMULATE_MACOS_ON_LINUX"] = "1"
|
||||||
|
spec.uses_from_macos("foo" => :build)
|
||||||
|
|
||||||
|
expect(spec.deps).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
it "ignores OS version specifications" do
|
it "ignores OS version specifications" do
|
||||||
spec.uses_from_macos("foo", since: :mojave)
|
spec.uses_from_macos("foo", since: :mojave)
|
||||||
spec.uses_from_macos("bar" => :build, :since => :mojave)
|
spec.uses_from_macos("bar" => :build, :since => :mojave)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user