author | prappo |
Thu, 01 Feb 2018 16:12:28 +0000 | |
branch | http-client-branch |
changeset 56064 | 255e21e86b99 |
parent 47217 | 72e3ae9a25eb |
permissions | -rw-r--r-- |
47217 | 1 |
#!/bin/bash |
25854 | 2 |
# |
47217 | 3 |
# Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. |
25854 | 4 |
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 |
# |
|
6 |
# This code is free software; you can redistribute it and/or modify it |
|
7 |
# under the terms of the GNU General Public License version 2 only, as |
|
8 |
# published by the Free Software Foundation. |
|
9 |
# |
|
10 |
# This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
# version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
# accompanied this code). |
|
15 |
# |
|
16 |
# You should have received a copy of the GNU General Public License version |
|
17 |
# 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
# |
|
20 |
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 |
# or visit www.oracle.com if you need additional information or have any |
|
22 |
# questions. |
|
23 |
# |
|
24 |
||
25 |
# Script for updating a patch file as per the shuffled/unshuffled source location. |
|
26 |
||
27 |
usage() { |
|
47217 | 28 |
echo "Usage: $0 [-h|--help] [-v|--verbose] [-to9|-to10] [-r <repo>] <input_patch> <output_patch>" |
29 |
echo "where:" |
|
30 |
echo " -to9 create patches appropriate for a JDK 9 source tree" |
|
31 |
echo " When going to 9, the output patches will be suffixed with the" |
|
32 |
echo " repo name" |
|
33 |
echo " -to10 create patches appropriate for a JDK 10 source tree" |
|
34 |
echo " -r <repo> specify repo for source patch, set to 'top' for top repo" |
|
35 |
echo " <input_patch> is the input patch file, that needs shuffling/unshuffling" |
|
36 |
echo " <output_patch> is the updated patch file " |
|
37 |
echo " " |
|
38 |
exit 1 |
|
25854 | 39 |
} |
40 |
||
26674
b002f9eb2b5e
8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents:
25854
diff
changeset
|
41 |
SCRIPT_DIR=`dirname $0` |
25854 | 42 |
UNSHUFFLE_LIST=$SCRIPT_DIR"/unshuffle_list.txt" |
43 |
||
44 |
if [ ! -f "$UNSHUFFLE_LIST" ] ; then |
|
26674
b002f9eb2b5e
8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents:
25854
diff
changeset
|
45 |
echo "FATAL: cannot find $UNSHUFFLE_LIST" >&2 |
25854 | 46 |
exit 1 |
47 |
fi |
|
48 |
||
49 |
vflag="false" |
|
50 |
while [ $# -gt 0 ] |
|
51 |
do |
|
52 |
case $1 in |
|
53 |
-h | --help ) |
|
54 |
usage |
|
55 |
;; |
|
56 |
||
57 |
-v | --verbose ) |
|
58 |
vflag="true" |
|
59 |
;; |
|
60 |
||
47217 | 61 |
-r) |
62 |
repo="$2" |
|
63 |
shift |
|
64 |
;; |
|
65 |
||
66 |
-to9) |
|
67 |
shuffle_to=9 |
|
68 |
;; |
|
69 |
||
70 |
-to10) |
|
71 |
shuffle_to=10 |
|
72 |
;; |
|
73 |
||
25854 | 74 |
-*) # bad option |
75 |
usage |
|
76 |
;; |
|
77 |
||
47217 | 78 |
* ) # non option |
25854 | 79 |
break |
80 |
;; |
|
81 |
esac |
|
82 |
shift |
|
83 |
done |
|
84 |
||
85 |
# Make sure we have the right number of arguments |
|
47217 | 86 |
if [ ! $# -eq 2 ] ; then |
26674
b002f9eb2b5e
8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents:
25854
diff
changeset
|
87 |
echo "ERROR: Invalid number of arguments." >&2 |
25854 | 88 |
usage |
89 |
fi |
|
90 |
||
91 |
# Check the given repo |
|
47217 | 92 |
repos="top corba jaxp jaxws jdk langtools nashorn hotspot" |
25854 | 93 |
found="false" |
47217 | 94 |
if [ -n "$repo" ]; then |
95 |
for r in $repos ; do |
|
96 |
if [ $repo = "$r" ] ; then |
|
97 |
found="true" |
|
98 |
break; |
|
99 |
fi |
|
100 |
done |
|
101 |
if [ $found = "false" ] ; then |
|
102 |
echo "ERROR: Unknown repo: $repo. Should be one of [$repos]." >&2 |
|
103 |
usage |
|
27595
cff167b3bfa2
8065914: Various improvements and cleanup of build system
ihse
parents:
26674
diff
changeset
|
104 |
fi |
47217 | 105 |
fi |
106 |
||
107 |
if [ "$shuffle_to" != "9" -a "$shuffle_to" != "10" ]; then |
|
108 |
echo "ERROR: Must pick either -to9 or -to10" |
|
109 |
exit 1 |
|
110 |
fi |
|
111 |
||
112 |
# When going to 10, a repo must be specified for the source patch |
|
113 |
if [ "$shuffle_to" = "10" -a -z "$repo" ]; then |
|
114 |
echo "ERROR: Must specify src repo for JDK 9 patch" |
|
115 |
exit 1 |
|
25854 | 116 |
fi |
117 |
||
118 |
# Check given input/output files |
|
47217 | 119 |
input="$1" |
26674
b002f9eb2b5e
8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents:
25854
diff
changeset
|
120 |
if [ "x$input" = "x-" ] ; then |
b002f9eb2b5e
8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents:
25854
diff
changeset
|
121 |
input="/dev/stdin" |
b002f9eb2b5e
8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents:
25854
diff
changeset
|
122 |
fi |
25854 | 123 |
|
26674
b002f9eb2b5e
8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents:
25854
diff
changeset
|
124 |
if [ ! -f $input -a "x$input" != "x/dev/stdin" ] ; then |
b002f9eb2b5e
8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents:
25854
diff
changeset
|
125 |
echo "ERROR: Cannot find input patch file: $input" >&2 |
25854 | 126 |
exit 1 |
127 |
fi |
|
128 |
||
47217 | 129 |
output="$2" |
26674
b002f9eb2b5e
8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents:
25854
diff
changeset
|
130 |
if [ "x$output" = "x-" ] ; then |
b002f9eb2b5e
8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents:
25854
diff
changeset
|
131 |
output="/dev/stdout" |
b002f9eb2b5e
8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents:
25854
diff
changeset
|
132 |
fi |
47217 | 133 |
base_output="$output" |
26674
b002f9eb2b5e
8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents:
25854
diff
changeset
|
134 |
|
47217 | 135 |
if [ "$shuffle_to" = "10" ]; then |
136 |
if [ -f $output -a "x$output" != "x/dev/stdout" ] ; then |
|
137 |
echo "ERROR: Output patch already exists: $output" >&2 |
|
138 |
exit 1 |
|
139 |
fi |
|
140 |
else |
|
141 |
for r in $repos; do |
|
142 |
if [ -f "$output.$r" ]; then |
|
143 |
echo "ERROR: Output patch already exists: $output.$r" >&2 |
|
144 |
exit 1 |
|
145 |
fi |
|
146 |
done |
|
25854 | 147 |
fi |
148 |
||
149 |
verbose() { |
|
150 |
if [ ${vflag} = "true" ] ; then |
|
26674
b002f9eb2b5e
8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents:
25854
diff
changeset
|
151 |
echo "$@" >&2 |
25854 | 152 |
fi |
153 |
} |
|
154 |
||
155 |
unshuffle() { |
|
156 |
line=$@ |
|
157 |
verbose "Attempting to rewrite: \"$line\"" |
|
158 |
||
159 |
# Retrieve the file name |
|
160 |
path= |
|
161 |
if echo "$line" | egrep '^diff' > /dev/null ; then |
|
162 |
if ! echo "$line" | egrep '\-\-git' > /dev/null ; then |
|
26674
b002f9eb2b5e
8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents:
25854
diff
changeset
|
163 |
echo "ERROR: Only git patches supported. Please use 'hg export --git ...'." >&2 |
25854 | 164 |
exit 1 |
165 |
fi |
|
166 |
path="`echo "$line" | sed -e s@'diff --git a/'@@ -e s@' b/.*$'@@`" |
|
167 |
elif echo "$line" | egrep '^\-\-\-' > /dev/null ; then |
|
168 |
path="`echo "$line" | sed -e s@'--- a/'@@`" |
|
169 |
elif echo "$line" | egrep '^\+\+\+' > /dev/null ; then |
|
170 |
path="`echo "$line" | sed s@'+++ b/'@@`" |
|
171 |
fi |
|
172 |
verbose "Extracted path: \"$path\"" |
|
173 |
||
174 |
# Find the most specific matches in the shuffle list |
|
175 |
matches= |
|
47217 | 176 |
if [ -n "$repo" -a "$repo" != "top" ]; then |
177 |
matchpath="$repo"/"$path"/x |
|
178 |
else |
|
179 |
matchpath="$path"/x |
|
180 |
fi |
|
25854 | 181 |
while [ "$matchpath" != "" ] ; do |
182 |
matchpath="`echo $matchpath | sed s@'\(.*\)/.*$'@'\1'@`" |
|
183 |
||
47217 | 184 |
if [ "$shuffle_to" = "10" ] ; then |
25854 | 185 |
pattern=": $matchpath$" |
186 |
else |
|
187 |
pattern="^$matchpath :" |
|
188 |
fi |
|
189 |
verbose "Attempting to find \"$matchpath\"" |
|
190 |
matches=`egrep "$pattern" "$UNSHUFFLE_LIST"` |
|
191 |
if ! [ "x${matches}" = "x" ] ; then |
|
192 |
verbose "Got matches: [$matches]" |
|
193 |
break; |
|
194 |
fi |
|
195 |
||
196 |
if ! echo "$matchpath" | egrep '.*/.*' > /dev/null ; then |
|
197 |
break; |
|
198 |
fi |
|
199 |
done |
|
200 |
||
201 |
# Rewrite the line, if we have a match |
|
202 |
if ! [ "x${matches}" = "x" ] ; then |
|
47217 | 203 |
shuffled="${matches%% : *}" |
204 |
unshuffled="${matches#* : }" |
|
205 |
patch_suffix_9="" |
|
206 |
for r in $repos; do |
|
207 |
if [ "$unshuffled" != "${unshuffled#$r}" ]; then |
|
208 |
unshuffled="${unshuffled#$r\/}" |
|
209 |
patch_suffix_9=".$r" |
|
210 |
fi |
|
211 |
done |
|
212 |
verbose "shuffled: $shuffled" |
|
213 |
verbose "unshuffled: $unshuffled" |
|
214 |
verbose "patch_suffix_9: $patch_suffix_9" |
|
215 |
if [ "$shuffle_to" = "10" ] ; then |
|
25854 | 216 |
newline="`echo "$line" | sed -e s@"$unshuffled"@"$shuffled"@g`" |
217 |
else |
|
218 |
newline="`echo "$line" | sed -e s@"$shuffled"@"$unshuffled"@g`" |
|
47217 | 219 |
output=$base_output$patch_suffix_9 |
220 |
verbose "Writing to $output" |
|
25854 | 221 |
fi |
222 |
verbose "Rewriting to \"$newline\"" |
|
223 |
echo "$newline" >> $output |
|
224 |
else |
|
225 |
echo "WARNING: no match found for $path" |
|
226 |
echo "$line" >> $output |
|
227 |
fi |
|
228 |
} |
|
229 |
||
230 |
while IFS= read -r line |
|
231 |
do |
|
232 |
if echo "$line" | egrep '^diff|^\-\-\-|^\+\+\+' > /dev/null ; then |
|
233 |
unshuffle "$line" |
|
234 |
else |
|
235 |
printf "%s\n" "$line" >> $output |
|
236 |
fi |
|
237 |
done < "$input" |