support/scripts/apply-patches.sh: do not blindly remove *.orig files
authorPeter Korsgaard <peter@korsgaard.com>
Tue, 6 Oct 2020 20:46:20 +0000 (22:46 +0200)
committerYann E. MORIN <yann.morin.1998@free.fr>
Tue, 6 Oct 2020 21:40:25 +0000 (23:40 +0200)
apply-patches currently blindly removes *.orig / .*.orig files as GNU patch
by default writes these as backup files when patches only apply with fuzz.

This is unfortunate as package sources may contain files ending in .orig as
well, breaking the build.  Luckily GNU patch can be told to not write these
backup files using the --no-backup-if-mismatch option, so used that instead
of the .orig removal step.

--no-backup-if-mismatch is supported since GNU patch 2.3.8 (1997-06-17) and
busybox patch if built with CONFIG_DESKTOP, but E.G.  isn't supported by the
BSD patch, so add logic to dependencies.sh to error out if patch doesn't
support the flag.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
support/dependencies/dependencies.sh
support/scripts/apply-patches.sh

index c1bd614edf5413c410902d320f2d68bafeaa070e..b44d28682ca27e064f56bfb4db123165e1e44323 100755 (executable)
@@ -180,6 +180,12 @@ if test "${missing_progs}" = "yes" ; then
        exit 1
 fi
 
+# apply-patches.sh needs patch with --no-backup-if-mismatch support (GNU, busybox w/DESKTOP)
+if ! patch --no-backup-if-mismatch </dev/null 2>/dev/null; then
+       echo "Your patch program does not support the --no-backup-if-mismatch option. Install GNU patch"
+       exit 1
+fi
+
 if grep ^BR2_NEEDS_HOST_UTF8_LOCALE=y $BR2_CONFIG > /dev/null; then
        if ! which locale > /dev/null ; then
                echo
index 66fef262ee5845a2cd99ddd0f17783404cb49781..2d39d63da16c8b79af88e88da81b5b5b277dfa8c 100755 (executable)
@@ -119,7 +119,7 @@ function apply_patch {
         exit 1
     fi
     echo "${path}/${patch}" >> ${builddir}/.applied_patches_list
-    ${uncomp} "${path}/$patch" | patch -g0 -p1 -E -d "${builddir}" -t -N $silent
+    ${uncomp} "${path}/$patch" | patch -g0 -p1 -E --no-backup-if-mismatch -d "${builddir}" -t -N $silent
     if [ $? != 0 ] ; then
         echo "Patch failed!  Please fix ${patch}!"
         exit 1
@@ -168,6 +168,3 @@ if [ "`find $builddir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
     echo "Aborting.  Reject files found."
     exit 1
 fi
-
-# Remove backup files
-find $builddir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;