1#!/bin/sh 2# 3# Copyright (C) 2010 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18# Script used to patch a source directory from a series of patches 19# located under a directory hierarchy 20 21. `dirname $0`/prebuilt-common.sh 22 23PROGRAM_PARAMETERS="<src-dir> <patches-dir>" 24PROGRAM_DESCRIPTION=\ 25"Patch a target source directory with a series of patches taken 26from another directory hierarchy. The idea is that anything that 27is found under <patches-dir>/subdir/foo.patch will be applied with 28'patch -p1' in <src-dir>/subdir. 29 30Patches are applied in the order they are found by 'find'." 31 32parse_parameters () 33{ 34 SRC_DIR=$1 35 if [ -z "$SRC_DIR" ] ; then 36 echo "ERROR: Missing source directory. See --help for usage." 37 exit 1 38 fi 39 40 if [ ! -d "$SRC_DIR" ] ; then 41 echo "ERROR: Invalid target source directory: $SRC_DIR" 42 exit 1 43 fi 44 45 PATCHES_DIR=$2 46 if [ -z "$PATCHES_DIR" ] ; then 47 echo "ERROR: Missing patches directory. See --help for usage." 48 exit 1 49 fi 50 51 if [ ! -d "$PATCHES_DIR" ] ; then 52 echo "ERROR: Invalid patches directory: $PATCHES_DIR" 53 exit 1 54 fi 55} 56 57extract_parameters "$@" 58parse_parameters $PARAMETERS 59 60PATCHES=`(cd $PATCHES_DIR && find . -name "*.patch" | sort ) 2> /dev/null` 61if [ -z "$PATCHES" ] ; then 62 log "No patches files in $PATCHES_DIR" 63 exit 0 64fi 65PATCHES=`echo $PATCHES | sed -e s%^\./%%g` 66for PATCH in $PATCHES; do 67 PATCHDIR=`dirname $PATCH` 68 PATCHNAME=`basename $PATCH` 69 log "Applying $PATCHNAME into $SRC_DIR/$PATCHDIR" 70 cd $SRC_DIR/$PATCHDIR && patch -p1 < $PATCHES_DIR/$PATCH 71 fail_panic "Patch failure with $PATCHES_DIR/$PATCH!! !! Please check your patches directory!" 72done 73 74dump "Done!" 75