Skip to contentSkip to conversation

Patching method

Buildroot Superseded Ludovic Desroches 6 participants 22 messages Apr 7, 2011 – Jan 31, 2012 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hello,

I was building a new file system and I have noticed something about patching that seems a little dangerous :

Quoted 1 line
Quoted 1 line
Quoted 1 line

liblockfile 1.08 Patching package/liblockfile

toolchain/patch-kernel.sh /home/ldesroches/buildroot/output/build/liblockfile-1.08 /home/ldesroches/buildroot/dl liblockfile_1.08-4.debian.tar.bz2

...

+ echo 'Applying liblockfile_1.08-4.debian.tar.bz2 using bzip2: ' Applying liblockfile_1.08-4.debian.tar.bz2 using bzip2:
+ echo liblockfile_1.08-4.debian.tar.bz2
+ cat
+ bunzip2 -dc /home/ldesroches/buildroot/dl/liblockfile_1.08-4.debian.tar.bz2
+ patch -p1 -E -d /home/ldesroches/buildroot/output/build/liblockfile-1.08 patching file dotlockfile.c
patching file lockfile.c
missing header for unified diff at line 320 of patch
patching file COPYRIGHT
patching file dotlockfile.1
patching file Makefile.in
patch unexpectedly ends in middle of line

...

As you can see, we have an archive and we don't extract it, we simply unzip the compressed file and send the tar file to the patch command. The content of this archive is a tree with files and directories (one of them is the patch directory) that's why I think this method is a little dangerous. The patches are not applied in the same order as defined into the series file because the patch order is not kept into the archive.

Am I wrong ? Do you think it can be a problem ?

Regards

Ludovic Desroches

#1 lore raw

PATCH 1/1 kernel-patch.sh: script changed to support archives in a proper way

The previous script doesn't support patching order with archives since it didn't extract archives but simply decompressed file and piped the result to the patch command.
This new script extracts archives in a temporary folder and then applies patches.

---
 toolchain/patch-kernel.sh |  159 +++++++++++++++++++++++++++++---------------
 1 files changed, 105 insertions(+), 54 deletions(-)
toolchain/patch-kernel.sh +105 -54
index 76cb9f7..0492e01 100755
@@ -1,66 +1,117 @@
-#! /bin/bash
-# A little script I whipped up to make it easy to
-# patch source trees and have sane error handling
-# -Erik
-#
-# (c) 2002 Erik Andersen <[email protected]>
+#!/bin/bash
 
-# Set directories from arguments, or use defaults.
-targetdir=${1-.}
-patchdir=${2-../kernel-patches}
-shift 2
-patchpattern=${@-*}
+# function apply_patch patch_file
+# this function no more deal with directory case since it is managed
+# in an upper layer
+function apply_patch {
+apply="patch -p1 -E -d"
+#if [ ! -e "${1}" ] ; then
+#	echo "${1} is not a file"
+#	exit 1
+#fi
 
-if [ ! -d "${targetdir}" ] ; then
-    echo "Aborting.  '${targetdir}' is not a directory."
-    exit 1
+case "${1}" in
+*\.tar\.gz$|*\.tgz$|*\.tar\.bz$|*\.tar\.bz2$|*\.tbz$|*\.tbz2$)
+	echo "Error with ${1}";
+	echo "Archives into a directory or another archive is not supported";
+	return 1;
+	;;
+*\.gz$)
+	type="gzip"; uncomp="gunzip -dc"; ;;
+*\.bz$)
+	type="bzip"; uncomp="bunzip -dc"; ;;
+*\.bz2$)
+	type="bzip2"; uncomp="bunzip2 -dc"; ;;
+*\.zip$)
+	type="zip"; uncomp="unzip -d"; ;;
+*\.Z$)
+	type="compress"; uncomp="uncompress -c"; ;;
+*\.diff*)
+	type="diff"; uncomp="cat"; ;;
+*\.patch*)
+	type="patch"; uncomp="cat"; ;;
+*)
+	echo "Unsupported format file for ${1}, skip it";
+	return 0;
+	;;
+esac
+
+echo ""
+echo "Applying ${1} using ${type}: "
+echo ${1} | cat >> ${builddir}/.applied_patches_list
+${uncomp} ${1} | ${apply} ${builddir}
+if [ $? != 0 ] ; then
+	echo "Patch failed! Please fix ${1}!"
+	return 1
 fi
+}
+
+
+# entry point
+builddir=${1}
+patchdir=${2}
+shift 2
+patchlist=${@}
+patchesdir="${builddir}/../$(basename $builddir)-patches"
+
+# check directories
 if [ ! -d "${patchdir}" ] ; then
-    echo "Aborting.  '${patchdir}' is not a directory."
-    exit 1
+	echo "Aborting: ${patchdir} is not a directory."
+	exit 1
 fi
-    
-for i in `cd ${patchdir}; ls -d ${patchpattern} 2> /dev/null` ; do 
-    apply="patch -p1 -E -d"
-    uncomp_parm=""
-    if [ -d "${patchdir}/$i" ] ; then
-	type="directory overlay"
-	uncomp="tar cf - --exclude=.svn --no-anchored -C"
-	uncomp_parm="."
-	apply="tar xvf - -C"
-    else case "$i" in
-	*.gz)
-	type="gzip"; uncomp="gunzip -dc"; ;; 
-	*.bz)
-	type="bzip"; uncomp="bunzip -dc"; ;; 
-	*.bz2)
-	type="bzip2"; uncomp="bunzip2 -dc"; ;; 
-	*.zip)
-	type="zip"; uncomp="unzip -d"; ;; 
-	*.Z)
-	type="compress"; uncomp="uncompress -c"; ;; 
-	*.tgz)
-	type="tar gzip"; uncomp="gunzip -dc"; apply="tar xvf - -C"; ;; 
-	*.tar)
-	type="tar"; uncomp="cat"; apply="tar xvf - -C"; ;; 
-	*)
-	type="plaintext"; uncomp="cat"; ;; 
-    esac fi
-    echo ""
-    echo "Applying ${i} using ${type}: " 
-	echo ${i} | cat >> ${targetdir}/.applied_patches_list
-    ${uncomp} ${patchdir}/${i} ${uncomp_parm} | ${apply} ${targetdir} 
-    if [ $? != 0 ] ; then
-        echo "Patch failed!  Please fix $i!"
+if [ ! -d "${builddir}" ] ; then
+	echo "Aborting: ${builddir} is not a directory."
 	exit 1
-    fi
+fi
+
+# parse patch list, extract archives, apply patches
+for i in $patchlist ; do
+	# for remote files, directory is buildroot dl dir
+	#if echo $i | grep -q -E "^http://|^ftp://" ; then
+	#	patchdir=$patchdir
+	#else
+	#	patchdir=$(dirname $i)
+	#fi
+	patch_path="${patchdir}/${i}"
+	# three cases: directory, archive, file patch (compressed or not)
+	# directory
+	if [ -d "${patch_path}" ] ; then
+		for p in $(ls ${patch_path}) ; do
+			apply_patch "${patch_path}/${p}" || exit 1
+		done
+	# archive
+	elif echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$|tar\.gz$|tgz$" ; then
+		mkdir "${patchesdir}"
+		# extract archive
+		if echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$" ; then
+			tar_options="-xjf"
+		else
+			tar_options="-xzf"
+		fi
+		tar -C ${patchesdir} --strip-components=1 ${tar_options} ${patch_path}
+		# apply patches from the archive
+		#echo ${patchesdir}
+		#find ${patchesdir} | sort
+		for p in $(find ${patchesdir} | sort) ; do
+			apply_patch "${p}" || { rm -rf "${patchesdir}" ; exit 1; }
+		done
+		rm -rf "${patchesdir}"
+	# file which is not an archive
+	else
+		# we can have regex into patch name as package*.patch.arm that's
+		# why using ls
+		for p in $(ls -d ${patch_path} 2> /dev/null) ; do
+			apply_patch "${p}" || exit 1
+		done
+	fi
 done
 
-# Check for rejects...
-if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+# check for rejects...
+if [ "`find ${builddir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
     echo "Aborting.  Reject files found."
     exit 1
 fi
 
-# Remove backup files
-find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+# remove backup files
+find ${builddir}/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+
Signature · 1 line
1.7.5

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

PATCH 1/1 kernel-patch.sh: script changed to support archives in a proper way

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Nicolas" == Nicolas Ferre <[email protected]> writes:

Nicolas> Le 18/05/2011 12:10, Ludovic Desroches :

Quoted 5 lines
Quoted 5 lines

The previous script doesn't support patching order with archives since it didn't extract archives but simply decompressed file and piped the result to the patch command.
This new script extracts archives in a temporary folder and then applies patches.

Nicolas> Hi guys,

Nicolas> Any comment on this patch?

Sorry, haven't looked at it yet. We're just about to release 2011.05, and then I'm leaving for 1 week of holiday. I'll take a look once I'm back.

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

PATCH 1/1 kernel-patch.sh: script changed to support archives in a proper way

Quoted 3 lines · On Tue, 24 May 2011 16:25:59 +0200 Peter Korsgaard <[email protected]> wrote:

Sorry, haven't looked at it yet. We're just about to release 2011.05, and then I'm leaving for 1 week of holiday. I'll take a look once I'm back.

If I can, I'll try to have a look in the mean time. Sorry for the long delay in getting back to you, I have been terribly busy the last two months, and I'm only slowly catching up on Buildroot development.

Regards,

Thomas

Signature · 4 lines
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#5 lore raw

RFC PATCH v2 1/1 kernel-patch.sh: script changed to support archives in a proper way

In reply to Ludovic Desroches

Hello,

This is the second version of this script. Sadly the first one was not working from a from scrath build ie downloading buildroot source code, patching it andrunning the build. The first patch was tested only with a make clean and the behavior was not the same since filesystem build was ok.

So this new patch has been tested from a clean buildroot directory and corrected the errors of the previous one. It was used to compile the crosstool chain, a root file system and a kernel whose patches were into a tar.gz archive. This last point was the purpose of this patch. Without it, the patches into the archive were not applied in the right order.

I am far to be a bash guru so if you see any improvements please tell me. Thanks.

Regards,

Ludovic

#6 lore raw

RFC PATCH v2 1/1 kernel-patch.sh: script changed to support archives in a proper way

From: Ludovic Desroches <[email protected]>

The previous script doesn't support patching order with archives since it didn't extract archives but simply decompressed file and piped the result to the patch command.
This new script extracts archives in a temporary folder and then applies patches.

---
 toolchain/patch-kernel.sh |  154 +++++++++++++++++++++++++++++----------------
 1 files changed, 100 insertions(+), 54 deletions(-)
toolchain/patch-kernel.sh +100 -54
index 76cb9f7..408a9a7 100755
@@ -1,66 +1,112 @@
-#! /bin/bash
-# A little script I whipped up to make it easy to
-# patch source trees and have sane error handling
-# -Erik
-#
-# (c) 2002 Erik Andersen <[email protected]>
+#!/bin/bash
 
-# Set directories from arguments, or use defaults.
-targetdir=${1-.}
-patchdir=${2-../kernel-patches}
-shift 2
-patchpattern=${@-*}
+# function apply_patch patch_file
+# this function no more deal with directory case since it is managed
+# in an upper layer
+function apply_patch {
+apply="patch -p1 -E -d"
 
-if [ ! -d "${targetdir}" ] ; then
-    echo "Aborting.  '${targetdir}' is not a directory."
-    exit 1
+case "${1}" in
+*\.tar\.gz|*\.tgz|*\.tar\.bz|*\.tar\.bz2|*\.tbz|*\.tbz2)
+	echo "Error with ${1}";
+	echo "Archives into a directory or another archive is not supported";
+	return 1;
+	;;
+*\.gz)
+	type="gzip"; uncomp="gunzip -dc"; ;;
+*\.bz)
+	type="bzip"; uncomp="bunzip -dc"; ;;
+*\.bz2)
+	type="bzip2"; uncomp="bunzip2 -dc"; ;;
+*\.zip)
+	type="zip"; uncomp="unzip -d"; ;;
+*\.Z)
+	type="compress"; uncomp="uncompress -c"; ;;
+*\.diff*)
+	type="diff"; uncomp="cat"; ;;
+# '*' at the end is needed for patch.arm for example
+*\.patch*)
+	type="patch"; uncomp="cat"; ;;
+*)
+	echo "Unsupported format file for ${1}, skip it";
+	return 0;
+	;;
+esac
+
+echo ""
+echo "Applying ${1} using ${type}: "
+echo ${1} | cat >> ${builddir}/.applied_patches_list
+${uncomp} ${1} | ${apply} ${builddir}
+if [ $? != 0 ] ; then
+	echo "Patch failed! Please fix ${1}!"
+	return 1
 fi
+}
+
+# entry point
+builddir=${1}
+patchdir=${2}
+shift 2
+patchlist=${@}
+patchesdir="${builddir}/../$(basename $builddir)-patches"
+
+# check directories
 if [ ! -d "${patchdir}" ] ; then
