-
Notifications
You must be signed in to change notification settings - Fork 4
/
package-issm-mac-binaries-python-3.sh
executable file
·195 lines (166 loc) · 6.24 KB
/
package-issm-mac-binaries-python-3.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
#!/bin/bash
################################################################################
# Packages and tests ISSM distributable package for macOS with Python 3 API.
#
# Options:
# -s/--skiptests Skip testing during packaging Use if packaging fails
# for some reason but build is valid.
#
# NOTE: The following variables *must* be defined in order for this script to
# work properly,
#
# COMPRESSED_PKG
# ISSM_DIR
# PKG
# PYTHON_NROPTIONS
#
# See also:
# - packagers/mac/<ARCH>/complete-issm-mac-<ARCH>-binaries-python-3.sh
#
# TODO:
# - Make sure that all TPL licenses are copied to package
################################################################################
# Expand aliases within the context of this script
shopt -s expand_aliases
## Override certain other aliases
#
alias cp=$(which cp)
alias grep=$(which grep)
## Constants
#
LIBGMT="${ISSM_DIR}/externalpackages/gmt/install/lib/libgmt.6.5.0.dylib" # Important that this is the library itself
LIBGMT_DIST="${ISSM_DIR}/lib/libgmt.6.dylib" # Important the file name matches the SONAME entry in the binaries and other shared libraries which link to it
LIBPSL="${ISSM_DIR}/externalpackages/gmt/install/lib/libpostscriptlight.6.5.0.dylib" # Important that this is the library itself
LIBPSL_DIST="${ISSM_DIR}/lib/libpostscriptlight.6.dylib" # Important the file name matches the SONAME entry in the binaries and other shared libraries which link to it
## Environment
#
export PATH="${ISSM_DIR}/bin:$(getconf PATH)" # Ensure that we pick up binaries from 'bin' directory rather than 'externalpackages'
## Parse options
#
if [ $# -gt 1 ]; then
echo "Can use only one option at a time"
exit 1
fi
skip_tests=0
if [ $# -eq 1 ]; then
case $1 in
-s|--skiptests) skip_tests=1; ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
fi
# Clean up from previous packaging
echo "Cleaning up existing assets"
cd ${ISSM_DIR}
rm -rf ${PKG} ${COMPRESSED_PKG}
mkdir ${PKG}
# Add required binaries and libraries to package and modify them where needed
cd ${ISSM_DIR}/bin
echo "Modify generic"
cat generic_static.py | sed -e "s/generic_static/generic/g" > generic.py
echo "Moving certain shared libraries to lib/"
cp ${LIBGMT} ${LIBGMT_DIST} 2>/dev/null
cp ${LIBPSL} ${LIBPSL_DIST} 2>/dev/null
echo "Moving MPICH binaries to bin/"
if [ -f ${ISSM_DIR}/externalpackages/petsc/install/bin/mpiexec ]; then
cp ${ISSM_DIR}/externalpackages/petsc/install/bin/mpiexec .
cp ${ISSM_DIR}/externalpackages/petsc/install/bin/hydra_pmi_proxy .
elif [ -f ${ISSM_DIR}/externalpackages/mpich/install/bin/mpiexec ]; then
cp ${ISSM_DIR}/externalpackages/mpich/install/bin/mpiexec .
cp ${ISSM_DIR}/externalpackages/mpich/install/bin/hydra_pmi_proxy .
else
echo "MPICH not found"
exit 1
fi
echo "Moving GDAL binaries to bin/"
if [ -f ${ISSM_DIR}/externalpackages/gdal/install/bin/gdal-config ]; then
cp ${ISSM_DIR}/externalpackages/gdal/install/bin/gdalsrsinfo .
cp ${ISSM_DIR}/externalpackages/gdal/install/bin/gdaltransform .
else
echo "GDAL not found"
exit 1
fi
echo "Moving Gmsh binaries to bin/"
if [ -f ${ISSM_DIR}/externalpackages/gmsh/install/bin/gmsh ]; then
cp ${ISSM_DIR}/externalpackages/gmsh/install/bin/gmsh .
else
echo "Gmsh not found"
exit 1
fi
echo "Moving GMT binaries to bin/"
if [ -f ${ISSM_DIR}/externalpackages/gmt/install/bin/gmt ]; then
cp ${ISSM_DIR}/externalpackages/gmt/install/bin/gmt .
elif [ -f ${ISSM_EXT_STATIC_DIR}/gmt/install/bin/gmtselect ]; then
cp ${ISSM_DIR}/externalpackages/gmt/install/bin/gmtselect .
else
echo "GMT not found"
exit 1
fi
echo "Moving GSHHG assets to share/"
if [ -d ${ISSM_DIR}/externalpackages/gshhg/install ]; then
mkdir ${ISSM_DIR}/share 2>/dev/null
cp -R ${ISSM_DIR}/externalpackages/gshhg/install/*.nc ${ISSM_DIR}/share
else
echo "GSHHG not found"
exit 1
fi
echo "Moving PROJ assets to bin/ and share/"
if [ -d ${ISSM_DIR}/externalpackages/proj/install/share/proj ]; then
cp ${ISSM_DIR}/externalpackages/proj/install/bin/projinfo .
mkdir ${ISSM_DIR}/share 2>/dev/null
cp -R ${ISSM_DIR}/externalpackages/proj/install/share/proj ${ISSM_DIR}/share
else
echo "PROJ not found"
exit 1
fi
# Run tests
if [ ${skip_tests} -eq 0 ]; then
echo "Running tests"
cd ${ISSM_DIR}/test/NightlyRun
rm python.log 2>/dev/null
# Set Python environment
export PYTHONPATH="${ISSM_DIR}/src/m/dev"
export PYTHONSTARTUP="${PYTHONPATH}/devpath.py"
export PYTHONUNBUFFERED=1 # We don't want Python to buffer output, otherwise issm.exe output is not captured
# Run tests, redirecting output to logfile and suppressing output to console
./runme.py ${PYTHON_NROPTIONS} &> python.log 2>&1
# Check that Python did not exit in error
pythonExitCode=`echo $?`
pythonExitedInError=`grep -c -E "Error|No such file or directory|Permission denied|Standard exception|Traceback|bad interpreter|syntax error|error:" python.log`
if [[ ${pythonExitCode} -ne 0 || ${pythonExitedInError} -ne 0 ]]; then
echo "----------Python exited in error!----------"
cat python.log
echo "-----------End of python.log-----------"
# Clean up execution directory
rm -rf ${ISSM_DIR}/execution/*
exit 1
fi
# Check that all tests passed
sed -i '' "/FAILED TO establish the default connection to the WindowServer/d" python.log # First, need to remove WindowServer error message
numTestsFailed=`grep -c -E "FAILED|ERROR" python.log`
if [ ${numTestsFailed} -ne 0 ]; then
echo "One or more tests FAILED"
cat python.log
exit 1
else
echo "All tests PASSED"
fi
else
echo "Skipping tests"
fi
# Create package
cd ${ISSM_DIR}
git clean -d -f test # Clean up test directory (before copying to package)
echo "Copying assets to package: ${PKG}"
cp -rf bin examples lib scripts share test ${PKG}
mkdir ${PKG}/execution
cp packagers/mac/issm-executable_entitlements.plist ${PKG}/bin/entitlements.plist
# ${ISSM_DIR}/scripts/py_to_pyc.sh ${PKG}/bin # Compile Python source files
echo "Cleaning up unneeded/unwanted files"
# rm -f ${PKG}/bin/*.py # Remove all Python scripts
rm -f ${PKG}/bin/generic_static.* # Remove static versions of generic cluster classes
rm -f ${PKG}/lib/*.a # Remove static libraries from package
rm -f ${PKG}/lib/*.la # Remove libtool libraries from package
rm -rf ${PKG}/test/SandBox # Remove testing sandbox from package
# Compress package
echo "Compressing package"
ditto -ck --sequesterRsrc --keepParent ${PKG} ${COMPRESSED_PKG}