Merge pull request #11756 from carlocab/deuniversalize-machos
formula: add `deuniversalize_machos` method
This commit is contained in:
commit
0ae032ad2f
@ -4,7 +4,9 @@
|
||||
class Formula
|
||||
undef shared_library
|
||||
undef rpath
|
||||
undef deuniversalize_machos
|
||||
|
||||
sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) }
|
||||
def shared_library(name, version = nil)
|
||||
suffix = if version == "*" || (name == "*" && version.blank?)
|
||||
"{,.*}"
|
||||
@ -14,10 +16,14 @@ class Formula
|
||||
"#{name}.so#{suffix}"
|
||||
end
|
||||
|
||||
sig { returns(String) }
|
||||
def rpath
|
||||
"'$ORIGIN/../lib'"
|
||||
end
|
||||
|
||||
sig { params(targets: T.nilable(T.any(Pathname, String))).void }
|
||||
def deuniversalize_machos(*targets); end
|
||||
|
||||
class << self
|
||||
undef ignore_missing_libraries
|
||||
|
||||
|
||||
@ -1589,6 +1589,38 @@ class Formula
|
||||
end
|
||||
end
|
||||
|
||||
# Replaces a universal binary with its native slice.
|
||||
#
|
||||
# If called with no parameters, does this with all compatible
|
||||
# universal binaries in a {Formula}'s {Keg}.
|
||||
sig { params(targets: T.nilable(T.any(Pathname, String))).void }
|
||||
def deuniversalize_machos(*targets)
|
||||
targets = nil if targets.blank?
|
||||
targets ||= any_installed_keg.mach_o_files.select do |file|
|
||||
file.arch == :universal && file.archs.include?(Hardware::CPU.arch)
|
||||
end
|
||||
|
||||
targets.each { |t| extract_macho_slice_from(Pathname.new(t), Hardware::CPU.arch) }
|
||||
end
|
||||
|
||||
# @private
|
||||
sig { params(file: Pathname, arch: T.nilable(Symbol)).void }
|
||||
def extract_macho_slice_from(file, arch = Hardware::CPU.arch)
|
||||
odebug "Extracting #{arch} slice from #{file}"
|
||||
file.ensure_writable do
|
||||
macho = MachO::FatFile.new(file)
|
||||
native_slice = macho.extract(Hardware::CPU.arch)
|
||||
native_slice.write file
|
||||
MachO.codesign! file if Hardware::CPU.arm?
|
||||
rescue MachO::MachOBinaryError
|
||||
onoe "#{file} is not a universal binary"
|
||||
raise
|
||||
rescue NoMethodError
|
||||
onoe "#{file} does not contain an #{arch} slice"
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
# an array of all core {Formula} names
|
||||
# @private
|
||||
def self.core_names
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user