1 #!/bin/sh |
1 #!/bin/bash |
2 # |
2 # |
3 # Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
3 # Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. |
4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 # |
5 # |
6 # This code is free software; you can redistribute it and/or modify it |
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 |
7 # under the terms of the GNU General Public License version 2 only, as |
8 # published by the Free Software Foundation. |
8 # published by the Free Software Foundation. |
23 # |
23 # |
24 |
24 |
25 # Script for updating a patch file as per the shuffled/unshuffled source location. |
25 # Script for updating a patch file as per the shuffled/unshuffled source location. |
26 |
26 |
27 usage() { |
27 usage() { |
28 echo "Usage: $0 [-h|--help] [-v|--verbose] <repo> <input_patch> <output_patch>" |
28 echo "Usage: $0 [-h|--help] [-v|--verbose] [-to9|-to10] [-r <repo>] <input_patch> <output_patch>" |
29 echo "where:" |
29 echo "where:" |
30 echo " <repo> is one of: corba, jaxp, jaxws, jdk, langtools, nashorn" |
30 echo " -to9 create patches appropriate for a JDK 9 source tree" |
31 echo " [Note: patches from other repos do not need updating]" |
31 echo " When going to 9, the output patches will be suffixed with the" |
32 echo " <input_patch> is the input patch file, that needs shuffling/unshuffling" |
32 echo " repo name" |
33 echo " <output_patch> is the updated patch file " |
33 echo " -to10 create patches appropriate for a JDK 10 source tree" |
34 echo " " |
34 echo " -r <repo> specify repo for source patch, set to 'top' for top repo" |
35 exit 1 |
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 |
36 } |
39 } |
37 |
40 |
38 SCRIPT_DIR=`dirname $0` |
41 SCRIPT_DIR=`dirname $0` |
39 UNSHUFFLE_LIST=$SCRIPT_DIR"/unshuffle_list.txt" |
42 UNSHUFFLE_LIST=$SCRIPT_DIR"/unshuffle_list.txt" |
40 |
43 |
53 |
56 |
54 -v | --verbose ) |
57 -v | --verbose ) |
55 vflag="true" |
58 vflag="true" |
56 ;; |
59 ;; |
57 |
60 |
|
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 |
58 -*) # bad option |
74 -*) # bad option |
59 usage |
75 usage |
60 ;; |
76 ;; |
61 |
77 |
62 * ) # non option |
78 * ) # non option |
63 break |
79 break |
64 ;; |
80 ;; |
65 esac |
81 esac |
66 shift |
82 shift |
67 done |
83 done |
68 |
84 |
69 # Make sure we have the right number of arguments |
85 # Make sure we have the right number of arguments |
70 if [ ! $# -eq 3 ] ; then |
86 if [ ! $# -eq 2 ] ; then |
71 echo "ERROR: Invalid number of arguments." >&2 |
87 echo "ERROR: Invalid number of arguments." >&2 |
72 usage |
88 usage |
73 fi |
89 fi |
74 |
90 |
75 # Check the given repo |
91 # Check the given repo |
76 repos="corba jaxp jaxws jdk langtools nashorn" |
92 repos="top corba jaxp jaxws jdk langtools nashorn hotspot" |
77 repo="$1" |
|
78 found="false" |
93 found="false" |
79 for r in $repos ; do |
94 if [ -n "$repo" ]; then |
80 if [ $repo = "$r" ] ; then |
95 for r in $repos ; do |
81 found="true" |
96 if [ $repo = "$r" ] ; then |
82 break; |
97 found="true" |
83 fi |
98 break; |
84 done |
99 fi |
85 if [ $found = "false" ] ; then |
100 done |
86 echo "ERROR: Unknown repo: $repo. Should be one of [$repos]." >&2 |
101 if [ $found = "false" ] ; then |
87 usage |
102 echo "ERROR: Unknown repo: $repo. Should be one of [$repos]." >&2 |
|
103 usage |
|
104 fi |
|
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 |
88 fi |
116 fi |
89 |
117 |
90 # Check given input/output files |
118 # Check given input/output files |
91 input="$2" |
119 input="$1" |
92 if [ "x$input" = "x-" ] ; then |
120 if [ "x$input" = "x-" ] ; then |
93 input="/dev/stdin" |
121 input="/dev/stdin" |
94 fi |
122 fi |
95 |
123 |
96 if [ ! -f $input -a "x$input" != "x/dev/stdin" ] ; then |
124 if [ ! -f $input -a "x$input" != "x/dev/stdin" ] ; then |
97 echo "ERROR: Cannot find input patch file: $input" >&2 |
125 echo "ERROR: Cannot find input patch file: $input" >&2 |
98 exit 1 |
126 exit 1 |
99 fi |
127 fi |
100 |
128 |
101 output="$3" |
129 output="$2" |
102 if [ "x$output" = "x-" ] ; then |
130 if [ "x$output" = "x-" ] ; then |
103 output="/dev/stdout" |
131 output="/dev/stdout" |
104 fi |
132 fi |
105 |
133 base_output="$output" |
106 if [ -f $output -a "x$output" != "x/dev/stdout" ] ; then |
134 |
107 echo "ERROR: Output patch already exists: $output" >&2 |
135 if [ "$shuffle_to" = "10" ]; then |
108 exit 1 |
136 if [ -f $output -a "x$output" != "x/dev/stdout" ] ; then |
109 fi |
137 echo "ERROR: Output patch already exists: $output" >&2 |
110 |
138 exit 1 |
111 what="" ## shuffle or unshuffle |
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 |
|
147 fi |
112 |
148 |
113 verbose() { |
149 verbose() { |
114 if [ ${vflag} = "true" ] ; then |
150 if [ ${vflag} = "true" ] ; then |
115 echo "$@" >&2 |
151 echo "$@" >&2 |
116 fi |
152 fi |
133 elif echo "$line" | egrep '^\+\+\+' > /dev/null ; then |
169 elif echo "$line" | egrep '^\+\+\+' > /dev/null ; then |
134 path="`echo "$line" | sed s@'+++ b/'@@`" |
170 path="`echo "$line" | sed s@'+++ b/'@@`" |
135 fi |
171 fi |
136 verbose "Extracted path: \"$path\"" |
172 verbose "Extracted path: \"$path\"" |
137 |
173 |
138 # Only source can be shuffled, or unshuffled |
|
139 if ! echo "$path" | egrep '^src/.*' > /dev/null ; then |
|
140 verbose "Not a src path, skipping." |
|
141 echo "$line" >> $output |
|
142 return |
|
143 fi |
|
144 |
|
145 # Shuffle or unshuffle? |
|
146 if [ "${what}" = "" ] ; then |
|
147 if echo "$path" | egrep '^src/java\..*|^src/jdk\..*' > /dev/null ; then |
|
148 what="unshuffle" |
|
149 else |
|
150 what="shuffle" |
|
151 fi |
|
152 verbose "Shuffle or unshuffle: $what" |
|
153 fi |
|
154 |
|
155 # Find the most specific matches in the shuffle list |
174 # Find the most specific matches in the shuffle list |
156 matches= |
175 matches= |
157 matchpath="$repo"/"$path"/x |
176 if [ -n "$repo" -a "$repo" != "top" ]; then |
|
177 matchpath="$repo"/"$path"/x |
|
178 else |
|
179 matchpath="$path"/x |
|
180 fi |
158 while [ "$matchpath" != "" ] ; do |
181 while [ "$matchpath" != "" ] ; do |
159 matchpath="`echo $matchpath | sed s@'\(.*\)/.*$'@'\1'@`" |
182 matchpath="`echo $matchpath | sed s@'\(.*\)/.*$'@'\1'@`" |
160 |
183 |
161 if [ "${what}" = "shuffle" ] ; then |
184 if [ "$shuffle_to" = "10" ] ; then |
162 pattern=": $matchpath$" |
185 pattern=": $matchpath$" |
163 else |
186 else |
164 pattern="^$matchpath :" |
187 pattern="^$matchpath :" |
165 fi |
188 fi |
166 verbose "Attempting to find \"$matchpath\"" |
189 verbose "Attempting to find \"$matchpath\"" |
175 fi |
198 fi |
176 done |
199 done |
177 |
200 |
178 # Rewrite the line, if we have a match |
201 # Rewrite the line, if we have a match |
179 if ! [ "x${matches}" = "x" ] ; then |
202 if ! [ "x${matches}" = "x" ] ; then |
180 shuffled="`echo "$matches" | sed -e s@' : .*'@@g -e s@'^[a-z]*\/'@@`" |
203 shuffled="${matches%% : *}" |
181 unshuffled="`echo "$matches" | sed -e s@'.* : '@@g -e s@'^[a-z]*\/'@@`" |
204 unshuffled="${matches#* : }" |
182 if [ "${what}" = "shuffle" ] ; then |
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 |
183 newline="`echo "$line" | sed -e s@"$unshuffled"@"$shuffled"@g`" |
216 newline="`echo "$line" | sed -e s@"$unshuffled"@"$shuffled"@g`" |
184 else |
217 else |
185 newline="`echo "$line" | sed -e s@"$shuffled"@"$unshuffled"@g`" |
218 newline="`echo "$line" | sed -e s@"$shuffled"@"$unshuffled"@g`" |
|
219 output=$base_output$patch_suffix_9 |
|
220 verbose "Writing to $output" |
186 fi |
221 fi |
187 verbose "Rewriting to \"$newline\"" |
222 verbose "Rewriting to \"$newline\"" |
188 echo "$newline" >> $output |
223 echo "$newline" >> $output |
189 else |
224 else |
190 echo "WARNING: no match found for $path" |
225 echo "WARNING: no match found for $path" |