-    echo "Aborting.  '${patchdir}' is not a directory."
-    exit 1
+	echo "Aborting: ${patchdir} is not a directory."
+	exit 1
 fi
-    
-for i in `cd ${patchdir}; ls -d ${patchpattern} 2> /dev/null` ; do 
-    apply="patch -p1 -E -d"
-    uncomp_parm=""
-    if [ -d "${patchdir}/$i" ] ; then
-	type="directory overlay"
-	uncomp="tar cf - --exclude=.svn --no-anchored -C"
-	uncomp_parm="."
-	apply="tar xvf - -C"
-    else case "$i" in
-	*.gz)
-	type="gzip"; uncomp="gunzip -dc"; ;; 
-	*.bz)
-	type="bzip"; uncomp="bunzip -dc"; ;; 
-	*.bz2)
-	type="bzip2"; uncomp="bunzip2 -dc"; ;; 
-	*.zip)
-	type="zip"; uncomp="unzip -d"; ;; 
-	*.Z)
-	type="compress"; uncomp="uncompress -c"; ;; 
-	*.tgz)
-	type="tar gzip"; uncomp="gunzip -dc"; apply="tar xvf - -C"; ;; 
-	*.tar)
-	type="tar"; uncomp="cat"; apply="tar xvf - -C"; ;; 
-	*)
-	type="plaintext"; uncomp="cat"; ;; 
-    esac fi
-    echo ""
-    echo "Applying ${i} using ${type}: " 
-	echo ${i} | cat >> ${targetdir}/.applied_patches_list
-    ${uncomp} ${patchdir}/${i} ${uncomp_parm} | ${apply} ${targetdir} 
-    if [ $? != 0 ] ; then
-        echo "Patch failed!  Please fix $i!"
+if [ ! -d "${builddir}" ] ; then
+	echo "Aborting: ${builddir} is not a directory."
 	exit 1
-    fi
+fi
+
+# go to the patch directory because $patchlist is interpreted when doing
+# for i in $patchlist
+pushd ${patchdir}
+index=0
+for i in $patchlist ; do
+	patchlist_interpreted[${index}]="$i"
+	index=`expr ${index} + 1`
+	echo patchlist_interpreted[${index}]=$i
 done
+popd
 
-# Check for rejects...
-if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+for index in "${!patchlist_interpreted[@]}" ; do
+	file="${patchlist_interpreted[${index}]}"
+	patch_path="${patchdir}/${file}"
+	# three cases: directory, archive, file patch (compressed or not)
+	# directory
+	if [ -d "${patch_path}" ] ; then
+		for p in $(ls ${patch_path}) ; do
+			apply_patch "${patch_path}/${p}" || exit 1
+		done
+	# archive
+	elif echo $file | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$|tar\.gz$|tgz$" ; then
+		mkdir "${patchesdir}"
+		# extract archive
+		if echo $file | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$" ; then
+			tar_options="-xjf"
+		else
+			tar_options="-xzf"
+		fi
+		tar -C ${patchesdir} --strip-components=1 ${tar_options} ${patch_path}
+		# apply patches from the archive
+		for p in $(find ${patchesdir} | sort) ; do
+			apply_patch "${p}" || { rm -rf "${patchesdir}" ; exit 1; }
+		done
+		rm -rf "${patchesdir}"
+	# file which is not an archive
+	else
+		apply_patch "${patch_path}" || exit 1
+	fi
+done
+
+# check for rejects...
+if [ "`find ${builddir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
     echo "Aborting.  Reject files found."
     exit 1
 fi
 
-# Remove backup files
-find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+# remove backup files
+find ${builddir}/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+
Signature · 1 line
1.7.0.4
#7 lore raw

RFC PATCH v2 1/1 kernel-patch.sh: script changed to support archives in a proper way

Quoted 169 lines · ludovic.desroches at atmel.com

From: Ludovic Desroches <[email protected]>

The previous script doesn't support patching order with archives since it didn't extract archives but simply decompressed file and piped the result to the patch command.
This new script extracts archives in a temporary folder and then applies patches.

---
 toolchain/patch-kernel.sh |  154 +++++++++++++++++++++++++++++----------------
 1 files changed, 100 insertions(+), 54 deletions(-)
toolchain/patch-kernel.sh +91 -52
index 76cb9f7..408a9a7 100755
@@ -1,66 +1,112 @@
-#! /bin/bash
-# A little script I whipped up to make it easy to
-# patch source trees and have sane error handling
-# -Erik
-#
-# (c) 2002 Erik Andersen <[email protected]>
+#!/bin/bash
 
-# Set directories from arguments, or use defaults.
-targetdir=${1-.}
-patchdir=${2-../kernel-patches}
-shift 2
-patchpattern=${@-*}
+# function apply_patch patch_file
+# this function no more deal with directory case since it is managed
+# in an upper layer
+function apply_patch {
+apply="patch -p1 -E -d"
 
-if [ ! -d "${targetdir}" ] ; then
-    echo "Aborting.  '${targetdir}' is not a directory."
-    exit 1
+case "${1}" in
+*\.tar\.gz|*\.tgz|*\.tar\.bz|*\.tar\.bz2|*\.tbz|*\.tbz2)
+	echo "Error with ${1}";
+	echo "Archives into a directory or another archive is not supported";
+	return 1;
+	;;
+*\.gz)
+	type="gzip"; uncomp="gunzip -dc"; ;;
+*\.bz)
+	type="bzip"; uncomp="bunzip -dc"; ;;
+*\.bz2)
+	type="bzip2"; uncomp="bunzip2 -dc"; ;;
+*\.zip)
+	type="zip"; uncomp="unzip -d"; ;;
+*\.Z)
+	type="compress"; uncomp="uncompress -c"; ;;
+*\.diff*)
+	type="diff"; uncomp="cat"; ;;
+# '*' at the end is needed for patch.arm for example
+*\.patch*)
+	type="patch"; uncomp="cat"; ;;
+*)
+	echo "Unsupported format file for ${1}, skip it";
+	return 0;
+	;;
+esac
+
+echo ""
+echo "Applying ${1} using ${type}: "
+echo ${1} | cat >> ${builddir}/.applied_patches_list
+${uncomp} ${1} | ${apply} ${builddir}
+if [ $? != 0 ] ; then
+	echo "Patch failed! Please fix ${1}!"
+	return 1
 fi
+}
+
+# entry point
+builddir=${1}
+patchdir=${2}
+shift 2
+patchlist=${@}
+patchesdir="${builddir}/../$(basename $builddir)-patches"
+
+# check directories
 if [ ! -d "${patchdir}" ] ; then
-    echo "Aborting.  '${patchdir}' is not a directory."
-    exit 1
+	echo "Aborting: ${patchdir} is not a directory."
+	exit 1
 fi
-    
-for i in `cd ${patchdir}; ls -d ${patchpattern} 2> /dev/null` ; do 
-    apply="patch -p1 -E -d"
-    uncomp_parm=""
-    if [ -d "${patchdir}/$i" ] ; then
-	type="directory overlay"
-	uncomp="tar cf - --exclude=.svn --no-anchored -C"
-	uncomp_parm="."
-	apply="tar xvf - -C"
-    else case "$i" in
-	*.gz)
-	type="gzip"; uncomp="gunzip -dc"; ;; 
-	*.bz)
-	type="bzip"; uncomp="bunzip -dc"; ;; 
-	*.bz2)
-	type="bzip2"; uncomp="bunzip2 -dc"; ;; 
-	*.zip)
-	type="zip"; uncomp="unzip -d"; ;; 
-	*.Z)
-	type="compress"; uncomp="uncompress -c"; ;; 
-	*.tgz)
-	type="tar gzip"; uncomp="gunzip -dc"; apply="tar xvf - -C"; ;; 
-	*.tar)
-	type="tar"; uncomp="cat"; apply="tar xvf - -C"; ;; 
-	*)
-	type="plaintext"; uncomp="cat"; ;; 
-    esac fi
-    echo ""
-    echo "Applying ${i} using ${type}: " 
-	echo ${i} | cat >> ${targetdir}/.applied_patches_list
-    ${uncomp} ${patchdir}/${i} ${uncomp_parm} | ${apply} ${targetdir} 
-    if [ $? != 0 ] ; then
-        echo "Patch failed!  Please fix $i!"
+if [ ! -d "${builddir}" ] ; then
+	echo "Aborting: ${builddir} is not a directory."
 	exit 1
-    fi
+fi
+
+# go to the patch directory because $patchlist is interpreted when doing
+# for i in $patchlist
+pushd ${patchdir}
+index=0
+for i in $patchlist ; do
+	patchlist_interpreted[${index}]="$i"
+	index=`expr ${index} + 1`
+	echo patchlist_interpreted[${index}]=$i
 done
+popd
 
-# Check for rejects...
-if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+for index in "${!patchlist_interpreted[@]}" ; do
+	file="${patchlist_interpreted[${index}]}"
+	patch_path="${patchdir}/${file}"
+	# three cases: directory, archive, file patch (compressed or not)
+	# directory
+	if [ -d "${patch_path}" ] ; then
+		for p in $(ls ${patch_path}) ; do
+			apply_patch "${patch_path}/${p}" || exit 1
+		done
+	# archive
+	elif echo $file | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$|tar\.gz$|tgz$" ; then
+		mkdir "${patchesdir}"
+		# extract archive
+		if echo $file | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$" ; then
+			tar_options="-xjf"
+		else
+			tar_options="-xzf"
+		fi
+		tar -C ${patchesdir} --strip-components=1 ${tar_options} ${patch_path}
+		# apply patches from the archive
+		for p in $(find ${patchesdir} | sort) ; do
+			apply_patch "${p}" || { rm -rf "${patchesdir}" ; exit 1; }
+		done
+		rm -rf "${patchesdir}"
+	# file which is not an archive
+	else

toolchain/patch-kernel.sh line 109

Quoted 10 lines
toolchain/patch-kernel.sh +6 -0
+		apply_patch "${patch_path}" || exit 1
+	fi
+done
+
+# check for rejects...
+if [ "`find ${builddir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
     echo "Aborting.  Reject files found."
     exit 1
 fi
 

It appears on a quick reading that you leave any reject files on the file system after an attempt to apply patches.

That seems reasonable, presuming that you expect human intervention to resolve the rejects before continuing.

But what if the second or subsequent attempt to run the patch application, and there are rejects still on the file system from a prior attempt? I.E: The previous human intervention did not include deleting the earlier reject files.

Wouldn't it make sense to be sure the file system is clean of any reject files __before__ attempting to run the patch application?
I.E: Only checking afterward does not tell you success/fail of most recent attempt because the rejects might have pre-existed the patch attempt.

Mike

Quoted 5 lines
toolchain/patch-kernel.sh +3 -2
-# Remove backup files
-find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+# remove backup files
+find ${builddir}/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+
#8 lore raw

RFC PATCH v2 1/1 kernel-patch.sh: script changed to support archives in a proper way

Hello Michael,

Thanks for your feedback.

Quoted 183 lines · Michael S. Zick
Quoted 169 lines · ludovic.desroches at atmel.com

From: Ludovic Desroches<[email protected]>

The previous script doesn't support patching order with archives since it didn't extract archives but simply decompressed file and piped the result to the patch command.
This new script extracts archives in a temporary folder and then applies patches.

---
  toolchain/patch-kernel.sh |  154 +++++++++++++++++++++++++++++----------------
  1 files changed, 100 insertions(+), 54 deletions(-)
toolchain/patch-kernel.sh +91 -52
index 76cb9f7..408a9a7 100755
@@ -1,66 +1,112 @@
-#! /bin/bash
-# A little script I whipped up to make it easy to
-# patch source trees and have sane error handling
-# -Erik
-#
-# (c) 2002 Erik Andersen<[email protected]>
+#!/bin/bash
 
-# Set directories from arguments, or use defaults.
-targetdir=${1-.}
-patchdir=${2-../kernel-patches}
-shift 2
-patchpattern=${@-*}
+# function apply_patch patch_file
+# this function no more deal with directory case since it is managed
+# in an upper layer
+function apply_patch {
+apply="patch -p1 -E -d"
 
-if [ ! -d "${targetdir}" ] ; then
-    echo "Aborting.  '${targetdir}' is not a directory."
-    exit 1
+case "${1}" in
+*\.tar\.gz|*\.tgz|*\.tar\.bz|*\.tar\.bz2|*\.tbz|*\.tbz2)
+	echo "Error with ${1}";
+	echo "Archives into a directory or another archive is not supported";
+	return 1;
+	;;
+*\.gz)
+	type="gzip"; uncomp="gunzip -dc"; ;;
+*\.bz)
+	type="bzip"; uncomp="bunzip -dc"; ;;
+*\.bz2)
+	type="bzip2"; uncomp="bunzip2 -dc"; ;;
+*\.zip)
+	type="zip"; uncomp="unzip -d"; ;;
+*\.Z)
+	type="compress"; uncomp="uncompress -c"; ;;
+*\.diff*)
+	type="diff"; uncomp="cat"; ;;
+# '*' at the end is needed for patch.arm for example
+*\.patch*)
+	type="patch"; uncomp="cat"; ;;
+*)
+	echo "Unsupported format file for ${1}, skip it";
+	return 0;
+	;;
+esac
+
+echo ""
+echo "Applying ${1} using ${type}: "
+echo ${1} | cat>>  ${builddir}/.applied_patches_list
+${uncomp} ${1} | ${apply} ${builddir}
+if [ $? != 0 ] ; then
+	echo "Patch failed! Please fix ${1}!"
+	return 1
  fi
