From b7532a86e14c7879f2815ae4c0a85e3daf7aa2ac Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Wed, 22 Nov 2023 21:22:00 -0500 Subject: [PATCH] Add commented out deprecations for `MacOS` when simulating Linux --- Library/Homebrew/os/mac.rb | 10 ++++++++++ Library/Homebrew/os/mac/xcode.rb | 4 ++++ Library/Homebrew/readall.rb | 8 +++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index 84a1775947eb3..ed9a875e04627 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -7,6 +7,9 @@ require "os/mac/sdk" require "os/mac/keg" +# TODO: remove this once the `MacOS` module is undefined on Linux +require "simulate_system" + module OS # Helper module for querying system information on macOS. module Mac @@ -21,6 +24,7 @@ module Mac # using the standard Ruby Comparable methods. sig { returns(MacOSVersion) } def self.version + # odeprecated "`MacOS.version` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? @version ||= full_version.strip_patch end @@ -28,6 +32,7 @@ def self.version # using the standard Ruby Comparable methods. sig { returns(MacOSVersion) } def self.full_version + # odeprecated "`MacOS.full_version` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? @full_version ||= if ENV["HOMEBREW_FAKE_EL_CAPITAN"] # for Portable Ruby building MacOSVersion.new("10.11.6") else @@ -60,6 +65,7 @@ def self.preferred_perl_version end def self.languages + # odeprecated "`MacOS.languages` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? return @languages if @languages os_langs = Utils.popen_read("defaults", "read", "-g", "AppleLanguages") @@ -73,6 +79,7 @@ def self.languages end def self.language + # odeprecated "`MacOS.language` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? languages.first end @@ -83,6 +90,7 @@ def self.active_developer_dir sig { returns(T::Boolean) } def self.sdk_root_needed? + # odeprecated "`MacOS.sdk_root_needed?` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? if MacOS::CLT.installed? # If there's no CLT SDK, return false return false unless MacOS::CLT.provides_sdk? @@ -131,11 +139,13 @@ def self.sdk_for_formula(formula, version = nil, check_only_runtime_requirements # Returns the path to an SDK or nil, following the rules set by {sdk}. def self.sdk_path(version = nil) + # odeprecated "`MacOS.sdk_path` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? s = sdk(version) s&.path end def self.sdk_path_if_needed(version = nil) + # odeprecated "`MacOS.sdk_path_if_needed` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? # Prefer CLT SDK when both Xcode and the CLT are installed. # Expected results: # 1. On Xcode-only systems, return the Xcode SDK. diff --git a/Library/Homebrew/os/mac/xcode.rb b/Library/Homebrew/os/mac/xcode.rb index 9402bf5d6e11d..e589d2d670c8e 100755 --- a/Library/Homebrew/os/mac/xcode.rb +++ b/Library/Homebrew/os/mac/xcode.rb @@ -126,6 +126,7 @@ def self.bundle_path sig { returns(T::Boolean) } def self.installed? + # odeprecated "`MacOS::Xcode.installed?` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? !prefix.nil? end @@ -174,6 +175,7 @@ def self.update_instructions sig { returns(::Version) } def self.version + # odeprecated "`MacOS::Xcode.version` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? # may return a version string # that is guessed based on the compiler, so do not # use it in order to check if Xcode is installed. @@ -264,6 +266,7 @@ module CLT # Returns true even if outdated tools are installed. sig { returns(T::Boolean) } def self.installed? + # odeprecated "`MacOS::CLT.installed?` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? !version.null? end @@ -397,6 +400,7 @@ def self.detect_version_from_clang_version # version numbers. sig { returns(::Version) } def self.version + # odeprecated "`MacOS::CLT.version` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? if @version ||= detect_version ::Version.new @version else diff --git a/Library/Homebrew/readall.rb b/Library/Homebrew/readall.rb index bfe714e02d9f6..8faa67554a6fa 100644 --- a/Library/Homebrew/readall.rb +++ b/Library/Homebrew/readall.rb @@ -11,6 +11,10 @@ module Readall class << self include Cachable + # TODO: remove this once the `MacOS` module is undefined on Linux + MACOS_MODULE_REGEX = /\b(MacOS|OS::Mac)(\.|::)\b/.freeze + private_constant :MACOS_MODULE_REGEX + private :cache def valid_ruby_syntax?(ruby_files) @@ -59,7 +63,9 @@ def valid_formulae?(tap, bottle_tag: nil) flags: [], ignore_errors: false) readall_formula = readall_formula_class.new(formula_name, file, :stable, tap: tap) readall_formula.to_hash - cache[:valid_formulae][file] = if readall_formula.on_system_blocks_exist? + # TODO: Remove check for MACOS_MODULE_REGEX once the `MacOS` module is undefined on Linux + cache[:valid_formulae][file] = if readall_formula.on_system_blocks_exist? || + formula_contents.match?(MACOS_MODULE_REGEX) [bottle_tag, *cache[:valid_formulae][file]] else true