StrawberryPerl / build-extlibs

16 stars 11 forks source link

patch.exe regression: can not handle general patches #51

Open zmughal opened 1 year ago

zmughal commented 1 year ago

When trying to apply a patch, patch gives the error:

patch: **** Can't rename file src/secure_allocator.hpp to src/secure_allocator.hpp.orig : No such file or directory

It appears to apply when there is a directory prefix, so for the above, a workaround is to do -d src -p2 to remove the a/src/ part.


Test case:

Commands:

mkdir C:\b & cd C:\b
curl -OL https://github.com/zeromq/libzmq/releases/download/v4.3.4/zeromq-4.3.4.tar.gz & curl -OL https://github.com/zeromq/libzmq/pull/4480.patch
tar xzf zeromq-4.3.4.tar.gz & cd zeromq-4.3.4
certUtil -hashfile src\secure_allocator.hpp MD5
patch --binary -p1 -i C:\b\4480.patch
certUtil -hashfile src\secure_allocator.hpp MD5
patch --binary -d src -p2 -i C:\b\4480.patch
certUtil -hashfile src\secure_allocator.hpp MD5
patch --version
where patch.exe

The following is a transcript with StrawberryPerl 5.38.1's patch.exe:

vagrant@VAGRANTVM C:\b>curl -OL https://github.com/zeromq/libzmq/releases/download/v4.3.4/zeromq-4.3.4.tar.gz & curl -OL https://github.com/zeromq/libzmq/pull/4480.patch
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 2428k  100 2428k    0     0  4735k      0 --:--:-- --:--:-- --:--:-- 4735k
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3537    0  3537    0     0   5513      0 --:--:-- --:--:-- --:--:-- 15051

vagrant@VAGRANTVM C:\b>tar xzf zeromq-4.3.4.tar.gz & cd zeromq-4.3.4

vagrant@VAGRANTVM C:\b\zeromq-4.3.4>certUtil -hashfile src\secure_allocator.hpp MD5
MD5 hash of src\secure_allocator.hpp:
47cd75dd30c5d9a7d4bb6a42df377664
CertUtil: -hashfile command completed successfully.

vagrant@VAGRANTVM C:\b\zeromq-4.3.4>patch --binary -p1 -i C:\b\4480.patch
patching file src/secure_allocator.hpp
Hunk StrawberryPerl/Perl-Dist-Strawberry#1 succeeded at 95 (offset -4 lines).
patch: **** Can't rename file src/secure_allocator.hpp to src/secure_allocator.hpp.orig : No such file or directory

vagrant@VAGRANTVM C:\b\zeromq-4.3.4>certUtil -hashfile src\secure_allocator.hpp MD5
MD5 hash of src\secure_allocator.hpp:
47cd75dd30c5d9a7d4bb6a42df377664
CertUtil: -hashfile command completed successfully.

vagrant@VAGRANTVM C:\b\zeromq-4.3.4>patch --binary -d src -p2 -i C:\b\4480.patch
patching file secure_allocator.hpp
Hunk StrawberryPerl/Perl-Dist-Strawberry#1 succeeded at 95 (offset -4 lines).

vagrant@VAGRANTVM C:\b\zeromq-4.3.4>certUtil -hashfile src\secure_allocator.hpp MD5
MD5 hash of src\secure_allocator.hpp:
a616d5049eddb65001856dbbc8f5105c
CertUtil: -hashfile command completed successfully.

vagrant@VAGRANTVM C:\b\zeromq-4.3.4>patch --version
GNU patch 2.7.5
Copyright (C) 2003, 2009-2012 Free Software Foundation, Inc.
Copyright (C) 1988 Larry Wall

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Larry Wall and Paul Eggert

vagrant@VAGRANTVM C:\b\zeromq-4.3.4>where patch.exe
C:\Strawberry\c\bin\patch.exe

The following is a transcript with StrawberryPerl 5.32.1.1's patch.exe:

