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 # typed: strict
# frozen_string_literal: true # 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) } sig { returns(String) }
def self.preferred_gcc def preferred_gcc
OS::LINUX_PREFERRED_GCC_COMPILER_FORMULA OS::LINUX_PREFERRED_GCC_COMPILER_FORMULA
end end
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 "Host glibc: #{host_glibc_version}"
out.puts "#{::DevelopmentTools.host_gcc_path}: #{host_gcc_version}" out.puts "#{::DevelopmentTools.host_gcc_path}: #{host_gcc_version}"
out.puts "/usr/bin/ruby: #{host_ruby_version}" if RUBY_PATH != HOST_RUBY_PATH 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)}" out.puts "#{f}: #{formula_linked_version(f)}"
end end
end end

View File

@ -1,9 +1,17 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module OS
module Mac
module Language module Language
module Java 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) openjdk = find_openjdk_formula(version)
return unless openjdk return unless openjdk
@ -11,3 +19,8 @@ module Language
end end
end end
end end
end
end
end
Language::Java.singleton_class.prepend(OS::Mac::Language::Java::ClassMethods)

View File

@ -1,9 +1,21 @@
# typed: strict # typed: strict
# frozen_string_literal: true # 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) } sig { returns(T::Boolean) }
def self.available? def available?
File.executable?(SANDBOX_EXEC) File.executable?(::Sandbox::SANDBOX_EXEC)
end end
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. # Helper class for running a sub-process inside of a sandboxed environment.
class Sandbox class Sandbox
SANDBOX_EXEC = "/usr/bin/sandbox-exec" 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 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. # This value can be found by compiling a C program that prints TIOCSCTTY.