@@ -44,23 +44,25 @@ def note(msg)
44
44
TARGET_EXECUTABLE_PATH = File . join ( TARGET_BUILD_DIR , EXECUTABLE_PATH )
45
45
TARGET_FRAMEWORKS_PATH = File . join ( TARGET_BUILD_DIR , FRAMEWORKS_FOLDER_PATH )
46
46
47
- def extract_link_dependencies
48
- deps = `otool -L #{ TARGET_EXECUTABLE_PATH } `
47
+ def extract_link_dependencies ( executable )
48
+ deps = `otool -L #{ executable } `
49
49
50
50
lines = deps . split ( "\n " ) . map ( &:strip )
51
51
lines . shift
52
- lines . shift
52
+ # lines.shift
53
53
lines . map do |dep |
54
54
path , compat , current = /^(.*) \( compatibility version (.*), current version (.*)\) $/ . match ( dep ) [ 1 ..3 ]
55
55
err "Failed to parse #{ dep } " if path . nil?
56
56
57
57
dep = OpenStruct . new
58
+ dep . is_self = ( File . basename ( path ) == File . basename ( executable ) )
59
+ dep . executable = executable
58
60
dep . install_name = path
59
61
dep . current_version = current
60
62
dep . compat_version = compat
61
63
dep . type = File . extname ( path )
62
64
dep . name = File . basename ( path )
63
- dep . is_packaged = ( dep . install_name =~ /^@rpath/ )
65
+ dep . is_packaged = !! ( dep . install_name =~ /^@rpath/ )
64
66
dep . path = if dep . install_name =~ /^@rpath/
65
67
File . join ( TARGET_FRAMEWORKS_PATH , dep . name )
66
68
else
@@ -72,7 +74,7 @@ def extract_link_dependencies
72
74
end
73
75
74
76
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)/
76
78
77
79
note "Packaging #{ dep . name } …"
78
80
@@ -88,22 +90,32 @@ def repackage_dependency(dep)
88
90
note "Copying #{ dep [ :path ] } to TARGET_FRAMEWORKS_PATH"
89
91
FileUtils . cp dep [ :path ] , TARGET_FRAMEWORKS_PATH
90
92
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 } `
92
94
if $? != 0
93
95
err "install_name_tool failed with error #{ $?} :\n #{ out } "
94
96
end
95
97
96
98
dep . path = File . join ( TARGET_FRAMEWORKS_PATH , dep . name )
97
99
dep . install_name = "@rpath/#{ dep . name } "
98
100
dep . is_packaged = true
99
-
100
101
else
101
102
warn "Unhandled type #{ dep . type } for #{ dep . path } , ignoring"
102
103
end
103
104
end
104
105
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
106
116
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
107
119
end
108
120
109
121
note "Packaging done"
0 commit comments