+}
+
+# entry point
+builddir=${1}
+patchdir=${2}
+shift 2
+patchlist=${@}
+patchesdir="${builddir}/../$(basename $builddir)-patches"
+
+# check directories
  if [ ! -d "${patchdir}" ] ; then
-    echo "Aborting.  '${patchdir}' is not a directory."
-    exit 1
+	echo "Aborting: ${patchdir} is not a directory."
+	exit 1
  fi
-
-for i in `cd ${patchdir}; ls -d ${patchpattern} 2>  /dev/null` ; do
-    apply="patch -p1 -E -d"
-    uncomp_parm=""
-    if [ -d "${patchdir}/$i" ] ; then
-	type="directory overlay"
-	uncomp="tar cf - --exclude=.svn --no-anchored -C"
-	uncomp_parm="."
-	apply="tar xvf - -C"
-    else case "$i" in
-	*.gz)
-	type="gzip"; uncomp="gunzip -dc"; ;;
-	*.bz)
-	type="bzip"; uncomp="bunzip -dc"; ;;
-	*.bz2)
-	type="bzip2"; uncomp="bunzip2 -dc"; ;;
-	*.zip)
-	type="zip"; uncomp="unzip -d"; ;;
-	*.Z)
-	type="compress"; uncomp="uncompress -c"; ;;
-	*.tgz)
-	type="tar gzip"; uncomp="gunzip -dc"; apply="tar xvf - -C"; ;;
-	*.tar)
-	type="tar"; uncomp="cat"; apply="tar xvf - -C"; ;;
-	*)
-	type="plaintext"; uncomp="cat"; ;;
-    esac fi
-    echo ""
-    echo "Applying ${i} using ${type}: "
-	echo ${i} | cat>>  ${targetdir}/.applied_patches_list
-    ${uncomp} ${patchdir}/${i} ${uncomp_parm} | ${apply} ${targetdir}
-    if [ $? != 0 ] ; then
-        echo "Patch failed!  Please fix $i!"
+if [ ! -d "${builddir}" ] ; then
+	echo "Aborting: ${builddir} is not a directory."
  	exit 1
-    fi
+fi
+
+# go to the patch directory because $patchlist is interpreted when doing
+# for i in $patchlist
+pushd ${patchdir}
+index=0
+for i in $patchlist ; do
+	patchlist_interpreted[${index}]="$i"
+	index=`expr ${index} + 1`
+	echo patchlist_interpreted[${index}]=$i
  done
+popd
 
-# Check for rejects...
-if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+for index in "${!patchlist_interpreted[@]}" ; do
+	file="${patchlist_interpreted[${index}]}"
+	patch_path="${patchdir}/${file}"
+	# three cases: directory, archive, file patch (compressed or not)
+	# directory
+	if [ -d "${patch_path}" ] ; then
+		for p in $(ls ${patch_path}) ; do
+			apply_patch "${patch_path}/${p}" || exit 1
+		done
+	# archive
+	elif echo $file | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$|tar\.gz$|tgz$" ; then
+		mkdir "${patchesdir}"
+		# extract archive
+		if echo $file | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$" ; then
+			tar_options="-xjf"
+		else
+			tar_options="-xzf"
+		fi
+		tar -C ${patchesdir} --strip-components=1 ${tar_options} ${patch_path}
+		# apply patches from the archive
+		for p in $(find ${patchesdir} | sort) ; do
+			apply_patch "${p}" || { rm -rf "${patchesdir}" ; exit 1; }
+		done
+		rm -rf "${patchesdir}"
+	# file which is not an archive
+	else

toolchain/patch-kernel.sh line 109

Quoted 10 lines
toolchain/patch-kernel.sh +6 -0
+		apply_patch "${patch_path}" || exit 1
+	fi
+done
+
+# check for rejects...
+if [ "`find ${builddir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
      echo "Aborting.  Reject files found."
      exit 1
  fi
 

It appears on a quick reading that you leave any reject files on the file system after an attempt to apply patches.

Quoted 7 lines

That seems reasonable, presuming that you expect human intervention to resolve the rejects before continuing.

But what if the second or subsequent attempt to run the patch application, and there are rejects still on the file system from a prior attempt? I.E: The previous human intervention did not include deleting the earlier reject files.

In fact, it was done likte this into the previous script so I was not focused on this but you are right: even if the patches are applied without errors the filesystem build will be aborted.

Quoted 7 lines

Wouldn't it make sense to be sure the file system is clean of any reject files __before__ attempting to run the patch application?
I.E: Only checking afterward does not tell you success/fail of most recent attempt because the rejects might have pre-existed the patch attempt.

Mike

I agree, I keep in mind your suggestion for v3 version.

Quoted 10 lines

toolchain/patch-kernel.sh line 112

Quoted 5 lines
toolchain/patch-kernel.sh +3 -2
-# Remove backup files
-find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+# remove backup files
+find ${builddir}/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

Regards,

Ludovic

#9 lore raw

RFC PATCH v3 1/1 kernel-patch.sh: script changed to support archives in a proper way

In reply to Michael S. Zick

Hello,

This is an update of the previous patch, it is based on BuildRoot 2011.11.

In addition the presency of rejected files is checked before applying patches.

Regards

Ludovic

#10 lore raw

RFC PATCH v3 1/2 apply-patches.sh: script changed to support archives in a proper way

From: Ludovic Desroches <[email protected]>

The previous script doesn't support patching order with archives since it didn't extract archives but simply decompressed file and piped the result to the patch command.
This new script extracts archives in a temporary folder and then applies patches.

Conflicts:

support/scripts/apply-patches.sh

---
 support/scripts/apply-patches.sh |  159 +++++++++++++++++++++++++-------------
 1 files changed, 105 insertions(+), 54 deletions(-)
support/scripts/apply-patches.sh +105 -54
index 1aef47e..0492e01 100755
@@ -1,66 +1,117 @@
-#! /bin/bash
-# A little script I whipped up to make it easy to
-# patch source trees and have sane error handling
-# -Erik
-#
-# (c) 2002 Erik Andersen <[email protected]>
+#!/bin/bash
 
-# Set directories from arguments, or use defaults.
-targetdir=${1-.}
-patchdir=${2-../kernel-patches}
-shift 2
-patchpattern=${@-*}
+# function apply_patch patch_file
+# this function no more deal with directory case since it is managed
+# in an upper layer
+function apply_patch {
+apply="patch -p1 -E -d"
+#if [ ! -e "${1}" ] ; then
+#	echo "${1} is not a file"
+#	exit 1
+#fi
 
-if [ ! -d "${targetdir}" ] ; then
-    echo "Aborting.  '${targetdir}' is not a directory."
-    exit 1
+case "${1}" in
+*\.tar\.gz$|*\.tgz$|*\.tar\.bz$|*\.tar\.bz2$|*\.tbz$|*\.tbz2$)
+	echo "Error with ${1}";
+	echo "Archives into a directory or another archive is not supported";
+	return 1;
+	;;
+*\.gz$)
+	type="gzip"; uncomp="gunzip -dc"; ;;
+*\.bz$)
+	type="bzip"; uncomp="bunzip -dc"; ;;
+*\.bz2$)
+	type="bzip2"; uncomp="bunzip2 -dc"; ;;
+*\.zip$)
+	type="zip"; uncomp="unzip -d"; ;;
+*\.Z$)
+	type="compress"; uncomp="uncompress -c"; ;;
+*\.diff*)
+	type="diff"; uncomp="cat"; ;;
+*\.patch*)
+	type="patch"; uncomp="cat"; ;;
+*)
+	echo "Unsupported format file for ${1}, skip it";
+	return 0;
+	;;
+esac
+
+echo ""
+echo "Applying ${1} using ${type}: "
+echo ${1} | cat >> ${builddir}/.applied_patches_list
+${uncomp} ${1} | ${apply} ${builddir}
+if [ $? != 0 ] ; then
+	echo "Patch failed! Please fix ${1}!"
+	return 1
 fi
+}
+
+
+# entry point
+builddir=${1}
+patchdir=${2}
+shift 2
+patchlist=${@}
+patchesdir="${builddir}/../$(basename $builddir)-patches"
+
+# check directories
 if [ ! -d "${patchdir}" ] ; then
-    echo "Aborting.  '${patchdir}' is not a directory."
-    exit 1
+	echo "Aborting: ${patchdir} is not a directory."
+	exit 1
 fi
-    
-for i in `cd ${patchdir}; ls -d ${patchpattern} 2> /dev/null` ; do 
-    apply="patch -g0 -p1 -E -d"
-    uncomp_parm=""
-    if [ -d "${patchdir}/$i" ] ; then
-	type="directory overlay"
-	uncomp="tar cf - --exclude=.svn --no-anchored -C"
-	uncomp_parm="."
-	apply="tar xvf - -C"
-    else case "$i" in
-	*.gz)
-	type="gzip"; uncomp="gunzip -dc"; ;; 
-	*.bz)
-	type="bzip"; uncomp="bunzip -dc"; ;; 
-	*.bz2)
-	type="bzip2"; uncomp="bunzip2 -dc"; ;; 
-	*.zip)
-	type="zip"; uncomp="unzip -d"; ;; 
-	*.Z)
-	type="compress"; uncomp="uncompress -c"; ;; 
-	*.tgz)
-	type="tar gzip"; uncomp="gunzip -dc"; apply="tar xvf - -C"; ;; 
-	*.tar)
-	type="tar"; uncomp="cat"; apply="tar xvf - -C"; ;; 
-	*)
-	type="plaintext"; uncomp="cat"; ;; 
-    esac fi
-    echo ""
-    echo "Applying ${i} using ${type}: " 
-	echo ${i} | cat >> ${targetdir}/.applied_patches_list
-    ${uncomp} ${patchdir}/${i} ${uncomp_parm} | ${apply} ${targetdir} 
-    if [ $? != 0 ] ; then
-        echo "Patch failed!  Please fix $i!"
+if [ ! -d "${builddir}" ] ; then
+	echo "Aborting: ${builddir} is not a directory."
 	exit 1
-    fi
+fi
+
+# parse patch list, extract archives, apply patches
+for i in $patchlist ; do
+	# for remote files, directory is buildroot dl dir
+	#if echo $i | grep -q -E "^http://|^ftp://" ; then
+	#	patchdir=$patchdir
+	#else
+	#	patchdir=$(dirname $i)
+	#fi
+	patch_path="${patchdir}/${i}"
+	# three cases: directory, archive, file patch (compressed or not)
+	# directory
+	if [ -d "${patch_path}" ] ; then
+		for p in $(ls ${patch_path}) ; do
+			apply_patch "${patch_path}/${p}" || exit 1
+		done
+	# archive
+	elif echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$|tar\.gz$|tgz$" ; then
+		mkdir "${patchesdir}"
+		# extract archive
+		if echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$" ; then
+			tar_options="-xjf"
+		else
+			tar_options="-xzf"
+		fi
+		tar -C ${patchesdir} --strip-components=1 ${tar_options} ${patch_path}
+		# apply patches from the archive
+		#echo ${patchesdir}
+		#find ${patchesdir} | sort
+		for p in $(find ${patchesdir} | sort) ; do
+			apply_patch "${p}" || { rm -rf "${patchesdir}" ; exit 1; }
+		done
+		rm -rf "${patchesdir}"
+	# file which is not an archive
+	else
+		# we can have regex into patch name as package*.patch.arm that's
+		# why using ls
+		for p in $(ls -d ${patch_path} 2> /dev/null) ; do
+			apply_patch "${p}" || exit 1
+		done
+	fi
 done
 
