Skip to content

Commit 2d917b3

Browse files
committed
wip
1 parent 8c7af63 commit 2d917b3

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

brewkit/scripts/fix-macho.rb

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,46 +71,36 @@ def fix_install_names
7171
next if lib.start_with? '/usr/lib' or lib.start_with? '/System/' or lib.start_with? '/Library/'
7272

7373
og_lib_name = lib
74+
file = $LIBS.find{ |dep| lib_basename(dep['string']) == lib_basename(lib) }
7475

75-
if lib.start_with? $PKGX_DIR and not lib.start_with? $prefix
76-
# should never be hit really since the linker by default takes the install name
77-
# of the library it links to and for all routes that should already be set by us since it will be a dep
78-
# it is here though on the off chance.
79-
rel_path = Pathname.new(lib).relative_path_from($PKGX_DIR)
80-
rel_path = rel_path.sub(%r{/v(\d+)\.(\d+\.)+\d+[a-z]?/}, '/v\1/') # use the pkgx `v` prefixed symlink
81-
rel_path = rel_path.sub(%r{\.(\d+)\.(\d+\.)+\d+\.dylib$}, '.\1.dylib') # use the dylib symlink
82-
change_install_name og_lib_name, "@rpath/#{rel_path}"
83-
else
84-
file = $LIBS.find{ |dep| lib_basename(dep['string']) == lib_basename(lib) }
85-
if file
86-
lib = file['string']
87-
# we sporadically use --prefix=/usr/local in conjunction with DESTDIR to work
88-
# around specifying eg. /etc as the conf path which then fails builds since it cannot write there
89-
if lib.start_with? $prefix or lib.start_with? "/usr/local/lib"
90-
91-
if lib.start_with? "/usr/local/lib"
92-
lib = lib.sub(%r{^/usr/local}, $prefix)
93-
end
94-
95-
rel_path = Pathname.new(lib).relative_path_from(Pathname.new($file.filename).parent)
96-
if $file.filetype == :execute
97-
change_install_name og_lib_name, "@executable_path/#{rel_path}"
98-
else
99-
change_install_name og_lib_name, "@loader_path/#{rel_path}"
100-
end
101-
else
102-
rel_path = Pathname.new(file['string']).relative_path_from($PKGX_DIR)
103-
rel_path = rel_path.sub(%r{/v(\d+)\.(\d+\.)+\d+[a-z]?/}, '/v\1/') # use the pkgx `v` prefixed symlink
104-
rel_path = rel_path.sub(%r{\.(\d+)\.(\d+\.)+\d+\.dylib$}, '.\1.dylib') # use the dylib symlink
105-
change_install_name og_lib_name, "@rpath/#{rel_path}"
76+
if file
77+
lib = file['string']
78+
# we sporadically use --prefix=/usr/local in conjunction with DESTDIR to work
79+
# around specifying eg. /etc as the conf path which then fails builds since it cannot write there
80+
if lib.start_with? $prefix or lib.start_with? "/usr/local/lib"
81+
82+
if lib.start_with? "/usr/local/lib"
83+
lib = lib.sub(%r{^/usr/local}, $prefix)
10684
end
107-
elsif lib.start_with? '@rpath/'
108-
foo = lib.sub(%r{^@rpath}, $PKGX_DIR)
109-
foo = foo.sub(%r{/v.*$}, '')
110-
pkgs = ENV['PKGS'].split(":").map{ |pkg| pkg.sub(%r{/v.*$}, '').sub('/pkgs/', '/dst/') }
111-
if not pkgs.include? foo
112-
puts "::error file=#{$file.filename}::no fix available for: #{lib}"
85+
86+
rel_path = Pathname.new(lib).relative_path_from(Pathname.new($file.filename).parent)
87+
if $file.filetype == :execute
88+
change_install_name og_lib_name, "@executable_path/#{rel_path}"
89+
else
90+
change_install_name og_lib_name, "@loader_path/#{rel_path}"
11391
end
92+
else
93+
rel_path = Pathname.new(file['string']).relative_path_from($PKGX_DIR)
94+
rel_path = rel_path.sub(%r{/v(\d+)\.(\d+\.)+\d+[a-z]?/}, '/v\1/') # use the pkgx `v` prefixed symlink
95+
rel_path = rel_path.sub(%r{\.(\d+)\.(\d+\.)+\d+\.dylib$}, '.\1.dylib') # use the dylib symlink
96+
change_install_name og_lib_name, "@rpath/#{rel_path}"
97+
end
98+
elsif lib.start_with? '@rpath/'
99+
foo = lib.sub(%r{^@rpath/}, '')
100+
foo = foo.sub(%r{/v.*$}, '')
101+
pkgs = ENV['PKGS'].split(":").map{ |pkg| pkg.sub(%r{/v.*$}, '').sub(%r{^.*/pkgs/}, '') }
102+
if not pkgs.include? foo
103+
puts "::error file=#{$file.filename}::no fix available for: #{lib}"
114104
end
115105
end
116106
end

0 commit comments

Comments
 (0)