527
|
1 |
#!/bin/bash
|
|
2 |
#
|
|
3 |
# utilities used by build scripts
|
|
4 |
#
|
|
5 |
# To include these utilites, add these lines to another script in the same folder.
|
|
6 |
#
|
|
7 |
# utilsDir=`dirname $0`
|
|
8 |
# [ "$utilsDir" = "." ] && utilsDir=`pwd`
|
|
9 |
# source $utilsDir/Utils.sh
|
|
10 |
#
|
|
11 |
|
|
12 |
program=$0
|
|
13 |
|
|
14 |
|
|
15 |
# ------------------------------------------------------------------
|
|
16 |
#
|
|
17 |
# prepare to parse command line args
|
|
18 |
# usage: prepare_parse_args arg1 [arg2] ...
|
|
19 |
#
|
|
20 |
# To parse command line args, add these lines after source $utilsDir/Utils.sh
|
|
21 |
#
|
|
22 |
# argsText="--ARG1:<varlue> --ARG2:<value>"
|
|
23 |
# prepare_parse_args ARG1 ARG2 > /tmp/$$.parse_args
|
|
24 |
# source /tmp/$$.parse_args
|
|
25 |
# rm -f /tmp/$$.parse_args
|
|
26 |
#
|
|
27 |
|
|
28 |
function prepare_parse_args {
|
|
29 |
local name
|
|
30 |
local sedcmd='`echo $i | sed 's/[-a-zA-Z0-9_]*://'`'
|
|
31 |
|
|
32 |
echo 'for i in $*'
|
|
33 |
echo 'do'
|
|
34 |
echo ' case $i in'
|
|
35 |
|
|
36 |
for name in $*
|
|
37 |
do
|
|
38 |
echo " --$name:*)"
|
|
39 |
echo " $name=$sedcmd"
|
|
40 |
echo " echo $name=\$$name"
|
|
41 |
echo ' ;;'
|
|
42 |
done
|
|
43 |
|
|
44 |
echo ' --help)'
|
|
45 |
echo ' usage $argsText'
|
|
46 |
echo ' ;;'
|
|
47 |
echo ' --verbose)'
|
|
48 |
echo ' verbose=YES'
|
|
49 |
echo ' ;;'
|
|
50 |
echo ' *)'
|
|
51 |
echo ' ;;'
|
|
52 |
echo 'esac'
|
|
53 |
echo 'done'
|
|
54 |
|
|
55 |
}
|
|
56 |
|
|
57 |
this_step=0
|
|
58 |
total_errors=0
|
|
59 |
return_code=0
|
|
60 |
|
|
61 |
#
|
|
62 |
# count and print number of errors
|
|
63 |
#
|
|
64 |
function set_returncode {
|
|
65 |
this_step=$(($this_step+1))
|
|
66 |
if [ $1 -ne 0 ]; then
|
|
67 |
total_errors=$(($total_errors+1))
|
|
68 |
fi
|
|
69 |
return_code=$1
|
|
70 |
echo time = `date +%R`, step = $this_step, return code = $1, total errors = $total_errors
|
|
71 |
}
|
|
72 |
|
|
73 |
#
|
|
74 |
# print error message and exit
|
|
75 |
#
|
|
76 |
function error_exit {
|
|
77 |
echo $program ERROR: $*
|
|
78 |
echo BUILD FAILED
|
|
79 |
set_returncode 1
|
|
80 |
exit $total_errors
|
|
81 |
}
|
|
82 |
|
|
83 |
#
|
|
84 |
# print a command line
|
|
85 |
# run the command line
|
|
86 |
# remember the exit status
|
|
87 |
#
|
|
88 |
function run {
|
|
89 |
echo $*
|
|
90 |
$*
|
|
91 |
set_returncode $?
|
|
92 |
}
|
|
93 |
|
|
94 |
#
|
|
95 |
# run and exit if non-zero return code
|
|
96 |
#
|
|
97 |
function must_run {
|
|
98 |
echo $*
|
|
99 |
$*
|
|
100 |
return_code=$?
|
|
101 |
set_returncode $return_code
|
|
102 |
if [ $return_code -ne 0 ]; then
|
|
103 |
exit $total_errors
|
|
104 |
fi
|
|
105 |
}
|
|
106 |
|
|
107 |
#
|
|
108 |
# run the command line
|
|
109 |
# remember the exit status
|
|
110 |
#
|
|
111 |
function run_quiet {
|
|
112 |
$*
|
|
113 |
set_returncode $?
|
|
114 |
}
|
|
115 |
|
|
116 |
#
|
|
117 |
# show a usage message and exit
|
|
118 |
#
|
|
119 |
function usage {
|
|
120 |
echo usage: $program $* --help --verbose
|
|
121 |
set_returncode 1
|
|
122 |
exit $total_errors
|
|
123 |
}
|
|
124 |
|
|
125 |
# ------------------------------------------------------------------
|
|
126 |
#
|
|
127 |
# move or copy plugins from one layout to another
|
|
128 |
# usage: move_or_copy_plugins <move_plugins | copy_plugins> [ -q] src_folder dst_folder map_file [map_file...]
|
|
129 |
#
|
|
130 |
function move_or_copy_plugins {
|
|
131 |
if [ "$1" != "move_plugins" -a "$1" != "copy_plugins" ]; then
|
|
132 |
echo 'usage: move_or_copy_plugins <move_plugins | copy_plugins> [ -q] src_folder dst_folder map_file [map_file...]'
|
|
133 |
return 1
|
|
134 |
fi
|
|
135 |
|
|
136 |
local move_or_copy=$1
|
|
137 |
shift
|
|
138 |
|
|
139 |
local verbose=1
|
|
140 |
if [ "$1" = "-q" ]; then
|
|
141 |
verbose=0
|
|
142 |
shift
|
|
143 |
fi
|
|
144 |
|
|
145 |
if [ $# -lt 3 ]; then
|
|
146 |
echo usage: $move_or_copy [ -q] src_folder dst_folder map_file [map_file...]
|
|
147 |
return 1
|
|
148 |
fi
|
|
149 |
|
|
150 |
local src_folder=$1
|
|
151 |
shift
|
|
152 |
local dst_folder=$1
|
|
153 |
shift
|
|
154 |
|
|
155 |
if [ ! -d $src_folder ]; then
|
|
156 |
echo ERROR: $move_or_copy: cannot find $src_folder
|
|
157 |
return 1
|
|
158 |
fi
|
|
159 |
|
|
160 |
[ -d $dst_folder/features ] || mkdir -p $dst_folder/features
|
|
161 |
[ -d $dst_folder/plugins ] || mkdir -p $dst_folder/plugins
|
|
162 |
|
|
163 |
local name
|
|
164 |
local name2
|
|
165 |
local have_x86_eol
|
|
166 |
|
|
167 |
for name in $*
|
|
168 |
do
|
|
169 |
if [ ! -f $name ]; then
|
|
170 |
echo ERROR: $move_or_copy: cannot find map file: $name
|
|
171 |
return 1
|
|
172 |
fi
|
|
173 |
done
|
|
174 |
|
|
175 |
for name in `cat $* | grep -v "^#" | grep , | cut -d"," -f2`
|
|
176 |
do
|
|
177 |
#echo $src_folder/${name} $src_folder/${name}_*
|
|
178 |
# Except for x86_64 plugins, plugins follow the convention that they do not have underscores in the name
|
|
179 |
# For example: org.eclipse.swt.win32.win32.x86_* matches
|
|
180 |
# org.eclipse.swt.win32.win32.x86_3.4.1.v3449c.jar
|
|
181 |
# org.eclipse.swt.win32.win32.x86_64.source_3.4.1.v3449c.jar
|
|
182 |
# org.eclipse.swt.win32.win32.x86_64_3.4.1.v3449c.jar
|
|
183 |
# Check for x86_64 and handle the exception
|
|
184 |
echo $name | grep x86$ > /dev/null 2>&1
|
|
185 |
if [ $? -eq 0 ]; then
|
|
186 |
have_x86_eol=1
|
|
187 |
else
|
|
188 |
have_x86_eol=0
|
|
189 |
fi
|
|
190 |
|
|
191 |
features_or_plugins=`echo $name | cut -d"/" -f1`
|
|
192 |
|
|
193 |
# The x86 names may expand to more than one filename
|
|
194 |
for name2 in $src_folder/${name}_*
|
|
195 |
do
|
|
196 |
if [ "$name2" = '$src_folder/${name}_*' ]; then
|
|
197 |
# no match found
|
|
198 |
[ $verbose -eq 1 ] && echo WARNING: $move_or_copy: cannot find $src_folder/${name}
|
|
199 |
else
|
|
200 |
echo $name2 | grep x86_64 > /dev/null 2>&1
|
|
201 |
if [ $? -ne 0 -o $have_x86_eol -eq 0 ]; then
|
|
202 |
# do this if name2 does not have x86_64 OR if pattern does end in x86
|
|
203 |
if [ "$move_or_copy" = "move_plugins" ]; then
|
|
204 |
run mv $name2 $dst_folder/$features_or_plugins
|
|
205 |
else
|
|
206 |
run cp -pr $name2 $dst_folder/$features_or_plugins
|
|
207 |
fi
|
|
208 |
fi
|
|
209 |
fi
|
|
210 |
done
|
|
211 |
done
|
|
212 |
}
|
|
213 |
|
|
214 |
#
|
|
215 |
# move plugins from one layout to another
|
|
216 |
# usage: move_plugins [ -q] src_folder dst_folder map_file [map_file...]
|
|
217 |
#
|
|
218 |
function move_plugins {
|
|
219 |
move_or_copy_plugins move_plugins $*
|
|
220 |
}
|
|
221 |
|
|
222 |
#
|
|
223 |
# copy plugins from one layout to another
|
|
224 |
# usage: copy_plugins [ -q] src_folder dst_folder map_file [map_file...]
|
|
225 |
#
|
|
226 |
function copy_plugins {
|
|
227 |
move_or_copy_plugins copy_plugins $*
|
|
228 |
}
|
|
229 |
|
|
230 |
# ------------------------------------------------------------------
|
|
231 |
#
|
|
232 |
# clone mercurial repository
|
|
233 |
# usage: hg_clone checkout_folder buildtags_file username password host revision repo [repo...]
|
|
234 |
#
|
|
235 |
function hg_clone {
|
|
236 |
if [ $# -lt 7 ]; then
|
|
237 |
echo usage: usage: hg_clone checkout_folder buildtags_file username password host revision repo [repo...]
|
|
238 |
set_returncode 1
|
|
239 |
return 1
|
|
240 |
fi
|
|
241 |
|
|
242 |
local checkout_folder=$1
|
|
243 |
shift
|
|
244 |
local buildtags_file=$1
|
|
245 |
shift
|
|
246 |
local username=$1
|
|
247 |
shift
|
|
248 |
local password=$1
|
|
249 |
shift
|
|
250 |
local host=$1
|
|
251 |
shift
|
|
252 |
local revision=$1
|
|
253 |
shift
|
|
254 |
|
|
255 |
if [ ! -d $checkout_folder ]; then
|
|
256 |
echo ERROR: hg_clone: cannot find $checkout_folder
|
|
257 |
set_returncode 1
|
|
258 |
return 1
|
|
259 |
fi
|
|
260 |
|
|
261 |
local url=http://${username}:${password}@$host
|
|
262 |
|
|
263 |
local name
|
|
264 |
for name in $*
|
|
265 |
do
|
|
266 |
if [ ! -d $checkout_folder/$name ]; then
|
|
267 |
run cd $checkout_folder
|
|
268 |
run mkdir -p $name
|
|
269 |
run rmdir $name
|
|
270 |
echo hg clone http://$host/$name $name
|
|
271 |
run_quiet hg clone $url/$name $name
|
|
272 |
else
|
|
273 |
run cd $checkout_folder/$name
|
|
274 |
echo hg pull http://$host/$name
|
|
275 |
run_quiet hg pull $url/$name
|
|
276 |
fi
|
|
277 |
run cd $checkout_folder/$name
|
|
278 |
run hg update -C $revision
|
|
279 |
echo http://$host/$name `hg identify` >> $buildtags_file
|
|
280 |
done
|
|
281 |
}
|
|
282 |
|
|
283 |
|
|
284 |
# ------------------------------------------------------------------
|
|
285 |
#
|
|
286 |
# remove update site URLs from feature.xml
|
|
287 |
#
|
|
288 |
|
|
289 |
function remove_update_site_urls {
|
|
290 |
local feature_xml=$1
|
|
291 |
local temp_file=$2
|
|
292 |
|
|
293 |
xml2oneline $feature_xml > $temp_file
|
|
294 |
grep tools.ext.nokia.com/updates $temp_file > /dev/null
|
|
295 |
if [ $? -eq 0 ]; then
|
|
296 |
echo remove update site tools.ext.nokia.com/updates from $feature_xml
|
|
297 |
grep -v tools.ext.nokia.com/updates $temp_file | grep -v \<url\> | grep -v \</url\> > $feature_xml
|
|
298 |
unix2dos $feature_xml
|
|
299 |
fi
|
|
300 |
rm -f $temp_file
|
|
301 |
}
|