-# Check for rejects...
-if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+# check for rejects...
+if [ "`find ${builddir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
     echo "Aborting.  Reject files found."
     exit 1
 fi
 
-# Remove backup files
-find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+# remove backup files
+find ${builddir}/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+
Signature · 1 line
1.7.5.4
#11 lore raw

RFC PATCH v3 1/2 apply-patches.sh: script changed to support archives in a proper way

Quoted 22 lines · On Fri, Jan 6, 2012 at 1:47 PM, <[email protected]> wrote:

From: Ludovic Desroches <[email protected]>

The previous script doesn't support patching order with archives since it didn't extract archives but simply decompressed file and piped the result to the patch command.
This new script extracts archives in a temporary folder and then applies patches.

Conflicts:

? ? ? ?support/scripts/apply-patches.sh
---
?support/scripts/apply-patches.sh | ?159 +++++++++++++++++++++++++------------- ?1 files changed, 105 insertions(+), 54 deletions(-)

support/scripts/apply-patches.sh +0 -0
index 1aef47e..0492e01 100755

support/scripts/apply-patches.sh line 1

Quoted 7 lines
support/scripts/apply-patches.sh +1 -6
@@ -1,66 +1,117 @@
-#! /bin/bash
-# A little script I whipped up to make it easy to
-# patch source trees and have sane error handling
-# -Erik
-#
-# (c) 2002 Erik Andersen <[email protected]>
+#!/bin/bash

I wonder why you removed the original copyright. I'd say you should keep it, possibly together with a description of the changes and your name.
Although it may not be the convention of adding explicit copyrights to scripts in buildroot, removing an existing one seems wrong IMO.

Quoted 171 lines
support/scripts/apply-patches.sh +42 -8
-# Set directories from arguments, or use defaults.
-targetdir=${1-.}
-patchdir=${2-../kernel-patches}
-shift 2
-patchpattern=${@-*}
+# function apply_patch patch_file
+# this function no more deal with directory case since it is managed
+# in an upper layer
+function apply_patch {
+apply="patch -p1 -E -d"
+#if [ ! -e "${1}" ] ; then
+# ? ? ?echo "${1} is not a file"
+# ? ? ?exit 1
+#fi
 
-if [ ! -d "${targetdir}" ] ; then
- ? ?echo "Aborting. ?'${targetdir}' is not a directory."
- ? ?exit 1
+case "${1}" in
+*\.tar\.gz$|*\.tgz$|*\.tar\.bz$|*\.tar\.bz2$|*\.tbz$|*\.tbz2$)
+ ? ? ? echo "Error with ${1}";
+ ? ? ? echo "Archives into a directory or another archive is not supported";
+ ? ? ? return 1;
+ ? ? ? ;;
+*\.gz$)
+ ? ? ? type="gzip"; uncomp="gunzip -dc"; ;;
+*\.bz$)
+ ? ? ? type="bzip"; uncomp="bunzip -dc"; ;;
+*\.bz2$)
+ ? ? ? type="bzip2"; uncomp="bunzip2 -dc"; ;;
+*\.zip$)
+ ? ? ? type="zip"; uncomp="unzip -d"; ;;
+*\.Z$)
+ ? ? ? type="compress"; uncomp="uncompress -c"; ;;
+*\.diff*)
+ ? ? ? type="diff"; uncomp="cat"; ;;
+*\.patch*)
+ ? ? ? type="patch"; uncomp="cat"; ;;
+*)
+ ? ? ? echo "Unsupported format file for ${1}, skip it";
+ ? ? ? return 0;
+ ? ? ? ;;
+esac
+
+echo ""
+echo "Applying ${1} using ${type}: "
+echo ${1} | cat >> ${builddir}/.applied_patches_list
+${uncomp} ${1} | ${apply} ${builddir}
+if [ $? != 0 ] ; then
+ ? ? ? echo "Patch failed! Please fix ${1}!"
+ ? ? ? return 1

?fi

support/scripts/apply-patches.sh +11 -0
+}
+
+
+# entry point
+builddir=${1}
+patchdir=${2}
+shift 2
+patchlist=${@}
+patchesdir="${builddir}/../$(basename $builddir)-patches"
+
+# check directories

?if [ ! -d "${patchdir}" ] ; then
- ? ?echo "Aborting. ?'${patchdir}' is not a directory."
- ? ?exit 1
+ ? ? ? echo "Aborting: ${patchdir} is not a directory."
+ ? ? ? exit 1
?fi

support/scripts/apply-patches.sh +2 -33
-
-for i in `cd ${patchdir}; ls -d ${patchpattern} 2> /dev/null` ; do
- ? ?apply="patch -g0 -p1 -E -d"
- ? ?uncomp_parm=""
- ? ?if [ -d "${patchdir}/$i" ] ; then
- ? ? ? type="directory overlay"
- ? ? ? uncomp="tar cf - --exclude=.svn --no-anchored -C"
- ? ? ? uncomp_parm="."
- ? ? ? apply="tar xvf - -C"
- ? ?else case "$i" in
- ? ? ? *.gz)
- ? ? ? type="gzip"; uncomp="gunzip -dc"; ;;
- ? ? ? *.bz)
- ? ? ? type="bzip"; uncomp="bunzip -dc"; ;;
- ? ? ? *.bz2)
- ? ? ? type="bzip2"; uncomp="bunzip2 -dc"; ;;
- ? ? ? *.zip)
- ? ? ? type="zip"; uncomp="unzip -d"; ;;
- ? ? ? *.Z)
- ? ? ? type="compress"; uncomp="uncompress -c"; ;;
- ? ? ? *.tgz)
- ? ? ? type="tar gzip"; uncomp="gunzip -dc"; apply="tar xvf - -C"; ;;
- ? ? ? *.tar)
- ? ? ? type="tar"; uncomp="cat"; apply="tar xvf - -C"; ;;
- ? ? ? *)
- ? ? ? type="plaintext"; uncomp="cat"; ;;
- ? ?esac fi
- ? ?echo ""
- ? ?echo "Applying ${i} using ${type}: "
- ? ? ? echo ${i} | cat >> ${targetdir}/.applied_patches_list
- ? ?${uncomp} ${patchdir}/${i} ${uncomp_parm} | ${apply} ${targetdir}
- ? ?if [ $? != 0 ] ; then
- ? ? ? ?echo "Patch failed! ?Please fix $i!"
+if [ ! -d "${builddir}" ] ; then
+ ? ? ? echo "Aborting: ${builddir} is not a directory."

? ? ? ?exit 1
- ? ?fi

support/scripts/apply-patches.sh +42 -0
+fi
+
+# parse patch list, extract archives, apply patches
+for i in $patchlist ; do
+ ? ? ? # for remote files, directory is buildroot dl dir
+ ? ? ? #if echo $i | grep -q -E "^http://|^ftp://" ; then
+ ? ? ? # ? ? ? patchdir=$patchdir
+ ? ? ? #else
+ ? ? ? # ? ? ? patchdir=$(dirname $i)
+ ? ? ? #fi
+ ? ? ? patch_path="${patchdir}/${i}"
+ ? ? ? # three cases: directory, archive, file patch (compressed or not)
+ ? ? ? # directory
+ ? ? ? if [ -d "${patch_path}" ] ; then
+ ? ? ? ? ? ? ? for p in $(ls ${patch_path}) ; do
+ ? ? ? ? ? ? ? ? ? ? ? apply_patch "${patch_path}/${p}" || exit 1
+ ? ? ? ? ? ? ? done
+ ? ? ? # archive
+ ? ? ? elif echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$|tar\.gz$|tgz$" ; then
+ ? ? ? ? ? ? ? mkdir "${patchesdir}"
+ ? ? ? ? ? ? ? # extract archive
+ ? ? ? ? ? ? ? if echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$" ; then
+ ? ? ? ? ? ? ? ? ? ? ? tar_options="-xjf"
+ ? ? ? ? ? ? ? else
+ ? ? ? ? ? ? ? ? ? ? ? tar_options="-xzf"
+ ? ? ? ? ? ? ? fi
+ ? ? ? ? ? ? ? tar -C ${patchesdir} --strip-components=1 ${tar_options} ${patch_path}
+ ? ? ? ? ? ? ? # apply patches from the archive
+ ? ? ? ? ? ? ? #echo ${patchesdir}
+ ? ? ? ? ? ? ? #find ${patchesdir} | sort
+ ? ? ? ? ? ? ? for p in $(find ${patchesdir} | sort) ; do
+ ? ? ? ? ? ? ? ? ? ? ? apply_patch "${p}" || { rm -rf "${patchesdir}" ; exit 1; }
+ ? ? ? ? ? ? ? done
+ ? ? ? ? ? ? ? rm -rf "${patchesdir}"
+ ? ? ? # file which is not an archive
+ ? ? ? else
+ ? ? ? ? ? ? ? # we can have regex into patch name as package*.patch.arm that's
+ ? ? ? ? ? ? ? # why using ls
+ ? ? ? ? ? ? ? for p in $(ls -d ${patch_path} 2> /dev/null) ; do
+ ? ? ? ? ? ? ? ? ? ? ? apply_patch "${p}" || exit 1
+ ? ? ? ? ? ? ? done
+ ? ? ? fi

?done

support/scripts/apply-patches.sh +2 -2
-# Check for rejects...
-if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+# check for rejects...
+if [ "`find ${builddir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then

? ? echo "Aborting. ?Reject files found."
? ? exit 1
?fi

support/scripts/apply-patches.sh +3 -3
-# Remove backup files
-find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+# remove backup files
+find ${builddir}/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+
--

1.7.5.4

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

#12 lore raw

RFC PATCH v3 1/2 apply-patches.sh: script changed to support archives in a proper way

Quoted 28 lines · Thomas De Schampheleire
Quoted 27 lines · On Fri, Jan 6, 2012 at 1:47 PM, <[email protected]> wrote:

From: Ludovic Desroches <[email protected]>

The previous script doesn't support patching order with archives since it didn't extract archives but simply decompressed file and piped the result to the patch command.
This new script extracts archives in a temporary folder and then applies patches.

Conflicts:

? ? ? ?support/scripts/apply-patches.sh
---
?support/scripts/apply-patches.sh | ?159 +++++++++++++++++++++++++------------- ?1 files changed, 105 insertions(+), 54 deletions(-)

support/scripts/apply-patches.sh +0 -5
index 1aef47e..0492e01 100755
@@ -1,66 +1,117 @@
-#! /bin/bash
-# A little script I whipped up to make it easy to
-# patch source trees and have sane error handling
-# -Erik
-#
Quoted 9 lines

support/scripts/apply-patches.sh line 1

Quoted 2 lines
support/scripts/apply-patches.sh +1 -1
-# (c) 2002 Erik Andersen <[email protected]>
+#!/bin/bash

I wonder why you removed the original copyright. I'd say you should keep it, possibly together with a description of the changes and your name.
Although it may not be the convention of adding explicit copyrights to scripts in buildroot, removing an existing one seems wrong IMO.

I removed it because I see it as a new script. The major part of the script has changed, I mainly kept the switch case but with some changes too.

Anyway it's not a problem for me to keep this copyright if needed.

Quoted 172 lines
Quoted 171 lines
support/scripts/apply-patches.sh +42 -8
-# Set directories from arguments, or use defaults.
-targetdir=${1-.}
-patchdir=${2-../kernel-patches}
-shift 2
-patchpattern=${@-*}
+# function apply_patch patch_file
+# this function no more deal with directory case since it is managed
+# in an upper layer
+function apply_patch {
+apply="patch -p1 -E -d"
+#if [ ! -e "${1}" ] ; then
+# ? ? ?echo "${1} is not a file"
+# ? ? ?exit 1
+#fi
 
-if [ ! -d "${targetdir}" ] ; then
- ? ?echo "Aborting. ?'${targetdir}' is not a directory."
- ? ?exit 1
+case "${1}" in
+*\.tar\.gz$|*\.tgz$|*\.tar\.bz$|*\.tar\.bz2$|*\.tbz$|*\.tbz2$)
+ ? ? ? echo "Error with ${1}";
+ ? ? ? echo "Archives into a directory or another archive is not supported";
+ ? ? ? return 1;
+ ? ? ? ;;
+*\.gz$)
+ ? ? ? type="gzip"; uncomp="gunzip -dc"; ;;
+*\.bz$)
+ ? ? ? type="bzip"; uncomp="bunzip -dc"; ;;
+*\.bz2$)
+ ? ? ? type="bzip2"; uncomp="bunzip2 -dc"; ;;
+*\.zip$)
+ ? ? ? type="zip"; uncomp="unzip -d"; ;;
+*\.Z$)
+ ? ? ? type="compress"; uncomp="uncompress -c"; ;;
+*\.diff*)
+ ? ? ? type="diff"; uncomp="cat"; ;;
+*\.patch*)
+ ? ? ? type="patch"; uncomp="cat"; ;;
+*)
+ ? ? ? echo "Unsupported format file for ${1}, skip it";
+ ? ? ? return 0;
+ ? ? ? ;;
+esac
+
+echo ""
+echo "Applying ${1} using ${type}: "
+echo ${1} | cat >> ${builddir}/.applied_patches_list
+${uncomp} ${1} | ${apply} ${builddir}
+if [ $? != 0 ] ; then
+ ? ? ? echo "Patch failed! Please fix ${1}!"
+ ? ? ? return 1

?fi

support/scripts/apply-patches.sh +11 -0
+}
+
+
+# entry point
+builddir=${1}
+patchdir=${2}
+shift 2
+patchlist=${@}
+patchesdir="${builddir}/../$(basename $builddir)-patches"
+
+# check directories

?if [ ! -d "${patchdir}" ] ; then
- ? ?echo "Aborting. ?'${patchdir}' is not a directory."
- ? ?exit 1
+ ? ? ? echo "Aborting: ${patchdir} is not a directory."
+ ? ? ? exit 1
?fi

