Ai
8 Star 9 Fork 3

Gitee 极速下载/IINA

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/lhc70000/iina
克隆/下载
change_lib_dependencies.rb 3.07 KB
一键复制 编辑 原始数据 按行查看 历史
Yuze Jiang 提交于 2024-06-08 14:13 +08:00 . Update change_lib_dependencies.rb
#!/usr/bin/env ruby
require "fileutils"
require "open3"
require "shellwords"
include FileUtils::Verbose
def safe_system(*args)
puts args.shelljoin
system(*args) || abort("Fail to run the last command!")
end
class DylibFile
OTOOL_RX = /\t(.*) \(compatibility version (?:\d+\.)*\d+, current version (?:\d+\.)*\d+\)/
attr_reader :path, :id, :deps
def initialize(path)
@path = path
parse_otool_L_output!
end
def parse_otool_L_output!
stdout, stderr, status = Open3.capture3("otool -L \"#{path}\"")
abort(stderr) unless status.success?
libs = stdout.split("\n")
libs.shift # first line is the filename
@id = libs.shift[OTOOL_RX, 1]
@deps = libs.map { |lib| lib[OTOOL_RX, 1] }.compact
end
def ensure_writeable
saved_perms = nil
unless File.writable_real?(path)
saved_perms = File.stat(path).mode
FileUtils.chmod 0644, path
end
yield
ensure
FileUtils.chmod saved_perms, path if saved_perms
end
def change_id!
ensure_writeable do
safe_system "install_name_tool", "-id", "@rpath/#{File.basename(self.id)}", path
end
end
def change_install_name!(old_name, new_name)
ensure_writeable do
safe_system "install_name_tool", "-change", old_name, new_name, path
end
end
end
if ARGV.length <= 1
abort <<~END
Usage: change_lib_dependencies.rb prefix libraries...
If you're using Homebrew, your invocation might look like this:
$ ./change_lib_dependencies.rb "$(brew --prefix)" "$(brew --prefix mpv-iina)/lib/libmpv.dylib"
If you're using MacPorts, your invocation might look like this:
$ port contents mpv | grep '\.dylib$' | xargs ./change_lib_dependencies.rb /opt/local
END
end
prefix = ARGV.shift
linked_files = ARGV
proj_path = File.expand_path(File.join(File.dirname(__FILE__), '../'))
lib_folder = File.join(proj_path, "deps/lib/")
libs = []
original_folder = []
rm_rf lib_folder
mkdir lib_folder
linked_files.each do |file|
# Grab the actual library on disk.
file = File.realpath(file)
# Keep the output filename the same as the library's install name
dylib = DylibFile.new file
dylib.parse_otool_L_output!
dest = File.join(lib_folder, File.basename(dylib.id))
puts "cp -p #{file} #{dest}"
copy_entry file, dest, preserve: true
libs << dest
original_folder << File.dirname(file)
end
fix_count = 0
while !libs.empty?
file = libs.pop
folder = original_folder.pop
puts "=== Fix dependencies for #{file} ==="
dylib = DylibFile.new file
dylib.change_id!
dylib.deps.each do |dep|
if dep.start_with?(prefix) || dep.start_with?("@rpath")
fix_count += 1
basename = File.basename(dep)
new_name = "@rpath/#{basename}"
dylib.change_install_name!(dep, new_name)
dest = File.join(lib_folder, basename)
src =
if dep.start_with?(prefix)
dep
else
File.join(folder, basename)
end
unless File.exists?(dest)
cp src, lib_folder, preserve: true
libs << dest
original_folder << File.dirname(src)
end
end
end
end
puts "Total #{fix_count}"
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Swift
1
https://gitee.com/mirrors/IINA.git
git@gitee.com:mirrors/IINA.git
mirrors
IINA
IINA
develop

搜索帮助