Skip to content

Commit ee29c6b

Browse files
authored
Merge pull request #162 from rancher-sandbox/monterey
Resolve /usr/local/bin symlinks in hacks/lima-and-qemu
2 parents 6e54f07 + 908005d commit ee29c6b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

hack/lima-and-qemu.pl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,16 @@
7777
for my $file (keys %deps) {
7878
my $copy = $file =~ s|^$install_dir|/tmp/$dist|r;
7979
system("mkdir -p " . dirname($copy));
80-
system("cp -R $file $copy");
81-
next if -l $file;
80+
if ($file =~ m|^$install_dir/bin/|) {
81+
# symlinks in the bin directory are replaced by the target file because in
82+
# macOS Monterey @executable_path refers to the symlink target and not the
83+
# symlink location itself, breaking the dylib lookup.
84+
system("cp $file $copy");
85+
}
86+
else {
87+
system("cp -R $file $copy");
88+
next if -l $file;
89+
}
8290
next unless qx(file $copy) =~ /Mach-O/;
8391

8492
open(my $fh, "otool -L $file |") or die "Failed to run 'otool -L $file': $!";
@@ -125,7 +133,11 @@ sub record {
125133
my $segment = shift @segments;
126134
my $name = "$filename/$segment";
127135
my $link = readlink $name;
128-
if (defined $link) {
136+
# symlinks in the bin directory are replaced by the target, and the symlinks are not
137+
# recorded (see above). However, at least "share/qemu" needs to remain a symlink to
138+
# "../Cellar/qemu/6.0.0/share/qemu" so qemu will still find its data files. Therefore
139+
# symlinks are still recorded for all other files.
140+
if (defined $link && $name !~ m|^$install_dir/bin/|) {
129141
# Record the symlink itself with the link target as the comment
130142
$deps{$name} = "$link";
131143
if ($link =~ m|^/|) {

0 commit comments

Comments
 (0)