support/scripts/apply-patches.sh +2 -33
-
-for i in `cd ${patchdir}; ls -d ${patchpattern} 2> /dev/null` ; do
- ? ?apply="patch -g0 -p1 -E -d"
- ? ?uncomp_parm=""
- ? ?if [ -d "${patchdir}/$i" ] ; then
- ? ? ? type="directory overlay"
- ? ? ? uncomp="tar cf - --exclude=.svn --no-anchored -C"
- ? ? ? uncomp_parm="."
- ? ? ? apply="tar xvf - -C"
- ? ?else case "$i" in
- ? ? ? *.gz)
- ? ? ? type="gzip"; uncomp="gunzip -dc"; ;;
- ? ? ? *.bz)
- ? ? ? type="bzip"; uncomp="bunzip -dc"; ;;
- ? ? ? *.bz2)
- ? ? ? type="bzip2"; uncomp="bunzip2 -dc"; ;;
- ? ? ? *.zip)
- ? ? ? type="zip"; uncomp="unzip -d"; ;;
- ? ? ? *.Z)
- ? ? ? type="compress"; uncomp="uncompress -c"; ;;
- ? ? ? *.tgz)
- ? ? ? type="tar gzip"; uncomp="gunzip -dc"; apply="tar xvf - -C"; ;;
- ? ? ? *.tar)
- ? ? ? type="tar"; uncomp="cat"; apply="tar xvf - -C"; ;;
- ? ? ? *)
- ? ? ? type="plaintext"; uncomp="cat"; ;;
- ? ?esac fi
- ? ?echo ""
- ? ?echo "Applying ${i} using ${type}: "
- ? ? ? echo ${i} | cat >> ${targetdir}/.applied_patches_list
- ? ?${uncomp} ${patchdir}/${i} ${uncomp_parm} | ${apply} ${targetdir}
- ? ?if [ $? != 0 ] ; then
- ? ? ? ?echo "Patch failed! ?Please fix $i!"
+if [ ! -d "${builddir}" ] ; then
+ ? ? ? echo "Aborting: ${builddir} is not a directory."

? ? ? ?exit 1
- ? ?fi

support/scripts/apply-patches.sh +42 -0
+fi
+
+# parse patch list, extract archives, apply patches
+for i in $patchlist ; do
+ ? ? ? # for remote files, directory is buildroot dl dir
+ ? ? ? #if echo $i | grep -q -E "^http://|^ftp://" ; then
+ ? ? ? # ? ? ? patchdir=$patchdir
+ ? ? ? #else
+ ? ? ? # ? ? ? patchdir=$(dirname $i)
+ ? ? ? #fi
+ ? ? ? patch_path="${patchdir}/${i}"
+ ? ? ? # three cases: directory, archive, file patch (compressed or not)
+ ? ? ? # directory
+ ? ? ? if [ -d "${patch_path}" ] ; then
+ ? ? ? ? ? ? ? for p in $(ls ${patch_path}) ; do
+ ? ? ? ? ? ? ? ? ? ? ? apply_patch "${patch_path}/${p}" || exit 1
+ ? ? ? ? ? ? ? done
+ ? ? ? # archive
+ ? ? ? elif echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$|tar\.gz$|tgz$" ; then
+ ? ? ? ? ? ? ? mkdir "${patchesdir}"
+ ? ? ? ? ? ? ? # extract archive
+ ? ? ? ? ? ? ? if echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$" ; then
+ ? ? ? ? ? ? ? ? ? ? ? tar_options="-xjf"
+ ? ? ? ? ? ? ? else
+ ? ? ? ? ? ? ? ? ? ? ? tar_options="-xzf"
+ ? ? ? ? ? ? ? fi
+ ? ? ? ? ? ? ? tar -C ${patchesdir} --strip-components=1 ${tar_options} ${patch_path}
+ ? ? ? ? ? ? ? # apply patches from the archive
+ ? ? ? ? ? ? ? #echo ${patchesdir}
+ ? ? ? ? ? ? ? #find ${patchesdir} | sort
+ ? ? ? ? ? ? ? for p in $(find ${patchesdir} | sort) ; do
+ ? ? ? ? ? ? ? ? ? ? ? apply_patch "${p}" || { rm -rf "${patchesdir}" ; exit 1; }
+ ? ? ? ? ? ? ? done
+ ? ? ? ? ? ? ? rm -rf "${patchesdir}"
+ ? ? ? # file which is not an archive
+ ? ? ? else
+ ? ? ? ? ? ? ? # we can have regex into patch name as package*.patch.arm that's
+ ? ? ? ? ? ? ? # why using ls
+ ? ? ? ? ? ? ? for p in $(ls -d ${patch_path} 2> /dev/null) ; do
+ ? ? ? ? ? ? ? ? ? ? ? apply_patch "${p}" || exit 1
+ ? ? ? ? ? ? ? done
+ ? ? ? fi

?done

support/scripts/apply-patches.sh +2 -2
-# Check for rejects...
-if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+# check for rejects...
+if [ "`find ${builddir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then

? ? echo "Aborting. ?Reject files found."
? ? exit 1
?fi

support/scripts/apply-patches.sh +3 -3
-# Remove backup files
-find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+# remove backup files
+find ${builddir}/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+
--

1.7.5.4

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

#13 lore raw

RFC PATCH v3 1/2 apply-patches.sh: script changed to support archives in a proper way

Quoted 39 lines · Ludovic Desroches
Quoted 28 lines · Thomas De Schampheleire
Quoted 27 lines · On Fri, Jan 6, 2012 at 1:47 PM, ?<[email protected]> wrote:

From: Ludovic Desroches <[email protected]>

The previous script doesn't support patching order with archives since it didn't extract archives but simply decompressed file and piped the result to the patch command.
This new script extracts archives in a temporary folder and then applies patches.

Conflicts:

? ? ? ?support/scripts/apply-patches.sh
---
?support/scripts/apply-patches.sh | ?159 +++++++++++++++++++++++++------------- ?1 files changed, 105 insertions(+), 54 deletions(-)

support/scripts/apply-patches.sh +0 -5
index 1aef47e..0492e01 100755
@@ -1,66 +1,117 @@
-#! /bin/bash
-# A little script I whipped up to make it easy to
-# patch source trees and have sane error handling
-# -Erik
-#
Quoted 9 lines

support/scripts/apply-patches.sh line 1

Quoted 2 lines
support/scripts/apply-patches.sh +1 -1
-# (c) 2002 Erik Andersen <[email protected]>
+#!/bin/bash

I wonder why you removed the original copyright. I'd say you should keep it, possibly together with a description of the changes and your name.
Although it may not be the convention of adding explicit copyrights to scripts in buildroot, removing an existing one seems wrong IMO.

Quoted 2 lines

I removed it because I see it as a new script. The major part of the script has changed, I mainly kept the switch case but with some changes too.

If I compare the original and the adapted script, I feel that the original code continues to live in the new one. As you say, the switch statement, but also the code that applies the patches below the switch, the checking for rejects, and the removal of backup files.

So, the way I see it, you improved and extended the script, but did not rewrite it from scratch.

Quoted 162 lines

Anyway it's not a problem for me to keep this copyright if needed.

Quoted 159 lines
Quoted 159 lines
support/scripts/apply-patches.sh +42 -8
-# Set directories from arguments, or use defaults.
-targetdir=${1-.}
-patchdir=${2-../kernel-patches}
-shift 2
-patchpattern=${@-*}
+# function apply_patch patch_file
+# this function no more deal with directory case since it is managed
+# in an upper layer
+function apply_patch {
+apply="patch -p1 -E -d"
+#if [ ! -e "${1}" ] ; then
+# ? ? ?echo "${1} is not a file"
+# ? ? ?exit 1
+#fi
 
-if [ ! -d "${targetdir}" ] ; then
- ? ?echo "Aborting. ?'${targetdir}' is not a directory."
- ? ?exit 1
+case "${1}" in
+*\.tar\.gz$|*\.tgz$|*\.tar\.bz$|*\.tar\.bz2$|*\.tbz$|*\.tbz2$)
+ ? ? ? echo "Error with ${1}";
+ ? ? ? echo "Archives into a directory or another archive is not supported";
+ ? ? ? return 1;
+ ? ? ? ;;
+*\.gz$)
+ ? ? ? type="gzip"; uncomp="gunzip -dc"; ;;
+*\.bz$)
+ ? ? ? type="bzip"; uncomp="bunzip -dc"; ;;
+*\.bz2$)
+ ? ? ? type="bzip2"; uncomp="bunzip2 -dc"; ;;
+*\.zip$)
+ ? ? ? type="zip"; uncomp="unzip -d"; ;;
+*\.Z$)
+ ? ? ? type="compress"; uncomp="uncompress -c"; ;;
+*\.diff*)
+ ? ? ? type="diff"; uncomp="cat"; ;;
+*\.patch*)
+ ? ? ? type="patch"; uncomp="cat"; ;;
+*)
+ ? ? ? echo "Unsupported format file for ${1}, skip it";
+ ? ? ? return 0;
+ ? ? ? ;;
+esac
+
+echo ""
+echo "Applying ${1} using ${type}: "
+echo ${1} | cat >> ${builddir}/.applied_patches_list
+${uncomp} ${1} | ${apply} ${builddir}
+if [ $? != 0 ] ; then
+ ? ? ? echo "Patch failed! Please fix ${1}!"
+ ? ? ? return 1

?fi

support/scripts/apply-patches.sh +11 -0
+}
+
+
+# entry point
+builddir=${1}
+patchdir=${2}
+shift 2
+patchlist=${@}
+patchesdir="${builddir}/../$(basename $builddir)-patches"
+
+# check directories

?if [ ! -d "${patchdir}" ] ; then
- ? ?echo "Aborting. ?'${patchdir}' is not a directory."
- ? ?exit 1
+ ? ? ? echo "Aborting: ${patchdir} is not a directory."
+ ? ? ? exit 1
?fi

support/scripts/apply-patches.sh +2 -33
-
-for i in `cd ${patchdir}; ls -d ${patchpattern} 2> /dev/null` ; do
- ? ?apply="patch -g0 -p1 -E -d"
- ? ?uncomp_parm=""
- ? ?if [ -d "${patchdir}/$i" ] ; then
- ? ? ? type="directory overlay"
- ? ? ? uncomp="tar cf - --exclude=.svn --no-anchored -C"
- ? ? ? uncomp_parm="."
- ? ? ? apply="tar xvf - -C"
- ? ?else case "$i" in
- ? ? ? *.gz)
- ? ? ? type="gzip"; uncomp="gunzip -dc"; ;;
- ? ? ? *.bz)
- ? ? ? type="bzip"; uncomp="bunzip -dc"; ;;
- ? ? ? *.bz2)
- ? ? ? type="bzip2"; uncomp="bunzip2 -dc"; ;;
- ? ? ? *.zip)
- ? ? ? type="zip"; uncomp="unzip -d"; ;;
- ? ? ? *.Z)
- ? ? ? type="compress"; uncomp="uncompress -c"; ;;
- ? ? ? *.tgz)
- ? ? ? type="tar gzip"; uncomp="gunzip -dc"; apply="tar xvf - -C"; ;;
- ? ? ? *.tar)
- ? ? ? type="tar"; uncomp="cat"; apply="tar xvf - -C"; ;;
- ? ? ? *)
- ? ? ? type="plaintext"; uncomp="cat"; ;;
- ? ?esac fi
- ? ?echo ""
- ? ?echo "Applying ${i} using ${type}: "
- ? ? ? echo ${i} | cat >> ${targetdir}/.applied_patches_list
- ? ?${uncomp} ${patchdir}/${i} ${uncomp_parm} | ${apply} ${targetdir}
- ? ?if [ $? != 0 ] ; then
- ? ? ? ?echo "Patch failed! ?Please fix $i!"
+if [ ! -d "${builddir}" ] ; then
+ ? ? ? echo "Aborting: ${builddir} is not a directory."

? ? ? ?exit 1
- ? ?fi

