Skip to content

Commit 7966189

Browse files
committed
Also fixup dependencies names & ids
1 parent ce59040 commit 7966189

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

script/repackage-dylibs.rb

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,25 @@ def note(msg)
4444
TARGET_EXECUTABLE_PATH = File.join(TARGET_BUILD_DIR, EXECUTABLE_PATH)
4545
TARGET_FRAMEWORKS_PATH = File.join(TARGET_BUILD_DIR, FRAMEWORKS_FOLDER_PATH)
4646

47-
def extract_link_dependencies
48-
deps = `otool -L #{TARGET_EXECUTABLE_PATH}`
47+
def extract_link_dependencies(executable)
48+
deps = `otool -L #{executable}`
4949

5050
lines = deps.split("\n").map(&:strip)
5151
lines.shift
52-
lines.shift
52+
# lines.shift
5353
lines.map do |dep|
5454
path, compat, current = /^(.*) \(compatibility version (.*), current version (.*)\)$/.match(dep)[1..3]
5555
err "Failed to parse #{dep}" if path.nil?
5656

5757
dep = OpenStruct.new
58+
dep.is_self = (File.basename(path) == File.basename(executable))
59+
dep.executable = executable
5860
dep.install_name = path
5961
dep.current_version = current
6062
dep.compat_version = compat
6163
dep.type = File.extname(path)
6264
dep.name = File.basename(path)
63-
dep.is_packaged = (dep.install_name =~ /^@rpath/)
65+
dep.is_packaged = !!(dep.install_name =~ /^@rpath/)
6466
dep.path = if dep.install_name =~ /^@rpath/
6567
File.join(TARGET_FRAMEWORKS_PATH, dep.name)
6668
else
@@ -72,7 +74,7 @@ def extract_link_dependencies
7274
end
7375

7476
def repackage_dependency(dep)
75-
return if dep.is_packaged or dep.path =~ /^(\/usr\/lib|\/System\/Library)/
77+
return if dep.is_self or dep.is_packaged or dep.path =~ /^(\/usr\/lib|\/System\/Library)/
7678

7779
note "Packaging #{dep.name}…"
7880

@@ -88,22 +90,32 @@ def repackage_dependency(dep)
8890
note "Copying #{dep[:path]} to TARGET_FRAMEWORKS_PATH"
8991
FileUtils.cp dep[:path], TARGET_FRAMEWORKS_PATH
9092

91-
out = `install_name_tool -change #{dep.path} "@rpath/#{dep.name}" #{TARGET_EXECUTABLE_PATH}`
93+
out = `install_name_tool -change #{dep.path} "@rpath/#{dep.name}" #{dep.executable}`
9294
if $? != 0
9395
err "install_name_tool failed with error #{$?}:\n#{out}"
9496
end
9597

9698
dep.path = File.join(TARGET_FRAMEWORKS_PATH, dep.name)
9799
dep.install_name = "@rpath/#{dep.name}"
98100
dep.is_packaged = true
99-
100101
else
101102
warn "Unhandled type #{dep.type} for #{dep.path}, ignoring"
102103
end
103104
end
104105

105-
extract_link_dependencies.each do |dep|
106+
def fix_install_id(dep)
107+
note "Fixing #{dep.name} install_name id…"
108+
out = `install_name_tool -id @rpath/#{dep.name} #{dep.executable}`
109+
if $? != 0
110+
err "install_name_tool failed with error #{$?}:\n#{out}"
111+
end
112+
end
113+
114+
deps = extract_link_dependencies(TARGET_EXECUTABLE_PATH)
115+
while (dep = deps.shift) do
106116
repackage_dependency dep
117+
fix_install_id dep if dep.is_self and dep.executable != TARGET_EXECUTABLE_PATH
118+
deps += extract_link_dependencies(dep[:path]) if dep.is_packaged and not dep.is_self
107119
end
108120

109121
note "Packaging done"

0 commit comments

Comments
 (0)