Skip to content

Commit

Permalink
Fix namespacing
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Sep 13, 2024
1 parent f09b35d commit 75369c9
Show file tree
Hide file tree
Showing 21 changed files with 290 additions and 220 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
32 changes: 18 additions & 14 deletions Library/Homebrew/extend/os/linux/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@
# frozen_string_literal: true

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

requires_ancestor { 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
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
end

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

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

requires_ancestor { Homebrew::CLI::Parser }

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?

# 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
end

Homebrew::CLI::Parser.prepend(Homebrew::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
96 changes: 51 additions & 45 deletions Library/Homebrew/extend/os/linux/formula.rb
Original file line number Diff line number Diff line change
@@ -1,52 +1,58 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# frozen_string_literal: true

module FormulaLinux
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}"
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}"
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) }
end

sig { returns(T::Boolean) }
def valid_platform?
requirements.none?(MacOSRequirement)
end
end
end
"#{name}.so#{suffix}"
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) }
end

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

Formula.prepend(FormulaLinux)
Formula.prepend(Homebrew::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
29 changes: 0 additions & 29 deletions Library/Homebrew/extend/os/linux/parser.rb

This file was deleted.

18 changes: 12 additions & 6 deletions Library/Homebrew/extend/os/mac/cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# typed: strict
# frozen_string_literal: true

module CleanerMac
private
module Homebrew
module OS
module MacOS
module Cleaner
private

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

Cleaner.prepend(CleanerMac)
Cleaner.prepend(Homebrew::OS::MacOS::Cleaner)
16 changes: 10 additions & 6 deletions Library/Homebrew/extend/os/mac/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
# frozen_string_literal: true

module Homebrew
module CleanupMac
sig { returns(T::Boolean) }
def use_system_ruby?
return false if Homebrew::EnvConfig.force_vendor_ruby?
module OS
module MacOS
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?
Homebrew::EnvConfig.developer? && ENV["HOMEBREW_USE_RUBY_FROM_PATH"].present?
end
end
end
end
end

Homebrew::Cleanup.prepend(Homebrew::CleanupMac)
Homebrew::Cleanup.prepend(Homebrew::OS::MacOS::Cleanup)
32 changes: 18 additions & 14 deletions Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@
# frozen_string_literal: true

module Homebrew
module DevCmd
module BottleMac
sig { returns(T::Array[String]) }
def tar_args
if MacOS.version >= :catalina
["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze
else
[].freeze
end
end
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
end

sig { params(gnu_tar_formula: Formula).returns(String) }
def gnu_tar(gnu_tar_formula)
"#{gnu_tar_formula.opt_bin}/gtar"
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
end

Homebrew::DevCmd::Bottle.prepend(Homebrew::DevCmd::BottleMac)
Homebrew::DevCmd::Bottle.prepend(Homebrew::OS::MacOS::DevCmd::Bottle)
Loading

0 comments on commit 75369c9

Please sign in to comment.