support/scripts/apply-patches.sh +42 -0
+fi
+
+# parse patch list, extract archives, apply patches
+for i in $patchlist ; do
+ ? ? ? # for remote files, directory is buildroot dl dir
+ ? ? ? #if echo $i | grep -q -E "^http://|^ftp://" ; then
+ ? ? ? # ? ? ? patchdir=$patchdir
+ ? ? ? #else
+ ? ? ? # ? ? ? patchdir=$(dirname $i)
+ ? ? ? #fi
+ ? ? ? patch_path="${patchdir}/${i}"
+ ? ? ? # three cases: directory, archive, file patch (compressed or not)
+ ? ? ? # directory
+ ? ? ? if [ -d "${patch_path}" ] ; then
+ ? ? ? ? ? ? ? for p in $(ls ${patch_path}) ; do
+ ? ? ? ? ? ? ? ? ? ? ? apply_patch "${patch_path}/${p}" || exit 1
+ ? ? ? ? ? ? ? done
+ ? ? ? # archive
+ ? ? ? elif echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$|tar\.gz$|tgz$" ; then
+ ? ? ? ? ? ? ? mkdir "${patchesdir}"
+ ? ? ? ? ? ? ? # extract archive
+ ? ? ? ? ? ? ? if echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$" ; then
+ ? ? ? ? ? ? ? ? ? ? ? tar_options="-xjf"
+ ? ? ? ? ? ? ? else
+ ? ? ? ? ? ? ? ? ? ? ? tar_options="-xzf"
+ ? ? ? ? ? ? ? fi
+ ? ? ? ? ? ? ? tar -C ${patchesdir} --strip-components=1 ${tar_options} ${patch_path}
+ ? ? ? ? ? ? ? # apply patches from the archive
+ ? ? ? ? ? ? ? #echo ${patchesdir}
+ ? ? ? ? ? ? ? #find ${patchesdir} | sort
+ ? ? ? ? ? ? ? for p in $(find ${patchesdir} | sort) ; do
+ ? ? ? ? ? ? ? ? ? ? ? apply_patch "${p}" || { rm -rf "${patchesdir}" ; exit 1; }
+ ? ? ? ? ? ? ? done
+ ? ? ? ? ? ? ? rm -rf "${patchesdir}"
+ ? ? ? # file which is not an archive
+ ? ? ? else
+ ? ? ? ? ? ? ? # we can have regex into patch name as package*.patch.arm that's
+ ? ? ? ? ? ? ? # why using ls
+ ? ? ? ? ? ? ? for p in $(ls -d ${patch_path} 2> /dev/null) ; do
+ ? ? ? ? ? ? ? ? ? ? ? apply_patch "${p}" || exit 1
+ ? ? ? ? ? ? ? done
+ ? ? ? fi

?done

support/scripts/apply-patches.sh +2 -2
-# Check for rejects...
-if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+# check for rejects...
+if [ "`find ${builddir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then

? ? echo "Aborting. ?Reject files found."
? ? exit 1
?fi

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
support/scripts/apply-patches.sh +3 -3
-# Remove backup files
-find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+# remove backup files
+find ${builddir}/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+
--

1.7.5.4

Best regards,
Thomas

#14 lore raw

RFC PATCH v4 1/1 kernel-patch.sh: script changed to support archives in a proper way

v4 changes:

- keep copyright
- remove dead code

Regards

Ludovic

#15 lore raw

RFC PATCH v4 1/2 apply-patches.sh: script changed to support archives in a proper way

From: Ludovic Desroches <[email protected]>

The previous script doesn't support patching order with archives since it didn't extract archives but simply decompressed file and piped the result to the patch command.
This new script extracts archives in a temporary folder and then applies patches.

Conflicts:

support/scripts/apply-patches.sh

---
 support/scripts/apply-patches.sh |  135 +++++++++++++++++++++++++-------------
 1 files changed, 89 insertions(+), 46 deletions(-)
support/scripts/apply-patches.sh +89 -46
index 1aef47e..2a25606 100755
@@ -5,62 +5,105 @@
 #
 # (c) 2002 Erik Andersen <[email protected]>
 
-# Set directories from arguments, or use defaults.
-targetdir=${1-.}
-patchdir=${2-../kernel-patches}
-shift 2
-patchpattern=${@-*}
+# function apply_patch patch_file
+# This function no more deals with directory case since it is managed
+# in an upper layer
+function apply_patch {
+apply="patch -p1 -E -d"
 
-if [ ! -d "${targetdir}" ] ; then
-    echo "Aborting.  '${targetdir}' is not a directory."
-    exit 1
+case "${1}" in
+*\.tar\.gz$|*\.tgz$|*\.tar\.bz$|*\.tar\.bz2$|*\.tbz$|*\.tbz2$)
+	echo "Error with ${1}";
+	echo "Archives into a directory or another archive is not supported";
+	return 1;
+	;;
+*\.gz$)
+	type="gzip"; uncomp="gunzip -dc"; ;;
+*\.bz$)
+	type="bzip"; uncomp="bunzip -dc"; ;;
+*\.bz2$)
+	type="bzip2"; uncomp="bunzip2 -dc"; ;;
+*\.zip$)
+	type="zip"; uncomp="unzip -d"; ;;
+*\.Z$)
+	type="compress"; uncomp="uncompress -c"; ;;
+*\.diff*)
+	type="diff"; uncomp="cat"; ;;
+*\.patch*)
+	type="patch"; uncomp="cat"; ;;
+*)
+	echo "Unsupported format file for ${1}, skip it";
+	return 0;
+	;;
+esac
+
+echo ""
+echo "Applying ${1} using ${type}: "
+echo ${1} | cat >> ${builddir}/.applied_patches_list
+${uncomp} ${1} | ${apply} ${builddir}
+if [ $? != 0 ] ; then
+	echo "Patch failed! Please fix ${1}!"
+	return 1
 fi
+}
+
+
+# Entry point
+builddir=${1}
+patchdir=${2}
+shift 2
+patchlist=${@}
+patchesdir="${builddir}/../$(basename $builddir)-patches"
+
+# Check directories
 if [ ! -d "${patchdir}" ] ; then
-    echo "Aborting.  '${patchdir}' is not a directory."
-    exit 1
+	echo "Aborting: ${patchdir} is not a directory."
+	exit 1
 fi
-    
-for i in `cd ${patchdir}; ls -d ${patchpattern} 2> /dev/null` ; do 
-    apply="patch -g0 -p1 -E -d"
-    uncomp_parm=""
-    if [ -d "${patchdir}/$i" ] ; then
-	type="directory overlay"
-	uncomp="tar cf - --exclude=.svn --no-anchored -C"
-	uncomp_parm="."
-	apply="tar xvf - -C"
-    else case "$i" in
-	*.gz)
-	type="gzip"; uncomp="gunzip -dc"; ;; 
-	*.bz)
-	type="bzip"; uncomp="bunzip -dc"; ;; 
-	*.bz2)
-	type="bzip2"; uncomp="bunzip2 -dc"; ;; 
-	*.zip)
-	type="zip"; uncomp="unzip -d"; ;; 
-	*.Z)
-	type="compress"; uncomp="uncompress -c"; ;; 
-	*.tgz)
-	type="tar gzip"; uncomp="gunzip -dc"; apply="tar xvf - -C"; ;; 
-	*.tar)
-	type="tar"; uncomp="cat"; apply="tar xvf - -C"; ;; 
-	*)
-	type="plaintext"; uncomp="cat"; ;; 
-    esac fi
-    echo ""
-    echo "Applying ${i} using ${type}: " 
-	echo ${i} | cat >> ${targetdir}/.applied_patches_list
-    ${uncomp} ${patchdir}/${i} ${uncomp_parm} | ${apply} ${targetdir} 
-    if [ $? != 0 ] ; then
-        echo "Patch failed!  Please fix $i!"
+if [ ! -d "${builddir}" ] ; then
+	echo "Aborting: ${builddir} is not a directory."
 	exit 1
-    fi
+fi
+
+# Parse patch list, extract archives, apply patches
+for i in $patchlist ; do
+	patch_path="${patchdir}/${i}"
+	# three cases: directory, archive, file patch (compressed or not)
+	# directory
+	if [ -d "${patch_path}" ] ; then
+		for p in $(ls ${patch_path}) ; do
+			apply_patch "${patch_path}/${p}" || exit 1
+		done
+	# archive
+	elif echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$|tar\.gz$|tgz$" ; then
+		mkdir "${patchesdir}"
+		# extract archive
+		if echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$" ; then
+			tar_options="-xjf"
+		else
+			tar_options="-xzf"
+		fi
+		tar -C ${patchesdir} --strip-components=1 ${tar_options} ${patch_path}
+		# apply patches from the archive
+		for p in $(find ${patchesdir} | sort) ; do
+			apply_patch "${p}" || { rm -rf "${patchesdir}" ; exit 1; }
+		done
+		rm -rf "${patchesdir}"
+	# file which is not an archive
+	else
+		# we can have regex into patch name as package*.patch.arm that's
+		# why using ls
+		for p in $(ls -d ${patch_path} 2> /dev/null) ; do
+			apply_patch "${p}" || exit 1
+		done
+	fi
 done
 
 # Check for rejects...
-if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+if [ "`find ${builddir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
     echo "Aborting.  Reject files found."
     exit 1
 fi
 
 # Remove backup files
-find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+find ${builddir}/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
Signature · 1 line
1.7.5.4
#16 lore raw

RFC PATCH v4 1/2 apply-patches.sh: script changed to support archives in a proper way

Quoted 7 lines · On Tuesday 10 January 2012 19:01:55 ludovic.desroches at atmel.com wrote:

From: Ludovic Desroches <[email protected]>

The previous script doesn't support patching order with archives since it didn't extract archives but simply decompressed file and piped the result to the patch command.
This new script extracts archives in a temporary folder and then applies patches.

You need to document the API changes clearly.

- Uncompressed patches must match *.diff* or *.patch*; else they are skipped.

- The defaults are removed; three or more arguments must be supplied.

- Behaviour of directories is changed: it is not considered an overlay, but rather a collection of patches.

Since these changes actually have nothing to do with supporting archives
in a proper way, I suggest you make separate patches for them.

Quoted 2 lines
Quoted 4 lines

Conflicts:

support/scripts/apply-patches.sh

Please remove this piece from the comment.

Quoted 10 lines
---
 support/scripts/apply-patches.sh |  135 +++++++++++++++++++++++++-------------
 1 files changed, 89 insertions(+), 46 deletions(-)
support/scripts/apply-patches.sh +0 -0
index 1aef47e..2a25606 100755
@@ -5,62 +5,105 @@
 #

support/scripts/apply-patches.sh line 10

Quoted 10 lines
support/scripts/apply-patches.sh +3 -5
 # (c) 2002 Erik Andersen <[email protected]>
 
-# Set directories from arguments, or use defaults.
-targetdir=${1-.}
-patchdir=${2-../kernel-patches}
-shift 2
-patchpattern=${@-*}
+# function apply_patch patch_file
+# This function no more deals with directory case since it is managed
+# in an upper layer

This comment isn't very helpful, since the reader can't see how it was before.
Actually, no comment is needed here (it's pretty obvious that it applies a single patch).

support/scripts/apply-patches.sh line 11

Quoted 1 line
support/scripts/apply-patches.sh +1 -0
+function apply_patch {

Please indent the body of the function. And preferably keep the same
whitespace convention as the original (4 spaces). That makes the diff smaller. Do feel free to get rid of the original's mixed tabs-and-spaces, though...

support/scripts/apply-patches.sh line 12

Quoted 1 line
support/scripts/apply-patches.sh +1 -0
+apply="patch -p1 -E -d"

Since apply is used only once it is no longer necessary to make it a variable.

Why did the -g0 option get dropped?

support/scripts/apply-patches.sh line 18

Quoted 8 lines
support/scripts/apply-patches.sh +5 -3
-if [ ! -d "${targetdir}" ] ; then
-    echo "Aborting.  '${targetdir}' is not a directory."
-    exit 1
+case "${1}" in
+*\.tar\.gz$|*\.tgz$|*\.tar\.bz$|*\.tar\.bz2$|*\.tbz$|*\.tbz2$)
+	echo "Error with ${1}";
+	echo "Archives into a directory or another archive is not supported";
+	return 1;

I think this piece is a bit redundant, but it doesn't hurt.

Quoted 14 lines
support/scripts/apply-patches.sh +14 -0
+	;;
+*\.gz$)
+	type="gzip"; uncomp="gunzip -dc"; ;;
+*\.bz$)
+	type="bzip"; uncomp="bunzip -dc"; ;;
+*\.bz2$)
+	type="bzip2"; uncomp="bunzip2 -dc"; ;;
+*\.zip$)
+	type="zip"; uncomp="unzip -d"; ;;
+*\.Z$)
+	type="compress"; uncomp="uncompress -c"; ;;
+*\.diff*)
+	type="diff"; uncomp="cat"; ;;
+*\.patch*)

support/scripts/apply-patches.sh line 42

Quoted 10 lines
support/scripts/apply-patches.sh +10 -0
+	type="patch"; uncomp="cat"; ;;
+*)
+	echo "Unsupported format file for ${1}, skip it";
+	return 0;
+	;;
+esac
+
+echo ""
+echo "Applying ${1} using ${type}: "
+echo ${1} | cat >> ${builddir}/.applied_patches_list

The 'cat' here is completely redundant AFAICS. (I realize this was
already present in the original.)

support/scripts/apply-patches.sh line 43

Quoted 1 line
support/scripts/apply-patches.sh +1 -0
+${uncomp} ${1} | ${apply} ${builddir}

If you use "$1" and "$builddir", you also support names with spaces and
other shell-interpreted stuff.

support/scripts/apply-patches.sh line 53

Quoted 10 lines
support/scripts/apply-patches.sh +9 -0
+if [ $? != 0 ] ; then
+	echo "Patch failed! Please fix ${1}!"
+	return 1
 fi
