Skip to content

Commit

Permalink
Use top-level OS instead
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Sep 18, 2024
1 parent 3a57f77 commit 466fdf6
Show file tree
Hide file tree
Showing 20 changed files with 223 additions and 259 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/attestation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.enabled?
return false if Homebrew::EnvConfig.no_verify_attestations?
return true if Homebrew::EnvConfig.verify_attestations?
return false if ENV.fetch("CI", false)
return false if ::OS.unsupported_configuration?
return false if OS.unsupported_configuration?

# Always check credentials last to avoid unnecessary credential extraction.
(Homebrew::EnvConfig.developer? || Homebrew::EnvConfig.devcmdrun?) && GitHub::API.credentials.present?
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ def formula_ignores(formula)
# On Linux, GCC installation can be moved so long as the whole directory tree is moved together:
# https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed.
when Version.formula_optionally_versioned_regex(:gcc)
Regexp.union(%r{#{cellar_regex}/gcc}, %r{#{prefix_regex}/opt/gcc}) if ::OS.linux?
Regexp.union(%r{#{cellar_regex}/gcc}, %r{#{prefix_regex}/opt/gcc}) if OS.linux?
# binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451.
when Version.formula_optionally_versioned_regex(:binutils)
%r{#{cellar_regex}/binutils} if ::OS.linux?
%r{#{cellar_regex}/binutils} if OS.linux?
end
# rubocop:enable Homebrew/MoveToExtendOS

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ def run

# TODO: Refactor and move to extend/os
# rubocop:disable Homebrew/MoveToExtendOS
unless ::OS.mac?
unless OS.mac?
bundle_args << "--tag" << "~needs_macos" << "--tag" << "~cask"
files = files.grep_v(%r{^test/(os/mac|cask)(/.*|_spec\.rb)$})
end

unless ::OS.linux?
unless OS.linux?
bundle_args << "--tag" << "~needs_linux"
files = files.grep_v(%r{^test/os/linux(/.*|_spec\.rb)$})
end
Expand Down
34 changes: 16 additions & 18 deletions Library/Homebrew/extend/os/linux/cleanup.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
# typed: strict
# frozen_string_literal: true

module Homebrew
module OS
module Linux
module Cleanup
extend T::Helpers
module OS
module Linux
module Cleanup
extend T::Helpers

requires_ancestor { Homebrew::Cleanup }
requires_ancestor { Homebrew::Cleanup }

sig { returns(T::Boolean) }
def use_system_ruby?
return false if Homebrew::EnvConfig.force_vendor_ruby?
sig { returns(T::Boolean) }
def use_system_ruby?
return false if Homebrew::EnvConfig.force_vendor_ruby?

rubies = [which("ruby"), which("ruby", ORIGINAL_PATHS)].compact
system_ruby = Pathname.new("/usr/bin/ruby")
rubies << system_ruby if system_ruby.exist?
rubies = [which("ruby"), which("ruby", ORIGINAL_PATHS)].compact
system_ruby = Pathname.new("/usr/bin/ruby")
rubies << system_ruby if system_ruby.exist?

check_ruby_version = HOMEBREW_LIBRARY_PATH/"utils/ruby_check_version_script.rb"
rubies.uniq.any? do |ruby|
quiet_system ruby, "--enable-frozen-string-literal", "--disable=gems,did_you_mean,rubyopt",
check_ruby_version, RUBY_VERSION
end
check_ruby_version = HOMEBREW_LIBRARY_PATH/"utils/ruby_check_version_script.rb"
rubies.uniq.any? do |ruby|
quiet_system ruby, "--enable-frozen-string-literal", "--disable=gems,did_you_mean,rubyopt",
check_ruby_version, RUBY_VERSION
end
end
end
end
end

Homebrew::Cleanup.prepend(Homebrew::OS::Linux::Cleanup)
Homebrew::Cleanup.prepend(OS::Linux::Cleanup)
38 changes: 18 additions & 20 deletions Library/Homebrew/extend/os/linux/cli/parser.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
# typed: strict
# frozen_string_literal: true

module Homebrew
module OS
module Linux
module CLI
module Parser
extend T::Helpers
module OS
module Linux
module CLI
module Parser
extend T::Helpers

requires_ancestor { Homebrew::CLI::Parser }
requires_ancestor { Homebrew::CLI::Parser }

sig { void }
def set_default_options
args["formula?"] = true if args.respond_to?(:formula?)
end
sig { void }
def set_default_options
args["formula?"] = true if args.respond_to?(:formula?)
end

sig { void }
def validate_options
return unless args.respond_to?(:cask?)
return unless args.cask?
sig { void }
def validate_options
return unless args.respond_to?(:cask?)
return unless args.cask?

# NOTE: We don't raise an error here because we don't want
# to print the help page or a stack trace.
odie "Invalid `--cask` usage: Casks do not work on Linux"
end
# NOTE: We don't raise an error here because we don't want
# to print the help page or a stack trace.
odie "Invalid `--cask` usage: Casks do not work on Linux"
end
end
end
end
end

Homebrew::CLI::Parser.prepend(Homebrew::OS::Linux::CLI::Parser)
Homebrew::CLI::Parser.prepend(OS::Linux::CLI::Parser)
12 changes: 6 additions & 6 deletions Library/Homebrew/extend/os/linux/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ def check_supported_architecture
end

def check_glibc_minimum_version
return unless ::OS::Linux::Glibc.below_minimum_version?
return unless OS::Linux::Glibc.below_minimum_version?

<<~EOS
Your system glibc #{::OS::Linux::Glibc.system_version} is too old.
We only support glibc #{::OS::Linux::Glibc.minimum_version} or later.
Your system glibc #{OS::Linux::Glibc.system_version} is too old.
We only support glibc #{OS::Linux::Glibc.minimum_version} or later.
#{please_create_pull_requests}
We recommend updating to a newer version via your distribution's
package manager, upgrading your distribution to the latest version,
Expand All @@ -108,11 +108,11 @@ def check_glibc_minimum_version
end

def check_kernel_minimum_version
return unless ::OS::Linux::Kernel.below_minimum_version?
return unless OS::Linux::Kernel.below_minimum_version?

<<~EOS
Your Linux kernel #{::OS.kernel_version} is too old.
We only support kernel #{::OS::Linux::Kernel.minimum_version} or later.
Your Linux kernel #{OS.kernel_version} is too old.
We only support kernel #{OS::Linux::Kernel.minimum_version} or later.
You will be unable to use binary packages (bottles).
#{please_create_pull_requests}
We recommend updating to a newer version via your distribution's
Expand Down
88 changes: 43 additions & 45 deletions Library/Homebrew/extend/os/linux/formula.rb
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# frozen_string_literal: true

module Homebrew
module OS
module Linux
module Formula
extend T::Helpers

requires_ancestor { ::Formula }

sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) }
def shared_library(name, version = nil)
suffix = if version == "*" || (name == "*" && version.blank?)
"{,.*}"
elsif version.present?
".#{version}"
end
"#{name}.so#{suffix}"
module OS
module Linux
module Formula
extend T::Helpers

requires_ancestor { ::Formula }

sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) }
def shared_library(name, version = nil)
suffix = if version == "*" || (name == "*" && version.blank?)
"{,.*}"
elsif version.present?
".#{version}"
end
"#{name}.so#{suffix}"
end

sig { returns(String) }
def loader_path
"$ORIGIN"
end
sig { returns(String) }
def loader_path
"$ORIGIN"
end

sig { params(targets: T.nilable(T.any(Pathname, String))).void }
def deuniversalize_machos(*targets); end

sig { params(spec: SoftwareSpec).void }
def add_global_deps_to_spec(spec)
return unless DevelopmentTools.needs_build_formulae?

@global_deps ||= begin
dependency_collector = spec.dependency_collector
related_formula_names = Set.new([
name,
*aliases,
*versioned_formulae_names,
])
[
dependency_collector.gcc_dep_if_needed(related_formula_names),
dependency_collector.glibc_dep_if_needed(related_formula_names),
].compact.freeze
end
@global_deps.each { |dep| spec.dependency_collector.add(dep) }
sig { params(targets: T.nilable(T.any(Pathname, String))).void }
def deuniversalize_machos(*targets); end

sig { params(spec: SoftwareSpec).void }
def add_global_deps_to_spec(spec)
return unless DevelopmentTools.needs_build_formulae?

@global_deps ||= begin
dependency_collector = spec.dependency_collector
related_formula_names = Set.new([
name,
*aliases,
*versioned_formulae_names,
])
[
dependency_collector.gcc_dep_if_needed(related_formula_names),
dependency_collector.glibc_dep_if_needed(related_formula_names),
].compact.freeze
end
@global_deps.each { |dep| spec.dependency_collector.add(dep) }
end

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

Formula.prepend(Homebrew::OS::Linux::Formula)
Formula.prepend(OS::Linux::Formula)
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/os/linux/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def self.symlink_ld_so
private_class_method :symlink_ld_so

def self.setup_preferred_gcc_libs
gcc_opt_prefix = HOMEBREW_PREFIX/"opt/#{::OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA}"
gcc_opt_prefix = HOMEBREW_PREFIX/"opt/#{OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA}"
glibc_installed = (HOMEBREW_PREFIX/"opt/glibc/bin/ld.so").readable?

return unless gcc_opt_prefix.readable?
Expand Down
18 changes: 8 additions & 10 deletions Library/Homebrew/extend/os/mac/cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# typed: strict
# frozen_string_literal: true

module Homebrew
module OS
module MacOS
module Cleaner
private
module OS
module Mac
module Cleaner
private

sig { params(path: Pathname).returns(T::Boolean) }
def executable_path?(path)
path.mach_o_executable? || path.text_executable?
end
sig { params(path: Pathname).returns(T::Boolean) }
def executable_path?(path)
path.mach_o_executable? || path.text_executable?
end
end
end
end

Cleaner.prepend(Homebrew::OS::MacOS::Cleaner)
Cleaner.prepend(OS::Mac::Cleaner)
18 changes: 8 additions & 10 deletions Library/Homebrew/extend/os/mac/cleanup.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# typed: strict
# frozen_string_literal: true

module Homebrew
module OS
module MacOS
module Cleanup
sig { returns(T::Boolean) }
def use_system_ruby?
return false if Homebrew::EnvConfig.force_vendor_ruby?
module OS
module Mac
module Cleanup
sig { returns(T::Boolean) }
def use_system_ruby?
return false if Homebrew::EnvConfig.force_vendor_ruby?

Homebrew::EnvConfig.developer? && ENV["HOMEBREW_USE_RUBY_FROM_PATH"].present?
end
Homebrew::EnvConfig.developer? && ENV["HOMEBREW_USE_RUBY_FROM_PATH"].present?
end
end
end
end

Homebrew::Cleanup.prepend(Homebrew::OS::MacOS::Cleanup)
Homebrew::Cleanup.prepend(OS::Mac::Cleanup)
32 changes: 15 additions & 17 deletions Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
# typed: strict
# frozen_string_literal: true

module Homebrew
module OS
module MacOS
module DevCmd
module Bottle
sig { returns(T::Array[String]) }
def tar_args
if ::MacOS.version >= :catalina
["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze
else
[].freeze
end
module OS
module Mac
module DevCmd
module Bottle
sig { returns(T::Array[String]) }
def tar_args
if MacOS.version >= :catalina
["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze
else
[].freeze
end
end

sig { params(gnu_tar_formula: Formula).returns(String) }
def gnu_tar(gnu_tar_formula)
"#{gnu_tar_formula.opt_bin}/gtar"
end
sig { params(gnu_tar_formula: Formula).returns(String) }
def gnu_tar(gnu_tar_formula)
"#{gnu_tar_formula.opt_bin}/gtar"
end
end
end
end
end

Homebrew::DevCmd::Bottle.prepend(Homebrew::OS::MacOS::DevCmd::Bottle)
Homebrew::DevCmd::Bottle.prepend(OS::Mac::DevCmd::Bottle)
6 changes: 3 additions & 3 deletions Library/Homebrew/extend/os/mac/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ def check_for_unsupported_macos
return if ENV["HOMEBREW_INTEGRATION_TEST"]

who = +"We"
what = if ::OS::Mac.version.prerelease?
what = if OS::Mac.version.prerelease?
"pre-release version"
elsif ::OS::Mac.version.outdated_release?
elsif OS::Mac.version.outdated_release?
who << " (and Apple)"
"old version"
end
Expand Down Expand Up @@ -149,7 +149,7 @@ def check_xcode_up_to_date
#{MacOS::Xcode.update_instructions}
EOS

if ::OS::Mac.version.prerelease?
if OS::Mac.version.prerelease?
current_path = Utils.popen_read("/usr/bin/xcode-select", "-p")
message += <<~EOS
If #{MacOS::Xcode.latest_version} is installed, you may need to:
Expand Down
Loading

0 comments on commit 466fdf6

Please sign in to comment.