Skip to content

Commit 76cca72

Browse files
committed
OnSystem: handle non-macOS current_os values
The `OnSystem.os_condition_met?` method only handles Linux and macOS values for the current OS, so this fails when testing with a generic OS. This shortcoming is only being surfaced now because there weren't any tests for `OnSystem` before. This addresses the issue by accounting for macOS values (`:macos` or a symbol from `MacOSVersion::SYMBOLS`) and returning `false` for any other values (`:linux`, `:generic`, etc.).
1 parent e6038c9 commit 76cca72

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Library/Homebrew/extend/on_system.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,17 @@ def self.os_condition_met?(os_name, or_condition = nil)
7777
raise ArgumentError, "Invalid OS `or_*` condition: #{or_condition.inspect}"
7878
end
7979

80-
return false if Homebrew::SimulateSystem.simulating_or_running_on_linux?
81-
82-
base_os = MacOSVersion.from_symbol(os_name)
83-
current_os = if Homebrew::SimulateSystem.current_os == :macos
80+
current_os_symbol = Homebrew::SimulateSystem.current_os
81+
current_os = if current_os_symbol == :macos
8482
# Assume the oldest macOS version when simulating a generic macOS version
8583
# Version::NULL is always treated as less than any other version.
8684
Version::NULL
85+
elsif MacOSVersion::SYMBOLS.key?(current_os_symbol)
86+
MacOSVersion.from_symbol(current_os_symbol)
8787
else
88-
MacOSVersion.from_symbol(Homebrew::SimulateSystem.current_os)
88+
return false
8989
end
90+
base_os = MacOSVersion.from_symbol(os_name)
9091

9192
return current_os >= base_os if or_condition == :or_newer
9293
return current_os <= base_os if or_condition == :or_older
@@ -194,7 +195,7 @@ def self.setup_macos_methods(base)
194195
comparator = OnSystem.comparator_from_or_condition(or_condition)
195196
@uses_on_system.macos_requirements << MacOSRequirement.new([os_condition], comparator:)
196197

197-
return unless OnSystem.os_condition_met? os_condition, or_condition
198+
return unless OnSystem.os_condition_met?(os_condition, or_condition)
198199

199200
@on_system_block_min_os = T.let(
200201
if or_condition == :or_older

0 commit comments

Comments
 (0)