repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/module.rb
Library/Homebrew/extend/module.rb
# typed: strict # frozen_string_literal: true class Module include T::Sig # The inverse of <tt>Module#include?</tt>. Returns true if the module # does not include the other module. sig { params(mod: T::Module[T.anything]).returns(T::Boolean) } def exclude?(mod) = !include?(mod) end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/pathname/write_mkpath_extension.rb
Library/Homebrew/extend/pathname/write_mkpath_extension.rb
# typed: strict # frozen_string_literal: true module WriteMkpathExtension extend T::Helpers requires_ancestor { Pathname } # Source for `sig`: https://github.com/sorbet/sorbet/blob/b4092efe0a4489c28aff7e1ead6ee8a0179dc8b3/rbi/stdlib/pathname.rbi#L1392-L1411 sig { params( content: Object, offset: Integer, external_encoding: T.any(String, Encoding), internal_encoding: T.any(String, Encoding), encoding: T.any(String, Encoding), textmode: BasicObject, binmode: BasicObject, autoclose: BasicObject, mode: String, perm: Integer, ).returns(Integer) } def write(content, offset = T.unsafe(nil), external_encoding: T.unsafe(nil), internal_encoding: T.unsafe(nil), encoding: T.unsafe(nil), textmode: T.unsafe(nil), binmode: T.unsafe(nil), autoclose: T.unsafe(nil), mode: T.unsafe(nil), perm: T.unsafe(nil)) raise "Will not overwrite #{self}" if exist? && !offset && !mode&.match?(/^a\+?$/) dirname.mkpath super end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/pathname/observer_pathname_extension.rb
Library/Homebrew/extend/pathname/observer_pathname_extension.rb
# typed: strict # frozen_string_literal: true require "context" module ObserverPathnameExtension extend T::Helpers requires_ancestor { Pathname } class << self include Context sig { returns(Integer) } def n @n ||= 0 end sig { params(n: Integer).void } attr_writer :n sig { returns(Integer) } def d @d ||= 0 end sig { params(d: Integer).void } attr_writer :d sig { void } def reset_counts! @n = T.let(0, T.nilable(Integer)) @d = T.let(0, T.nilable(Integer)) @put_verbose_trimmed_warning = T.let(false, T.nilable(T::Boolean)) end sig { returns(Integer) } def total n + d end sig { returns([Integer, Integer]) } def counts [n, d] end MAXIMUM_VERBOSE_OUTPUT = 100 private_constant :MAXIMUM_VERBOSE_OUTPUT sig { returns(T::Boolean) } def verbose? return super unless ENV["CI"] return false unless super if total < MAXIMUM_VERBOSE_OUTPUT true else unless @put_verbose_trimmed_warning puts "Only the first #{MAXIMUM_VERBOSE_OUTPUT} operations were output." @put_verbose_trimmed_warning = true end false end end end sig { void } def unlink super puts "rm #{self}" if ObserverPathnameExtension.verbose? ObserverPathnameExtension.n += 1 end sig { void } def mkpath super puts "mkdir -p #{self}" if ObserverPathnameExtension.verbose? end sig { void } def rmdir super puts "rmdir #{self}" if ObserverPathnameExtension.verbose? ObserverPathnameExtension.d += 1 end sig { params(src: Pathname).void } def make_relative_symlink(src) super puts "ln -s #{src.relative_path_from(dirname)} #{basename}" if ObserverPathnameExtension.verbose? ObserverPathnameExtension.n += 1 end sig { void } def install_info super puts "info #{self}" if ObserverPathnameExtension.verbose? end sig { void } def uninstall_info super puts "uninfo #{self}" if ObserverPathnameExtension.verbose? end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/pathname/disk_usage_extension.rb
Library/Homebrew/extend/pathname/disk_usage_extension.rb
# typed: strict # frozen_string_literal: true module DiskUsageExtension extend T::Helpers requires_ancestor { Pathname } sig { returns(Integer) } def disk_usage @disk_usage ||= T.let(nil, T.nilable(Integer)) return @disk_usage unless @disk_usage.nil? @file_count, @disk_usage = compute_disk_usage @disk_usage end sig { returns(Integer) } def file_count @file_count ||= T.let(nil, T.nilable(Integer)) return @file_count unless @file_count.nil? @file_count, @disk_usage = compute_disk_usage @file_count end sig { returns(String) } def abv out = +"" @file_count, @disk_usage = compute_disk_usage out << "#{number_readable(@file_count)} files, " if @file_count > 1 out << disk_usage_readable(@disk_usage).to_s out.freeze end private sig { returns([Integer, Integer]) } def compute_disk_usage if symlink? && !exist? file_count = 1 disk_usage = 0 return [file_count, disk_usage] end path = if symlink? resolved_path else self end if path.directory? scanned_files = Set.new file_count = 0 disk_usage = 0 path.find do |f| if f.directory? disk_usage += f.lstat.size else file_count += 1 if f.basename.to_s != ".DS_Store" # use Pathname#lstat instead of Pathname#stat to get info of symlink itself. stat = f.lstat file_id = [stat.dev, stat.ino] # count hardlinks only once. unless scanned_files.include?(file_id) disk_usage += stat.size scanned_files.add(file_id) end end end else file_count = 1 disk_usage = path.lstat.size end [file_count, disk_usage] end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/file/atomic.rb
Library/Homebrew/extend/file/atomic.rb
# typed: strict # frozen_string_literal: true require "fileutils" class File # Write to a file atomically. Useful for situations where you don't # want other processes or threads to see half-written files. # # File.atomic_write('important.file') do |file| # file.write('hello') # end # # This method needs to create a temporary file. By default it will create it # in the same directory as the destination file. If you don't like this # behavior you can provide a different directory but it must be on the # same physical filesystem as the file you're trying to write. # # File.atomic_write('/data/something.important', '/data/tmp') do |file| # file.write('hello') # end sig { type_parameters(:Out).params( file_name: T.any(Pathname, String), temp_dir: String, _block: T.proc.params(arg0: Tempfile).returns(T.type_parameter(:Out)), ).returns(T.type_parameter(:Out)) } def self.atomic_write(file_name, temp_dir = dirname(file_name), &_block) require "tempfile" unless defined?(Tempfile) Tempfile.open(".#{basename(file_name)}", temp_dir) do |temp_file| temp_file.binmode return_val = yield temp_file temp_file.close old_stat = if exist?(file_name) # Get original file permissions stat(file_name) else # If not possible, probe which are the default permissions in the # destination directory. probe_stat_in(dirname(file_name)) end if old_stat # Set correct permissions on new file begin chown(old_stat.uid, old_stat.gid, T.must(temp_file.path)) # This operation will affect filesystem ACL's chmod(old_stat.mode, T.must(temp_file.path)) rescue Errno::EPERM, Errno::EACCES # Changing file ownership failed, moving on. end end # Overwrite original file with temp file rename(T.must(temp_file.path), file_name) return_val end end # Private utility method. sig { params(dir: String).returns(T.nilable(File::Stat)) } private_class_method def self.probe_stat_in(dir) # :nodoc: basename = [ ".permissions_check", Thread.current.object_id, Process.pid, rand(1_000_000), ].join(".") file_name = join(dir, basename) FileUtils.touch(file_name) stat(file_name) rescue Errno::ENOENT file_name = nil ensure FileUtils.rm_f(file_name) if file_name end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/hash/keys.rb
Library/Homebrew/extend/hash/keys.rb
# typed: strict # frozen_string_literal: true class Hash # Validates all keys in a hash match `*valid_keys`, raising # `ArgumentError` on a mismatch. # # Note that keys are treated differently than `HashWithIndifferentAccess`, # meaning that string and symbol keys will not match. # # ### Example# # # ```ruby # { name: 'Rob', years: '28' }.assert_valid_keys(:name, :age) # # => raises "ArgumentError: Unknown key: :years. Valid keys are: :name, :age" # { name: 'Rob', age: '28' }.assert_valid_keys('name', 'age') # # => raises "ArgumentError: Unknown key: :name. Valid keys are: 'name', 'age'" # { name: 'Rob', age: '28' }.assert_valid_keys(:name, :age) # => passes, raises nothing # ``` sig { params(valid_keys: T.untyped).void } def assert_valid_keys(*valid_keys) valid_keys.flatten! each_key do |k| next if valid_keys.include?(k) raise ArgumentError, "Unknown key: #{T.unsafe(k).inspect}. Valid keys are: #{valid_keys.map(&:inspect).join(", ")}" end end # Returns a new hash with all keys converted by the block operation. # This includes the keys from the root hash and from all # nested hashes and arrays. # # ### Example # # ```ruby # hash = { person: { name: 'Rob', age: '28' } } # # hash.deep_transform_keys{ |key| key.to_s.upcase } # # => {"PERSON"=>{"NAME"=>"Rob", "AGE"=>"28"}} # ``` def deep_transform_keys(&block) = _deep_transform_keys_in_object(self, &block) # Destructively converts all keys by using the block operation. # This includes the keys from the root hash and from all # nested hashes and arrays. def deep_transform_keys!(&block) = _deep_transform_keys_in_object!(self, &block) # Returns a new hash with all keys converted to strings. # This includes the keys from the root hash and from all # nested hashes and arrays. # # ### Example # # ```ruby # hash = { person: { name: 'Rob', age: '28' } } # # hash.deep_stringify_keys # # => {"person"=>{"name"=>"Rob", "age"=>"28"}} # ``` def deep_stringify_keys = T.unsafe(self).deep_transform_keys(&:to_s) # Destructively converts all keys to strings. # This includes the keys from the root hash and from all # nested hashes and arrays. def deep_stringify_keys! = T.unsafe(self).deep_transform_keys!(&:to_s) # Returns a new hash with all keys converted to symbols, as long as # they respond to `to_sym`. This includes the keys from the root hash # and from all nested hashes and arrays. # # ### Example # # ```ruby # hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } } # # hash.deep_symbolize_keys # # => {:person=>{:name=>"Rob", :age=>"28"}} # ``` def deep_symbolize_keys deep_transform_keys do |key| T.unsafe(key).to_sym rescue key end end # Destructively converts all keys to symbols, as long as they respond # to `to_sym`. This includes the keys from the root hash and from all # nested hashes and arrays. def deep_symbolize_keys! deep_transform_keys! do |key| T.unsafe(key).to_sym rescue key end end private # Support methods for deep transforming nested hashes and arrays. sig { params(object: T.anything, block: T.proc.params(k: T.untyped).returns(T.untyped)).returns(T.untyped) } def _deep_transform_keys_in_object(object, &block) case object when Hash object.each_with_object({}) do |(key, value), result| result[yield(key)] = _deep_transform_keys_in_object(value, &block) end when Array object.map { |e| _deep_transform_keys_in_object(e, &block) } else object end end sig { params(object: T.anything, block: T.proc.params(k: T.untyped).returns(T.untyped)).returns(T.untyped) } def _deep_transform_keys_in_object!(object, &block) case object when Hash # We can't use `each_key` here because we're updating the hash in-place. object.keys.each do |key| value = object.delete(key) object[yield(key)] = _deep_transform_keys_in_object!(value, &block) end object when Array object.map! { |e| _deep_transform_keys_in_object!(e, &block) } else object end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/hash/deep_merge.rb
Library/Homebrew/extend/hash/deep_merge.rb
# typed: strict # frozen_string_literal: true class Hash # Returns a new hash with `self` and `other_hash` merged recursively. # # ### Examples # # ```ruby # h1 = { a: true, b: { c: [1, 2, 3] } } # h2 = { a: false, b: { x: [3, 4, 5] } } # # h1.deep_merge(h2) # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } } # ``` # # Like with Hash#merge in the standard library, a block can be provided # to merge values: # # ```ruby # h1 = { a: 100, b: 200, c: { c1: 100 } } # h2 = { b: 250, c: { c1: 200 } } # h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val } # # => { a: 100, b: 450, c: { c1: 300 } } # ``` def deep_merge(other_hash, &block) dup.deep_merge!(other_hash, &block) end # Same as {#deep_merge}, but modifies `self`. def deep_merge!(other_hash, &block) merge!(other_hash) do |key, this_val, other_val| if T.unsafe(this_val).is_a?(Hash) && other_val.is_a?(Hash) T.unsafe(this_val).deep_merge(other_val, &block) elsif block yield(key, this_val, other_val) else other_val end end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/hash/deep_transform_values.rb
Library/Homebrew/extend/hash/deep_transform_values.rb
# typed: strict # frozen_string_literal: true class Hash # Returns a new hash with all values converted by the block operation. # This includes the values from the root hash and from all # nested hashes and arrays. # # ### Example # # ```ruby # hash = { person: { name: 'Rob', age: '28' } } # # hash.deep_transform_values{ |value| value.to_s.upcase } # # => {person: {name: "ROB", age: "28"}} # ``` def deep_transform_values(&block) = _deep_transform_values_in_object(self, &block) # Destructively converts all values by using the block operation. # This includes the values from the root hash and from all # nested hashes and arrays. def deep_transform_values!(&block) = _deep_transform_values_in_object!(self, &block) private # Support methods for deep transforming nested hashes and arrays. sig { params(object: T.anything, block: T.proc.params(v: T.untyped).returns(T.untyped)).returns(T.untyped) } def _deep_transform_values_in_object(object, &block) case object when Hash object.transform_values { |value| _deep_transform_values_in_object(value, &block) } when Array object.map { |e| _deep_transform_values_in_object(e, &block) } else yield(object) end end sig { params(object: T.anything, block: T.proc.params(v: T.untyped).returns(T.untyped)).returns(T.untyped) } def _deep_transform_values_in_object!(object, &block) case object when Hash object.transform_values! { |value| _deep_transform_values_in_object!(value, &block) } when Array object.map! { |e| _deep_transform_values_in_object!(e, &block) } else yield(object) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/object/duplicable.rb
Library/Homebrew/extend/object/duplicable.rb
# typed: strict # frozen_string_literal: true # Most objects are cloneable, but not all. For example you can't dup methods: # # ```ruby # method(:puts).dup # => TypeError: allocator undefined for Method # ``` # # Classes may signal their instances are not duplicable removing +dup+/+clone+ # or raising exceptions from them. So, to dup an arbitrary object you normally # use an optimistic approach and are ready to catch an exception, say: # # ```ruby # arbitrary_object.dup rescue object # ``` # # Rails dups objects in a few critical spots where they are not that arbitrary. # That `rescue` is very expensive (like 40 times slower than a predicate) and it # is often triggered. # # That's why we hardcode the following cases and check duplicable? instead of # using that rescue idiom. # rubocop:disable Layout/EmptyLines # rubocop:enable Layout/EmptyLines class Object # Can you safely dup this object? # # False for method objects; # true otherwise. sig { returns(T::Boolean) } def duplicable? = true end class Method # Methods are not duplicable: # # ```ruby # method(:puts).duplicable? # => false # method(:puts).dup # => TypeError: allocator undefined for Method # ``` sig { returns(FalseClass) } def duplicable? = false end class UnboundMethod # Unbound methods are not duplicable: # # ```ruby # method(:puts).unbind.duplicable? # => false # method(:puts).unbind.dup # => TypeError: allocator undefined for UnboundMethod # ``` sig { returns(FalseClass) } def duplicable? = false end require "singleton" module Singleton # Singleton instances are not duplicable: # # ```ruby # Class.new.include(Singleton).instance.dup # TypeError (can't dup instance of singleton # ``` sig { returns(FalseClass) } def duplicable? = false end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/object/deep_dup.rb
Library/Homebrew/extend/object/deep_dup.rb
# typed: strict # frozen_string_literal: true require "extend/object/duplicable" class Object # Returns a deep copy of object if it's duplicable. If it's # not duplicable, returns +self+. # # object = Object.new # dup = object.deep_dup # dup.instance_variable_set(:@a, 1) # # object.instance_variable_defined?(:@a) # => false # dup.instance_variable_defined?(:@a) # => true sig { returns(T.self_type) } def deep_dup duplicable? ? dup : self end end class Array # Returns a deep copy of array. # # array = [1, [2, 3]] # dup = array.deep_dup # dup[1][2] = 4 # # array[1][2] # => nil # dup[1][2] # => 4 sig { returns(T.self_type) } def deep_dup T.unsafe(self).map(&:deep_dup) end end class Hash # Returns a deep copy of hash. # # hash = { a: { b: 'b' } } # dup = hash.deep_dup # dup[:a][:c] = 'c' # # hash[:a][:c] # => nil # dup[:a][:c] # => "c" sig { returns(T.self_type) } def deep_dup hash = dup each_pair do |key, value| case key when ::String, ::Symbol hash[key] = T.unsafe(value).deep_dup else hash.delete(key) hash[T.unsafe(key).deep_dup] = T.unsafe(value).deep_dup end end hash end end class Module # Returns a copy of module or class if it's anonymous. If it's # named, returns +self+. # # Object.deep_dup == Object # => true # klass = Class.new # klass.deep_dup == klass # => false sig { returns(T.self_type) } def deep_dup if name.nil? super else self end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/hardware.rb
Library/Homebrew/extend/os/hardware.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/hardware" require "extend/os/mac/hardware/cpu" elsif OS.linux? require "extend/os/linux/hardware/cpu" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/readall.rb
Library/Homebrew/extend/os/readall.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/readall" if OS.mac?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/sandbox.rb
Library/Homebrew/extend/os/sandbox.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/sandbox" if OS.mac?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/bottles.rb
Library/Homebrew/extend/os/bottles.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/utils/bottles" if OS.mac?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/bottle_specification.rb
Library/Homebrew/extend/os/bottle_specification.rb
# typed: strict # frozen_string_literal: true require "extend/os/linux/bottle_specification" if OS.linux?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/keg_relocate.rb
Library/Homebrew/extend/os/keg_relocate.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/keg_relocate" elsif OS.linux? require "extend/os/linux/keg_relocate" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/reinstall.rb
Library/Homebrew/extend/os/reinstall.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/reinstall" if OS.mac?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/cleanup.rb
Library/Homebrew/extend/os/cleanup.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/cleanup" elsif OS.linux? require "extend/os/linux/cleanup" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/missing_formula.rb
Library/Homebrew/extend/os/missing_formula.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/missing_formula" if OS.mac?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/cleaner.rb
Library/Homebrew/extend/os/cleaner.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/cleaner" elsif OS.linux? require "extend/os/linux/cleaner" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/keg_only_reason.rb
Library/Homebrew/extend/os/keg_only_reason.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/keg_only_reason" if OS.mac?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/compilers.rb
Library/Homebrew/extend/os/compilers.rb
# typed: strict # frozen_string_literal: true require "extend/os/linux/compilers" if OS.linux?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/diagnostic.rb
Library/Homebrew/extend/os/diagnostic.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/diagnostic" elsif OS.linux? require "extend/os/linux/diagnostic" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/tap.rb
Library/Homebrew/extend/os/tap.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/tap" if OS.mac?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/system_config.rb
Library/Homebrew/extend/os/system_config.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/system_config" elsif OS.linux? require "extend/os/linux/system_config" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/pathname.rb
Library/Homebrew/extend/os/pathname.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/extend/pathname" elsif OS.linux? require "extend/os/linux/extend/pathname" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/formula_cellar_checks.rb
Library/Homebrew/extend/os/formula_cellar_checks.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/formula_cellar_checks" elsif OS.linux? require "extend/os/linux/formula_cellar_checks" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/dependency_collector.rb
Library/Homebrew/extend/os/dependency_collector.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/dependency_collector" elsif OS.linux? require "extend/os/linux/dependency_collector" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/linkage_checker.rb
Library/Homebrew/extend/os/linkage_checker.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/linkage_checker" else require "extend/os/linux/linkage_checker" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/formula.rb
Library/Homebrew/extend/os/formula.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/formula" elsif OS.linux? require "extend/os/linux/formula" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/keg.rb
Library/Homebrew/extend/os/keg.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/keg" elsif OS.linux? require "extend/os/linux/keg" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/install.rb
Library/Homebrew/extend/os/install.rb
# typed: strict # frozen_string_literal: true require "extend/os/linux/install" if OS.linux?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/simulate_system.rb
Library/Homebrew/extend/os/simulate_system.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/simulate_system" elsif OS.linux? require "extend/os/linux/simulate_system" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/development_tools.rb
Library/Homebrew/extend/os/development_tools.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/development_tools" elsif OS.linux? require "extend/os/linux/development_tools" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/formula_installer.rb
Library/Homebrew/extend/os/formula_installer.rb
# typed: strict # frozen_string_literal: true if OS.mac? require "extend/os/mac/formula_installer" elsif OS.linux? require "extend/os/linux/formula_installer" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/cmd/update-report.rb
Library/Homebrew/extend/os/cmd/update-report.rb
# typed: strict # frozen_string_literal: true require "extend/os/linux/cmd/update-report" if OS.linux?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/dev-cmd/update-test.rb
Library/Homebrew/extend/os/dev-cmd/update-test.rb
# typed: strict # frozen_string_literal: true require "extend/os/linux/dev-cmd/update-test" if OS.linux?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/dev-cmd/bottle.rb
Library/Homebrew/extend/os/dev-cmd/bottle.rb
# typed: strict # frozen_string_literal: true require "extend/os/linux/dev-cmd/bottle" if OS.linux? require "extend/os/mac/dev-cmd/bottle" if OS.mac?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/dev-cmd/tests.rb
Library/Homebrew/extend/os/dev-cmd/tests.rb
# typed: strict # frozen_string_literal: true require "extend/os/linux/dev-cmd/tests" if OS.linux? require "extend/os/mac/dev-cmd/tests" if OS.mac?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/cask/dsl.rb
Library/Homebrew/extend/os/cask/dsl.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/cask/dsl" if OS.mac?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/cask/caskroom.rb
Library/Homebrew/extend/os/cask/caskroom.rb
# typed: strict # frozen_string_literal: true require "extend/os/linux/cask/caskroom" if OS.linux?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/cask/installer.rb
Library/Homebrew/extend/os/cask/installer.rb
# typed: strict # frozen_string_literal: true require "extend/os/linux/cask/installer" if OS.linux?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/cask/config.rb
Library/Homebrew/extend/os/cask/config.rb
# typed: strict # frozen_string_literal: true require "extend/os/linux/cask/config" if OS.linux?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/cask/quarantine.rb
Library/Homebrew/extend/os/cask/quarantine.rb
# typed: strict # frozen_string_literal: true require "extend/os/linux/cask/quarantine" if OS.linux?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/cask/artifact/symlinked.rb
Library/Homebrew/extend/os/cask/artifact/symlinked.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/cask/artifact/symlinked" if OS.mac?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/cask/artifact/abstract_uninstall.rb
Library/Homebrew/extend/os/cask/artifact/abstract_uninstall.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/cask/artifact/abstract_uninstall" if OS.mac?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/cask/artifact/moved.rb
Library/Homebrew/extend/os/cask/artifact/moved.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/cask/artifact/moved" if OS.mac?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/cask/artifact/relocated.rb
Library/Homebrew/extend/os/cask/artifact/relocated.rb
# typed: strict # frozen_string_literal: true require "extend/os/linux/cask/artifact/relocated" if OS.linux?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/hardware.rb
Library/Homebrew/extend/os/mac/hardware.rb
# typed: strict # frozen_string_literal: true module OS module Mac module Hardware module ClassMethods sig { params(version: T.nilable(MacOSVersion)).returns(Symbol) } def oldest_cpu(version = nil) version = if version MacOSVersion.new(version.to_s) else MacOS.version end if ::Hardware::CPU.arm64? :arm_vortex_tempest # This cannot use a newer CPU e.g. haswell because Rosetta 2 does not # support AVX instructions in bottles: # https://github.com/Homebrew/homebrew-core/issues/67713 elsif version >= :ventura :westmere elsif version >= :catalina :nehalem else super end end end end end end Hardware.singleton_class.prepend(OS::Mac::Hardware::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/readall.rb
Library/Homebrew/extend/os/mac/readall.rb
# typed: strict # frozen_string_literal: true require "utils/output" module OS module Mac module Readall module ClassMethods extend T::Helpers include ::Utils::Output::Mixin requires_ancestor { Kernel } sig { params(tap: ::Tap, os_name: T.nilable(Symbol), arch: T.nilable(Symbol)).returns(T::Boolean) } def valid_casks?(tap, os_name: nil, arch: ::Hardware::CPU.type) return true if os_name == :linux current_macos_version = if os_name.is_a?(Symbol) MacOSVersion.from_symbol(os_name) else MacOS.version end success = T.let(true, T::Boolean) tap.cask_files.each do |file| cask = ::Cask::CaskLoader.load(file) # Fine to have missing URLs for unsupported macOS macos_req = cask.depends_on.macos next if macos_req&.version && Array(macos_req.version).none? do |macos_version| current_macos_version.compare(macos_req.comparator, macos_version) end raise "Missing URL" if cask.url.nil? rescue Interrupt raise # Handle all possible exceptions reading Casks. rescue Exception => e # rubocop:disable Lint/RescueException os_and_arch = "macOS #{current_macos_version} on #{arch}" onoe "Invalid cask (#{os_and_arch}): #{file}" $stderr.puts e success = false end success end end end end end Readall.singleton_class.prepend(OS::Mac::Readall::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/sandbox.rb
Library/Homebrew/extend/os/mac/sandbox.rb
# typed: strict # frozen_string_literal: true module OS module Mac module Sandbox module ClassMethods extend T::Helpers requires_ancestor { T.class_of(::Sandbox) } sig { returns(T::Boolean) } def available? File.executable?(::Sandbox::SANDBOX_EXEC) end end end end end Sandbox.singleton_class.prepend(OS::Mac::Sandbox::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/keg_relocate.rb
Library/Homebrew/extend/os/mac/keg_relocate.rb
# typed: strict # frozen_string_literal: true module OS module Mac module Keg extend T::Helpers requires_ancestor { ::Keg } module ClassMethods sig { params(file: ::Pathname, string: String).returns(T::Array[String]) } def file_linked_libraries(file, string) file = MachOPathname.wrap(file) # Check dynamic library linkage. Importantly, do not perform for static # libraries, which will falsely report "linkage" to themselves. if file.mach_o_executable? || file.dylib? || file.mach_o_bundle? file.dynamically_linked_libraries.select { |lib| lib.include? string } else [] end end end sig { params(relocation: ::Keg::Relocation, skip_protodesc_cold: T::Boolean).void } def relocate_dynamic_linkage(relocation, skip_protodesc_cold: false) mach_o_files.each do |file| file.ensure_writable do modified = T.let(false, T::Boolean) needs_codesigning = T.let(false, T::Boolean) if file.dylib? id = relocated_name_for(file.dylib_id, relocation) modified = change_dylib_id(id, file) if id needs_codesigning ||= modified end each_linkage_for(file, :dynamically_linked_libraries) do |old_name| new_name = relocated_name_for(old_name, relocation) modified = change_install_name(old_name, new_name, file) if new_name needs_codesigning ||= modified end each_linkage_for(file, :rpaths) do |old_name| new_name = relocated_name_for(old_name, relocation) modified = change_rpath(old_name, new_name, file) if new_name needs_codesigning ||= modified end # codesign the file if needed codesign_patched_binary(file.to_s) if needs_codesigning end end end sig { void } def fix_dynamic_linkage mach_o_files.each do |file| file.ensure_writable do modified = T.let(false, T::Boolean) needs_codesigning = T.let(false, T::Boolean) modified = change_dylib_id(dylib_id_for(file), file) if file.dylib? needs_codesigning ||= modified each_linkage_for(file, :dynamically_linked_libraries) do |bad_name| # Don't fix absolute paths unless they are rooted in the build directory. new_name = if bad_name.start_with?("/") && !rooted_in_build_directory?(bad_name) bad_name else fixed_name(file, bad_name) end loader_name = loader_name_for(file, new_name) modified = change_install_name(bad_name, loader_name, file) if loader_name != bad_name needs_codesigning ||= modified end each_linkage_for(file, :rpaths) do |bad_name| new_name = opt_name_for(bad_name) loader_name = loader_name_for(file, new_name) next if loader_name == bad_name modified = change_rpath(bad_name, loader_name, file) needs_codesigning ||= modified end # Strip duplicate rpaths and rpaths rooted in the build directory. # We do this separately from the rpath relocation above to avoid # failing to relocate an rpath whose variable duplicate we deleted. each_linkage_for(file, :rpaths, resolve_variable_references: true) do |bad_name| next if !rooted_in_build_directory?(bad_name) && file.rpaths.count(bad_name) == 1 modified = delete_rpath(bad_name, file) needs_codesigning ||= modified end # codesign the file if needed codesign_patched_binary(file.to_s) if needs_codesigning end end super end sig { params(file: MachOShim, target: String).returns(String) } def loader_name_for(file, target) # Use @loader_path-relative install names for other Homebrew-installed binaries. if ENV["HOMEBREW_RELOCATABLE_INSTALL_NAMES"] && target.start_with?(HOMEBREW_PREFIX) dylib_suffix = find_dylib_suffix_from(target) target_dir = ::Pathname.new(target.delete_suffix(dylib_suffix)).cleanpath "@loader_path/#{target_dir.relative_path_from(file.dirname)/dylib_suffix}" else target end end # If file is a dylib or bundle itself, look for the dylib named by # bad_name relative to the lib directory, so that we can skip the more # expensive recursive search if possible. sig { params(file: MachOShim, bad_name: String).returns(String) } def fixed_name(file, bad_name) if bad_name.start_with? ::Keg::PREFIX_PLACEHOLDER bad_name.sub(::Keg::PREFIX_PLACEHOLDER, HOMEBREW_PREFIX) elsif bad_name.start_with? ::Keg::CELLAR_PLACEHOLDER bad_name.sub(::Keg::CELLAR_PLACEHOLDER, HOMEBREW_CELLAR) elsif (file.dylib? || file.mach_o_bundle?) && (file.dirname/bad_name).exist? "@loader_path/#{bad_name}" elsif file.mach_o_executable? && (lib/bad_name).exist? "#{lib}/#{bad_name}" elsif file.mach_o_executable? && (libexec/"lib"/bad_name).exist? "#{libexec}/lib/#{bad_name}" elsif (abs_name = find_dylib(bad_name)) && abs_name.exist? abs_name.to_s else opoo "Could not fix #{bad_name} in #{file}" bad_name end end VARIABLE_REFERENCE_RX = T.let(/^@(loader_|executable_|r)path/, Regexp) sig { params(file: MachOShim, linkage_type: Symbol, resolve_variable_references: T::Boolean, block: T.proc.params(arg0: String).void).void } def each_linkage_for(file, linkage_type, resolve_variable_references: false, &block) file.public_send(linkage_type, resolve_variable_references:) .grep_v(VARIABLE_REFERENCE_RX) .each(&block) end sig { params(file: MachOShim).returns(String) } def dylib_id_for(file) # Swift dylib IDs should be /usr/lib/swift return file.dylib_id if file.dylib_id.start_with?("/usr/lib/swift/libswift") # Preserve @rpath install names if the formula has specified preserve_rpath return file.dylib_id if file.dylib_id.start_with?("@rpath") && formula_preserve_rpath? # The new dylib ID should have the same basename as the old dylib ID, not # the basename of the file itself. basename = File.basename(file.dylib_id) relative_dirname = file.dirname.relative_path_from(path) (opt_record/relative_dirname/basename).to_s end sig { returns(T::Boolean) } def formula_preserve_rpath? ::Formula[name].preserve_rpath? rescue FormulaUnavailableError false end sig { params(old_name: String, relocation: ::Keg::Relocation).returns(T.nilable(String)) } def relocated_name_for(old_name, relocation) old_prefix, new_prefix = relocation.replacement_pair_for(:prefix) old_cellar, new_cellar = relocation.replacement_pair_for(:cellar) if old_name.start_with? old_cellar old_name.sub(old_cellar, new_cellar) elsif old_name.start_with? old_prefix old_name.sub(old_prefix, new_prefix) end end # Matches framework references like `XXX.framework/Versions/YYY/XXX` and # `XXX.framework/XXX`, both with or without a slash-delimited prefix. FRAMEWORK_RX = %r{(?:^|/)(([^/]+)\.framework/(?:Versions/[^/]+/)?\2)$} sig { params(bad_name: String).returns(String) } def find_dylib_suffix_from(bad_name) if (framework = bad_name.match(FRAMEWORK_RX)) T.must(framework[1]) else File.basename(bad_name) end end sig { params(bad_name: String).returns(T.nilable(::Pathname)) } def find_dylib(bad_name) return unless lib.directory? suffix = "/#{find_dylib_suffix_from(bad_name)}" lib.find { |pn| break pn if pn.to_s.end_with?(suffix) } end sig { returns(T::Array[MachOShim]) } def mach_o_files hardlinks = Set.new mach_o_files = [] path.find do |pn| next if pn.symlink? || pn.directory? pn = MachOPathname.wrap(pn) next if !pn.dylib? && !pn.mach_o_bundle? && !pn.mach_o_executable? # if we've already processed a file, ignore its hardlinks (which have the same dev ID and inode) # this prevents relocations from being performed on a binary more than once next unless hardlinks.add? [pn.stat.dev, pn.stat.ino] mach_o_files << pn end mach_o_files end sig { returns(::Keg::Relocation) } def prepare_relocation_to_locations relocation = super brewed_perl = runtime_dependencies&.any? { |dep| dep["full_name"] == "perl" && dep["declared_directly"] } perl_path = if brewed_perl || name == "perl" "#{HOMEBREW_PREFIX}/opt/perl/bin/perl" elsif tab.built_on.present? perl_path = "/usr/bin/perl#{tab.built_on["preferred_perl"]}" # For `:all` bottles, we could have built this bottle with a Perl we don't have. # Such bottles typically don't have strict version requirements. perl_path = "/usr/bin/perl#{MacOS.preferred_perl_version}" unless File.exist?(perl_path) perl_path else "/usr/bin/perl#{MacOS.preferred_perl_version}" end relocation.add_replacement_pair(:perl, ::Keg::PERL_PLACEHOLDER, perl_path) if (openjdk = openjdk_dep_name_if_applicable) openjdk_path = HOMEBREW_PREFIX/"opt"/openjdk/"libexec/openjdk.jdk/Contents/Home" relocation.add_replacement_pair(:java, ::Keg::JAVA_PLACEHOLDER, openjdk_path.to_s) end relocation end sig { returns(String) } def recursive_fgrep_args # Don't recurse into symlinks; the man page says this is the default, but # it's wrong. -O is a BSD-grep-only option. "-lrO" end sig { returns([String, String]) } def egrep_args grep_bin = "egrep" grep_args = "--files-with-matches" [grep_bin, grep_args] end private CELLAR_RX = T.let(%r{\A#{HOMEBREW_CELLAR}/(?<formula_name>[^/]+)/[^/]+}, Regexp) private_constant :CELLAR_RX # Replace HOMEBREW_CELLAR references with HOMEBREW_PREFIX/opt references # if the Cellar reference is to a different keg. sig { params(filename: String).returns(String) } def opt_name_for(filename) return filename unless filename.start_with?(HOMEBREW_PREFIX.to_s) return filename if filename.start_with?(path.to_s) return filename if (matches = CELLAR_RX.match(filename)).blank? filename.sub(CELLAR_RX, "#{HOMEBREW_PREFIX}/opt/#{matches[:formula_name]}") end sig { params(filename: String).returns(T::Boolean) } def rooted_in_build_directory?(filename) # CMake normalises `/private/tmp` to `/tmp`. # https://gitlab.kitware.com/cmake/cmake/-/issues/23251 return true if HOMEBREW_TEMP.to_s == "/private/tmp" && filename.start_with?("/tmp/") filename.start_with?(HOMEBREW_TEMP.to_s, HOMEBREW_TEMP.realpath.to_s) end end end end Keg.singleton_class.prepend(OS::Mac::Keg::ClassMethods) Keg.prepend(OS::Mac::Keg)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/reinstall.rb
Library/Homebrew/extend/os/mac/reinstall.rb
# typed: strict # frozen_string_literal: true require "install" require "utils/output" module OS module Mac module Reinstall module ClassMethods extend T::Helpers include ::Utils::Output::Mixin requires_ancestor { ::Homebrew::Reinstall } sig { params(dry_run: T::Boolean).void } def reinstall_pkgconf_if_needed!(dry_run: false) mismatch = Homebrew::Pkgconf.macos_sdk_mismatch return unless mismatch if dry_run opoo "pkgconf would be reinstalled due to macOS version mismatch" return end pkgconf = ::Formula["pkgconf"] context = T.unsafe(self).build_install_context(pkgconf, flags: []) begin Homebrew::Install.fetch_formulae([context.formula_installer]) T.unsafe(self).reinstall_formula(context) ohai "Reinstalled pkgconf due to macOS version mismatch" rescue ofail Homebrew::Pkgconf.mismatch_warning_message(mismatch) end end end end end end Homebrew::Reinstall.singleton_class.prepend(OS::Mac::Reinstall::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/cleanup.rb
Library/Homebrew/extend/os/mac/cleanup.rb
# typed: strict # frozen_string_literal: true 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 end end end Homebrew::Cleanup.prepend(OS::Mac::Cleanup)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/missing_formula.rb
Library/Homebrew/extend/os/mac/missing_formula.rb
# typed: strict # frozen_string_literal: true require "cask/info" require "cask/cask_loader" require "cask/caskroom" module OS module Mac module MissingFormula module ClassMethods sig { params(name: String).returns(T.nilable(String)) } def disallowed_reason(name) case name.downcase when "xcode" <<~EOS Xcode can be installed from the App Store. EOS else super end end sig { params(name: String, silent: T::Boolean, show_info: T::Boolean).returns(T.nilable(String)) } def cask_reason(name, silent: false, show_info: false) return if silent suggest_command(name, show_info ? "info" : "install") end sig { params(name: String, command: String).returns(T.nilable(String)) } def suggest_command(name, command) suggestion = <<~EOS Found a cask named "#{name}" instead. Try brew #{command} --cask #{name} EOS case command when "install" ::Cask::CaskLoader.load(name) when "uninstall" cask = ::Cask::Caskroom.casks.find { |installed_cask| installed_cask.to_s == name } Kernel.raise ::Cask::CaskUnavailableError, name if cask.nil? when "info" cask = ::Cask::CaskLoader.load(name) suggestion = <<~EOS Found a cask named "#{name}" instead. #{::Cask::Info.get_info(cask)} EOS else return end suggestion rescue ::Cask::CaskUnavailableError nil end end end end end Homebrew::MissingFormula.singleton_class.prepend(OS::Mac::MissingFormula::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/cleaner.rb
Library/Homebrew/extend/os/mac/cleaner.rb
# typed: strict # frozen_string_literal: true module OS module Mac module Cleaner private sig { params(path: ::Pathname).returns(T::Boolean) } def executable_path?(path) return true if path.text_executable? path = MachOPathname.wrap(path) path.mach_o_executable? end end end end Cleaner.prepend(OS::Mac::Cleaner)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/pkgconf.rb
Library/Homebrew/extend/os/mac/pkgconf.rb
# typed: strict # frozen_string_literal: true module Homebrew module Pkgconf module_function sig { returns(T.nilable([String, String])) } def macos_sdk_mismatch # We don't provide suitable bottles for these versions. return if OS::Mac.version.prerelease? || OS::Mac.version.outdated_release? pkgconf = begin ::Formulary.factory_stub("pkgconf") rescue FormulaUnavailableError nil end return unless pkgconf&.any_version_installed? tab = Tab.for_formula(pkgconf) return unless tab.built_on built_on_version = tab.built_on["os_version"] &.delete_prefix("macOS ") &.sub(/\.\d+$/, "") return unless built_on_version current_version = MacOS.version.to_s return if built_on_version == current_version [built_on_version, current_version] end sig { params(mismatch: [String, String]).returns(String) } def mismatch_warning_message(mismatch) <<~EOS You have pkgconf installed that was built on macOS #{mismatch[0]}, but you are running macOS #{mismatch[1]}. This can cause issues with packages that depend on system libraries, such as libffi. To fix this issue, reinstall pkgconf: brew reinstall pkgconf For more information, see: https://github.com/Homebrew/brew/issues/16137 EOS end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/keg_only_reason.rb
Library/Homebrew/extend/os/mac/keg_only_reason.rb
# typed: strict # frozen_string_literal: true class KegOnlyReason sig { returns(T::Boolean) } def applicable? true end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/diagnostic.rb
Library/Homebrew/extend/os/mac/diagnostic.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/pkgconf" module OS module Mac module Diagnostic class Volumes sig { void } def initialize @volumes = T.let(get_mounts, T::Array[String]) end sig { params(path: T.nilable(::Pathname)).returns(Integer) } def index_of(path) vols = get_mounts path # no volume found return -1 if vols.empty? vol_index = @volumes.index(vols[0]) # volume not found in volume list return -1 if vol_index.nil? vol_index end sig { params(path: T.nilable(::Pathname)).returns(T::Array[String]) } def get_mounts(path = nil) vols = [] # get the volume of path, if path is nil returns all volumes args = %w[/bin/df -P] args << path.to_s if path Utils.popen_read(*args) do |io| io.each_line do |line| case line.chomp # regex matches: /dev/disk0s2 489562928 440803616 48247312 91% / when /^.+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+[0-9]{1,3}%\s+(.+)/ vols << Regexp.last_match(1) end end end vols end end module Checks extend T::Helpers requires_ancestor { Homebrew::Diagnostic::Checks } sig { params(verbose: T::Boolean).void } def initialize(verbose: true) super @found = T.let([], T::Array[String]) end sig { returns(T::Array[String]) } def fatal_preinstall_checks checks = %w[ check_access_directories ] # We need the developer tools for `codesign`. checks << "check_for_installed_developer_tools" if ::Hardware::CPU.arm? checks.freeze end sig { returns(T::Array[String]) } def fatal_build_from_source_checks %w[ check_xcode_license_approved check_xcode_minimum_version check_clt_minimum_version check_if_xcode_needs_clt_installed check_if_supported_sdk_available check_broken_sdks ].freeze end sig { returns(T::Array[String]) } def fatal_setup_build_environment_checks %w[ check_xcode_minimum_version check_clt_minimum_version check_if_supported_sdk_available ].freeze end sig { returns(T::Array[String]) } def supported_configuration_checks %w[ check_for_unsupported_macos ].freeze end sig { returns(T::Array[String]) } def build_from_source_checks %w[ check_for_installed_developer_tools check_xcode_up_to_date check_clt_up_to_date ].freeze end sig { returns(T.nilable(String)) } def check_for_non_prefixed_findutils findutils = ::Formula["findutils"] return unless findutils.any_version_installed? gnubin = %W[#{findutils.opt_libexec}/gnubin #{findutils.libexec}/gnubin] default_names = Tab.for_name("findutils").with? "default-names" return if !default_names && !paths.intersect?(gnubin) <<~EOS Putting non-prefixed findutils in your path can cause python builds to fail. EOS rescue FormulaUnavailableError nil end sig { returns(T.nilable(String)) } def check_for_unsupported_macos return if Homebrew::EnvConfig.developer? return if ENV["HOMEBREW_INTEGRATION_TEST"] tier = 2 who = +"We" what = if OS::Mac.version.prerelease? "pre-release version." elsif OS::Mac.version.outdated_release? tier = 3 who << " (and Apple)" <<~EOS.chomp old version. You may have better luck with MacPorts which supports older versions of macOS: #{Formatter.url("https://www.macports.org")} EOS end return if what.blank? who.freeze <<~EOS You are using macOS #{MacOS.version}. #{who} do not provide support for this #{what} #{support_tier_message(tier:)} EOS end sig { returns(T.nilable(String)) } def check_for_opencore return if ::Hardware::CPU.physical_cpu_arm64? # https://dortania.github.io/OpenCore-Legacy-Patcher/UPDATE.html#checking-oclp-and-opencore-versions begin opencore_version = Utils.safe_popen_read("/usr/sbin/nvram", "4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:opencore-version").split[1] oclp_version = Utils.safe_popen_read("/usr/sbin/nvram", "4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:OCLP-Version").split[1] return if opencore_version.blank? || oclp_version.blank? rescue ErrorDuringExecution return end oclp_support_tier = ::Hardware::CPU.features.include?(:pclmulqdq) ? 2 : 3 <<~EOS You have booted macOS using OpenCore Legacy Patcher. We do not provide support for this configuration. #{support_tier_message(tier: oclp_support_tier)} EOS end sig { returns(T.nilable(String)) } def check_xcode_up_to_date return unless MacOS::Xcode.outdated? # avoid duplicate very similar messages return if MacOS::Xcode.below_minimum_version? # CI images are going to end up outdated so don't complain when # `brew test-bot` runs `brew doctor` in the CI for the Homebrew/brew # repository. This only needs to support whatever CI providers # Homebrew/brew is currently using. return if GitHub::Actions.env_set? message = <<~EOS Your Xcode (#{MacOS::Xcode.version}) is outdated. Please update to Xcode #{MacOS::Xcode.latest_version} (or delete it). #{MacOS::Xcode.update_instructions} #{support_tier_message(tier: 2)} EOS 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: sudo xcode-select --switch /Applications/Xcode.app Current developer directory is: #{current_path} EOS end message end sig { returns(T.nilable(String)) } def check_clt_up_to_date return unless MacOS::CLT.outdated? # avoid duplicate very similar messages return if MacOS::CLT.below_minimum_version? # CI images are going to end up outdated so don't complain when # `brew test-bot` runs `brew doctor` in the CI for the Homebrew/brew # repository. This only needs to support whatever CI providers # Homebrew/brew is currently using. return if GitHub::Actions.env_set? <<~EOS A newer Command Line Tools release is available. #{MacOS::CLT.update_instructions} #{support_tier_message(tier: 2)} EOS end sig { returns(T.nilable(String)) } def check_xcode_minimum_version return unless MacOS::Xcode.below_minimum_version? xcode = MacOS::Xcode.version.to_s xcode += " => #{MacOS::Xcode.prefix}" unless MacOS::Xcode.default_prefix? <<~EOS Your Xcode (#{xcode}) at #{MacOS::Xcode.bundle_path} is too outdated. Please update to Xcode #{MacOS::Xcode.latest_version} (or delete it). #{MacOS::Xcode.update_instructions} EOS end sig { returns(T.nilable(String)) } def check_clt_minimum_version return unless MacOS::CLT.below_minimum_version? <<~EOS Your Command Line Tools are too outdated. #{MacOS::CLT.update_instructions} EOS end sig { returns(T.nilable(String)) } def check_if_xcode_needs_clt_installed return unless MacOS::Xcode.needs_clt_installed? <<~EOS Xcode alone is not sufficient on #{MacOS.version.pretty_name}. #{::DevelopmentTools.installation_instructions} EOS end sig { returns(T.nilable(String)) } def check_xcode_prefix prefix = MacOS::Xcode.prefix return if prefix.nil? return unless prefix.to_s.include?(" ") <<~EOS Xcode is installed to a directory with a space in the name. This will cause some formulae to fail to build. EOS end sig { returns(T.nilable(String)) } def check_xcode_prefix_exists prefix = MacOS::Xcode.prefix return if prefix.nil? || prefix.exist? <<~EOS The directory Xcode is reportedly installed to doesn't exist: #{prefix} You may need to `xcode-select` the proper path if you have moved Xcode. EOS end sig { returns(T.nilable(String)) } def check_xcode_select_path return if MacOS::CLT.installed? return unless MacOS::Xcode.installed? return if File.file?("#{MacOS.active_developer_dir}/usr/bin/xcodebuild") path = MacOS::Xcode.bundle_path path = "/Developer" if path.nil? || !path.directory? <<~EOS Your Xcode is configured with an invalid path. You should change it to the correct path: sudo xcode-select --switch #{path} EOS end sig { returns(T.nilable(String)) } def check_xcode_license_approved # If the user installs Xcode-only, they have to approve the # license or no "xc*" tool will work. return unless `/usr/bin/xcrun clang 2>&1`.include?("license") return if $CHILD_STATUS.success? <<~EOS You have not agreed to the Xcode license. Agree to the license by opening Xcode.app or running: sudo xcodebuild -license EOS end sig { returns(T.nilable(String)) } def check_filesystem_case_sensitive dirs_to_check = [ HOMEBREW_PREFIX, HOMEBREW_REPOSITORY, HOMEBREW_CELLAR, HOMEBREW_TEMP, ] case_sensitive_dirs = dirs_to_check.select do |dir| # We select the dir as being case-sensitive if either the UPCASED or the # downcased variant is missing. # Of course, on a case-insensitive fs, both exist because the os reports so. # In the rare situation when the user has indeed a downcased and an upcased # dir (e.g. /TMP and /tmp) this check falsely thinks it is case-insensitive # but we don't care because: 1. there is more than one dir checked, 2. the # check is not vital and 3. we would have to touch files otherwise. upcased = ::Pathname.new(dir.to_s.upcase) downcased = ::Pathname.new(dir.to_s.downcase) dir.exist? && !(upcased.exist? && downcased.exist?) end return if case_sensitive_dirs.empty? volumes = Volumes.new case_sensitive_vols = case_sensitive_dirs.map do |case_sensitive_dir| volumes.get_mounts(case_sensitive_dir) end case_sensitive_vols.uniq! <<~EOS The filesystem on #{case_sensitive_vols.join(",")} appears to be case-sensitive. The default macOS filesystem is case-insensitive. Please report any apparent problems. EOS end sig { returns(T.nilable(String)) } def check_for_gettext find_relative_paths("lib/libgettextlib.dylib", "lib/libintl.dylib", "include/libintl.h") return if @found.empty? # Our gettext formula will be caught by check_linked_keg_only_brews gettext = begin Formulary.factory("gettext") rescue nil end if gettext&.linked_keg&.directory? allowlist = ["#{HOMEBREW_CELLAR}/gettext"] if ::Hardware::CPU.physical_cpu_arm64? allowlist += %W[ #{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}/Cellar/gettext #{HOMEBREW_DEFAULT_PREFIX}/Cellar/gettext ] end return if @found.all? do |path| realpath = ::Pathname.new(path).realpath.to_s realpath.start_with?(*allowlist) end end inject_file_list @found, <<~EOS gettext files detected at a system prefix. These files can cause compilation and link failures, especially if they are compiled with improper architectures. Consider removing these files: EOS end sig { returns(T.nilable(String)) } def check_for_iconv find_relative_paths("lib/libiconv.dylib", "include/iconv.h") return if @found.empty? libiconv = begin Formulary.factory("libiconv") rescue nil end if libiconv&.linked_keg&.directory? unless libiconv&.keg_only? <<~EOS A libiconv formula is installed and linked. This will break stuff. For serious. Unlink it. EOS end else inject_file_list @found, <<~EOS libiconv files detected at a system prefix other than /usr. Homebrew doesn't provide a libiconv formula and expects to link against the system version in /usr. libiconv in other prefixes can cause compile or link failure, especially if compiled with improper architectures. macOS itself never installs anything to /usr/local so it was either installed by a user or some other third party software. tl;dr: delete these files: EOS end end sig { returns(T.nilable(String)) } def check_for_multiple_volumes return unless HOMEBREW_CELLAR.exist? volumes = Volumes.new # Find the volumes for the TMP folder & HOMEBREW_CELLAR real_cellar = HOMEBREW_CELLAR.realpath where_cellar = volumes.index_of real_cellar begin tmp = ::Pathname.new(Dir.mktmpdir("doctor", HOMEBREW_TEMP)) begin real_tmp = tmp.realpath.parent where_tmp = volumes.index_of real_tmp ensure Dir.delete tmp.to_s end rescue return end return if where_cellar == where_tmp <<~EOS Your Cellar and TEMP directories are on different volumes. macOS won't move relative symlinks across volumes unless the target file already exists. Formulae known to be affected by this are Git and Narwhal. You should set the `$HOMEBREW_TEMP` environment variable to a suitable directory on the same volume as your Cellar. #{support_tier_message(tier: 2)} EOS end sig { returns(T.nilable(String)) } def check_if_supported_sdk_available return unless ::DevelopmentTools.installed? return if MacOS.sdk locator = MacOS.sdk_locator source = if locator.source == :clt return if MacOS::CLT.below_minimum_version? # Handled by other diagnostics. update_instructions = MacOS::CLT.update_instructions "Command Line Tools (CLT)" else return if MacOS::Xcode.below_minimum_version? # Handled by other diagnostics. update_instructions = MacOS::Xcode.update_instructions "Xcode" end <<~EOS Your #{source} does not support macOS #{MacOS.version}. It is either outdated or was modified. Please update your #{source} or delete it if no updates are available. #{update_instructions} EOS end # The CLT 10.x -> 11.x upgrade process on 10.14 contained a bug which broke the SDKs. # Notably, MacOSX10.14.sdk would indirectly symlink to MacOSX10.15.sdk. # This diagnostic was introduced to check for this and recommend a full reinstall. sig { returns(T.nilable(String)) } def check_broken_sdks locator = MacOS.sdk_locator return if locator.all_sdks.all? do |sdk| path_version = sdk.path.basename.to_s[MacOS::SDK::VERSIONED_SDK_REGEX, 1] next true if path_version.blank? sdk.version == MacOSVersion.new(path_version).strip_patch end if locator.source == :clt source = "Command Line Tools (CLT)" path_to_remove = MacOS::CLT::PKG_PATH installation_instructions = MacOS::CLT.installation_instructions else source = "Xcode" path_to_remove = MacOS::Xcode.bundle_path installation_instructions = MacOS::Xcode.installation_instructions end <<~EOS The contents of the SDKs in your #{source} installation do not match the SDK folder names. A clean reinstall of #{source} should fix this. Remove the broken installation before reinstalling: sudo rm -rf #{path_to_remove} #{installation_instructions} EOS end sig { returns(T.nilable(String)) } def check_cask_software_versions super add_info "macOS", MacOS.full_version add_info "SIP", begin csrutil = "/usr/bin/csrutil" if File.executable?(csrutil) Open3.capture2(csrutil, "status") .first .gsub("This is an unsupported configuration, likely to break in " \ "the future and leave your machine in an unknown state.", "") .gsub("System Integrity Protection status: ", "") .delete("\t.") .capitalize .strip else "N/A" end end nil end sig { returns(T.nilable(String)) } def check_pkgconf_macos_sdk_mismatch mismatch = Homebrew::Pkgconf.macos_sdk_mismatch return unless mismatch Homebrew::Pkgconf.mismatch_warning_message(mismatch) end sig { returns(T.nilable(String)) } def check_cask_quarantine_support status, check_output = ::Cask::Quarantine.check_quarantine_support case status when :quarantine_available nil when :xattr_broken "No Cask quarantine support available: there's no working version of `xattr` on this system." when :no_swift "No Cask quarantine support available: there's no available version of `swift` on this system." when :swift_broken_clt <<~EOS No Cask quarantine support available: Swift is not working due to missing Command Line Tools. #{MacOS::CLT.installation_then_reinstall_instructions} EOS when :swift_compilation_failed <<~EOS No Cask quarantine support available: Swift compilation failed. This is usually due to a broken or incompatible Command Line Tools installation. #{MacOS::CLT.installation_then_reinstall_instructions} EOS when :swift_runtime_error <<~EOS No Cask quarantine support available: Swift runtime error. Your Command Line Tools installation may be broken or incomplete. #{MacOS::CLT.installation_then_reinstall_instructions} EOS when :swift_not_executable <<~EOS No Cask quarantine support available: Swift is not executable. Your Command Line Tools installation may be incomplete. #{MacOS::CLT.installation_then_reinstall_instructions} EOS when :swift_unexpected_error <<~EOS No Cask quarantine support available: Swift returned an unexpected error: #{check_output} EOS else <<~EOS No Cask quarantine support available: unknown reason: #{status.inspect}: #{check_output} EOS end end end end end end Homebrew::Diagnostic::Checks.prepend(OS::Mac::Diagnostic::Checks)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/tap.rb
Library/Homebrew/extend/os/mac/tap.rb
# typed: strict # frozen_string_literal: true module OS module Mac module Tap module ClassMethods sig { returns(T::Array[::Tap]) } def core_taps [CoreTap.instance, CoreCaskTap.instance].freeze end end end end end Tap.singleton_class.prepend(OS::Mac::Tap::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/system_config.rb
Library/Homebrew/extend/os/mac/system_config.rb
# typed: strict # frozen_string_literal: true require "system_command" module OS module Mac module SystemConfig module ClassMethods extend T::Helpers requires_ancestor { T.class_of(::SystemConfig) } sig { void } def initialize @xcode = T.let(nil, T.nilable(String)) @clt = T.let(nil, T.nilable(Version)) end sig { returns(String) } def describe_clang return "N/A" if ::SystemConfig.clang.null? clang_build_info = ::SystemConfig.clang_build.null? ? "(parse error)" : ::SystemConfig.clang_build "#{::SystemConfig.clang} build #{clang_build_info}" end sig { returns(T.nilable(String)) } def xcode @xcode ||= if MacOS::Xcode.installed? xcode = MacOS::Xcode.version.to_s xcode += " => #{MacOS::Xcode.prefix}" unless MacOS::Xcode.default_prefix? xcode end end sig { returns(T.nilable(Version)) } def clt @clt ||= MacOS::CLT.version if MacOS::CLT.installed? end sig { params(out: T.any(File, StringIO, IO)).void } def core_tap_config(out = $stdout) dump_tap_config(CoreTap.instance, out) dump_tap_config(CoreCaskTap.instance, out) end sig { returns(T.nilable(String)) } def metal_toolchain return unless ::Hardware::CPU.arm64? @metal_toolchain ||= T.let(nil, T.nilable(String)) @metal_toolchain ||= if MacOS::Xcode.installed? || MacOS::CLT.installed? result = SystemCommand.run("xcrun", args: ["--find", "metal"], print_stderr: false, print_stdout: false) pattern = /MetalToolchain-v(?<major>\d+)\.(?<letter>\d+)\.(?<build>\d+)\.(?<minor>\d+)/ if result.success? && (m = result.stdout.match(pattern)) letter = ("A".ord - 1 + m[:letter].to_i).chr "#{m[:major]}.#{m[:minor]} (#{m[:major]}#{letter}#{m[:build]})" end end end sig { params(out: T.any(File, StringIO, IO)).void } def dump_verbose_config(out = $stdout) super out.puts "macOS: #{MacOS.full_version}-#{kernel}" out.puts "CLT: #{clt || "N/A"}" out.puts "Xcode: #{xcode || "N/A"}" # Metal Toolchain is a separate install starting with Xcode 26. if ::Hardware::CPU.arm64? && MacOS::Xcode.installed? && MacOS::Xcode.version >= "26.0" out.puts "Metal Toolchain: #{metal_toolchain || "N/A"}" end out.puts "Rosetta 2: #{::Hardware::CPU.in_rosetta2?}" if ::Hardware::CPU.physical_cpu_arm64? end end end end end SystemConfig.singleton_class.prepend(OS::Mac::SystemConfig::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb
Library/Homebrew/extend/os/mac/formula_cellar_checks.rb
# typed: strict # frozen_string_literal: true require "cache_store" require "linkage_checker" module OS module Mac module FormulaCellarChecks extend T::Helpers requires_ancestor { Homebrew::FormulaAuditor } requires_ancestor { ::FormulaCellarChecks } sig { returns(T.nilable(String)) } def check_shadowed_headers return if ["libtool", "subversion", "berkeley-db"].any? do |formula_name| formula.name.start_with?(formula_name) end return if formula.name.match?(Version.formula_optionally_versioned_regex(:php)) return if formula.keg_only? || !formula.include.directory? files = relative_glob(formula.include, "**/*.h") files &= relative_glob("#{MacOS.sdk_path}/usr/include", "**/*.h") files.map! { |p| File.join(formula.include, p) } return if files.empty? <<~EOS Header files that shadow system header files were installed to "#{formula.include}" The offending files are: #{files * "\n "} EOS end sig { returns(T.nilable(String)) } def check_openssl_links return unless formula.prefix.directory? keg = ::Keg.new(formula.prefix) system_openssl = keg.mach_o_files.select do |obj| dlls = obj.dynamically_linked_libraries dlls.any? { |dll| %r{/usr/lib/lib(crypto|ssl|tls)\..*dylib}.match? dll } end return if system_openssl.empty? <<~EOS object files were linked against system openssl These object files were linked against the deprecated system OpenSSL or the system's private LibreSSL. Adding `depends_on "openssl"` to the formula may help. #{system_openssl * "\n "} EOS end sig { params(lib: ::Pathname).returns(T.nilable(String)) } def check_python_framework_links(lib) python_modules = ::Pathname.glob lib/"python*/site-packages/**/*.so" framework_links = python_modules.select do |obj| obj = MachOPathname.wrap(obj) dlls = obj.dynamically_linked_libraries dlls.any? { |dll| dll.include?("Python.framework") } end return if framework_links.empty? <<~EOS python modules have explicit framework links These python extension modules were linked directly to a Python framework binary. They should be linked with -undefined dynamic_lookup instead of -lpython or -framework Python. #{framework_links * "\n "} EOS end sig { void } def check_linkage return unless formula.prefix.directory? keg = ::Keg.new(formula.prefix) CacheStoreDatabase.use(:linkage) do |db| checker = ::LinkageChecker.new(keg, formula, cache_db: db) next unless checker.broken_library_linkage? output = <<~EOS #{formula} has broken dynamic library links: #{checker.display_test_output} EOS tab = keg.tab if tab.poured_from_bottle output += <<~EOS Rebuild this from source with: brew reinstall --build-from-source #{formula} If that's successful, file an issue#{formula.tap ? " here:\n #{formula.tap.issues_url}" : "."} EOS end problem_if_output output end end sig { params(formula: ::Formula).returns(T.nilable(String)) } def check_flat_namespace(formula) return unless formula.prefix.directory? return if formula.tap&.audit_exception(:flat_namespace_allowlist, formula.name) keg = ::Keg.new(formula.prefix) flat_namespace_files = keg.mach_o_files.reject do |file| next true unless file.dylib? macho = MachO.open(file) if MachO::Utils.fat_magic?(macho.magic) macho.machos.map(&:header).all? { |h| h.flag? :MH_TWOLEVEL } else macho.header.flag? :MH_TWOLEVEL end end return if flat_namespace_files.empty? <<~EOS Libraries were compiled with a flat namespace. This can cause linker errors due to name collisions and is often due to a bug in detecting the macOS version. #{flat_namespace_files * "\n "} EOS end sig { void } def audit_installed super problem_if_output(check_shadowed_headers) problem_if_output(check_openssl_links) problem_if_output(check_python_framework_links(formula.lib)) check_linkage problem_if_output(check_flat_namespace(formula)) end MACOS_LIB_EXTENSIONS = %w[.dylib .framework].freeze sig { params(filename: ::Pathname).returns(T::Boolean) } def valid_library_extension?(filename) super || MACOS_LIB_EXTENSIONS.include?(filename.extname) end end end end FormulaCellarChecks.prepend(OS::Mac::FormulaCellarChecks)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/dependency_collector.rb
Library/Homebrew/extend/os/mac/dependency_collector.rb
# typed: true # rubocop:disable Sorbet/StrictSigil # frozen_string_literal: true module OS module Mac module DependencyCollector def git_dep_if_needed(tags); end def subversion_dep_if_needed(tags) Dependency.new("subversion", [*tags, :implicit]) end def cvs_dep_if_needed(tags) Dependency.new("cvs", [*tags, :implicit]) end def xz_dep_if_needed(tags); end def unzip_dep_if_needed(tags); end def bzip2_dep_if_needed(tags); end end end end DependencyCollector.prepend(OS::Mac::DependencyCollector)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/linkage_checker.rb
Library/Homebrew/extend/os/mac/linkage_checker.rb
# typed: strict # frozen_string_literal: true module OS module Mac module LinkageChecker private sig { returns(T::Boolean) } 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 end end LinkageChecker.prepend(OS::Mac::LinkageChecker)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/formula.rb
Library/Homebrew/extend/os/mac/formula.rb
# typed: strict # frozen_string_literal: true module OS module Mac module Formula extend T::Helpers requires_ancestor { ::Formula } 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 = super # Ensure CMake is using the same SDK we are using. args << "-DCMAKE_OSX_SYSROOT=#{T.must(MacOS.sdk_for_formula(self)).path}" args end sig { params( prefix: T.any(String, ::Pathname), release_mode: Symbol, ).returns(T::Array[String]) } def std_zig_args(prefix: self.prefix, release_mode: :fast) args = super args << "-fno-rosetta" if ::Hardware::CPU.arm? args end end end end Formula.prepend(OS::Mac::Formula)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/keg.rb
Library/Homebrew/extend/os/mac/keg.rb
# typed: strict # frozen_string_literal: true require "system_command" module OS module Mac module Keg include SystemCommand::Mixin module ClassMethods sig { returns(T::Array[String]) } def keg_link_directories @keg_link_directories ||= T.let((super + ["Frameworks"]).freeze, T.nilable(T::Array[String])) end sig { returns(T::Array[::Pathname]) } def must_exist_subdirectories @must_exist_subdirectories ||= T.let(( super + [HOMEBREW_PREFIX/"Frameworks"] ).sort.uniq.freeze, T.nilable(T::Array[::Pathname])) end sig { returns(T::Array[::Pathname]) } def must_exist_directories @must_exist_directories ||= T.let(( super + [HOMEBREW_PREFIX/"Frameworks"] ).sort.uniq.freeze, T.nilable(T::Array[::Pathname])) end sig { returns(T::Array[::Pathname]) } def must_be_writable_directories @must_be_writable_directories ||= T.let(( super + [HOMEBREW_PREFIX/"Frameworks"] ).sort.uniq.freeze, T.nilable(T::Array[::Pathname])) end end sig { params(path: ::Pathname).void } def initialize(path) super @require_relocation = T.let(false, T::Boolean) end sig { params(id: String, file: MachOShim).returns(T::Boolean) } def change_dylib_id(id, file) return false if file.dylib_id == id @require_relocation = true odebug "Changing dylib ID of #{file}\n from #{file.dylib_id}\n to #{id}" file.change_dylib_id(id, strict: false) true rescue MachO::MachOError onoe <<~EOS Failed changing dylib ID of #{file} from #{file.dylib_id} to #{id} EOS raise end sig { params(old: String, new: String, file: MachOShim).returns(T::Boolean) } def change_install_name(old, new, file) return false if old == new @require_relocation = true odebug "Changing install name in #{file}\n from #{old}\n to #{new}" file.change_install_name(old, new, strict: false) true rescue MachO::MachOError onoe <<~EOS Failed changing install name in #{file} from #{old} to #{new} EOS raise end sig { params(old: String, new: String, file: MachOShim).returns(T::Boolean) } def change_rpath(old, new, file) return false if old == new @require_relocation = true odebug "Changing rpath in #{file}\n from #{old}\n to #{new}" file.change_rpath(old, new, strict: false) true rescue MachO::MachOError onoe <<~EOS Failed changing rpath in #{file} from #{old} to #{new} EOS raise end sig { params(rpath: String, file: MachOShim).returns(T::Boolean) } def delete_rpath(rpath, file) odebug "Deleting rpath #{rpath} in #{file}" file.delete_rpath(rpath, strict: false) true rescue MachO::MachOError onoe <<~EOS Failed deleting rpath #{rpath} in #{file} EOS raise end sig { returns(T::Array[MachOShim]) } def binary_executable_or_library_files = mach_o_files sig { params(file: String).void } def codesign_patched_binary(file) return if MacOS.version < :big_sur unless ::Hardware::CPU.arm? result = system_command("codesign", args: ["--verify", file], print_stderr: false) return unless result.stderr.match?(/invalid signature/i) end odebug "Codesigning #{file}" prepare_codesign_writable_files(file) do # Use quiet_system to squash notifications about resigning binaries # which already have valid signatures. return if quiet_system("codesign", "--sign", "-", "--force", "--preserve-metadata=entitlements,requirements,flags,runtime", file) # If the codesigning fails, it may be a bug in Apple's codesign utility # A known workaround is to copy the file to another inode, then move it back # erasing the previous file. Then sign again. # # TODO: remove this once the bug in Apple's codesign utility is fixed Dir::Tmpname.create("workaround") do |tmppath| FileUtils.cp file, tmppath FileUtils.mv tmppath, file, force: true end # Try signing again odebug "Codesigning (2nd try) #{file}" result = system_command("codesign", args: [ "--sign", "-", "--force", "--preserve-metadata=entitlements,requirements,flags,runtime", file ], print_stderr: false) return if result.success? # If it fails again, error out onoe <<~EOS Failed applying an ad-hoc signature to #{file}: #{result.stderr} EOS end end sig { params(file: String, _block: T.proc.void).void } def prepare_codesign_writable_files(file, &_block) result = system_command("codesign", args: [ "--display", "--file-list", "-", file ], print_stderr: false) return unless result.success? files = result.stdout.lines.map { |f| Pathname(f.chomp) } saved_perms = {} files.each do |f| unless f.writable? saved_perms[f] = f.stat.mode FileUtils.chmod "u+rw", f.to_path end end yield ensure saved_perms&.each do |f, p| f.chmod p if p end end sig { void } def prepare_debug_symbols binary_executable_or_library_files.each do |file| file = file.to_s odebug "Extracting symbols #{file}" result = system_command("dsymutil", args: [file], print_stderr: false) next if result.success? # If it fails again, error out ofail <<~EOS Failed to extract symbols from #{file}: #{result.stderr} EOS end end # Needed to make symlink permissions consistent on macOS and Linux for # reproducible bottles. sig { void } def consistent_reproducible_symlink_permissions! path.find do |file| file.lchmod 0777 if file.symlink? end end end end end Keg.singleton_class.prepend(OS::Mac::Keg::ClassMethods) Keg.prepend(OS::Mac::Keg)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/simulate_system.rb
Library/Homebrew/extend/os/mac/simulate_system.rb
# typed: strict # frozen_string_literal: true module OS module Mac module SimulateSystem module ClassMethods sig { returns(T::Boolean) } def simulating_or_running_on_macos? return true if Homebrew::SimulateSystem.os.blank? [:macos, *MacOSVersion::SYMBOLS.keys].include?(Homebrew::SimulateSystem.os) end sig { returns(Symbol) } def current_os ::Homebrew::SimulateSystem.os || MacOS.version.to_sym end end end end end Homebrew::SimulateSystem.singleton_class.prepend(OS::Mac::SimulateSystem::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/development_tools.rb
Library/Homebrew/extend/os/mac/development_tools.rb
# typed: strict # frozen_string_literal: true require "os/mac/xcode" module OS module Mac module DevelopmentTools module ClassMethods extend T::Helpers requires_ancestor { ::DevelopmentTools } sig { params(tool: T.any(String, Symbol)).returns(T.nilable(::Pathname)) } def locate(tool) @locate ||= T.let({}, T.nilable(T::Hash[T.any(String, Symbol), Pathname])) @locate.fetch(tool) do |key| @locate[key] = if (located_tool = super(tool)) located_tool else path = Utils.popen_read("/usr/bin/xcrun", "-no-cache", "-find", tool.to_s, err: :close).chomp ::Pathname.new(path) if File.executable?(path) end end end # Checks if the user has any developer tools installed, either via Xcode # or the CLT. Convenient for guarding against formula builds when building # is impossible. sig { returns(T::Boolean) } def installed? MacOS::Xcode.installed? || MacOS::CLT.installed? end sig { returns(Symbol) } def default_compiler :clang end sig { returns(Version) } def ld64_version @ld64_version ||= T.let(begin json = Utils.popen_read("/usr/bin/ld", "-version_details") if $CHILD_STATUS.success? Version.parse(JSON.parse(json)["version"]) else Version::NULL end end, T.nilable(Version)) end sig { returns(T::Boolean) } def curl_handles_most_https_certificates? # The system Curl is too old for some modern HTTPS certificates on # older macOS versions. ENV["HOMEBREW_SYSTEM_CURL_TOO_OLD"].nil? end sig { returns(String) } def installation_instructions MacOS::CLT.installation_instructions end sig { returns(String) } def custom_installation_instructions <<~EOS Install GNU's GCC: brew install gcc EOS end sig { returns(T::Hash[String, T.nilable(String)]) } def build_system_info build_info = { "xcode" => MacOS::Xcode.version.to_s.presence, "clt" => MacOS::CLT.version.to_s.presence, "preferred_perl" => MacOS.preferred_perl_version, } super.merge build_info end end end end end DevelopmentTools.singleton_class.prepend(OS::Mac::DevelopmentTools::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/formula_installer.rb
Library/Homebrew/extend/os/mac/formula_installer.rb
# typed: strict # frozen_string_literal: true module OS module Mac module FormulaInstaller extend T::Helpers requires_ancestor { ::FormulaInstaller } sig { params(formula: Formula).returns(T.nilable(T::Boolean)) } def fresh_install?(formula) !::Homebrew::EnvConfig.developer? && !OS::Mac.version.outdated_release? && (!installed_as_dependency? || !formula.any_version_installed?) end end end end FormulaInstaller.prepend(OS::Mac::FormulaInstaller)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb
Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb
# typed: strict # frozen_string_literal: true module OS module Mac module DevCmd module Bottle sig { returns(T::Array[String]) } def tar_args ["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze 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(OS::Mac::DevCmd::Bottle)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/dev-cmd/tests.rb
Library/Homebrew/extend/os/mac/dev-cmd/tests.rb
# typed: strict # frozen_string_literal: true module OS module Mac module DevCmd module Tests extend T::Helpers requires_ancestor { Homebrew::DevCmd::Tests } private sig { params(bundle_args: T::Array[String]).returns(T::Array[String]) } def os_bundle_args(bundle_args) non_linux_bundle_args(bundle_args) end sig { params(files: T::Array[String]).returns(T::Array[String]) } def os_files(files) non_linux_files(files) end end end end end Homebrew::DevCmd::Tests.prepend(OS::Mac::DevCmd::Tests)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/hardware/cpu.rb
Library/Homebrew/extend/os/mac/hardware/cpu.rb
# typed: strict # frozen_string_literal: true require "macho" module OS module Mac module Hardware module CPU module ClassMethods extend T::Helpers # These methods use info spewed out by sysctl. # Look in <mach/machine.h> for decoding info. sig { returns(Symbol) } def type case ::Hardware::CPU.sysctl_int("hw.cputype") when MachO::Headers::CPU_TYPE_I386 :intel when MachO::Headers::CPU_TYPE_ARM64 :arm else :dunno end end sig { returns(Symbol) } def family if ::Hardware::CPU.arm? ::Hardware::CPU.arm_family elsif ::Hardware::CPU.intel? ::Hardware::CPU.intel_family else :dunno end end # True when running under an Intel-based shell via Rosetta 2 on an # Apple Silicon Mac. This can be detected via seeing if there's a # conflict between what `uname` reports and the underlying `sysctl` flags, # since the `sysctl` flags don't change behaviour under Rosetta 2. sig { returns(T::Boolean) } def in_rosetta2? ::Hardware::CPU.sysctl_bool!("sysctl.proc_translated") end sig { returns(T::Array[Symbol]) } def features @features ||= T.let(::Hardware::CPU.sysctl_n( "machdep.cpu.features", "machdep.cpu.extfeatures", "machdep.cpu.leaf7_features", ).split.map { |s| s.downcase.to_sym }, T.nilable(T::Array[Symbol])) end sig { returns(T::Boolean) } def sse4? ::Hardware::CPU.sysctl_bool!("hw.optional.sse4_1") end end end end end end Hardware::CPU.singleton_class.prepend(OS::Mac::Hardware::CPU::ClassMethods) module Hardware class CPU class << self sig { returns(Integer) } def extmodel sysctl_int("machdep.cpu.extmodel") end sig { returns(T::Boolean) } def aes? sysctl_bool!("hw.optional.aes") end sig { returns(T::Boolean) } def altivec? sysctl_bool!("hw.optional.altivec") end sig { returns(T::Boolean) } def avx? sysctl_bool!("hw.optional.avx1_0") end sig { returns(T::Boolean) } def avx2? sysctl_bool!("hw.optional.avx2_0") end sig { returns(T::Boolean) } def sse3? sysctl_bool!("hw.optional.sse3") end sig { returns(T::Boolean) } def ssse3? sysctl_bool!("hw.optional.supplementalsse3") end sig { returns(T::Boolean) } def sse4_2? sysctl_bool!("hw.optional.sse4_2") end # NOTE: This is more reliable than checking `uname`. `sysctl` returns # the right answer even when running in Rosetta 2. sig { returns(T::Boolean) } def physical_cpu_arm64? sysctl_bool!("hw.optional.arm64") end sig { returns(T::Boolean) } def virtualized? sysctl_bool!("kern.hv_vmm_present") end sig { returns(Symbol) } def arm_family case sysctl_int("hw.cpufamily") when 0x2c91a47e # ARMv8.0-A (Typhoon) :arm_typhoon when 0x92fb37c8 # ARMv8.0-A (Twister) :arm_twister when 0x67ceee93 # ARMv8.1-A (Hurricane, Zephyr) :arm_hurricane_zephyr when 0xe81e7ef6 # ARMv8.2-A (Monsoon, Mistral) :arm_monsoon_mistral when 0x07d34b9f # ARMv8.3-A (Vortex, Tempest) :arm_vortex_tempest when 0x462504d2 # ARMv8.4-A (Lightning, Thunder) :arm_lightning_thunder when 0x573b5eec, 0x1b588bb3 # ARMv8.4-A (Firestorm, Icestorm) :arm_firestorm_icestorm when 0xda33d83d # ARMv8.5-A (Blizzard, Avalanche) :arm_blizzard_avalanche when 0xfa33415e # ARMv8.6-A (M3, Ibiza) :arm_ibiza when 0x5f4dea93 # ARMv8.6-A (M3 Pro, Lobos) :arm_lobos when 0x72015832 # ARMv8.6-A (M3 Max, Palma) :arm_palma when 0x6f5129ac # ARMv9.2-A (M4, Donan) :arm_donan when 0x17d5b93a # ARMv9.2-A (M4 Pro / M4 Max, Brava) :arm_brava else # When adding new ARM CPU families, please also update # test/hardware/cpu_spec.rb to include the new families. :dunno end end sig { params(_family: Integer, _cpu_model: Integer).returns(Symbol) } def intel_family(_family = T.unsafe(nil), _cpu_model = T.unsafe(nil)) case sysctl_int("hw.cpufamily") when 0x73d67300 # Yonah: Core Solo/Duo :core when 0x426f69ef # Merom: Core 2 Duo :core2 when 0x78ea4fbc # Penryn :penryn when 0x6b5a4cd2 # Nehalem :nehalem when 0x573b5eec # Westmere :westmere when 0x5490b78c # Sandy Bridge :sandybridge when 0x1f65e835 # Ivy Bridge :ivybridge when 0x10b282dc # Haswell :haswell when 0x582ed09c # Broadwell :broadwell when 0x37fc219f # Skylake :skylake when 0x0f817246 # Kaby Lake :kabylake when 0x38435547 # Ice Lake :icelake when 0x1cf8a03e # Comet Lake :cometlake else :dunno end end sig { params(key: String).returns(T::Boolean) } def sysctl_bool!(key) sysctl_int(key) == 1 end sig { params(key: String).returns(Integer) } def sysctl_int(key) sysctl_n(key).to_i & 0xffffffff end sig { params(keys: String).returns(String) } def sysctl_n(*keys) (@properties ||= T.let({}, T.nilable(T::Hash[T::Array[String], String]))).fetch(keys) do @properties[keys] = Utils.popen_read("/usr/sbin/sysctl", "-n", *keys) end end end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/cask/dsl.rb
Library/Homebrew/extend/os/mac/cask/dsl.rb
# typed: strict # frozen_string_literal: true require "cask/macos" module OS module Mac module Cask module DSL extend T::Helpers requires_ancestor { ::Cask::DSL } sig { returns(T.nilable(MacOSVersion)) } def os_version MacOS.full_version end end end end end Cask::DSL.prepend(OS::Mac::Cask::DSL)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/cask/artifact/symlinked.rb
Library/Homebrew/extend/os/mac/cask/artifact/symlinked.rb
# typed: strict # frozen_string_literal: true require "cask/macos" module OS module Mac module Cask module Artifact module Symlinked extend T::Helpers requires_ancestor { ::Cask::Artifact::Symlinked } sig { params(command: T.class_of(SystemCommand)).void } def create_filesystem_link(command) ::Cask::Utils.gain_permissions_mkpath(target.dirname, command:) command.run! "/bin/ln", args: ["-h", "-f", "-s", "--", source, target], sudo: !target.dirname.writable? add_altname_metadata(source, target.basename, command:) end end end end end end Cask::Artifact::Symlinked.prepend(OS::Mac::Cask::Artifact::Symlinked)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/cask/artifact/abstract_uninstall.rb
Library/Homebrew/extend/os/mac/cask/artifact/abstract_uninstall.rb
# typed: strict # frozen_string_literal: true require "cask/macos" module OS module Mac module Cask module Artifact module AbstractUninstall extend T::Helpers requires_ancestor { ::Cask::Artifact::AbstractUninstall } sig { params(target: ::Pathname).returns(T::Boolean) } def undeletable?(target) MacOS.undeletable?(target) end end end end end end Cask::Artifact::AbstractUninstall.prepend(OS::Mac::Cask::Artifact::AbstractUninstall)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/cask/artifact/moved.rb
Library/Homebrew/extend/os/mac/cask/artifact/moved.rb
# typed: strict # frozen_string_literal: true require "cask/macos" module OS module Mac module Cask module Artifact module Moved extend T::Helpers requires_ancestor { ::Cask::Artifact::Moved } sig { params(target: ::Pathname).returns(T::Boolean) } def undeletable?(target) MacOS.undeletable?(target) end end end end end end Cask::Artifact::Moved.prepend(OS::Mac::Cask::Artifact::Moved)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/utils/bottles.rb
Library/Homebrew/extend/os/mac/utils/bottles.rb
# typed: strict # frozen_string_literal: true module OS module Mac module Bottles module ClassMethods sig { params(tag: T.nilable(T.any(Symbol, Utils::Bottles::Tag))).returns(Utils::Bottles::Tag) } def tag(tag = nil) if tag.nil? Utils::Bottles::Tag.new(system: MacOS.version.to_sym, arch: ::Hardware::CPU.arch) else super end end end module Collector extend T::Helpers requires_ancestor { Utils::Bottles::Collector } private sig { params(tag: Utils::Bottles::Tag, no_older_versions: T::Boolean).returns(T.nilable(Utils::Bottles::Tag)) } def find_matching_tag(tag, no_older_versions: false) # Used primarily by developers testing beta macOS releases. if no_older_versions || (OS::Mac.version.prerelease? && Homebrew::EnvConfig.developer? && Homebrew::EnvConfig.skip_or_later_bottles?) super(tag) else super(tag) || find_older_compatible_tag(tag) end end # Find a bottle built for a previous version of macOS. sig { params(tag: Utils::Bottles::Tag).returns(T.nilable(Utils::Bottles::Tag)) } def find_older_compatible_tag(tag) tag_version = begin tag.to_macos_version rescue MacOSVersion::Error nil end return if tag_version.blank? tags.find do |candidate| next if candidate.standardized_arch != tag.standardized_arch candidate.to_macos_version <= tag_version rescue MacOSVersion::Error false end end end end end end Utils::Bottles.singleton_class.prepend(OS::Mac::Bottles::ClassMethods) Utils::Bottles::Collector.prepend(OS::Mac::Bottles::Collector)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/utils/socket.rb
Library/Homebrew/extend/os/mac/utils/socket.rb
# typed: strict # frozen_string_literal: true require "socket" module OS module Mac # Wrapper around UNIXSocket to allow > 104 characters on macOS. module UNIXSocketExt module ClassMethods extend T::Helpers requires_ancestor { Kernel } sig { params(path: String).returns(String) } def sockaddr_un(path) if path.bytesize > 252 # largest size that can fit into a single-byte length raise ArgumentError, "too long unix socket path (#{path.bytesize} bytes given but 252 bytes max)" end [ path.bytesize + 3, # = length (1 byte) + family (1 byte) + path (variable) + null terminator (1 byte) 1, # AF_UNIX path, ].pack("CCZ*") end end end end end Utils::UNIXSocketExt.singleton_class.prepend(OS::Mac::UNIXSocketExt::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/bundle/bundle.rb
Library/Homebrew/extend/os/mac/bundle/bundle.rb
# typed: strict # frozen_string_literal: true module OS module Mac module Bundle module ClassMethods sig { returns(T::Boolean) } def flatpak_installed? false end end end end end Homebrew::Bundle.singleton_class.prepend(OS::Mac::Bundle::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/bundle/skipper.rb
Library/Homebrew/extend/os/mac/bundle/skipper.rb
# typed: strict # frozen_string_literal: true module OS module Mac module Bundle module Skipper module ClassMethods sig { params(entry: Homebrew::Bundle::Dsl::Entry).returns(T::Boolean) } def linux_only_entry?(entry) entry.type == :flatpak end sig { params(entry: Homebrew::Bundle::Dsl::Entry, silent: T::Boolean).returns(T::Boolean) } def skip?(entry, silent: false) if linux_only_entry?(entry) unless silent Kernel.puts Formatter.warning "Skipping #{entry.type} #{entry.name} (unsupported on macOS)" end true else super end end end end end end end Homebrew::Bundle::Skipper.singleton_class.prepend(OS::Mac::Bundle::Skipper::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/extend/pathname.rb
Library/Homebrew/extend/os/mac/extend/pathname.rb
# typed: strict # frozen_string_literal: true require "os/mac/mach" module MachOPathname module ClassMethods sig { params(path: T.any(Pathname, String, MachOShim)).returns(MachOShim) } def wrap(path) return path if path.is_a?(MachOShim) path = ::Pathname.new(path) path.extend(MachOShim) T.cast(path, MachOShim) end end extend ClassMethods end BinaryPathname.singleton_class.prepend(MachOPathname::ClassMethods) module OS module Mac module Pathname module ClassMethods extend T::Helpers requires_ancestor { T.class_of(::Pathname) } sig { void } def activate_extensions! super prepend(MachOShim) end end end end end Pathname.singleton_class.prepend(OS::Mac::Pathname::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/extend/ENV/std.rb
Library/Homebrew/extend/os/mac/extend/ENV/std.rb
# typed: strict # frozen_string_literal: true module OS module Mac module Stdenv extend T::Helpers requires_ancestor { SharedEnvExtension } requires_ancestor { ::Stdenv } sig { returns(T::Array[::Pathname]) } def homebrew_extra_pkg_config_paths %W[ #{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version} ].map { |p| ::Pathname.new(p) } end private :homebrew_extra_pkg_config_paths sig { params( formula: T.nilable(Formula), cc: T.nilable(String), build_bottle: T.nilable(T::Boolean), bottle_arch: T.nilable(String), testing_formula: T::Boolean, debug_symbols: T.nilable(T::Boolean), ).void } def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false, debug_symbols: false) super append "LDFLAGS", "-Wl,-headerpad_max_install_names" # `sed` is strict and errors out when it encounters files with mixed character sets. delete("LC_ALL") self["LC_CTYPE"] = "C" # Add `lib` and `include` etc. from the current `macosxsdk` to compiler flags: macosxsdk(formula:, testing_formula:) return unless MacOS::Xcode.without_clt? append_path "PATH", "#{MacOS::Xcode.prefix}/usr/bin" append_path "PATH", "#{MacOS::Xcode.toolchain_path}/usr/bin" end sig { void } def llvm_clang super append "CPLUS_INCLUDE_PATH", "#{HOMEBREW_SHIMS_PATH}/mac/shared/include/llvm" end sig { params(version: T.nilable(MacOSVersion)).void } def remove_macosxsdk(version = nil) # Clear all `lib` and `include` dirs from `CFLAGS`, `CPPFLAGS`, `LDFLAGS` that were # previously added by `macosxsdk`. remove_from_cflags(/ ?-mmacosx-version-min=\d+\.\d+/) delete("CPATH") remove "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib" sdk = self["SDKROOT"] || MacOS.sdk_path(version) return unless sdk delete("SDKROOT") remove_from_cflags "-isysroot#{sdk}" remove "CPPFLAGS", "-isysroot#{sdk}" remove "LDFLAGS", "-isysroot#{sdk}" if HOMEBREW_PREFIX.to_s == "/usr/local" delete("CMAKE_PREFIX_PATH") else # It was set in `setup_build_environment`, so we have to restore it here. self["CMAKE_PREFIX_PATH"] = HOMEBREW_PREFIX.to_s end remove "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks" end sig { params(version: T.nilable(MacOSVersion), formula: T.nilable(Formula), testing_formula: T::Boolean).void } def macosxsdk(version = nil, formula: nil, testing_formula: false) # Sets all needed `lib` and `include` dirs to `CFLAGS`, `CPPFLAGS`, `LDFLAGS`. remove_macosxsdk min_version = version || MacOS.version append_to_cflags("-mmacosx-version-min=#{min_version}") self["CPATH"] = "#{HOMEBREW_PREFIX}/include" prepend "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib" sdk = if formula MacOS.sdk_for_formula(formula, version, check_only_runtime_requirements: testing_formula) else MacOS.sdk(version) end Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks) sdk = T.must(sdk).path # Extra setup to support Xcode 4.3+ without CLT. self["SDKROOT"] = sdk.to_s # Tell clang/gcc where system include's are: append_path "CPATH", "#{sdk}/usr/include" # The -isysroot is needed, too, because of the Frameworks append_to_cflags "-isysroot#{sdk}" append "CPPFLAGS", "-isysroot#{sdk}" # And the linker needs to find sdk/usr/lib append "LDFLAGS", "-isysroot#{sdk}" # Needed to build cmake itself and perhaps some cmake projects: append_path "CMAKE_PREFIX_PATH", "#{sdk}/usr" append_path "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks" end # Some configure scripts won't find libxml2 without help. # This is a no-op with macOS SDK 10.15.4 and later. sig { void } def libxml2 sdk = self["SDKROOT"] || MacOS.sdk_path # Use the includes from the sdk append "CPPFLAGS", "-I#{sdk}/usr/include/libxml2" unless Pathname("#{sdk}/usr/include/libxml").directory? end sig { void } def no_weak_imports append "LDFLAGS", "-Wl,-no_weak_imports" if no_weak_imports_support? end sig { void } def no_fixup_chains append "LDFLAGS", "-Wl,-no_fixup_chains" if no_fixup_chains_support? end end end end Stdenv.prepend(OS::Mac::Stdenv)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/extend/ENV/super.rb
Library/Homebrew/extend/os/mac/extend/ENV/super.rb
# typed: strict # frozen_string_literal: true module OS module Mac module Superenv extend T::Helpers requires_ancestor { SharedEnvExtension } requires_ancestor { ::Superenv } module ClassMethods sig { returns(::Pathname) } def shims_path HOMEBREW_SHIMS_PATH/"mac/super" end sig { returns(T.nilable(::Pathname)) } def bin return unless ::DevelopmentTools.installed? shims_path.realpath end end sig { returns(T::Array[::Pathname]) } def homebrew_extra_pkg_config_paths %W[ /usr/lib/pkgconfig #{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version} ].map { |p| ::Pathname.new(p) } end sig { returns(T::Boolean) } def libxml2_include_needed? return false if deps.any? { |d| d.name == "libxml2" } return false if ::Pathname.new("#{self["HOMEBREW_SDKROOT"]}/usr/include/libxml").directory? true end sig { returns(T::Array[::Pathname]) } def homebrew_extra_isystem_paths paths = [] paths << "#{self["HOMEBREW_SDKROOT"]}/usr/include/libxml2" if libxml2_include_needed? paths << "#{self["HOMEBREW_SDKROOT"]}/usr/include/apache2" if MacOS::Xcode.without_clt? paths << "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers" paths.map { |p| ::Pathname.new(p) } end sig { returns(T::Array[::Pathname]) } def homebrew_extra_library_paths paths = [] if compiler == :llvm_clang paths << "#{self["HOMEBREW_SDKROOT"]}/usr/lib" paths << ::Formula["llvm"].opt_lib end paths << "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries" paths.map { |p| ::Pathname.new(p) } end sig { returns(T::Array[::Pathname]) } def homebrew_extra_cmake_include_paths paths = [] paths << "#{self["HOMEBREW_SDKROOT"]}/usr/include/libxml2" if libxml2_include_needed? paths << "#{self["HOMEBREW_SDKROOT"]}/usr/include/apache2" if MacOS::Xcode.without_clt? paths << "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers" paths.map { |p| ::Pathname.new(p) } end sig { returns(T::Array[::Pathname]) } def homebrew_extra_cmake_library_paths %W[ #{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries ].map { |p| ::Pathname.new(p) } end sig { returns(T::Array[::Pathname]) } def homebrew_extra_cmake_frameworks_paths paths = [] paths << "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks" if MacOS::Xcode.without_clt? paths.map { |p| ::Pathname.new(p) } end sig { returns(String) } def determine_cccfg s = +"" # Fix issue with >= Mountain Lion apr-1-config having broken paths s << "a" s.freeze end # @private sig { params( formula: T.nilable(Formula), cc: T.nilable(String), build_bottle: T.nilable(T::Boolean), bottle_arch: T.nilable(String), testing_formula: T::Boolean, debug_symbols: T.nilable(T::Boolean), ).void } def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false, debug_symbols: false) sdk = formula ? MacOS.sdk_for_formula(formula) : MacOS.sdk is_xcode_sdk = sdk&.source == :xcode Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks) self["HOMEBREW_SDKROOT"] = sdk.path.to_s if sdk self["HOMEBREW_DEVELOPER_DIR"] = if is_xcode_sdk MacOS::Xcode.prefix.to_s else MacOS::CLT::PKG_PATH end # This is a workaround for the missing `m4` in Xcode CLT 15.3, which was # reported in FB13679972. Apple has fixed this in Xcode CLT 16.0. # See https://github.com/Homebrew/homebrew-core/issues/165388 if deps.none? { |d| d.name == "m4" } && MacOS.active_developer_dir == MacOS::CLT::PKG_PATH && !File.exist?("#{MacOS::CLT::PKG_PATH}/usr/bin/m4") && (gm4 = ::DevelopmentTools.locate("gm4").to_s).present? self["M4"] = gm4 end super # On macOS Sonoma (at least release candidate), iconv() is generally # present and working, but has a minor regression that defeats the # test implemented in gettext's configure script (and used by many # gettext dependents). ENV["am_cv_func_iconv_works"] = "yes" if MacOS.version == "14" # The tools in /usr/bin proxy to the active developer directory. # This means we can use them for any combination of CLT and Xcode. self["HOMEBREW_PREFER_CLT_PROXIES"] = "1" # Deterministic timestamping. self["ZERO_AR_DATE"] = "1" # Pass `-no_fixup_chains` whenever the linker is invoked with `-undefined dynamic_lookup`. # See: https://github.com/python/cpython/issues/97524 # https://github.com/pybind/pybind11/pull/4301 no_fixup_chains # Strip build prefixes from linker where supported, for deterministic builds. append_to_cccfg "o" # Pass `-ld_classic` whenever the linker is invoked with `-dead_strip_dylibs` # on `ld` versions that don't properly handle that option. return unless ::DevelopmentTools.ld64_version.between?("1015.7", "1022.1") append_to_cccfg "c" end sig { void } def no_weak_imports append_to_cccfg "w" if no_weak_imports_support? end sig { void } def no_fixup_chains append_to_cccfg "f" if no_fixup_chains_support? end end end end Superenv.singleton_class.prepend(OS::Mac::Superenv::ClassMethods) Superenv.prepend(OS::Mac::Superenv)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/extend/ENV/shared.rb
Library/Homebrew/extend/os/mac/extend/ENV/shared.rb
# typed: strict # frozen_string_literal: true module OS module Mac module SharedEnvExtension extend T::Helpers requires_ancestor { ::SharedEnvExtension } sig { params( formula: T.nilable(::Formula), cc: T.nilable(String), build_bottle: T.nilable(T::Boolean), bottle_arch: T.nilable(String), testing_formula: T::Boolean, debug_symbols: T.nilable(T::Boolean), ).void } def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false, debug_symbols: false) super # Normalise the system Perl version used, where multiple may be available self["VERSIONER_PERL_VERSION"] = MacOS.preferred_perl_version end sig { returns(T::Boolean) } def no_weak_imports_support? compiler == :clang end sig { returns(T::Boolean) } def no_fixup_chains_support? # This is supported starting Xcode 13, which ships ld64-711. # https://developer.apple.com/documentation/xcode-release-notes/xcode-13-release-notes # https://en.wikipedia.org/wiki/Xcode#Xcode_11.0_-_14.x_(since_SwiftUI_framework)_2 ::DevelopmentTools.ld64_version >= 711 end end end end SharedEnvExtension.prepend(OS::Mac::SharedEnvExtension)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb
Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb
# typed: strict # frozen_string_literal: true require "system_command" module UnpackStrategy class Zip module MacOSZipExtension extend T::Helpers requires_ancestor { UnpackStrategy } private sig { params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) with_env(TZ: "UTC") do if merge_xattrs && contains_extended_attributes?(path) # We use ditto directly, because dot_clean has issues if the __MACOSX # folder has incorrect permissions. # (Also, Homebrew's ZIP artifact automatically deletes this folder.) return system_command! "ditto", args: ["-x", "-k", path, unpack_dir], verbose:, print_stderr: false end result = begin T.let(super, T.nilable(SystemCommand::Result)) rescue ErrorDuringExecution => e raise unless e.stderr.include?("End-of-central-directory signature not found.") system_command!("ditto", args: ["-x", "-k", path, unpack_dir], verbose:) nil end return if result.blank? volumes = result.stderr.chomp .split("\n") .filter_map { |l| l[/\A skipping: (.+) volume label\Z/, 1] } return if volumes.empty? Dir.mktmpdir("homebrew-zip", HOMEBREW_TEMP) do |tmp_unpack_dir| tmp_unpack_dir = Pathname(tmp_unpack_dir) # `ditto` keeps Finder attributes intact and does not skip volume labels # like `unzip` does, which can prevent disk images from being unzipped. system_command!("ditto", args: ["-x", "-k", path, tmp_unpack_dir], verbose:) volumes.each do |volume| FileUtils.mv tmp_unpack_dir/volume, unpack_dir/volume, verbose: end end end end sig { params(path: Pathname).returns(T::Boolean) } def contains_extended_attributes?(path) path.zipinfo.grep(/(^__MACOSX|\._)/).any? end end private_constant :MacOSZipExtension prepend MacOSZipExtension end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/mac/language/java.rb
Library/Homebrew/extend/os/mac/language/java.rb
# typed: strict # frozen_string_literal: true module OS module Mac module Language module Java 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)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/utils/socket.rb
Library/Homebrew/extend/os/utils/socket.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/utils/socket" if OS.mac?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/requirements/xcode_requirement.rb
Library/Homebrew/extend/os/requirements/xcode_requirement.rb
# typed: strict # frozen_string_literal: true require "extend/os/linux/requirements/xcode_requirement" if OS.linux?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/bundle/bundle.rb
Library/Homebrew/extend/os/bundle/bundle.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/bundle/bundle" if OS.mac? require "extend/os/linux/bundle/bundle" if OS.linux?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/bundle/skipper.rb
Library/Homebrew/extend/os/bundle/skipper.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/bundle/skipper" if OS.mac? require "extend/os/linux/bundle/skipper" if OS.linux?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/bundle/commands/cleanup.rb
Library/Homebrew/extend/os/bundle/commands/cleanup.rb
# typed: strict # frozen_string_literal: true require "extend/os/mac/bundle/commands/cleanup" if OS.mac? require "extend/os/linux/bundle/commands/cleanup" if OS.linux?
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/linux/bottle_specification.rb
Library/Homebrew/extend/os/linux/bottle_specification.rb
# typed: strict # frozen_string_literal: true class BottleSpecification sig { params(tag: Utils::Bottles::Tag).returns(T::Boolean) } def skip_relocation?(tag: Utils::Bottles.tag) false end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/linux/keg_relocate.rb
Library/Homebrew/extend/os/linux/keg_relocate.rb
# typed: strict # frozen_string_literal: true require "compilers" module OS module Linux module Keg extend T::Helpers requires_ancestor { ::Keg } sig { params(relocation: ::Keg::Relocation, skip_protodesc_cold: T::Boolean).void } def relocate_dynamic_linkage(relocation, skip_protodesc_cold: false) # Patching the dynamic linker of glibc breaks it. return if name.match? Version.formula_optionally_versioned_regex(:glibc) old_prefix, new_prefix = relocation.replacement_pair_for(:prefix) elf_files.each do |file| file.ensure_writable do change_rpath!(file, old_prefix, new_prefix, skip_protodesc_cold:) end end end sig { params(file: ELFShim, old_prefix: T.any(String, Regexp), new_prefix: String, skip_protodesc_cold: T::Boolean).returns(T::Boolean) } def change_rpath!(file, old_prefix, new_prefix, skip_protodesc_cold: false) return false if !file.elf? || !file.dynamic_elf? # Skip relocation of files with `protodesc_cold` sections because patchelf.rb seems to break them, # but only when bottling (as we don't want to break existing bottles that require relocation). # https://github.com/Homebrew/homebrew-core/pull/232490#issuecomment-3161362452 return false if skip_protodesc_cold && file.section_names.include?("protodesc_cold") updated = {} old_rpath = file.rpath new_rpath = if old_rpath rpath = old_rpath.split(":") .map { |x| x.sub(old_prefix, new_prefix) } .select { |x| x.start_with?(new_prefix, "$ORIGIN") } lib_path = "#{new_prefix}/lib" rpath << lib_path unless rpath.include? lib_path # Add GCC's lib directory (as of GCC 12+) to RPATH when there is existing versioned linkage. # This prevents broken linkage when pouring bottles built with an old GCC formula. unless name.match?(Version.formula_optionally_versioned_regex(:gcc)) rpath.map! { |rp| rp.sub(%r{lib/gcc/\d+$}, "lib/gcc/current") } end rpath.join(":") end updated[:rpath] = new_rpath if old_rpath != new_rpath old_interpreter = file.interpreter new_interpreter = if old_interpreter.nil? nil elsif File.readable? "#{new_prefix}/lib/ld.so" "#{new_prefix}/lib/ld.so" else old_interpreter.sub old_prefix, new_prefix end updated[:interpreter] = new_interpreter if old_interpreter != new_interpreter file.patch!(interpreter: updated[:interpreter], rpath: updated[:rpath]) true end sig { params(options: T::Hash[Symbol, T::Boolean]).returns(T::Array[Symbol]) } def detect_cxx_stdlibs(options = {}) skip_executables = options.fetch(:skip_executables, false) results = Set.new elf_files.each do |file| next unless file.dynamic_elf? next if file.binary_executable? && skip_executables dylibs = file.dynamically_linked_libraries results << :libcxx if dylibs.any? { |s| s.include? "libc++.so" } results << :libstdcxx if dylibs.any? { |s| s.include? "libstdc++.so" } end results.to_a end sig { returns(T::Array[ELFShim]) } def elf_files hardlinks = Set.new elf_files = [] path.find do |pn| next if pn.symlink? || pn.directory? pn = ELFPathname.wrap(pn) next if !pn.dylib? && !pn.binary_executable? # If we've already processed a file, ignore its hardlinks (which have the # same dev ID and inode). This prevents relocations from being performed # on a binary more than once. next unless hardlinks.add? [pn.stat.dev, pn.stat.ino] elf_files << pn end elf_files end end end end Keg.prepend(OS::Linux::Keg)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/linux/cleanup.rb
Library/Homebrew/extend/os/linux/cleanup.rb
# typed: strict # frozen_string_literal: true module OS module Linux module Cleanup extend T::Helpers requires_ancestor { Homebrew::Cleanup } 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? 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(OS::Linux::Cleanup)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/linux/cleaner.rb
Library/Homebrew/extend/os/linux/cleaner.rb
# typed: strict # frozen_string_literal: true module OS module Linux module Cleaner private sig { params(path: ::Pathname).returns(T::Boolean) } def executable_path?(path) return true if path.text_executable? ELFPathname.wrap(path).elf? end end end end Cleaner.prepend(OS::Linux::Cleaner)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/linux/compilers.rb
Library/Homebrew/extend/os/linux/compilers.rb
# typed: strict # frozen_string_literal: true module OS module Linux module CompilerSelector module ClassMethods extend T::Helpers requires_ancestor { T.class_of(::CompilerSelector) } sig { returns(String) } def preferred_gcc OS::LINUX_PREFERRED_GCC_COMPILER_FORMULA end end end end end CompilerSelector.singleton_class.prepend(OS::Linux::CompilerSelector::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/linux/diagnostic.rb
Library/Homebrew/extend/os/linux/diagnostic.rb
# typed: strict # frozen_string_literal: true require "tempfile" require "utils/shell" require "hardware" require "os/linux/glibc" require "os/linux/kernel" module OS module Linux module Diagnostic # Linux-specific diagnostic checks for Homebrew. module Checks extend T::Helpers requires_ancestor { Homebrew::Diagnostic::Checks } sig { returns(T::Array[String]) } def fatal_preinstall_checks %w[ check_access_directories check_linuxbrew_core check_linuxbrew_bottle_domain ].freeze end sig { returns(T::Array[String]) } def supported_configuration_checks %w[ check_glibc_minimum_version check_kernel_minimum_version check_supported_architecture ].freeze end sig { returns(T.nilable(String)) } def check_tmpdir_sticky_bit message = super return if message.nil? message + <<~EOS If you don't have administrative privileges on this machine, create a directory and set the `$HOMEBREW_TEMP` environment variable, for example: install -d -m 1755 ~/tmp #{Utils::Shell.set_variable_in_profile("HOMEBREW_TEMP", "~/tmp")} EOS end sig { returns(T.nilable(String)) } def check_tmpdir_executable f = Tempfile.new(%w[homebrew_check_tmpdir_executable .sh], HOMEBREW_TEMP) f.write "#!/bin/sh\n" f.chmod 0700 f.close return if system T.must(f.path) <<~EOS The directory #{HOMEBREW_TEMP} does not permit executing programs. It is likely mounted as "noexec". Please set `$HOMEBREW_TEMP` in your #{Utils::Shell.profile} to a different directory, for example: export HOMEBREW_TEMP=~/tmp echo 'export HOMEBREW_TEMP=~/tmp' >> #{Utils::Shell.profile} EOS ensure f&.unlink end sig { returns(T.nilable(String)) } def check_umask_not_zero return unless File.umask.zero? <<~EOS umask is currently set to 000. Directories created by Homebrew cannot be world-writable. This issue can be resolved by adding "umask 002" to your #{Utils::Shell.profile}: echo 'umask 002' >> #{Utils::Shell.profile} EOS end sig { returns(T.nilable(String)) } def check_supported_architecture return if ::Hardware::CPU.intel? return if ::Hardware::CPU.arm64? <<~EOS Your CPU architecture (#{::Hardware::CPU.arch}) is not supported. We only support x86_64 or ARM64/AArch64 CPU architectures. You will be unable to use binary packages (bottles). #{support_tier_message(tier: 2)} EOS end sig { returns(T.nilable(String)) } def check_glibc_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. We recommend updating to a newer version via your distribution's package manager, upgrading your distribution to the latest version, or changing distributions. #{support_tier_message(tier: :unsupported)} EOS end sig { returns(T.nilable(String)) } def check_glibc_version return unless OS::Linux::Glibc.below_ci_version? # We want to bypass this check in some tests. return if ENV["HOMEBREW_GLIBC_TESTING"] <<~EOS Your system glibc #{OS::Linux::Glibc.system_version} is too old. We will need to automatically install a newer version. We recommend updating to a newer version via your distribution's package manager, upgrading your distribution to the latest version, or changing distributions. #{support_tier_message(tier: 2)} EOS end sig { returns(T.nilable(String)) } def check_kernel_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. You will be unable to use binary packages (bottles). We recommend updating to a newer version via your distribution's package manager, upgrading your distribution to the latest version, or changing distributions. #{support_tier_message(tier: 3)} EOS end sig { returns(T.nilable(String)) } def check_linuxbrew_core return unless Homebrew::EnvConfig.no_install_from_api? return unless CoreTap.instance.linuxbrew_core? <<~EOS Your Linux core repository is still linuxbrew-core. You must either unset `$HOMEBREW_NO_INSTALL_FROM_API` or set the repository's remote to homebrew-core to update core formulae. EOS end sig { returns(T.nilable(String)) } def check_linuxbrew_bottle_domain return unless Homebrew::EnvConfig.bottle_domain.include?("linuxbrew") <<~EOS Your `$HOMEBREW_BOTTLE_DOMAIN` still contains "linuxbrew". You must unset it (or adjust it to not contain linuxbrew e.g. by using homebrew instead). EOS end sig { returns(T.nilable(String)) } def check_for_symlinked_home return unless File.symlink?("/home") <<~EOS Your /home directory is a symlink. This is known to cause issues with formula linking, particularly when installing multiple formulae that create symlinks in shared directories. While this may be a standard directory structure in some distributions (e.g. Fedora Silverblue) there are known issues as-is. If you encounter linking issues, you may need to manually create conflicting directories or use `brew link --overwrite` as a workaround. We'd welcome a PR to fix this functionality. See https://github.com/Homebrew/brew/issues/18036 for more context. #{support_tier_message(tier: 2)} EOS end sig { returns(T.nilable(String)) } def check_gcc_dependent_linkage gcc_dependents = ::Formula.installed.select do |formula| next false unless formula.tap&.core_tap? # FIXME: This includes formulae that have no runtime dependency on GCC. formula.recursive_dependencies.map(&:name).include? "gcc" rescue TapFormulaUnavailableError false end return if gcc_dependents.empty? badly_linked = gcc_dependents.select do |dependent| dependent_prefix = dependent.any_installed_prefix # Keg.new() may raise an error if it is not a directory. # As the result `brew doctor` may display `Error: <keg> is not a directory` # instead of proper `doctor` information. # There are other checks that test that, we can skip broken kegs. next if dependent_prefix.nil? || !dependent_prefix.exist? || !dependent_prefix.directory? keg = ::Keg.new(dependent_prefix) keg.binary_executable_or_library_files.any? do |binary| paths = binary.rpaths versioned_linkage = paths.any? { |path| path.match?(%r{lib/gcc/\d+$}) } unversioned_linkage = paths.any? { |path| path.match?(%r{lib/gcc/current$}) } versioned_linkage && !unversioned_linkage end end return if badly_linked.empty? inject_file_list badly_linked, <<~EOS Formulae which link to GCC through a versioned path were found. These formulae are prone to breaking when GCC is updated. You should `brew reinstall` these formulae: EOS end sig { returns(T.nilable(String)) } def check_cask_software_versions super add_info "Linux", OS::Linux.os_version nil end end end end end Homebrew::Diagnostic::Checks.prepend(OS::Linux::Diagnostic::Checks)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/linux/system_config.rb
Library/Homebrew/extend/os/linux/system_config.rb
# typed: strict # frozen_string_literal: true require "compilers" require "os/linux/glibc" require "os/linux/libstdcxx" require "system_command" module OS module Linux module SystemConfig module ClassMethods include SystemCommand::Mixin HOST_RUBY_PATH = "/usr/bin/ruby" sig { returns(T.any(String, Version)) } def host_glibc_version version = OS::Linux::Glibc.system_version return "N/A" if version.null? version end sig { returns(T.any(String, Version)) } def host_libstdcxx_version version = OS::Linux::Libstdcxx.system_version return "N/A" if version.null? version end sig { returns(String) } def host_gcc_version gcc = ::DevelopmentTools.host_gcc_path return "N/A" unless gcc.executable? Utils.popen_read(gcc, "--version")[/ (\d+\.\d+\.\d+)/, 1] || "N/A" end sig { params(formula: T.any(::Pathname, String)).returns(T.any(String, PkgVersion)) } def formula_linked_version(formula) return "N/A" if Homebrew::EnvConfig.no_install_from_api? && !CoreTap.instance.installed? Formulary.factory(formula).any_installed_version || "N/A" rescue FormulaUnavailableError "N/A" end sig { returns(String) } def host_ruby_version out, _, status = system_command(HOST_RUBY_PATH, args: ["-e", "puts RUBY_VERSION"], print_stderr: false).to_a return "N/A" unless status.success? out end sig { params(out: T.any(File, StringIO, IO)).void } def dump_verbose_config(out = $stdout) kernel = Utils.safe_popen_read("uname", "-mors").chomp super out.puts "Kernel: #{kernel}" out.puts "OS: #{OS::Linux.os_version}" out.puts "WSL: #{OS::Linux.wsl_version}" if OS::Linux.wsl? out.puts "Host glibc: #{host_glibc_version}" out.puts "Host libstdc++: #{host_libstdcxx_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| out.puts "#{f}: #{formula_linked_version(f)}" end end end end end end SystemConfig.singleton_class.prepend(OS::Linux::SystemConfig::ClassMethods)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/linux/formula_cellar_checks.rb
Library/Homebrew/extend/os/linux/formula_cellar_checks.rb
# typed: strict # frozen_string_literal: true module OS module Linux module FormulaCellarChecks sig { params(filename: ::Pathname).returns(T::Boolean) } def valid_library_extension?(filename) super || filename.basename.to_s.include?(".so.") end end end end FormulaCellarChecks.prepend(OS::Linux::FormulaCellarChecks)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/extend/os/linux/dependency_collector.rb
Library/Homebrew/extend/os/linux/dependency_collector.rb
# typed: strict # frozen_string_literal: true require "os/linux/glibc" module OS module Linux module DependencyCollector sig { params(related_formula_names: T::Set[String]).returns(T.nilable(Dependency)) } def gcc_dep_if_needed(related_formula_names) # gcc is required for libgcc_s.so.1 if glibc or gcc are too old return unless ::DevelopmentTools.needs_build_formulae? return if building_global_dep_tree? return if related_formula_names.include?(GCC) return if global_dep_tree[GCC]&.intersect?(related_formula_names) return unless formula_for(GCC) Dependency.new(GCC, [:implicit]) end sig { params(related_formula_names: T::Set[String]).returns(T.nilable(Dependency)) } def glibc_dep_if_needed(related_formula_names) return unless ::DevelopmentTools.needs_libc_formula? return if building_global_dep_tree? return if related_formula_names.include?(GLIBC) return if global_dep_tree[GLIBC]&.intersect?(related_formula_names) return unless formula_for(GLIBC) Dependency.new(GLIBC, [:implicit]) end private GLIBC = "glibc" GCC = OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA private_constant :GLIBC, :GCC sig { void } def init_global_dep_tree_if_needed! return unless ::DevelopmentTools.needs_build_formulae? return if building_global_dep_tree? return unless global_dep_tree.empty? building_global_dep_tree! global_dep_tree[GLIBC] = Set.new(global_deps_for(GLIBC)) # gcc depends on glibc global_dep_tree[GCC] = Set.new([*global_deps_for(GCC), GLIBC, *@@global_dep_tree[GLIBC]]) built_global_dep_tree! end sig { params(name: String).returns(T.nilable(::Formula)) } def formula_for(name) @formula_for ||= T.let({}, T.nilable(T::Hash[String, ::Formula])) @formula_for[name] ||= ::Formula[name] rescue FormulaUnavailableError nil end sig { params(name: String).returns(T::Array[String]) } def global_deps_for(name) @global_deps_for ||= T.let({}, T.nilable(T::Hash[String, T::Array[String]])) # Always strip out glibc and gcc from all parts of dependency tree when # we're calculating their dependency trees. Other parts of Homebrew will # catch any circular dependencies. @global_deps_for[name] ||= if (formula = formula_for(name)) formula.deps.map(&:name).flat_map do |dep| [dep, *global_deps_for(dep)].compact end.uniq else [] end end # Use class variables to avoid this expensive logic needing to be done more # than once. # rubocop:disable Style/ClassVars @@global_dep_tree = T.let({}, T::Hash[String, T::Set[String]]) @@building_global_dep_tree = T.let(false, T::Boolean) sig { returns(T::Hash[String, T::Set[String]]) } def global_dep_tree @@global_dep_tree end sig { void } def building_global_dep_tree! @@building_global_dep_tree = true end sig { void } def built_global_dep_tree! @@building_global_dep_tree = false end sig { returns(T::Boolean) } def building_global_dep_tree? @@building_global_dep_tree.present? end # rubocop:enable Style/ClassVars end end end DependencyCollector.prepend(OS::Linux::DependencyCollector)
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false