vagrant@VAGRANTVM C:\b>curl -OL https://github.com/zeromq/libzmq/releases/download/v4.3.4/zeromq-4.3.4.tar.gz & curl -OL https://github.com/zeromq/libzmq/pull/4480.patch
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 2428k  100 2428k    0     0  4431k      0 --:--:-- --:--:-- --:--:-- 7833k
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3537    0  3537    0     0   6267      0 --:--:-- --:--:-- --:--:--  6267

vagrant@VAGRANTVM C:\b>tar xzf zeromq-4.3.4.tar.gz & cd zeromq-4.3.4

vagrant@VAGRANTVM C:\b\zeromq-4.3.4>certUtil -hashfile src\secure_allocator.hpp MD5
MD5 hash of src\secure_allocator.hpp:
47cd75dd30c5d9a7d4bb6a42df377664
CertUtil: -hashfile command completed successfully.

vagrant@VAGRANTVM C:\b\zeromq-4.3.4>patch --binary -p1 -i C:\b\4480.patch
patching file src/secure_allocator.hpp
Hunk StrawberryPerl/Perl-Dist-Strawberry#1 succeeded at 95 (offset -4 lines).

vagrant@VAGRANTVM C:\b\zeromq-4.3.4>certUtil -hashfile src\secure_allocator.hpp MD5
MD5 hash of src\secure_allocator.hpp:
a616d5049eddb65001856dbbc8f5105c
CertUtil: -hashfile command completed successfully.

vagrant@VAGRANTVM C:\b\zeromq-4.3.4>patch --binary -d src -p2 -i C:\b\4480.patch
patching file secure_allocator.hpp
Reversed (or previously applied) patch detected!  Assume -R? [n] n
Apply anyway? [n] n
Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file secure_allocator.hpp.rej

vagrant@VAGRANTVM C:\b\zeromq-4.3.4>certUtil -hashfile src\secure_allocator.hpp MD5
MD5 hash of src\secure_allocator.hpp:
a616d5049eddb65001856dbbc8f5105c
CertUtil: -hashfile command completed successfully.

vagrant@VAGRANTVM C:\b\zeromq-4.3.4>patch --version
patch 2.5.9
Copyright (C) 1988 Larry Wall
Copyright (C) 2003 Free Software Foundation, Inc.

This program comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of this program
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

written by Larry Wall and Paul Eggert

vagrant@VAGRANTVM C:\b\zeromq-4.3.4>where patch.exe
C:\Strawberry\c\bin\patch.exe

Connects with https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/74.

shawnlaffan commented 1 year ago

The patch utility distributed with 5.38.0.1 (and 5.36.1.1) is built without any additional patching. The one distributed with 5.32.1.1 and earlier had some patches applied as part of its build.

Possibly we should apply one or more of the previous SP and MSYS2 patches.

https://github.com/StrawberryPerl/build-extlibs/blob/master/patches/patch-2.7.5/patch-2.7.5.diff https://github.com/msys2/MSYS2-packages/blob/master/patch/msys2-patch-2.7.1.patch https://github.com/msys2/MSYS2-packages/blob/master/patch/msys2-patch-manifest.patch

shawnlaffan commented 1 year ago

Issue transferred to the build-extlibs repo given that's where the code is.

shawnlaffan commented 9 months ago

I have built patch with the MSYS and Strawberry Perl patches listed in https://github.com/StrawberryPerl/build-extlibs/issues/51#issuecomment-1646350068

It still does not work. In some cases it silently fails to make changes.

Unless someone knows of additional patches for the build, the simplest approach would seem to be to use a patch.exe from elsewhere.

The MSYS2 patch works but depends on msys-2.0.dll. The chocolatey patch.exe is version 2.5.9, which is the same as the numeric version that comes with SP 5.32 so presumably won't handle recent diff formats (https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/74). That needs to be tested, though.