-
Notifications
You must be signed in to change notification settings - Fork 12
/
install
executable file
·569 lines (482 loc) · 16 KB
/
install
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
#!/usr/bin/env bash
# (C) Copyright 2018- ECMWF.
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
set -euo pipefail
# Configuration of package versions:
loki_ant_version=1.10.15
hpc2020_java_version=11.0.6
hpc2020_python_version=3.11.8-01
hpc2020_cmake_version=3.28.3
# Determine base path for loki
# Either take the root of the current git tree or, if not inside a git repository, then
# use the path of this install script
if [ $(git rev-parse --git-dir > /dev/null 2>&1) ]; then
loki_path=$(git rev-parse --show-toplevel)
else
loki_path=$(realpath $(dirname "$0"))
fi
# Configuration default values
verbose=false
is_hpc2020=false
proxy_certificate=""
jdk_certificate=""
venv_path=
with_jdk=false
with_ant=false
with_claw=false
claw_install_env=""
with_omni=false
with_ofp=false
with_docs=false
with_dace=true
with_tests=true
with_examples=true
# Helper functions
print_usage() {
echo "Usage: $0 [-v] [--hpc2020] [--*-certificate[=]<path>] [--use-venv[=]<path>] [--with-*] [...]" >&2
}
print_usage_with_options() {
echo "Loki install script. This installs Loki and selected dependencies."
echo
print_usage
echo
echo "Available options:"
echo " -h / --help Display this help message"
echo " -v Enable verbose output"
echo " --hpc2020 Load HPC2020 (Atos) specific modules and settings"
echo " --proxy-certificate[=]<path> Provide https proxy certificate, disable cert verification for JDK/ant/OFP downloads"
echo " --jdk-certificate[=]<path> Provide trusted certificate for JDK runtime"
echo " --use-venv[=]<path> Use existing virtual environment at <path>"
echo " --with[out]-jdk Install JDK instead of using system version (default: use system version)"
echo " --with[out]-ant Install ant instead of using system version (default: use system version)"
echo " --with[out]-claw Install CLAW and OMNI Compiler (default: disabled)"
echo " --with[out]-omni Install OMNI Compiler; cannot be combined with --with-claw (default: disabled)"
echo " --with[out]-ofp Install Open Fortran Parser (default: disabled)"
echo " --with[out]-dace Install DaCe (default: enabled)"
echo " --with[out]-tests Install dependencies to run tests (default: enabled)"
echo " --with[out]-docs Install dependencies to generate documentation (default: disabled)"
echo " --with[out]-examples Install dependencies to run the example notebooks (default: enabled)"
echo " --claw-install-env[=]<...> Specify environmental variables for CLAW build and install"
}
print_step() {
echo "------------------------------------------------------"
echo " $1"
echo "------------------------------------------------------"
}
# Parse arguments
# (see https://stackoverflow.com/a/7680682)
optspec=":hv-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
-)
case "${OPTARG}" in
proxy-certificate)
proxy_certificate=$(realpath "${!OPTIND}")
OPTIND=$(( OPTIND + 1 ))
;;
proxy-certificate=*)
proxy_certificate=$(realpath "${!OPTARG#*=}")
;;
jdk-certificate)
jdk_certificate=$(realpath "${!OPTIND}")
OPTIND=$(( OPTIND + 1 ))
;;
jdk-certificate=*)
jdk_certificate=$(realpath "${!OPTARG#*=}")
;;
claw-install-env) # Provide custom environment variables for CLAW build
claw_install_env="${!OPTIND}"
OPTIND=$(( OPTIND + 1 ))
;;
claw-install-env=*) # Provide custom environment variables for CLAW build
claw_install_env="${!OPTARG#*=}"
;;
hpc2020) # Load ECMWF HPC2020 (Atos) specific modules and settings
is_hpc2020=true
;;
use-venv) # Specify existing virtual environment
venv_path=$(realpath "${!OPTIND}")
OPTIND=$(( OPTIND + 1 ))
;;
use-venv=*) # Specify existing virtual environment
venv_path=$(realpath "${OPTARG#*=}")
;;
with-jdk) # Enable installation of Java
with_jdk=true
;;
without-jdk) # Disable installation of Java
with_jdk=false
;;
with-ant) # Enable installation of ant
with_ant=true
;;
without-ant) # Disable installation of ant
with_ant=false
;;
with-ofp) # Enable installation of OFP
with_ofp=true
;;
without-ofp) # Disable installation of OFP
with_ofp=false
;;
with-claw) # Enable installation of OMNI+CLAW
with_claw=true
;;
without-claw) # Disable installation of OMNI+CLAW
with_claw=false
;;
with-omni) # Enable installation of OMNI
with_omni=true
;;
without-omni) # Disable installation of OMNI
with_omni=false
;;
with-dace) # Enable installation of DaCe
with_dace=true
;;
without-dace) # Disable installation of DaCe
with_dace=false
;;
with-tests) # Enable installation of dependencies for running tests
with_tests=true
;;
without-tests) # Disable installation of dependencies for running tests
with_tests=false
;;
with-docs) # Enable installation of dependencies for docs generation
with_docs=true
;;
without-docs) # Disable installation of dependencies for docs generation
with_docs=false
;;
with-examples) # Enable installation of dependencies for notebook examples
with_examples=true
;;
without-examples) # Disable installation of dependencies for notebook examples
with_examples=false
;;
help)
print_usage_with_options
exit 2
;;
*)
echo "Unknown option '--${OPTARG}'." >&2
print_usage
echo "Try '$0 -h' for more options."
exit 1
;;
esac
;;
h)
print_usage_with_options
exit 2
;;
v)
verbose=true
;;
*)
echo "Unknown option '-${OPTARG}'." >&2
print_usage
echo "Try '$0 -h' for more options."
exit 1
;;
esac
done
if [ "$with_omni" == true ]; then
if [ "$with_claw" == true ]; then
echo "ERROR: Cannot combine --with-claw and --with-omni"
exit 1
fi
fi
# Print configuration
if [ "$verbose" == true ]; then
print_step "Installation configuration:"
[[ "$is_hpc2020" == true ]] && echo " --hpc2020"
[[ "$venv_path" != "" ]] && echo " --use-venv='$venv_path'"
[[ "$with_jdk" == true ]] && echo " --with-jdk"
[[ "$with_ant" == true ]] && echo " --with-ant"
[[ "$with_claw" == true ]] && echo " --with-claw"
[[ "$with_omni" == true ]] && echo " --with-omni"
[[ "$with_ofp" == false ]] && echo " --without-ofp"
[[ "$with_dace" == false ]] && echo " --without-dace"
[[ "$with_tests" == false ]] && echo " --without-tests"
[[ "$with_docs" == false ]] && echo " --without-docs"
[[ "$with_examples" == false ]] && echo " --without-examples"
[[ "$proxy_certificate" != "" ]] && echo " --proxy-certificate='$proxy_certificate'"
[[ "$jdk_certificate" != "" ]] && echo " --jdk-certificate='$jdk_certificate'"
fi
if [ "x$proxy_certificate" != "x" ]; then
PIPPROXYOPTIONS="--cert $proxy_certificate"
WGETPROXYOPTIONS="--no-check-certificate"
else
PIPPROXYOPTIONS=""
WGETPROXYOPTIONS=""
fi
# Load modules
if [ "$is_hpc2020" == true ]; then
print_step "Loading HPC2020 modules and settings"
module unload cmake
module load cmake/${hpc2020_cmake_version}
if [ "$with_jdk" == false ]; then
module unload java
module load java/${hpc2020_java_version}
fi
if [ "$venv_path" == "" ]; then
module unload python3
module load python3/${hpc2020_python_version}
fi
fi
#
# Create Python virtualenv
#
if [ "$venv_path" == "" ]; then
print_step "Creating virtualenv"
venv_path=${loki_path}/loki_env
for activate_file in activate activate.csh activate.fish Activate.ps1; do
if [ -f "${loki_path}/loki_env/bin/${activate_file}" ]; then
chmod u+w "${loki_path}/loki_env/bin/${activate_file}"
fi
done
python3 -m venv "${venv_path}"
fi
#
# Activate Python virtualenv
#
print_step "Activating virtualenv"
source "${venv_path}/bin/activate"
if [ "x$proxy_certificate" != "x" ]
then
export SSL_CERT_FILE=$proxy_certificate
fi
#
# Install Loki with Python dependencies
#
print_step "Installing Loki and Python dependencies"
cd "$loki_path"
pip_opts=()
[[ "$with_tests" == true ]] && pip_opts+=(tests)
[[ "$with_ofp" == true ]] && pip_opts+=(ofp)
[[ "$with_dace" == true ]] && pip_opts+=(dace)
[[ "$with_docs" == true ]] && pip_opts+=(docs)
[[ "$with_examples" == true ]] && pip_opts+=(examples)
pip_opts=$(printf ",%s" "${pip_opts[@]}")
if [ "$pip_opts" == "," ]; then
pip_opts=
else
pip_opts=[${pip_opts:1}]
fi
# Supply pretend version if not a git worktree
if [ ! -e .git ]; then
export "SETUPTOOLS_SCM_PRETEND_VERSION=$(cat VERSION)"
fi
pip install $PIPPROXYOPTIONS --upgrade pip
pip install $PIPPROXYOPTIONS -e .$pip_opts # Installs Loki dev copy in editable mode
pip install $PIPPROXYOPTIONS -e ./lint_rules
#
# Install Java
#
if [ "$with_jdk" == true ]; then
print_step "Downloading and installing JDK"
JDK_ARCHIVE=openjdk-11.0.2_linux-x64_bin.tar.gz
JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/${JDK_ARCHIVE}
JAVA_INSTALL_DIR=${venv_path}/opt/java
export JAVA_HOME=${JAVA_INSTALL_DIR}/jdk-11.0.2
mkdir -p "${JAVA_INSTALL_DIR}"
rm -rf "${JAVA_HOME}" "${JAVA_INSTALL_DIR}/${JDK_ARCHIVE}"
cd "${JAVA_INSTALL_DIR}"
wget $WGETPROXYOPTIONS -O "${JDK_ARCHIVE}" "${JDK_URL}"
tar -xzf "${JDK_ARCHIVE}"
if [ "x$jdk_certificate" != "x" ]; then
f1=$jdk_certificate
f2=${JAVA_HOME}/lib/security/cacerts
mv "$f2" "$f2.bak"
cp "$f1" "$f2"
fi
fi
#
# Install ant
#
if [ "$with_ant" == true ]; then
print_step "Downloading and installing ANT"
ANT_INSTALL_DIR=${venv_path}/opt/ant
export ANT_HOME=${ANT_INSTALL_DIR}/apache-ant-${loki_ant_version}
# Cache NetRexx if it doesn't exist (Download fails from time to time)
NETREXX_TEMP=${HOME}/.ant/tempcache/NetRexx.zip
mkdir -p "${HOME}/.ant/tempcache"
if [[ $(shasum -a 1 "${NETREXX_TEMP}" | cut -d ' ' -f1) != "1a47bf7b5d0055d4a94befc999c593d15b66c119" ]]
then
for mirror in https://public.dhe.ibm.com ftp://ftp.software.ibm.com
do
wget --tries 3 $WGETPROXYOPTIONS -O "${NETREXX_TEMP}" $mirror/software/awdtools/netrexx/NetRexx.zip
if [ $? -eq 0 ]
then
break
fi
done
fi
# Download, unpack and install ant
ANT_ARCHIVE=apache-ant-${loki_ant_version}-bin.tar.gz
mkdir -p "${ANT_INSTALL_DIR}"
rm -rf "${ANT_HOME}" "${ANT_INSTALL_DIR}/${ANT_ARCHIVE}"
cd "${ANT_INSTALL_DIR}"
set +e
for mirror in http://ftp.fau.de/apache http://mirror.ox.ac.uk/sites/rsync.apache.org http://archive.apache.org/dist
do
wget --tries 3 $WGETPROXYOPTIONS -O "${ANT_ARCHIVE}" $mirror/ant/binaries/${ANT_ARCHIVE}
if [ $? -eq 0 ]
then
break
fi
done
set -e
tar -xzf "${ANT_ARCHIVE}"
export PATH="${ANT_HOME}/bin:${PATH}"
ant -f "${ANT_HOME}/fetch.xml" -Ddest=optional
fi
#
# Install CLAW+OMNI
#
if [ "$with_claw" == true ]; then
print_step "Downloading and installing CLAW and OMNI Compiler"
CLAW_INSTALL_DIR=${venv_path}/opt/claw
mkdir -p "${CLAW_INSTALL_DIR}"
cd "${CLAW_INSTALL_DIR}"
rm -rf claw-compiler
# git clone --recursive --single-branch https://github.com/claw-project/claw-compiler.git claw-compiler
# Note that the deprecated CLAW variants in CLOUDSC will fail due to faulty offload
# directives with current CLAW-master. The fixes exist in this pinned branch:
# However, this branch fails to build with recent GNU versions (GNU 10+)
git clone --recursive --single-branch --branch=mlange-dev https://github.com/mlange05/claw-compiler.git claw-compiler
cd claw-compiler
(
set -a
eval ${claw_install_env}
cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${CLAW_INSTALL_DIR}"
cmake --build build
cmake --install build
)
fi
#
# Install OMNI
#
if [ "$with_omni" == true ]; then
print_step "Downloading and installing OMNI Compiler"
OMNI_INSTALL_DIR=${venv_path}/opt/omni
mkdir -p "${OMNI_INSTALL_DIR}"
cd "${OMNI_INSTALL_DIR}"
rm -rf xcodeml-tools
git clone --recursive --single-branch https://github.com/omni-compiler/xcodeml-tools.git xcodeml-tools
cd xcodeml-tools
omni_opts=()
[[ ! -z "${JAVA_HOME}" ]] && omni_opts+=("JAVA_HOME=${JAVA_HOME}")
# A CMake install would be cleaner but they inject without good reason a -Werror for
# GNU and Clang without writing good enough code that actually avoids any warnings...
# cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${OMNI_INSTALL_DIR}" "${omni_opts[@]}"
# cmake --build build
# cmake --install build
./configure --prefix="${OMNI_INSTALL_DIR}" "${omni_opts[@]}"
make && make install
fi
#
# Install OFP
#
OFP_HOME=${venv_path}/src/open-fortran-parser
if [ "$with_ofp" == true ]; then
print_step "Installing OFP"
# Reinstall OFP editable to enable below hack
pip install $PIPPROXYOPTIONS -e git+https://github.com/mlange05/open-fortran-parser-xml@mlange05-dev#egg=open-fortran-parser
# HACK: Force OFP version
echo "VERSION = '0.5.3'" > "${OFP_HOME}/open_fortran_parser/_version.py"
if [ "x$proxy_certificate" != "x" ]; then
# Bypass certificate verification
perl -e '
use FileHandle;
my $py = shift;
my $code = do { local $/ = undef; my $fh = "FileHandle"->new ("<$py"); <$fh> };
"FileHandle"->new (">$py")->print (<< "EOF");
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
$code
EOF
' "${OFP_HOME}/open_fortran_parser/__main__.py"
fi
# Install Java dependencies
python3 -m open_fortran_parser --deps
# Copy downloaded binaries to lib
cd "${OFP_HOME}"
mkdir -p lib
cp open_fortran_parser/*.jar lib
# Rebuild OFP binaries to include custom changes
ant
fi
#
# Writing loki-activate script
#
print_step "Writing loki-activate script"
path_var=\${PATH}
echo "
# This script activates Loki's virtual environment, loads additional modules and sets dependend paths.
#
# Run as 'source loki-activate'
# Load virtualenv
. ${venv_path}/bin/activate
" > "${loki_path}/loki-activate"
# Load ECMWF modules, if required
if [ "${is_hpc2020}" == true ]; then
if [ "$with_jdk" == false ]; then
echo "
module unload java
module load java/${hpc2020_java_version}
" >> "${loki_path}/loki-activate"
fi
echo "
module unload cmake
module load cmake/${hpc2020_cmake_version}
" >> "${loki_path}/loki-activate"
fi
# Setup Java for OFP
if [ "$with_ofp" == true ]; then
echo "
export _OLD_CLASSPATH=\"\${CLASSPATH}\"
export CLASSPATH=\"${OFP_HOME}/open_fortran_parser/*:\${CLASSPATH}\"
" >> "${loki_path}/loki-activate"
fi
# Inject self-installed JDK into env
if [ "$with_jdk" == true ]; then
echo "
export JAVA_HOME=\"\${JAVA_HOME}\"
" >> "${loki_path}/loki-activate"
path_var=${JAVA_HOME}/bin:$path_var
fi
# Inject CLAW into env
if [ "$with_claw" == true ]; then
path_var=${CLAW_INSTALL_DIR}/bin:$path_var
fi
# Inject OMNI into env
if [ "$with_omni" == true ]; then
path_var=${OMNI_INSTALL_DIR}/bin:$path_var
fi
# Update path variable
echo "
export PATH=\"$path_var\"
echo \"Activated loki environment. Unload with 'deactivate'.\"
" >> "${loki_path}/loki-activate"
#
# Finish
#
print_step "Installation finished"
echo
echo "Activate the Loki environment with"
echo
echo " source loki-activate"
echo
if [ "$with_tests" == true ]; then
echo "You can test the Loki installation by running"
echo
echo " pytest --pyargs loki lint_rules"
echo
fi