source: freewrt/scripts/update-patches@ fdd4f59

freewrt_1_0 freewrt_2_0
Last change on this file since fdd4f59 was f266cab, checked in by Thorsten Glaser <tg@…>, 19 years ago

if ${WRKSRC}/.patched-newfiles was not created by the
prepare target of the original extraction (i.e. the
pre-existing diffs did not patch any new files into
existence), quell generation of patch files for files
which exist in ${WRKSRC} but do not exist in the
distfile

this quells creation of stuff like patch-deflate_o
in zlib after running a compile (although there are
still fallouts: patch-Makefile and patch-zconf_h,
which will only be not generated if WRKBUILD!=WRKSRC)

new policy (from OpenBSD ports): do not patch any
files into existence, use the ./extra facility instead.

git-svn-id: svn://www.freewrt.org/trunk/freewrt@410 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 5.0 KB
Line 
1#!/usr/bin/env bash
2# $FreeWRT$
3# $MirOS: ports/infrastructure/scripts/update-patches,v 1.5 2006/06/15 19:18:43 tg Exp $
4#-
5# Copyright (c) 2006
6# Thorsten Glaser <tg@freewrt.org>
7#
8# Derived from the MirPorts Framework "update-patches" script:
9#
10# Copyright (c) 2003, 2004, 2005
11# Thorsten "mirabile" Glaser <tg@MirBSD.de>
12# Based upon code and idea (c) 2000
13# Marc Espie for the OpenBSD project. All rights reserved.
14#
15# Licensee is hereby permitted to deal in this work without restric-
16# tion, including unlimited rights to use, publicly perform, modify,
17# merge, distribute, sell, give away or sublicence, provided all co-
18# pyright notices above, these terms and the disclaimer are retained
19# in all redistributions or reproduced in accompanying documentation
20# or other materials provided with binary redistributions.
21#
22# Licensor offers the work "AS IS" and WITHOUT WARRANTY of any kind,
23# express, or implied, to the maximum extent permitted by applicable
24# law, without malicious intent or gross negligence; in no event may
25# licensor, an author or contributor be held liable for any indirect
26# or other damage, or direct damage except proven a consequence of a
27# direct error of said person and intended use of this work, loss or
28# other issues arising in any way out of its use, even if advised of
29# the possibility of such damage or existence of a nontrivial bug.
30
31shopt -s extglob
32
33do_diff()
34{
35 local f1=$2/$1
36 local f2=$3/$1
37
38 if [[ ! -e $f1 ]]; then
39 if [[ ! -s $f2 ]]; then
40 cat <<EOF
41--- $f1 (non-existant)
42+++ $f2 (empty)
43@@ -0,0 +0,0 @@
44EOF
45 return 0
46 fi
47 touch -t 197001010000.00 "$f1"
48 fi
49 diff -adup "$f1" "$f2"
50 return $?
51}
52
53TRANSFORM='sed s/[.+]/\\\\&/g'
54PATCHDIR=$CURDIR/patches
55EXTRADIR=$CURDIR/extra
56
57mkdir -p $PATCHDIR
58
59SUBDIST=${WRKDIST##${WRKDIR1}?(/)}
60if [[ -n $SUBDIST ]]; then
61 mv ${WRKDIR1}.orig/${SUBDIST} ${WRKDIR1}/${SUBDIST}.orig
62 D_BASE=${WRKDIR1}
63 D_SUB=${SUBDIST}
64 D_CMP=$D_SUB
65else
66 # WRKSRC == WRKDIR
67 D_BASE=$(dirname ${WRKDIR1})
68 D_SUB=$(basename ${WRKDIR1})
69 D_CMP=
70fi
71ORGDIST=${D_BASE}/${D_SUB}.orig
72
73[[ -d $EXTRADIR ]] && \
74 (cd $EXTRADIR; find . -print0) | \
75 (cd $WRKDIST; pax -rw -0 -d $ORGDIST/) >/dev/null 2>&1
76
77if [[ -e $WRKDIST/.patched-newfiles ]]; then
78 touch $ORGDIST/.patched-newfiles
79 patch_newfiles=1
80else
81 patch_newfiles=0
82fi
83
84DIFF_FLAGS="-adu -I \"^--- $(echo $D_SUB.orig/ | $TRANSFORM)@@ .*\""
85DIFF_FLAGS="$DIFF_FLAGS -I \"^\+\+\+ $(echo $D_SUB/ | $TRANSFORM)@@ .*\""
86
87for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do
88 [[ ! -e $ORGDIST/$file && $patch_newfiles = 0 ]] && continue
89 cmp -s "$ORGDIST/$file" "$WRKDIST/$file" && continue
90 echo "Processing ${file}..." >&2
91 # look in patchdir for an existing patchfile matching this
92 cd $PATCHDIR
93 for i in $PATCH_LIST; do
94 # Ignore non-files, or old backup
95 [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue
96
97 # Patch found. Is this the one?
98 if grep "^[+-][+-][+-] $D_CMP[^/]*/$file " "$i" >/dev/null; then
99 # Multiple files in the diff?
100 if [ $(grep -c "^--- $D_CMP" "$i") -gt 1 -o \
101 $(grep -c "^\+\+\+ $D_CMP" "$i") -gt 1 ]; then
102 echo "Cannot process, $i contains patches" >&2
103 echo "to multiple files! Aborting." >&2
104 echo FAIL
105 [[ -n $SUBDIST ]] && mv \
106 ${WRKDIR1}/${SUBDIST}.orig \
107 ${WRKDIR1}.orig/${SUBDIST}
108 exit 0
109 fi
110 # Multiple diffs with this file?
111 let n=0
112 pflst=
113 for j in $PATCH_LIST; do
114 [[ ! -f $j || $j = *@(.orig|.rej|~) ]] && \
115 continue
116 grep "^[+-][+-][+-] $D_CMP[^/]*/$file " \
117 "$j" >/dev/null || continue
118 let n++
119 pflst="$pflst '$j'"
120 done
121 if (( n != 1 )); then
122 echo "Cannot process, file $file" >&2
123 echo "is contained in multiple patches:" >&2
124 echo "$pflst" >&2
125 echo FAIL
126 [[ -n $SUBDIST ]] && mv \
127 ${WRKDIR1}/${SUBDIST}.orig \
128 ${WRKDIR1}.orig/${SUBDIST}
129 exit 0
130 fi
131 # No, process this patch
132
133 accounted="$accounted $i"
134 # found it, copy preamble before comparision
135 ( sed -e "/^--- /,\$d" <$i; \
136 cd $D_BASE && do_diff "$file" "$D_SUB.orig" "$D_SUB" \
137 ) >"$i.new"
138 # did it change ? mark it as changed
139 tfile="$(echo "$file" | $TRANSFORM)"
140 if eval diff "$(echo "${DIFF_FLAGS}" \
141 | sed "s#@@#${tfile}#g")" \
142 "$i" "$i.new" 1>&2; then
143 rm "$i.new"
144 else
145 echo "Patch $i for $file updated" >&2
146 mv "$i" "$i.orig"
147 mv "$i.new" "$i"
148 edit="$edit $i"
149 fi
150 continue 2
151 fi
152 done
153
154 # Build a sensible name for the new patch file
155 patchname=patch-$(echo "$file" | sed -e 's#[/. ]#_#g')
156 echo "No patch-* found for $file, creating $patchname" >&2
157 ( echo '$Free''WRT$'; \
158 cd $D_BASE && do_diff "$file" "$D_SUB.orig" "$D_SUB" \
159 ) >$patchname
160 edit="$edit $patchname"
161 accounted="$accounted $patchname"
162done
163
164# Verify all patches accounted for
165cd $PATCHDIR
166for i in *; do
167 [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue
168 grep '^\\ No newline at end of file' $i >/dev/null \
169 && echo "*** Patch $i needs manual intervention" >&2
170 [[ $accounted != *@($i)* ]] \
171 && echo "*** Patch $i not accounted for" >&2
172done
173
174echo $edit
175[[ -n $SUBDIST ]] && mv ${WRKDIR1}/${SUBDIST}.orig ${WRKDIR1}.orig/${SUBDIST}
176exit 0
Note: See TracBrowser for help on using the repository browser.