formula: add deuniversalize_machos method

This method takes an optional array of `Pathnames`s or `Strings`s and
extracts the native slice from the specified universal binary. If no
parameter is supplied, this is done on all compatible universal binaries
in a formula's keg.

`deuniversalize_machos` is a no-op on Linux.

I still need to look into a) error handling, and b) whether using this
method requires codesigning on ARM.

I've also added signatures to the methods in `extend/os/linux/formula`.
This commit is contained in:
Carlo Cabrera 2021-07-22 00:43:46 +08:00
parent b18bbacced
commit 5e0b786da2
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
2 changed files with 21 additions and 0 deletions

View File

@ -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

View File

@ -1582,6 +1582,21 @@ class Formula
end
end
sig { params(targets: T.nilable(T.any(Pathname, String))).void }
def deuniversalize_machos(*targets)
if targets.blank?
targets = any_installed_keg.mach_o_files.select do |file|
file.arch == :universal && file.archs.include?(Hardware::CPU.arch)
end
end
targets.each do |t|
macho = MachO::FatFile.new(t)
native_slice = macho.extract(Hardware::CPU.arch)
native_slice.write t
end
end
# an array of all core {Formula} names
# @private
def self.core_names