Remove more monkey-patching in extend/os

This commit is contained in:
Rylan Polster 2025-06-21 21:34:20 -04:00
parent 508c8b606c
commit 267afac198
No known key found for this signature in database
5 changed files with 52 additions and 16 deletions

View File

@ -1,9 +1,21 @@
# typed: strict
# frozen_string_literal: true
class CompilerSelector
module OS
module Linux
module CompilerSelector
module ClassMethods
extend T::Helpers
requires_ancestor { T.class_of(::CompilerSelector) }
sig { returns(String) }
def self.preferred_gcc
def preferred_gcc
OS::LINUX_PREFERRED_GCC_COMPILER_FORMULA
end
end
end
end
end
CompilerSelector.singleton_class.prepend(OS::Linux::CompilerSelector::ClassMethods)

View File

@ -51,7 +51,7 @@ module OS
out.puts "Host glibc: #{host_glibc_version}"
out.puts "#{::DevelopmentTools.host_gcc_path}: #{host_gcc_version}"
out.puts "/usr/bin/ruby: #{host_ruby_version}" if RUBY_PATH != HOST_RUBY_PATH
["glibc", CompilerSelector.preferred_gcc, OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA, "xorg"].each do |f|
["glibc", ::CompilerSelector.preferred_gcc, OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA, "xorg"].each do |f|
out.puts "#{f}: #{formula_linked_version(f)}"
end
end

View File

@ -1,13 +1,26 @@
# typed: strict
# frozen_string_literal: true
module Language
module OS
module Mac
module Language
module Java
def self.java_home(version = nil)
module ClassMethods
extend T::Helpers
requires_ancestor { T.class_of(::Language::Java) }
sig { params(version: T.nilable(String)).returns(T.nilable(Pathname)) }
def java_home(version = nil)
openjdk = find_openjdk_formula(version)
return unless openjdk
openjdk.opt_libexec/"openjdk.jdk/Contents/Home"
end
end
end
end
end
end
Language::Java.singleton_class.prepend(OS::Mac::Language::Java::ClassMethods)

View File

@ -1,9 +1,21 @@
# typed: strict
# frozen_string_literal: true
class Sandbox
module OS
module Mac
module Sandbox
module ClassMethods
extend T::Helpers
requires_ancestor { T.class_of(::Sandbox) }
sig { returns(T::Boolean) }
def self.available?
File.executable?(SANDBOX_EXEC)
def available?
File.executable?(::Sandbox::SANDBOX_EXEC)
end
end
end
end
end
Sandbox.singleton_class.prepend(OS::Mac::Sandbox::ClassMethods)

View File

@ -10,7 +10,6 @@ require "utils/fork"
# Helper class for running a sub-process inside of a sandboxed environment.
class Sandbox
SANDBOX_EXEC = "/usr/bin/sandbox-exec"
private_constant :SANDBOX_EXEC
# This is defined in the macOS SDK but Ruby unfortunately does not expose it.
# This value can be found by compiling a C program that prints TIOCSCTTY.