+}
+
+
+# Entry point
+builddir=${1}
+patchdir=${2}

Any particular reason why you renamed 'targetdir' to 'builddir'? Also,
keep this in the beginning of the file so the diff becomes clearer.

Again, quoting would be useful.

support/scripts/apply-patches.sh line 55

Quoted 2 lines
support/scripts/apply-patches.sh +2 -0
+shift 2
+patchlist=${@}

Note that $@ implies the quotes already, so they're not required here.

support/scripts/apply-patches.sh line 56

Quoted 1 line
support/scripts/apply-patches.sh +1 -0
+patchesdir="${builddir}/../$(basename $builddir)-patches"

I would make the patchesdir a subdirectory of the builddir, so it does
get cleaned up with a -dirclean. E.g. $builddir/.patches-$(basename $tarfile)-unpacked

support/scripts/apply-patches.sh line 61

Quoted 7 lines
support/scripts/apply-patches.sh +4 -2
+
+# Check directories
 if [ ! -d "${patchdir}" ] ; then
-    echo "Aborting.  '${patchdir}' is not a directory."
-    exit 1
+	echo "Aborting: ${patchdir} is not a directory."
+	exit 1

Preferably, don't modify things unnecessarily.

Quoted 42 lines
support/scripts/apply-patches.sh +6 -34
 fi
-    
-for i in `cd ${patchdir}; ls -d ${patchpattern} 2> /dev/null` ; do 
-    apply="patch -g0 -p1 -E -d"
-    uncomp_parm=""
-    if [ -d "${patchdir}/$i" ] ; then
-	type="directory overlay"
-	uncomp="tar cf - --exclude=.svn --no-anchored -C"
-	uncomp_parm="."
-	apply="tar xvf - -C"
-    else case "$i" in
-	*.gz)
-	type="gzip"; uncomp="gunzip -dc"; ;; 
-	*.bz)
-	type="bzip"; uncomp="bunzip -dc"; ;; 
-	*.bz2)
-	type="bzip2"; uncomp="bunzip2 -dc"; ;; 
-	*.zip)
-	type="zip"; uncomp="unzip -d"; ;; 
-	*.Z)
-	type="compress"; uncomp="uncompress -c"; ;; 
-	*.tgz)
-	type="tar gzip"; uncomp="gunzip -dc"; apply="tar xvf - -C"; ;; 
-	*.tar)
-	type="tar"; uncomp="cat"; apply="tar xvf - -C"; ;; 
-	*)
-	type="plaintext"; uncomp="cat"; ;; 
-    esac fi
-    echo ""
-    echo "Applying ${i} using ${type}: " 
-	echo ${i} | cat >> ${targetdir}/.applied_patches_list
-    ${uncomp} ${patchdir}/${i} ${uncomp_parm} | ${apply} ${targetdir} 
-    if [ $? != 0 ] ; then
-        echo "Patch failed!  Please fix $i!"
+if [ ! -d "${builddir}" ] ; then
+	echo "Aborting: ${builddir} is not a directory."
 	exit 1
-    fi
+fi
+
+# Parse patch list, extract archives, apply patches
+for i in $patchlist ; do

support/scripts/apply-patches.sh line 79

Quoted 10 lines
support/scripts/apply-patches.sh +10 -0
+	patch_path="${patchdir}/${i}"
+	# three cases: directory, archive, file patch (compressed or not)
+	# directory
+	if [ -d "${patch_path}" ] ; then
+		for p in $(ls ${patch_path}) ; do
+			apply_patch "${patch_path}/${p}" || exit 1
+		done
+	# archive
+	elif echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$|tar\.gz$|tgz$" ; then
+		mkdir "${patchesdir}"

Remove the patchesdir first, in case it got left behind by an interrupted
previous run.

support/scripts/apply-patches.sh line 86

Quoted 7 lines
support/scripts/apply-patches.sh +7 -0
+		# extract archive
+		if echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$" ; then
+			tar_options="-xjf"
+		else
+			tar_options="-xzf"
+		fi
+		tar -C ${patchesdir} --strip-components=1 ${tar_options} ${patch_path}

This will give problems on CentOS 5 IIRC - the issue with host-tar, which
ThomasDS solved recently.

Actually it is probably a better idea to handle the tar case in the
Makefiles...

support/scripts/apply-patches.sh line 91

Quoted 5 lines
support/scripts/apply-patches.sh +5 -0
+		# apply patches from the archive
+		for p in $(find ${patchesdir} | sort) ; do
+			apply_patch "${p}" || { rm -rf "${patchesdir}" ; exit 1; }
+		done
+		rm -rf "${patchesdir}"

I would not remove the patchesdir; makes it easier for a developer to read
and/or unapply the patches.

support/scripts/apply-patches.sh line 94

Quoted 3 lines
support/scripts/apply-patches.sh +3 -0
+	# file which is not an archive
+	else
+		# we can have regex into patch name as package*.patch.arm that's

Actually, it's not a regex but a glob pattern.

Quoted 8 lines
support/scripts/apply-patches.sh +5 -0
+		# why using ls
+		for p in $(ls -d ${patch_path} 2> /dev/null) ; do
+			apply_patch "${p}" || exit 1
+		done
+	fi
 done
 
 # Check for rejects...

support/scripts/apply-patches.sh

Quoted 10 lines
support/scripts/apply-patches.sh +2 -2
-if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+if [ "`find ${builddir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
     echo "Aborting.  Reject files found."
     exit 1
 fi
 
 # Remove backup files
-find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+find ${builddir}/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
 

Regards,
Arnout

Signature · 6 lines
Arnout Vandecappelle                               arnout at mind be
Senior Embedded Software Architect                 +32-16-286540
Essensium/Mind                                     http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium                BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
#17 lore raw

RFC PATCH v4 1/2 apply-patches.sh: script changed to support archives in a proper way

Hello Arnout,

Thanks for your comments, I will rework this patch and send a new one.

Regards

Ludovic

#18 lore raw

RFC PATCH v4 1/2 apply-patches.sh: script changed to support archives in a proper way

In reply to Arnout Vandecappelle

Hello Arnout,

First sorry for some mistakes, I wanted to quickly send this patch for the upstream version and I forgot to do some basic checks. I thought this file was only moved from toolchain/patch-kernel.sh to support/scripts/apply-patches.sh. It explains some errors as dropping -g0 option.

I wanted to send a new version but I am facing some issues in relation with your advices:

Quoted 9 lines · Arnout Vandecappelle
Quoted 7 lines · On Tuesday 10 January 2012 19:01:55 ludovic.desroches at atmel.com wrote:

From: Ludovic Desroches <[email protected]>

The previous script doesn't support patching order with archives since it didn't extract archives but simply decompressed file and piped the result to the patch command.
This new script extracts archives in a temporary folder and then applies patches.

Quoted 8 lines

You need to document the API changes clearly.

- Uncompressed patches must match *.diff* or *.patch*; else they are skipped.

- The defaults are removed; three or more arguments must be supplied.

- Behaviour of directories is changed: it is not considered an overlay, but rather a collection of patches.

Ok I will do it.

Quoted 3 lines

Since these changes actually have nothing to do with supporting archives
in a proper way, I suggest you make separate patches for them.

It is my main issue splitting the patch into archive management and the change of the behaviour of directories.
I may have to split we apply_patch function: one part to compute type, uncomp, etc. and one other for the command to apply the patch

Quoted 24 lines
Quoted 3 lines
Quoted 4 lines

Conflicts:

support/scripts/apply-patches.sh

Please remove this piece from the comment.

Quoted 12 lines
---
 support/scripts/apply-patches.sh |  135 +++++++++++++++++++++++++-------------
 1 files changed, 89 insertions(+), 46 deletions(-)
support/scripts/apply-patches.sh +0 -0
index 1aef47e..2a25606 100755
@@ -5,62 +5,105 @@
 #
 # (c) 2002 Erik Andersen <[email protected]>
 
Quoted 11 lines

support/scripts/apply-patches.sh line 10

Quoted 8 lines
support/scripts/apply-patches.sh +3 -5
-# Set directories from arguments, or use defaults.
-targetdir=${1-.}
-patchdir=${2-../kernel-patches}
-shift 2
-patchpattern=${@-*}
+# function apply_patch patch_file
+# This function no more deals with directory case since it is managed
+# in an upper layer

This comment isn't very helpful, since the reader can't see how it was before.
Actually, no comment is needed here (it's pretty obvious that it applies a single patch).

Yes you're right.

Quoted 11 lines

support/scripts/apply-patches.sh line 11

Quoted 2 lines
support/scripts/apply-patches.sh +1 -0
+function apply_patch {

Please indent the body of the function. And preferably keep the same
whitespace convention as the original (4 spaces). That makes the diff smaller. Do feel free to get rid of the original's mixed tabs-and-spaces, though...

support/scripts/apply-patches.sh line 12

Quoted 1 line
support/scripts/apply-patches.sh +1 -0
+apply="patch -p1 -E -d"

Since apply is used only once it is no longer necessary to make it a variable.

Why did the -g0 option get dropped?

As I told a mistake on my side...

Quoted 10 lines

support/scripts/apply-patches.sh line 18

Quoted 9 lines
support/scripts/apply-patches.sh +5 -3
-if [ ! -d "${targetdir}" ] ; then
-    echo "Aborting.  '${targetdir}' is not a directory."
-    exit 1
+case "${1}" in
+*\.tar\.gz$|*\.tgz$|*\.tar\.bz$|*\.tar\.bz2$|*\.tbz$|*\.tbz2$)
+	echo "Error with ${1}";
+	echo "Archives into a directory or another archive is not supported";
+	return 1;

I think this piece is a bit redundant, but it doesn't hurt.

I don't see why. If we have an archive here we will have the old behavior which can cause isssues when applying patches since the patch order may not be kept.

Quoted 19 lines
Quoted 19 lines
support/scripts/apply-patches.sh +18 -0
+	;;
+*\.gz$)
+	type="gzip"; uncomp="gunzip -dc"; ;;
+*\.bz$)
+	type="bzip"; uncomp="bunzip -dc"; ;;
+*\.bz2$)
+	type="bzip2"; uncomp="bunzip2 -dc"; ;;
+*\.zip$)
+	type="zip"; uncomp="unzip -d"; ;;
+*\.Z$)
+	type="compress"; uncomp="uncompress -c"; ;;
+*\.diff*)
+	type="diff"; uncomp="cat"; ;;
+*\.patch*)
+	type="patch"; uncomp="cat"; ;;
+*)
+	echo "Unsupported format file for ${1}, skip it";
+	return 0;
Quoted 8 lines

support/scripts/apply-patches.sh line 42

Quoted 6 lines
support/scripts/apply-patches.sh +6 -0
+	;;
+esac
+
+echo ""
+echo "Applying ${1} using ${type}: "
+echo ${1} | cat >> ${builddir}/.applied_patches_list

The 'cat' here is completely redundant AFAICS. (I realize this was
already present in the original.)

Yes I will remove it.

Quoted 5 lines

support/scripts/apply-patches.sh line 43

Quoted 2 lines
support/scripts/apply-patches.sh +1 -0
+${uncomp} ${1} | ${apply} ${builddir}

If you use "$1" and "$builddir", you also support names with spaces and
other shell-interpreted stuff.

Quoted 12 lines

support/scripts/apply-patches.sh line 53

Quoted 10 lines
support/scripts/apply-patches.sh +9 -0
+if [ $? != 0 ] ; then
+	echo "Patch failed! Please fix ${1}!"
+	return 1
 fi
+}
+
+
+# Entry point
+builddir=${1}
+patchdir=${2}

Any particular reason why you renamed 'targetdir' to 'builddir'? Also,
keep this in the beginning of the file so the diff becomes clearer.

I thought builddir was a better name since targetdir is not output/target as it can suggest. It can be a separated patch and maybe this change is not useful.

Quoted 2 lines

Again, quoting would be useful.

Ok.

Quoted 10 lines

support/scripts/apply-patches.sh line 55

Quoted 3 lines
support/scripts/apply-patches.sh +2 -0
+shift 2
+patchlist=${@}

Note that $@ implies the quotes already, so they're not required here.

support/scripts/apply-patches.sh line 56

Quoted 1 line
support/scripts/apply-patches.sh +1 -0
+patchesdir="${builddir}/../$(basename $builddir)-patches"

I would make the patchesdir a subdirectory of the builddir, so it does
get cleaned up with a -dirclean. E.g. $builddir/.patches-$(basename $tarfile)-unpacked

Good idea, thanks.

Quoted 55 lines

support/scripts/apply-patches.sh line 61

Quoted 7 lines
support/scripts/apply-patches.sh +4 -2
+
+# Check directories
 if [ ! -d "${patchdir}" ] ; then
-    echo "Aborting.  '${patchdir}' is not a directory."
-    exit 1
+	echo "Aborting: ${patchdir} is not a directory."
+	exit 1

Preferably, don't modify things unnecessarily.

Quoted 46 lines
support/scripts/apply-patches.sh +10 -34
 fi
