-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·428 lines (356 loc) · 10.3 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#!/bin/bash
# Copyright (c) 2002-2024, Rice University.
# SPDX-FileCopyrightText: 2024 Contributors to the HPCToolkit Project
#
# SPDX-License-Identifier: BSD-3-Clause
#
# Build hpcviewer and generate tar or zip files
# This script is only for Unix and X windows.
#
#------------------------------------------------------------
# Error messages
#------------------------------------------------------------
die()
{
echo "$0: error: $*" 1>&2
exit 1
}
#------------------------------------------------------------
# Check maven existence: exit if it doesn't exist
#------------------------------------------------------------
check_maven()
{
if ! command -v mvn &> /dev/null
then
die "Apache Maven (mvn) command is not found"
fi
}
#------------------------------------------------------------
# Check the java version.
#------------------------------------------------------------
check_java()
{
JAVA=`type -p java`
if [ "$JAVA"x != "x" ]; then
JAVA=java
elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
echo found java executable in JAVA_HOME
JAVA="$JAVA_HOME/bin/java"
else
die "unable to find program 'java' on your PATH"
fi
JAVA_MAJOR_VERSION=`java -version 2>&1 \
| head -1 \
| cut -d'"' -f2 \
| sed 's/^1\.//' \
| cut -d'.' -f1`
echo "Java version $JAVA_MAJOR_VERSION"
# we need Java 17 at least
jvm_min=17
jvm_max=22
# issue #308: we don't support too new Java
if [ "$JAVA_MAJOR_VERSION" -lt "$jvm_min" ] || [ "$JAVA_MAJOR_VERSION" -gt "$jvm_max" ]; then
die "$name requires Java between $jvm_min and $jvm_max"
fi
}
#------------------------------------------------------------
# Show all the options and then exit
#------------------------------------------------------------
show_help(){
echo "Syntax: $0 [-options] [commands]"
echo "Options: "
echo " -c create a package and generate the release number"
echo " -n (Mac only) notarize the package"
echo " -i (Mac only) create a disk image file"
echo " -r <release> specify the release number"
echo "Commands:"
echo " check build and run the tests."
echo " clean remove objects and temporary files"
echo " distclean remove the temporary and target files"
exit
}
#------------------------------------------------------------
# remove all the temporary files
#------------------------------------------------------------
clean_up() {
./mvnw clean
rm -f scripts/hpcviewer_launcher.sh
cd edu.rice.cs.hpcdata.app/scripts/
./build.sh clean
cd ../..
}
#------------------------------------------------------------
# remove all the temporary AND product files
#------------------------------------------------------------
distclean_up() {
clean_up
rm -rf hpcviewer-* hpcdata-* prepare_sign*
cd edu.rice.cs.hpcdata.app/scripts/
./build.sh distclean
cd ../..
}
#------------------------------------------------------------
# Generate a hpcviewer for Linux package inside
# `edu.rice.cs.hpcviewer.product/target/products/edu.rice.cs.hpcviewer-${prefix}.${platform}*``
# @param prefix
# @param machine_platform
#------------------------------------------------------------
repackage_linux(){
prefix=$1
platform=$2
package=`ls edu.rice.cs.hpcviewer.product/target/products/edu.rice.cs.hpcviewer-${prefix}.${platform}*`
extension="tgz"
[[ -z $package ]] && { echo "$package doesn't exist"; exit 1; }
mkdir -p tmp/hpcviewer
cd tmp/hpcviewer
#tar xzf ../../$package | grep -v 'LIBARCHIVE.creationtime'
unzip -qq ../../$package
cp ../../$launcher .
cp ../../scripts/install.sh .
cp ../../scripts/README .
cd ..
output="hpcviewer-${prefix}.${platform}.$extension"
if [[ "$VERBOSE" == 1 ]]; then
echo "Packaging $output from $package"
fi
tar czf ../$output hpcviewer/
chmod 664 ../$output
cd ..
#ls -l $output
rm -rf tmp
}
#------------------------------------------------------------
# Generate a hpcviewer package for mac
#------------------------------------------------------------
repackage_mac() {
input=$1
output=$2
if [[ "$VERBOSE" == 1 ]]; then
echo "Packaging $output from $input"
fi
cp $input $output
chmod 664 $output
}
#------------------------------------------------------------
# Generate a hpcviewer package for Windows
#------------------------------------------------------------
repackage_windows() {
input=$1
output=$2
if [[ "$VERBOSE" == 1 ]]; then
echo "Packaging $output from $input"
fi
# for windows, we need to create a special hpcviewer directory
if [ -e hpcviewer ]; then
echo "File or directory hpcviewer already exist. Do you want to remove it? (y/n) "
read tobecontinue
if [ $tobecontinue != "y" ]; then
exit
fi
fi
rm -rf hpcviewer
mkdir hpcviewer
cd hpcviewer
unzip -q ../$input
cd ..
zip -q -r -y $output hpcviewer/
rm -rf hpcviewer
chmod 664 $output
}
#------------------------------------------------------------
# Generate hpcdata stand alone application
#------------------------------------------------------------
repackage_hpcdata(){
echo "=================================="
echo " Building hpcdata"
echo "=================================="
cd edu.rice.cs.hpcdata.app/scripts
if [[ "$VERBOSE" == "1" ]]; then
OPTION="-v"
fi
./build.sh ${OPTION} --release "$RELEASE"
if [ -f hpcdata.tgz ]; then
cp hpcdata.tgz ../..
else
echo "Fail to build hpcdata"
fi
cd ../..
}
#------------------------------------------------------------
# generate HTML documents and make a package of them
#------------------------------------------------------------
generate_documents()
{
cd doc
../mvnw site
if [ ! -f target/site/index.html ]; then
die "Unable to generate the documentation"
fi
tar cf manual.tar target/site/*
cd ..
}
###################################################################
# packaging the hpcdata
###################################################################
#
# checking dependencies
#
check_maven
check_java
#
# parse the arguments
#
CHECK_PACKAGE=0
CREATE_PACKAGE=1
VERBOSE=0
NOTARIZE=0
RELEASE=`date +"%Y.%m"`
IMAGE_ONLY=0
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
check)
CHECK_PACKAGE=1
shift # past argument
;;
clean)
clean_up
shift # past argument
exit
;;
distclean)
distclean_up
shift # past argument
exit
;;
-c|--create)
CREATE_PACKAGE=0
shift # past argument
;;
-h|--help)
show_help
shift # past argument
;;
-i|--image)
IMAGE_ONLY=1
shift # past argument
;;
-n|--notarize)
NOTARIZE=1
shift # past argument
;;
-r|--release)
RELEASE="$2"
CREATE_PACKAGE=0
shift # past argument
shift # past value
;;
-v|--verbose)
VERBOSE=1
shift # past argument
;;
--default)
DEFAULT=YES
shift # past argument
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
#
# Update the release file
#
GITC=`git rev-parse --short HEAD`
name="hpcviewer"
sh_file="scripts/${name}.sh"
launcher_name="${name}_launcher.sh"
launcher="scripts/${launcher_name}"
RELEASE_FILE="edu.rice.cs.hpcviewer.ui/release.txt"
OS=`uname`
# insert the release number to the launcher script:
# first, copy the launcher script
# second, replace the release variable with the current version
cp -f "$sh_file" "$launcher" \
|| die "unable to copy files"
if [ "$CREATE_PACKAGE" == "0" ]; then
# create the release number: the current month and the commit hash
# users may don't care with the hash, but it's important for debugging
VERSION="Release ${RELEASE}. Commit $GITC"
echo "$VERSION" > ${RELEASE_FILE}
else
VERSION=`cat $RELEASE_FILE`
fi
if [[ "$OS" == "Darwin" ]]; then
sed -i '' "s/__VERSION__/\"$VERSION\"/g" $launcher
else
sed -i "s/__VERSION__/\"$VERSION\"/g" $launcher
fi
#
# build the viewer
#
echo "=================================="
echo " Building the viewer"
echo "=================================="
if [ $CHECK_PACKAGE != "0" ]; then
./mvnw clean verify -Pjacoco
if [ -d tests/edu.rice.cs.hpctest.report/target/site/jacoco-aggregate/ ]; then
echo "Code coverage result: tests/edu.rice.cs.hpctest.report/target/site/jacoco-aggregate/"
fi
else
./mvnw clean package
fi
# The result should be:
# edu.rice.cs.hpcviewer.product/target/products/*
if [ ! -e "edu.rice.cs.hpcviewer.product/target/products" ]; then
die "Fail to build hpcviewer"
fi
#
# Generate the user manual
#
generate_documents
echo "=================================="
echo " Repackaging the viewer"
echo "=================================="
#
# wrap the generated files into standard hpcviewer product
#
repackage_linux linux.gtk x86_64
repackage_linux linux.gtk aarch64
repackage_linux linux.gtk ppc64le
# copy and rename windows package
output="hpcviewer-win32.win32.x86_64.zip"
input=edu.rice.cs.hpcviewer.product/target/products/edu.rice.cs.hpcviewer-win32.win32.x86_64.zip
repackage_windows $input $output
# copy and rename mac x86_64 package
output="hpcviewer-macosx.cocoa.x86_64.zip"
input=edu.rice.cs.hpcviewer.product/target/products/edu.rice.cs.hpcviewer-macosx.cocoa.x86_64.zip
repackage_mac $input $output
# copy and rename mac aarch64 package
output="hpcviewer-macosx.cocoa.aarch64.zip"
input=edu.rice.cs.hpcviewer.product/target/products/edu.rice.cs.hpcviewer-macosx.cocoa.aarch64.zip
repackage_mac $input $output
# special treatment for mac OS to notarize if needed
if [[ "$OS" == "Darwin" && "$NOTARIZE" == "1" ]]; then
macPkgs="hpcviewer-macosx.cocoa.x86_64.zip"
macos/notarize.sh $macPkgs
macPkgs="hpcviewer-macosx.cocoa.aarch64.zip"
macos/notarize.sh $macPkgs
elif [[ "$OS" == "Darwin" && "$IMAGE_ONLY" == "1" ]]; then
macPkgs="hpcviewer-macosx.cocoa.aarch64.zip"
macos/notarize.sh -i $macPkgs
fi
###################################################################
# End
###################################################################
echo "=================================="
echo " Done"
echo "=================================="
ls -l hpcviewer-*
if [ -f hpcdata.tgz ]; then
ls -l hpcdata.tgz
fi