Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michael S. Zick <minimod@morethan.org>
To: buildroot@busybox.net
Subject: [Buildroot] [RFC PATCH v2 1/1] kernel-patch.sh: script changed to support archives in a proper way
Date: Wed, 29 Jun 2011 05:42:24 -0500	[thread overview]
Message-ID: <201106290542.26383.minimod@morethan.org> (raw)
In-Reply-To: <8ff3fd34b12e4bb70ad95bcb8a026b1f31980d8a.1309333591.git.ludovic.desroches@atmel.com>

On Wed June 29 2011, ludovic.desroches at atmel.com wrote:
> From: Ludovic Desroches <ludovic.desroches@atmel.com>
> 
> 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.
> 
> Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
> ---
>  toolchain/patch-kernel.sh |  154 +++++++++++++++++++++++++++++----------------
>  1 files changed, 100 insertions(+), 54 deletions(-)
> 
> diff --git a/toolchain/patch-kernel.sh b/toolchain/patch-kernel.sh
> index 76cb9f7..408a9a7 100755
> --- a/toolchain/patch-kernel.sh
> +++ b/toolchain/patch-kernel.sh
> @@ -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 <andersen@codepoet.org>
> +#!/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
>

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
> -# 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 {} \;
> +

  reply	other threads:[~2011-06-29 10:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-07  9:32 [Buildroot] Patching method Ludovic Desroches
2011-05-18 10:10 ` [Buildroot] [PATCH 1/1] kernel-patch.sh: script changed to support archives in a proper way Ludovic Desroches
     [not found]   ` <4DDBBB89.2020301@atmel.com>
2011-05-24 14:25     ` Peter Korsgaard
2011-05-24 14:50       ` Thomas Petazzoni
2011-06-29  9:12   ` [Buildroot] [RFC PATCH v2]kernel-patch.sh: " ludovic.desroches at atmel.com
2011-06-29  9:12     ` [Buildroot] [RFC PATCH v2 1/1] kernel-patch.sh: " ludovic.desroches at atmel.com
2011-06-29 10:42       ` Michael S. Zick [this message]
2011-06-29 13:21         ` Ludovic Desroches
2012-01-06 12:47         ` [Buildroot] [RFC PATCH v3]kernel-patch.sh: " ludovic.desroches at atmel.com
2012-01-06 12:47           ` [Buildroot] [RFC PATCH v3 1/2] apply-patches.sh: " ludovic.desroches at atmel.com
2012-01-09  9:45             ` Thomas De Schampheleire
2012-01-10 10:31               ` Ludovic Desroches
2012-01-10 11:46                 ` Thomas De Schampheleire
2012-01-10 18:01                   ` [Buildroot] [RFC PATCH v4]kernel-patch.sh: " ludovic.desroches at atmel.com
2012-01-10 18:01                     ` [Buildroot] [RFC PATCH v4 1/2] apply-patches.sh: " ludovic.desroches at atmel.com
2012-01-19 22:21                       ` Arnout Vandecappelle
2012-01-23  8:22                         ` Ludovic Desroches
2012-01-29 16:28                         ` Ludovic Desroches
2012-01-31  6:59                           ` Arnout Vandecappelle
2012-01-10 18:01                     ` [Buildroot] [RFC PATCH v4 2/2] apply-patches.sh check if they are rejects before applying patches ludovic.desroches at atmel.com
2012-01-19 22:26                       ` Arnout Vandecappelle
2012-01-06 12:47           ` [Buildroot] [RFC PATCH v3 " ludovic.desroches at atmel.com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201106290542.26383.minimod@morethan.org \
    --to=minimod@morethan.org \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox