Skip to content

Commit

Permalink
Merge pull request #16224 from Rylan12/remove-os-mac-on-linux
Browse files Browse the repository at this point in the history
Deprecate `OS::Mac` on Linux
  • Loading branch information
MikeMcQuaid authored Nov 23, 2023
2 parents 1cb3f20 + b7532a8 commit e93b0fc
Show file tree
Hide file tree
Showing 14 changed files with 243 additions and 30 deletions.
4 changes: 1 addition & 3 deletions Library/Homebrew/cmd/gist-logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ def gistify_logs(formula, args:)
EOS
end

if args.new_issue?
url = GitHub.create_issue(formula.tap, "#{formula.name} failed to build on #{MacOS.full_version}", url)
end
url = GitHub.create_issue(formula.tap, "#{formula.name} failed to build on #{OS_VERSION}", url) if args.new_issue?

puts url if url
end
Expand Down
6 changes: 5 additions & 1 deletion Library/Homebrew/extend/os/linkage_checker.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# typed: strict
# frozen_string_literal: true

require "extend/os/linux/linkage_checker" if OS.linux?
if OS.mac?
require "extend/os/mac/linkage_checker"
else
require "extend/os/linux/linkage_checker"
end
22 changes: 22 additions & 0 deletions Library/Homebrew/extend/os/mac/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,31 @@

class Formula
undef valid_platform?
undef std_cmake_args

sig { returns(T::Boolean) }
def valid_platform?
requirements.none?(LinuxRequirement)
end

sig {
params(
install_prefix: T.any(String, Pathname),
install_libdir: T.any(String, Pathname),
find_framework: String,
).returns(T::Array[String])
}
def std_cmake_args(install_prefix: prefix, install_libdir: "lib", find_framework: "LAST")
args = generic_std_cmake_args(install_prefix: install_prefix, install_libdir: install_libdir,
find_framework: find_framework)

# Avoid false positives for clock_gettime support on 10.11.
# CMake cache entries for other weak symbols may be added here as needed.
args << "-DHAVE_CLOCK_GETTIME:INTERNAL=0" if MacOS.version == "10.11" && MacOS::Xcode.version >= "8.0"

# Ensure CMake is using the same SDK we are using.
args << "-DCMAKE_OSX_SYSROOT=#{MacOS.sdk_for_formula(self).path}" if MacOS.sdk_root_needed?

args
end
end
13 changes: 13 additions & 0 deletions Library/Homebrew/extend/os/mac/linkage_checker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# typed: true
# frozen_string_literal: true

class LinkageChecker
undef system_libraries_exist_in_cache?

private

