summaryrefslogtreecommitdiff
path: root/debian/patches/fixes/eumm-usrmerge.diff
blob: e228aaaed8764398dcf3858fce6a500f6b8b1ef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
From: =?utf-8?q?Dagfinn_Ilmari_Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Tue, 13 Nov 2018 16:00:48 +0000
Subject: Avoid mangling /bin non-perl shebangs on merged-/usr systems

If the shebang is absolute and exists in PATH, but was not the first
one found, leave it alone if it's actually the same file as first one.

This avoids packages built on merged-/usr systems with /usr/bin before
/bin in the path breaking when installed on systems without merged
/usr.  See e.g. https://bugs.debian.org/913637.

Origin: backport, https://github.com/Perl-Toolchain-Gang/ExtUtils-MakeMaker/commit/9766f9c5ffd1ac915d75b309cd18c9f42794b710
Bug: https://github.com/Perl-Toolchain-Gang/ExtUtils-MakeMaker/pull/330
Bug-Debian: https://bugs.debian.org/913637
---
 cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm    | 22 +++++++++++++--
 cpan/ExtUtils-MakeMaker/t/fixin.t                  | 33 +++++++++++++++++++++-
 .../t/lib/MakeMaker/Test/Setup/BFD.pm              |  3 ++
 3 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm b/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm
index bb41b27..2e33d0a 100644
--- a/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm
+++ b/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm
@@ -1243,8 +1243,8 @@ sub _fixin_replace_shebang {
     my ( $self, $file, $line ) = @_;
 
     # Now figure out the interpreter name.
-    my ( $cmd, $arg ) = split ' ', $line, 2;
-    $cmd =~ s!^.*/!!;
+    my ( $origcmd, $arg ) = split ' ', $line, 2;
+    (my $cmd = $origcmd) =~ s!^.*/!!;
 
     # Now look (in reverse) for interpreter in absolute PATH (unless perl).
     my $interpreter;
@@ -1270,6 +1270,24 @@ sub _fixin_replace_shebang {
                 $interpreter = $maybefile;
             }
         }
+
+        # If the shebang is absolute and exists in PATH, but was not
+        # the first one found, leave it alone if it's actually the
+        # same file as first one.  This avoids packages built on
+        # merged-/usr systems with /usr/bin before /bin in the path
+        # breaking when installed on systems without merged /usr
+        if ($origcmd ne $interpreter and $self->file_name_is_absolute($origcmd)) {
+            my $origdir = dirname($origcmd);
+            if ($self->maybe_command($origcmd) && grep { $_ eq $origdir } @absdirs) {
+                my ($odev, $oino) = stat $origcmd;
+                my ($idev, $iino) = stat $interpreter;
+                if ($odev == $idev && $oino == $iino) {
+                    warn "$origcmd is the same as $interpreter, leaving alone"
+                        if $Verbose;
+                    $interpreter = $origcmd;
+                }
+            }
+        }
     }
 
     # Figure out how to invoke interpreter on this machine.
diff --git a/cpan/ExtUtils-MakeMaker/t/fixin.t b/cpan/ExtUtils-MakeMaker/t/fixin.t
index 061e456..872b023 100644
--- a/cpan/ExtUtils-MakeMaker/t/fixin.t
+++ b/cpan/ExtUtils-MakeMaker/t/fixin.t
@@ -9,7 +9,7 @@ BEGIN {
 
 use File::Spec;
 
-use Test::More tests => 22;
+use Test::More tests => 30;
 
 use Config;
 use TieOut;
@@ -123,3 +123,34 @@ END
         }
     );
 }
+
+SKIP: {
+    eval { chmod(0755, "usrbin/interp") }
+        or skip "no chmod", 8;
+
+    my $dir = getcwd();
+    local $ENV{PATH} = join $Config{path_sep}, map "$dir/$_", qw(usrbin bin);
+
+    test_fixin(<<END,
+#!$dir/bin/interp
+
+blah blah blah
+END
+         sub {
+             is $_[0], "#!$dir/usrbin/interp\n", 'interpreter updated to one found in PATH';
+         }
+     );
+
+    eval { symlink("../usrbin/interp", "bin/interp") }
+        or skip "no symlinks", 4;
+
+    test_fixin(<<END,
+#!$dir/bin/interp
+
+blah blah blah
+END
+         sub {
+             is $_[0], "#!$dir/bin/interp\n", 'symlinked interpreter later in PATH not mangled';
+         }
+     );
+}
diff --git a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/BFD.pm b/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/BFD.pm
index 3d093fc..cfe49e5 100644
--- a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/BFD.pm
+++ b/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/BFD.pm
@@ -53,6 +53,9 @@ program - this is a program
 =cut
 
 1;
+END
+             'Big-Dummy/usrbin/interp'       => <<'END',
+This is a dummy interpreter
 END
 
              'Big-Dummy/test.pl'          => <<'END',