Skip to contentSkip to conversation

support/scripts/apply-patches.sh: do not blindly remove *.orig files

PATCH Superseded Peter Korsgaard 2 participants 4 messages Oct 6, 2020 – Oct 10, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 support/scripts/apply-patches.sh: do not blindly remove *.orig files

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.

---
 support/dependencies/dependencies.sh | 6 ++++++
 support/scripts/apply-patches.sh     | 5 +----
 2 files changed, 7 insertions(+), 4 deletions(-)
support/dependencies/dependencies.sh +6 -0
index c1bd614edf..b44d28682c 100755
@@ -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
support/scripts/apply-patches.sh +1 -4
index 66fef262ee..2d39d63da1 100755
@@ -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 {} \;
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/1 support/scripts/apply-patches.sh: do not blindly remove *.orig files

Peter, All,

On 2020-10-06 22:46 +0200, Peter Korsgaard spake thusly:

Quoted 8 lines

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.

Quoted 6 lines

--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.

Applied to master, thanks.

However, does that make sense to also use --no-backup-if-mismatch in our LIBTOOL_PATCH_HOOK ?

Regards,
Yann E. MORIN.

Quoted 49 lines
---
 support/dependencies/dependencies.sh | 6 ++++++
 support/scripts/apply-patches.sh     | 5 +----
 2 files changed, 7 insertions(+), 4 deletions(-)
support/dependencies/dependencies.sh +6 -0
index c1bd614edf..b44d28682c 100755
@@ -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
support/scripts/apply-patches.sh +1 -4
index 66fef262ee..2d39d63da1 100755
@@ -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 {} \;
Signature · 6 lines
2.20.1

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#2 lore raw

PATCH v2 1/1 support/scripts/apply-patches.sh: do not blindly remove *.orig files

Quoted 17 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Peter, All,
On 2020-10-06 22:46 +0200, Peter Korsgaard spake thusly:

Quoted 13 lines

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.

Quoted 6 lines
Quoted 1 line

Applied to master, thanks.

However, does that make sense to also use --no-backup-if-mismatch in our LIBTOOL_PATCH_HOOK ?

We don't do any cleanup after that, but yes - I indeed think it makes sense to ensure patch don't write out ltmain.sh.orig files.

I'll send a patch.

Signature · 1 line
Bye, Peter Korsgaard
#3 lore raw

PATCH v2 1/1 support/scripts/apply-patches.sh: do not blindly remove *.orig files

In reply to Peter Korsgaard
Quoted 10 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Peter" == Peter Korsgaard <[email protected]> writes:

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.

Quoted 6 lines

--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.

Committed to 2020.02.x, 2020.05.x and 2020.08.x, thanks.

Signature · 1 line
Bye, Peter Korsgaard