Merge pull request #20494 from Homebrew/keg_relocate_typed_strict
**/keg_relocate.rb: add set Sorbet `typed: strict`
This commit is contained in:
commit
8b0b8a8b1c
@ -590,7 +590,7 @@ module Homebrew
|
|||||||
ensure
|
ensure
|
||||||
ignore_interrupts do
|
ignore_interrupts do
|
||||||
original_tab&.write
|
original_tab&.write
|
||||||
keg.replace_placeholders_with_locations changed_files unless args.skip_relocation?
|
keg.replace_placeholders_with_locations(changed_files) if changed_files && !args.skip_relocation?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "compilers"
|
require "compilers"
|
||||||
|
|
||||||
class Keg
|
class Keg
|
||||||
|
sig { params(relocation: Relocation, skip_protodesc_cold: T::Boolean).void }
|
||||||
def relocate_dynamic_linkage(relocation, skip_protodesc_cold: false)
|
def relocate_dynamic_linkage(relocation, skip_protodesc_cold: false)
|
||||||
# Patching the dynamic linker of glibc breaks it.
|
# Patching the dynamic linker of glibc breaks it.
|
||||||
return if name.match? Version.formula_optionally_versioned_regex(:glibc)
|
return if name.match? Version.formula_optionally_versioned_regex(:glibc)
|
||||||
@ -17,6 +18,10 @@ class Keg
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig {
|
||||||
|
params(file: Pathname, 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)
|
def change_rpath!(file, old_prefix, new_prefix, skip_protodesc_cold: false)
|
||||||
return false if !file.elf? || !file.dynamic_elf?
|
return false if !file.elf? || !file.dynamic_elf?
|
||||||
|
|
||||||
@ -59,6 +64,7 @@ class Keg
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(options: T::Hash[Symbol, T::Boolean]).returns(T::Array[Symbol]) }
|
||||||
def detect_cxx_stdlibs(options = {})
|
def detect_cxx_stdlibs(options = {})
|
||||||
skip_executables = options.fetch(:skip_executables, false)
|
skip_executables = options.fetch(:skip_executables, false)
|
||||||
results = Set.new
|
results = Set.new
|
||||||
@ -73,6 +79,7 @@ class Keg
|
|||||||
results.to_a
|
results.to_a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[Pathname]) }
|
||||||
def elf_files
|
def elf_files
|
||||||
hardlinks = Set.new
|
hardlinks = Set.new
|
||||||
elf_files = []
|
elf_files = []
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true # rubocop:disable Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module OS
|
module OS
|
||||||
@ -9,6 +9,7 @@ module OS
|
|||||||
requires_ancestor { ::Keg }
|
requires_ancestor { ::Keg }
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
sig { params(file: Pathname, string: String).returns(T::Array[String]) }
|
||||||
def file_linked_libraries(file, string)
|
def file_linked_libraries(file, string)
|
||||||
# Check dynamic library linkage. Importantly, do not perform for static
|
# Check dynamic library linkage. Importantly, do not perform for static
|
||||||
# libraries, which will falsely report "linkage" to themselves.
|
# libraries, which will falsely report "linkage" to themselves.
|
||||||
@ -20,6 +21,7 @@ module OS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(relocation: ::Keg::Relocation, skip_protodesc_cold: T::Boolean).void }
|
||||||
def relocate_dynamic_linkage(relocation, skip_protodesc_cold: false)
|
def relocate_dynamic_linkage(relocation, skip_protodesc_cold: false)
|
||||||
mach_o_files.each do |file|
|
mach_o_files.each do |file|
|
||||||
file.ensure_writable do
|
file.ensure_writable do
|
||||||
@ -50,6 +52,7 @@ module OS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def fix_dynamic_linkage
|
def fix_dynamic_linkage
|
||||||
mach_o_files.each do |file|
|
mach_o_files.each do |file|
|
||||||
file.ensure_writable do
|
file.ensure_writable do
|
||||||
@ -98,6 +101,7 @@ module OS
|
|||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(file: Pathname, target: String).returns(String) }
|
||||||
def loader_name_for(file, target)
|
def loader_name_for(file, target)
|
||||||
# Use @loader_path-relative install names for other Homebrew-installed binaries.
|
# Use @loader_path-relative install names for other Homebrew-installed binaries.
|
||||||
if ENV["HOMEBREW_RELOCATABLE_INSTALL_NAMES"] && target.start_with?(HOMEBREW_PREFIX)
|
if ENV["HOMEBREW_RELOCATABLE_INSTALL_NAMES"] && target.start_with?(HOMEBREW_PREFIX)
|
||||||
@ -113,6 +117,7 @@ module OS
|
|||||||
# If file is a dylib or bundle itself, look for the dylib named by
|
# 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
|
# bad_name relative to the lib directory, so that we can skip the more
|
||||||
# expensive recursive search if possible.
|
# expensive recursive search if possible.
|
||||||
|
sig { params(file: Pathname, bad_name: String).returns(String) }
|
||||||
def fixed_name(file, bad_name)
|
def fixed_name(file, bad_name)
|
||||||
if bad_name.start_with? ::Keg::PREFIX_PLACEHOLDER
|
if bad_name.start_with? ::Keg::PREFIX_PLACEHOLDER
|
||||||
bad_name.sub(::Keg::PREFIX_PLACEHOLDER, HOMEBREW_PREFIX)
|
bad_name.sub(::Keg::PREFIX_PLACEHOLDER, HOMEBREW_PREFIX)
|
||||||
@ -132,14 +137,16 @@ module OS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
VARIABLE_REFERENCE_RX = /^@(loader_|executable_|r)path/
|
VARIABLE_REFERENCE_RX = T.let(/^@(loader_|executable_|r)path/, Regexp)
|
||||||
|
|
||||||
|
sig { params(file: Pathname, 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)
|
def each_linkage_for(file, linkage_type, resolve_variable_references: false, &block)
|
||||||
file.public_send(linkage_type, resolve_variable_references:)
|
file.public_send(linkage_type, resolve_variable_references:)
|
||||||
.grep_v(VARIABLE_REFERENCE_RX)
|
.grep_v(VARIABLE_REFERENCE_RX)
|
||||||
.each(&block)
|
.each(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(file: Pathname).returns(String) }
|
||||||
def dylib_id_for(file)
|
def dylib_id_for(file)
|
||||||
# Swift dylib IDs should be /usr/lib/swift
|
# Swift dylib IDs should be /usr/lib/swift
|
||||||
return file.dylib_id if file.dylib_id.start_with?("/usr/lib/swift/libswift")
|
return file.dylib_id if file.dylib_id.start_with?("/usr/lib/swift/libswift")
|
||||||
@ -167,14 +174,16 @@ module OS
|
|||||||
# `XXX.framework/XXX`, both with or without a slash-delimited prefix.
|
# `XXX.framework/XXX`, both with or without a slash-delimited prefix.
|
||||||
FRAMEWORK_RX = %r{(?:^|/)(([^/]+)\.framework/(?:Versions/[^/]+/)?\2)$}
|
FRAMEWORK_RX = %r{(?:^|/)(([^/]+)\.framework/(?:Versions/[^/]+/)?\2)$}
|
||||||
|
|
||||||
|
sig { params(bad_name: String).returns(String) }
|
||||||
def find_dylib_suffix_from(bad_name)
|
def find_dylib_suffix_from(bad_name)
|
||||||
if (framework = bad_name.match(FRAMEWORK_RX))
|
if (framework = bad_name.match(FRAMEWORK_RX))
|
||||||
framework[1]
|
T.must(framework[1])
|
||||||
else
|
else
|
||||||
File.basename(bad_name)
|
File.basename(bad_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(bad_name: String).returns(T.nilable(Pathname)) }
|
||||||
def find_dylib(bad_name)
|
def find_dylib(bad_name)
|
||||||
return unless lib.directory?
|
return unless lib.directory?
|
||||||
|
|
||||||
@ -182,6 +191,7 @@ module OS
|
|||||||
lib.find { |pn| break pn if pn.to_s.end_with?(suffix) }
|
lib.find { |pn| break pn if pn.to_s.end_with?(suffix) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[Pathname]) }
|
||||||
def mach_o_files
|
def mach_o_files
|
||||||
hardlinks = Set.new
|
hardlinks = Set.new
|
||||||
mach_o_files = []
|
mach_o_files = []
|
||||||
@ -198,6 +208,7 @@ module OS
|
|||||||
mach_o_files
|
mach_o_files
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(::Keg::Relocation) }
|
||||||
def prepare_relocation_to_locations
|
def prepare_relocation_to_locations
|
||||||
relocation = super
|
relocation = super
|
||||||
|
|
||||||
@ -225,12 +236,14 @@ module OS
|
|||||||
relocation
|
relocation
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
def recursive_fgrep_args
|
def recursive_fgrep_args
|
||||||
# Don't recurse into symlinks; the man page says this is the default, but
|
# Don't recurse into symlinks; the man page says this is the default, but
|
||||||
# it's wrong. -O is a BSD-grep-only option.
|
# it's wrong. -O is a BSD-grep-only option.
|
||||||
"-lrO"
|
"-lrO"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns([String, String]) }
|
||||||
def egrep_args
|
def egrep_args
|
||||||
grep_bin = "egrep"
|
grep_bin = "egrep"
|
||||||
grep_args = "--files-with-matches"
|
grep_args = "--files-with-matches"
|
||||||
@ -239,11 +252,12 @@ module OS
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
CELLAR_RX = %r{\A#{HOMEBREW_CELLAR}/(?<formula_name>[^/]+)/[^/]+}
|
CELLAR_RX = T.let(%r{\A#{HOMEBREW_CELLAR}/(?<formula_name>[^/]+)/[^/]+}, Regexp)
|
||||||
private_constant :CELLAR_RX
|
private_constant :CELLAR_RX
|
||||||
|
|
||||||
# Replace HOMEBREW_CELLAR references with HOMEBREW_PREFIX/opt references
|
# Replace HOMEBREW_CELLAR references with HOMEBREW_PREFIX/opt references
|
||||||
# if the Cellar reference is to a different keg.
|
# if the Cellar reference is to a different keg.
|
||||||
|
sig { params(filename: String).returns(String) }
|
||||||
def opt_name_for(filename)
|
def opt_name_for(filename)
|
||||||
return filename unless filename.start_with?(HOMEBREW_PREFIX.to_s)
|
return filename unless filename.start_with?(HOMEBREW_PREFIX.to_s)
|
||||||
return filename if filename.start_with?(path.to_s)
|
return filename if filename.start_with?(path.to_s)
|
||||||
@ -252,6 +266,7 @@ module OS
|
|||||||
filename.sub(CELLAR_RX, "#{HOMEBREW_PREFIX}/opt/#{matches[:formula_name]}")
|
filename.sub(CELLAR_RX, "#{HOMEBREW_PREFIX}/opt/#{matches[:formula_name]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(filename: String).returns(T::Boolean) }
|
||||||
def rooted_in_build_directory?(filename)
|
def rooted_in_build_directory?(filename)
|
||||||
# CMake normalises `/private/tmp` to `/tmp`.
|
# CMake normalises `/private/tmp` to `/tmp`.
|
||||||
# https://gitlab.kitware.com/cmake/cmake/-/issues/23251
|
# https://gitlab.kitware.com/cmake/cmake/-/issues/23251
|
||||||
|
@ -2024,7 +2024,7 @@ class Formula
|
|||||||
|
|
||||||
raise "No universal binaries found to deuniversalize" if targets.blank?
|
raise "No universal binaries found to deuniversalize" if targets.blank?
|
||||||
|
|
||||||
targets&.each do |target|
|
targets.compact.each do |target|
|
||||||
extract_macho_slice_from(Pathname(target), Hardware::CPU.arch)
|
extract_macho_slice_from(Pathname(target), Hardware::CPU.arch)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -234,7 +234,7 @@ module FormulaCellarChecks
|
|||||||
keg = Keg.new(prefix)
|
keg = Keg.new(prefix)
|
||||||
|
|
||||||
matches = []
|
matches = []
|
||||||
keg.each_unique_file_matching(HOMEBREW_SHIMS_PATH) do |f|
|
keg.each_unique_file_matching(HOMEBREW_SHIMS_PATH.to_s) do |f|
|
||||||
match = f.relative_path_from(keg.to_path)
|
match = f.relative_path_from(keg.to_path)
|
||||||
|
|
||||||
next if match.to_s.match? %r{^share/doc/.+?/INFO_BIN$}
|
next if match.to_s.match? %r{^share/doc/.+?/INFO_BIN$}
|
||||||
|
@ -1591,7 +1591,7 @@ on_request: installed_on_request?, options:)
|
|||||||
|
|
||||||
keg = Keg.new(formula.prefix)
|
keg = Keg.new(formula.prefix)
|
||||||
skip_linkage = formula.bottle_specification.skip_relocation?
|
skip_linkage = formula.bottle_specification.skip_relocation?
|
||||||
keg.replace_placeholders_with_locations(tab.changed_files, skip_linkage:)
|
keg.replace_placeholders_with_locations(tab.changed_files, skip_linkage:) if tab.changed_files
|
||||||
|
|
||||||
cellar = formula.bottle_specification.tag_to_cellar(Utils::Bottles.tag)
|
cellar = formula.bottle_specification.tag_to_cellar(Utils::Bottles.tag)
|
||||||
return if [:any, :any_skip_relocation].include?(cellar)
|
return if [:any, :any_skip_relocation].include?(cellar)
|
||||||
|
@ -1,23 +1,25 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Keg
|
class Keg
|
||||||
PREFIX_PLACEHOLDER = "@@HOMEBREW_PREFIX@@"
|
PREFIX_PLACEHOLDER = T.let("@@HOMEBREW_PREFIX@@", String)
|
||||||
CELLAR_PLACEHOLDER = "@@HOMEBREW_CELLAR@@"
|
CELLAR_PLACEHOLDER = T.let("@@HOMEBREW_CELLAR@@", String)
|
||||||
REPOSITORY_PLACEHOLDER = "@@HOMEBREW_REPOSITORY@@"
|
REPOSITORY_PLACEHOLDER = T.let("@@HOMEBREW_REPOSITORY@@", String)
|
||||||
LIBRARY_PLACEHOLDER = "@@HOMEBREW_LIBRARY@@"
|
LIBRARY_PLACEHOLDER = T.let("@@HOMEBREW_LIBRARY@@", String)
|
||||||
PERL_PLACEHOLDER = "@@HOMEBREW_PERL@@"
|
PERL_PLACEHOLDER = T.let("@@HOMEBREW_PERL@@", String)
|
||||||
JAVA_PLACEHOLDER = "@@HOMEBREW_JAVA@@"
|
JAVA_PLACEHOLDER = T.let("@@HOMEBREW_JAVA@@", String)
|
||||||
NULL_BYTE = "\x00"
|
NULL_BYTE = T.let("\x00", String)
|
||||||
NULL_BYTE_STRING = "\\x00"
|
NULL_BYTE_STRING = T.let("\\x00", String)
|
||||||
|
|
||||||
class Relocation
|
class Relocation
|
||||||
RELOCATABLE_PATH_REGEX_PREFIX = /(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))/
|
RELOCATABLE_PATH_REGEX_PREFIX = T.let(/(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))/, Regexp)
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def initialize
|
def initialize
|
||||||
@replacement_map = T.let({}, T::Hash[Symbol, [T.any(String, Regexp), String]])
|
@replacement_map = T.let({}, T::Hash[Symbol, [T.any(String, Regexp), String]])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Relocation) }
|
||||||
def freeze
|
def freeze
|
||||||
@replacement_map.freeze
|
@replacement_map.freeze
|
||||||
super
|
super
|
||||||
@ -62,6 +64,7 @@ class Keg
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def fix_dynamic_linkage
|
def fix_dynamic_linkage
|
||||||
symlink_files.each do |file|
|
symlink_files.each do |file|
|
||||||
link = file.readlink
|
link = file.readlink
|
||||||
@ -78,9 +81,8 @@ class Keg
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def relocate_dynamic_linkage(_relocation, skip_protodesc_cold: false)
|
sig { params(_relocation: Relocation, skip_protodesc_cold: T::Boolean).void }
|
||||||
[]
|
def relocate_dynamic_linkage(_relocation, skip_protodesc_cold: false); end
|
||||||
end
|
|
||||||
|
|
||||||
JAVA_REGEX = %r{#{HOMEBREW_PREFIX}/opt/openjdk(@\d+(\.\d+)*)?/libexec(/openjdk\.jdk/Contents/Home)?}
|
JAVA_REGEX = %r{#{HOMEBREW_PREFIX}/opt/openjdk(@\d+(\.\d+)*)?/libexec(/openjdk\.jdk/Contents/Home)?}
|
||||||
|
|
||||||
@ -102,6 +104,7 @@ class Keg
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Relocation) }
|
||||||
def prepare_relocation_to_placeholders
|
def prepare_relocation_to_placeholders
|
||||||
relocation = Relocation.new
|
relocation = Relocation.new
|
||||||
|
|
||||||
@ -130,12 +133,14 @@ class Keg
|
|||||||
relocation
|
relocation
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[Pathname]) }
|
||||||
def replace_locations_with_placeholders
|
def replace_locations_with_placeholders
|
||||||
relocation = prepare_relocation_to_placeholders.freeze
|
relocation = prepare_relocation_to_placeholders.freeze
|
||||||
relocate_dynamic_linkage(relocation, skip_protodesc_cold: true)
|
relocate_dynamic_linkage(relocation, skip_protodesc_cold: true)
|
||||||
replace_text_in_files(relocation)
|
replace_text_in_files(relocation)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Relocation) }
|
||||||
def prepare_relocation_to_locations
|
def prepare_relocation_to_locations
|
||||||
relocation = Relocation.new
|
relocation = Relocation.new
|
||||||
relocation.add_replacement_pair(:prefix, PREFIX_PLACEHOLDER, HOMEBREW_PREFIX.to_s)
|
relocation.add_replacement_pair(:prefix, PREFIX_PLACEHOLDER, HOMEBREW_PREFIX.to_s)
|
||||||
@ -150,12 +155,14 @@ class Keg
|
|||||||
relocation
|
relocation
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(files: T::Array[Pathname], skip_linkage: T::Boolean).void }
|
||||||
def replace_placeholders_with_locations(files, skip_linkage: false)
|
def replace_placeholders_with_locations(files, skip_linkage: false)
|
||||||
relocation = prepare_relocation_to_locations.freeze
|
relocation = prepare_relocation_to_locations.freeze
|
||||||
relocate_dynamic_linkage(relocation) unless skip_linkage
|
relocate_dynamic_linkage(relocation) unless skip_linkage
|
||||||
replace_text_in_files(relocation, files:)
|
replace_text_in_files(relocation, files:)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T.nilable(String)) }
|
||||||
def openjdk_dep_name_if_applicable
|
def openjdk_dep_name_if_applicable
|
||||||
deps = runtime_dependencies
|
deps = runtime_dependencies
|
||||||
return if deps.blank?
|
return if deps.blank?
|
||||||
@ -164,10 +171,11 @@ class Keg
|
|||||||
dep_names.find { |d| d.match? Version.formula_optionally_versioned_regex(:openjdk) }
|
dep_names.find { |d| d.match? Version.formula_optionally_versioned_regex(:openjdk) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(relocation: Relocation, files: T.nilable(T::Array[Pathname])).returns(T::Array[Pathname]) }
|
||||||
def replace_text_in_files(relocation, files: nil)
|
def replace_text_in_files(relocation, files: nil)
|
||||||
files ||= text_files | libtool_files
|
files ||= text_files | libtool_files
|
||||||
|
|
||||||
changed_files = T.let([], Array)
|
changed_files = T.let([], T::Array[Pathname])
|
||||||
files.map { path.join(_1) }.group_by { |f| f.stat.ino }.each_value do |first, *rest|
|
files.map { path.join(_1) }.group_by { |f| f.stat.ino }.each_value do |first, *rest|
|
||||||
s = first.open("rb", &:read)
|
s = first.open("rb", &:read)
|
||||||
|
|
||||||
@ -188,6 +196,7 @@ class Keg
|
|||||||
changed_files
|
changed_files
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(keg: Keg, old_prefix: T.any(String, Pathname), new_prefix: T.any(String, Pathname)).void }
|
||||||
def relocate_build_prefix(keg, old_prefix, new_prefix)
|
def relocate_build_prefix(keg, old_prefix, new_prefix)
|
||||||
each_unique_file_matching(old_prefix) do |file|
|
each_unique_file_matching(old_prefix) do |file|
|
||||||
# Skip files which are not binary, as they do not need null padding.
|
# Skip files which are not binary, as they do not need null padding.
|
||||||
@ -202,12 +211,12 @@ class Keg
|
|||||||
binary = File.binread file
|
binary = File.binread file
|
||||||
odebug "Replacing build prefix in: #{file}"
|
odebug "Replacing build prefix in: #{file}"
|
||||||
binary_strings = binary.split(/#{NULL_BYTE}/o, -1)
|
binary_strings = binary.split(/#{NULL_BYTE}/o, -1)
|
||||||
match_indices = binary_strings.each_index.select { |i| binary_strings.fetch(i).include?(old_prefix) }
|
match_indices = binary_strings.each_index.select { |i| binary_strings.fetch(i).include?(old_prefix.to_s) }
|
||||||
|
|
||||||
# Only perform substitution on strings which match prefix regex.
|
# Only perform substitution on strings which match prefix regex.
|
||||||
match_indices.each do |i|
|
match_indices.each do |i|
|
||||||
s = binary_strings.fetch(i)
|
s = binary_strings.fetch(i)
|
||||||
binary_strings[i] = s.gsub(old_prefix, new_prefix)
|
binary_strings[i] = s.gsub(old_prefix.to_s, new_prefix.to_s)
|
||||||
.ljust(s.size, NULL_BYTE)
|
.ljust(s.size, NULL_BYTE)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -227,15 +236,18 @@ class Keg
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(_options: T::Hash[Symbol, T::Boolean]).returns(T::Array[Symbol]) }
|
||||||
def detect_cxx_stdlibs(_options = {})
|
def detect_cxx_stdlibs(_options = {})
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
def recursive_fgrep_args
|
def recursive_fgrep_args
|
||||||
# for GNU grep; overridden for BSD grep on OS X
|
# for GNU grep; overridden for BSD grep on OS X
|
||||||
"-lr"
|
"-lr"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns([String, T::Array[String]]) }
|
||||||
def egrep_args
|
def egrep_args
|
||||||
grep_bin = "grep"
|
grep_bin = "grep"
|
||||||
grep_args = [
|
grep_args = [
|
||||||
@ -247,7 +259,8 @@ class Keg
|
|||||||
[grep_bin, grep_args]
|
[grep_bin, grep_args]
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_unique_file_matching(string)
|
sig { params(string: T.any(String, Pathname), _block: T.proc.params(arg0: Pathname).void).void }
|
||||||
|
def each_unique_file_matching(string, &_block)
|
||||||
Utils.popen_read("fgrep", recursive_fgrep_args, string, to_s) do |io|
|
Utils.popen_read("fgrep", recursive_fgrep_args, string, to_s) do |io|
|
||||||
hardlinks = Set.new
|
hardlinks = Set.new
|
||||||
|
|
||||||
@ -263,6 +276,7 @@ class Keg
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(file: Pathname).returns(T::Boolean) }
|
||||||
def binary_file?(file)
|
def binary_file?(file)
|
||||||
grep_bin, grep_args = egrep_args
|
grep_bin, grep_args = egrep_args
|
||||||
|
|
||||||
@ -272,14 +286,17 @@ class Keg
|
|||||||
Utils.popen_read(grep_bin, *grep_args, NULL_BYTE_STRING, file).present?
|
Utils.popen_read(grep_bin, *grep_args, NULL_BYTE_STRING, file).present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Pathname) }
|
||||||
def lib
|
def lib
|
||||||
path/"lib"
|
path/"lib"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Pathname) }
|
||||||
def libexec
|
def libexec
|
||||||
path/"libexec"
|
path/"libexec"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[Pathname]) }
|
||||||
def text_files
|
def text_files
|
||||||
text_files = []
|
text_files = []
|
||||||
return text_files if !which("file") || !which("xargs")
|
return text_files if !which("file") || !which("xargs")
|
||||||
@ -327,6 +344,7 @@ class Keg
|
|||||||
text_files
|
text_files
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[Pathname]) }
|
||||||
def libtool_files
|
def libtool_files
|
||||||
libtool_files = []
|
libtool_files = []
|
||||||
|
|
||||||
@ -338,6 +356,7 @@ class Keg
|
|||||||
libtool_files
|
libtool_files
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[Pathname]) }
|
||||||
def symlink_files
|
def symlink_files
|
||||||
symlink_files = []
|
symlink_files = []
|
||||||
path.find do |pn|
|
path.find do |pn|
|
||||||
@ -347,6 +366,10 @@ class Keg
|
|||||||
symlink_files
|
symlink_files
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig {
|
||||||
|
params(file: Pathname, string: String, ignores: T::Array[Regexp], linked_libraries: T::Array[Pathname],
|
||||||
|
formula_and_runtime_deps_names: T.nilable(T::Array[String])).returns(T::Array[[String, String]])
|
||||||
|
}
|
||||||
def self.text_matches_in_file(file, string, ignores, linked_libraries, formula_and_runtime_deps_names)
|
def self.text_matches_in_file(file, string, ignores, linked_libraries, formula_and_runtime_deps_names)
|
||||||
text_matches = []
|
text_matches = []
|
||||||
path_regex = Relocation.path_to_regex(string)
|
path_regex = Relocation.path_to_regex(string)
|
||||||
@ -386,6 +409,7 @@ class Keg
|
|||||||
text_matches
|
text_matches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(_file: Pathname, _string: String).returns(T::Array[Pathname]) }
|
||||||
def self.file_linked_libraries(_file, _string)
|
def self.file_linked_libraries(_file, _string)
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user