def system_libraries_exist_in_cache?
# In macOS Big Sur and later, system libraries do not exist on-disk and instead exist in a cache.
MacOS.version >= :big_sur
end
end
12 changes: 2 additions & 10 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ def std_cargo_args(root: prefix, path: ".")
).returns(T::Array[String])
}
def std_cmake_args(install_prefix: prefix, install_libdir: "lib", find_framework: "LAST")
args = %W[
%W[
-DCMAKE_INSTALL_PREFIX=#{install_prefix}
-DCMAKE_INSTALL_LIBDIR=#{install_libdir}
-DCMAKE_BUILD_TYPE=Release
Expand All @@ -1655,16 +1655,8 @@ def std_cmake_args(install_prefix: prefix, install_libdir: "lib", find_framework
-Wno-dev
-DBUILD_TESTING=OFF
]

# Avoid false positives for clock_gettime support on 10.11.
# CMake cache entries for other weak symbols may be added here as needed.
args << "-DHAVE_CLOCK_GETTIME:INTERNAL=0" if MacOS.version == "10.11" && MacOS::Xcode.version >= "8.0"

# Ensure CMake is using the same SDK we are using.
args << "-DCMAKE_OSX_SYSROOT=#{MacOS.sdk_for_formula(self).path}" if MacOS.sdk_root_needed?

args
end
alias generic_std_cmake_args std_cmake_args

# Standard parameters for Go builds.
sig {
Expand Down
8 changes: 6 additions & 2 deletions Library/Homebrew/linkage_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,8 @@ def check_dylibs(rebuild_cache:)

if (dep = dylib_to_dep(dylib))
@broken_deps[dep] |= [dylib]
elsif MacOS.version >= :big_sur && dylib_found_via_dlopen(dylib)
elsif system_libraries_exist_in_cache? && dylib_found_via_dlopen(dylib)
# If we cannot associate the dylib with a dependency, then it may be a system library.
# In macOS Big Sur and later, system libraries do not exist on-disk and instead exist in a cache.
# If dlopen finds the dylib, then the linkage is not broken.
@system_dylibs << dylib
elsif !system_framework?(dylib)
Expand Down Expand Up @@ -227,6 +226,11 @@ def check_dylibs(rebuild_cache:)
end
alias generic_check_dylibs check_dylibs

def system_libraries_exist_in_cache?
false
end
alias generic_system_libraries_exist_in_cache? system_libraries_exist_in_cache?

def dylib_found_via_dlopen(dylib)
Fiddle.dlopen(dylib).close
true
Expand Down
11 changes: 11 additions & 0 deletions Library/Homebrew/os/linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,49 +55,60 @@ module Mac
raise "Loaded OS::Linux on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"]

def self.version
# odeprecated "`MacOS.version` on Linux"
MacOSVersion::NULL
end

def self.full_version
# odeprecated "`MacOS.full_version` on Linux"
MacOSVersion::NULL
end

def self.languages
# odeprecated "`MacOS.languages` on Linux"
@languages ||= Array(ENV["LANG"]&.slice(/[a-z]+/)).uniq
end

def self.language
# odeprecated "`MacOS.language` on Linux"
languages.first
end

def self.sdk_root_needed?
# odeprecated "`MacOS.sdk_root_needed?` on Linux"
false
end

def self.sdk_path_if_needed(_version = nil)
# odeprecated "`MacOS.sdk_path_if_needed` on Linux"
nil
end

def self.sdk_path(_version = nil)
# odeprecated "`MacOS.sdk_path` on Linux"
nil
end

module Xcode
def self.version
# odeprecated "`MacOS::Xcode.version` on Linux"
::Version::NULL
end

def self.installed?
# odeprecated "`MacOS::Xcode.installed?` on Linux"
false
end
end

module CLT
def self.version
# odeprecated "`MacOS::CLT.version` on Linux"
::Version::NULL
end

def self.installed?
# odeprecated "`MacOS::CLT.installed?` on Linux"
false
end
end
Expand Down
10 changes: 10 additions & 0 deletions Library/Homebrew/os/mac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,13 +24,15 @@ 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

# This can be compared to numerics, strings, or symbols
# 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
Expand Down Expand Up @@ -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")
Expand All @@ -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

Expand All @@ -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?
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/os/mac/xcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion Library/Homebrew/readall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions Library/Homebrew/rubocops/lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,21 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
end
end

# This cop makes sure the `MacOS` module is not used in Linux-facing formula code
#
# @api private
class MacOSOnLinux < FormulaCop
include OnSystemConditionalsHelper

ON_MACOS_BLOCKS = [:macos, *MACOS_VERSION_OPTIONS].map { |os| :"on_#{os}" }.freeze

def audit_formula(_node, _class_node, _parent_class_node, body_node)
audit_macos_references(body_node,
allowed_methods: OnSystemConditionals::NO_ON_SYSTEM_METHOD_NAMES,
allowed_blocks: OnSystemConditionals::NO_ON_SYSTEM_BLOCK_NAMES + ON_MACOS_BLOCKS)
end
end

# This cop makes sure that the `generate_completions_from_executable` DSL is used.
#
# @api private
Expand Down
Loading

0 comments on commit e93b0fc

Please sign in to comment.