-    
-for i in `cd ${patchdir}; ls -d ${patchpattern} 2> /dev/null` ; do 
-    apply="patch -g0 -p1 -E -d"
-    uncomp_parm=""
-    if [ -d "${patchdir}/$i" ] ; then
-	type="directory overlay"
-	uncomp="tar cf - --exclude=.svn --no-anchored -C"
-	uncomp_parm="."
-	apply="tar xvf - -C"
-    else case "$i" in
-	*.gz)
-	type="gzip"; uncomp="gunzip -dc"; ;; 
-	*.bz)
-	type="bzip"; uncomp="bunzip -dc"; ;; 
-	*.bz2)
-	type="bzip2"; uncomp="bunzip2 -dc"; ;; 
-	*.zip)
-	type="zip"; uncomp="unzip -d"; ;; 
-	*.Z)
-	type="compress"; uncomp="uncompress -c"; ;; 
-	*.tgz)
-	type="tar gzip"; uncomp="gunzip -dc"; apply="tar xvf - -C"; ;; 
-	*.tar)
-	type="tar"; uncomp="cat"; apply="tar xvf - -C"; ;; 
-	*)
-	type="plaintext"; uncomp="cat"; ;; 
-    esac fi
-    echo ""
-    echo "Applying ${i} using ${type}: " 
-	echo ${i} | cat >> ${targetdir}/.applied_patches_list
-    ${uncomp} ${patchdir}/${i} ${uncomp_parm} | ${apply} ${targetdir} 
-    if [ $? != 0 ] ; then
-        echo "Patch failed!  Please fix $i!"
+if [ ! -d "${builddir}" ] ; then
+	echo "Aborting: ${builddir} is not a directory."
 	exit 1
-    fi
+fi
+
+# Parse patch list, extract archives, apply patches
+for i in $patchlist ; do
+	patch_path="${patchdir}/${i}"
+	# three cases: directory, archive, file patch (compressed or not)
+	# directory
+	if [ -d "${patch_path}" ] ; then
Quoted 8 lines

support/scripts/apply-patches.sh line 79

Quoted 6 lines
support/scripts/apply-patches.sh +6 -0
+		for p in $(ls ${patch_path}) ; do
+			apply_patch "${patch_path}/${p}" || exit 1
+		done
+	# archive
+	elif echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$|tar\.gz$|tgz$" ; then
+		mkdir "${patchesdir}"

Remove the patchesdir first, in case it got left behind by an interrupted
previous run.

Thanks I forgot this case.

Quoted 10 lines

support/scripts/apply-patches.sh line 86

Quoted 8 lines
support/scripts/apply-patches.sh +7 -0
+		# extract archive
+		if echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$" ; then
+			tar_options="-xjf"
+		else
+			tar_options="-xzf"
+		fi
+		tar -C ${patchesdir} --strip-components=1 ${tar_options} ${patch_path}

This will give problems on CentOS 5 IIRC - the issue with host-tar, which
ThomasDS solved recently.

Ok I have to checked what is this issue and how it has been solved.

Quoted 3 lines

Actually it is probably a better idea to handle the tar case in the
Makefiles...

Isn't better here? It will involve changing many files, isn't it?

Quoted 8 lines

support/scripts/apply-patches.sh line 91

Quoted 6 lines
support/scripts/apply-patches.sh +5 -0
+		# apply patches from the archive
+		for p in $(find ${patchesdir} | sort) ; do
+			apply_patch "${p}" || { rm -rf "${patchesdir}" ; exit 1; }
+		done
+		rm -rf "${patchesdir}"

I would not remove the patchesdir; makes it easier for a developer to read
and/or unapply the patches.

Ok, why not.

Quoted 20 lines

support/scripts/apply-patches.sh line 94

Quoted 4 lines
support/scripts/apply-patches.sh +3 -0
+	# file which is not an archive
+	else
+		# we can have regex into patch name as package*.patch.arm that's

Actually, it's not a regex but a glob pattern.

Quoted 14 lines
support/scripts/apply-patches.sh +6 -1
+		# why using ls
+		for p in $(ls -d ${patch_path} 2> /dev/null) ; do
+			apply_patch "${p}" || exit 1
+		done
+	fi
 done
 
 # Check for rejects...
-if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+if [ "`find ${builddir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
     echo "Aborting.  Reject files found."
     exit 1
 fi
 
Quoted 16 lines

support/scripts/apply-patches.sh

Quoted 4 lines
support/scripts/apply-patches.sh +1 -1
 # Remove backup files
-find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+find ${builddir}/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
 

Regards,
Arnout

Signature · 6 lines
Arnout Vandecappelle                               arnout at mind be
Senior Embedded Software Architect                 +32-16-286540
Essensium/Mind                                     http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium                BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F

Thanks for your help.

Regards

Ludovic

#19 lore raw

RFC PATCH v4 1/2 apply-patches.sh: script changed to support archives in a proper way

Quoted 32 lines · On Sunday 29 January 2012 17:28:25 Ludovic Desroches wrote:

Hello Arnout,

First sorry for some mistakes, I wanted to quickly send this patch for the upstream version and I forgot to do some basic checks. I thought this file was only moved from toolchain/patch-kernel.sh to support/scripts/apply-patches.sh. It explains some errors as dropping -g0 option.

I wanted to send a new version but I am facing some issues in relation with your advices:

Quoted 9 lines · Arnout Vandecappelle
Quoted 7 lines · On Tuesday 10 January 2012 19:01:55 ludovic.desroches at atmel.com wrote:

From: Ludovic Desroches <[email protected]>

The previous script doesn't support patching order with archives since it didn't extract archives but simply decompressed file and piped the result to the patch command.
This new script extracts archives in a temporary folder and then applies patches.

Quoted 8 lines

You need to document the API changes clearly.

- Uncompressed patches must match *.diff* or *.patch*; else they are skipped.

- The defaults are removed; three or more arguments must be supplied.

- Behaviour of directories is changed: it is not considered an overlay, but rather a collection of patches.

Ok I will do it.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

Since these changes actually have nothing to do with supporting archives
in a proper way, I suggest you make separate patches for them.

It is my main issue splitting the patch into archive management and the change of the behaviour of directories.
I may have to split we apply_patch function: one part to compute type, uncomp, etc. and one other for the command to apply the patch

You misunderstand my point. You now have one patch (i.e. one git commit)
that fixes the support for patch archives. This patch also changes the API of apply-patches.sh. There may be good reasons for that - AFAICS currently the only way apply-patches.sh is used in existing buildroot packages, is for *.patch files. So it makes sense to simplify the script and remove the redundant features. However, such a thing should be done in a separate patch, with a separate git commit, so it is easier to trace back afterwards when the feature got removed. So you'd have a first patch that removes redundant features, and a second patch that fixes the support for archives.

[snip]

Quoted 10 lines
Quoted 9 lines

support/scripts/apply-patches.sh line 18

Quoted 8 lines
support/scripts/apply-patches.sh +5 -3
-if [ ! -d "${targetdir}" ] ; then
-    echo "Aborting.  '${targetdir}' is not a directory."
-    exit 1
+case "${1}" in
+*\.tar\.gz$|*\.tgz$|*\.tar\.bz$|*\.tar\.bz2$|*\.tbz$|*\.tbz2$)
+	echo "Error with ${1}";
+	echo "Archives into a directory or another archive is not supported";
+	return 1;

I think this piece is a bit redundant, but it doesn't hurt.

Quoted 3 lines

I don't see why. If we have an archive here we will have the old behavior which can cause isssues when applying patches since the patch order may not be kept.

You're right, my mistake, I had just considered the .tgz case, which
doesn't match any of the case branches and will fall into the default "Unsupported file format..." branch.

BTW, just noticed now: the \. is redundant. The case branches match
glob patterns, not regular expressions, so . isn't anything special. Same for the $.

[snip]

Quoted 9 lines
Quoted 5 lines

support/scripts/apply-patches.sh line 53

Quoted 3 lines
support/scripts/apply-patches.sh +3 -0
+# Entry point
+builddir=${1}
+patchdir=${2}

Any particular reason why you renamed 'targetdir' to 'builddir'? Also,
keep this in the beginning of the file so the diff becomes clearer.

I thought builddir was a better name since targetdir is not output/target as it can suggest. It can be a separated patch and maybe this change is not useful.

This could be part of that first cleanup patch.

[snip]

Quoted 9 lines
Quoted 9 lines

support/scripts/apply-patches.sh line 86

Quoted 7 lines
support/scripts/apply-patches.sh +7 -0
+		# extract archive
+		if echo $i | grep -q -E "tar\.bz$|tar\.bz2$|tbz$|tbz2$" ; then
+			tar_options="-xjf"
+		else
+			tar_options="-xzf"
+		fi
+		tar -C ${patchesdir} --strip-components=1 ${tar_options} ${patch_path}

This will give problems on CentOS 5 IIRC - the issue with host-tar, which
ThomasDS solved recently.

Actually, it's probably a good idea to export HOST_PATH from the Makefile.
This issue probably occurs in other places as well. But that's not for you to take care of, Ludovic.

Quoted 8 lines

Ok I have to checked what is this issue and how it has been solved.

Quoted 3 lines

Actually it is probably a better idea to handle the tar case in the
Makefiles...

Isn't better here? It will involve changing many files, isn't it?

You're right, I wasn't thinking.

[snip]

Regards,
Arnout

Signature · 6 lines
Arnout Vandecappelle                               arnout at mind be
Senior Embedded Software Architect                 +32-16-286540
Essensium/Mind                                     http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium                BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
#20 lore raw

RFC PATCH v4 2/2 apply-patches.sh check if they are rejects before applying patches

In reply to ludovic.desroches at atmel.com

From: Ludovic Desroches <[email protected]>

If we don't do it, the rejects' check at the end of the script can complain about rejects not deleted by the user from a previous try.

---
 support/scripts/apply-patches.sh |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
support/scripts/apply-patches.sh +7 -0
index 2a25606..a15b5c1 100755
@@ -64,6 +64,13 @@ if [ ! -d "${builddir}" ] ; then
 	echo "Aborting: ${builddir} is not a directory."
 	exit 1
 fi
+# check for rejects because if there are some, even if patches are well
+# applied, at the end it will complain about rejects into buildir
+if [ "`find ${builddir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+    echo "There are remaining rejecting file into ${buildir}, please delete them"
+    exit 1
+fi
+
 
 # Parse patch list, extract archives, apply patches
 for i in $patchlist ; do
Signature · 1 line
1.7.5.4
#21 lore raw

RFC PATCH v4 2/2 apply-patches.sh check if they are rejects before applying patches

Short commit message should be:
apply-patches.sh: check if there are rejects before applying patches

Quoted 6 lines · On Tuesday 10 January 2012 19:01:56 ludovic.desroches at atmel.com wrote:

From: Ludovic Desroches <[email protected]>

If we don't do it, the rejects' check at the end of the script can complain about rejects not deleted by the user from a previous try.

Since this patch is much more likely to go in on the short term, I would
reverse the order of the patches. That means: revert builddir to targetdir.

Quoted 9 lines
---
 support/scripts/apply-patches.sh |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
support/scripts/apply-patches.sh +0 -0
index 2a25606..a15b5c1 100755

support/scripts/apply-patches.sh if [ ! -d "${builddir}" ] ; then · line 70

Quoted 7 lines
support/scripts/apply-patches.sh +4 -0
@@ -64,6 +64,13 @@ if [ ! -d "${builddir}" ] ; then
 	echo "Aborting: ${builddir} is not a directory."
 	exit 1
 fi
+# check for rejects because if there are some, even if patches are well
+# applied, at the end it will complain about rejects into buildir
+if [ "`find ${builddir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+    echo "There are remaining rejecting file into ${buildir}, please delete them"

Should be:
echo "There are remaining reject files in '${buildir}', please delete them."

Otherwise, looks perfect.

Regards,
Arnout

Signature · 6 lines
Arnout Vandecappelle                               arnout at mind be
Senior Embedded Software Architect                 +32-16-286540
Essensium/Mind                                     http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium                BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
#22 lore raw

RFC PATCH v3 2/2 apply-patches.sh check if they are rejects before applying patches

In reply to ludovic.desroches at atmel.com

From: Ludovic Desroches <[email protected]>

If we don't do it, the rejects' check at the end of the script can complain about rejects not deleted by the user from a previous try.

---
 support/scripts/apply-patches.sh |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
support/scripts/apply-patches.sh +7 -0
index 0492e01..4dafacb 100755
@@ -63,6 +63,13 @@ if [ ! -d "${builddir}" ] ; then
 	echo "Aborting: ${builddir} is not a directory."
 	exit 1
 fi
+# check for rejects because if there are some, even if patches are well
+# applied, at the end it will complain about rejects into buildir
+if [ "`find ${builddir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+    echo "There are remaining rejecting file into ${buildir}, please delete them"
+    exit 1
+fi
+
 
 # parse patch list, extract archives, apply patches
 for i in $patchlist ; do
Signature · 1 line
1.7.5.4