-
Notifications
You must be signed in to change notification settings - Fork 236
/
build.sh
188 lines (138 loc) · 5.07 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
#!/bin/bash
PYTHONS=("cp38" "cp39" "cp310" "cp311" "cp12")
export KRATOS_VERSION="9.5"
BASE_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
export KRATOS_ROOT="/workspace/kratos/Kratos"
WHEEL_ROOT="/workspace/wheel"
WHEEL_OUT="/data_swap_guest"
CORE_LIB_DIR="/workspace/coreLibs"
# Created the wheel building directory.
setup_wheel_dir () {
cd $KRATOS_ROOT
mkdir $WHEEL_ROOT
cp scripts/wheels/setup.py ${WHEEL_ROOT}/setup.py
mkdir ${WHEEL_ROOT}/KratosMultiphysics
mkdir ${WHEEL_ROOT}/KratosMultiphysics/.libs # This dir is necessary mainly to store the shared libs in windows
}
# Creates the wheel for KratosCore.
build_core_wheel () {
setup_wheel_dir
cd $KRATOS_ROOT
PREFIX_LOCATION=$1
mkdir ${WHEEL_ROOT}/KratosMultiphysics
cp ${PREFIX_LOCATION}/KratosMultiphysics/* ${WHEEL_ROOT}/KratosMultiphysics
cp ${KRATOS_ROOT}/kratos/KratosMultiphysics.json ${WHEEL_ROOT}/wheel.json
cd $WHEEL_ROOT
$PYTHON_LOCATION setup.py bdist_wheel
cd ${WHEEL_ROOT}/dist
auditwheel repair *.whl
mkdir $CORE_LIB_DIR
unzip -j wheelhouse/KratosMultiphysics* 'KratosMultiphysics.libs/*' -d $CORE_LIB_DIR
cp wheelhouse/* ${WHEEL_OUT}/
cd
rm -r $WHEEL_ROOT
}
# Creates the wheel for each KratosApplication.
build_application_wheel () {
setup_wheel_dir
cp ${KRATOS_ROOT}/applications/${1}/${1}.json ${WHEEL_ROOT}/wheel.json
cd $WHEEL_ROOT
$PYTHON_LOCATION setup.py bdist_wheel
auditwheel repair dist/*.whl
optimize_wheel
cp ${WHEEL_ROOT}/wheelhouse/* ${WHEEL_OUT}/
cd
rm -r $WHEEL_ROOT
}
# Kreates the wheel bundle.
build_kratos_all_wheel () {
setup_wheel_dir
cp ${KRATOS_ROOT}/kratos/KratosMultiphysics-all.json ${WHEEL_ROOT}/wheel.json
cp ${KRATOS_ROOT}/scripts/wheels/linux/setup_kratos_all.py ${WHEEL_ROOT}/setup.py
cd ${WHEEL_ROOT}
$PYTHON_LOCATION setup.py bdist_wheel
cp dist/* ${WHEEL_OUT}/
cd
rm -r $WHEEL_ROOT
}
# Removes duplicated libraries from existing wheels.
optimize_wheel(){
cd ${WHEEL_ROOT}/wheelhouse
ARCHIVE_NAME=$(ls .)
mkdir tmp
unzip ${ARCHIVE_NAME} -d tmp
rm $ARCHIVE_NAME
echo "Begin exclude list for ${APPNAME}"
echo "List of core libs to be excluded:"
echo "$(ls ${CORE_LIB_DIR})"
# Clean excluded libraries
for LIBRARY in $(ls tmp/Kratos${APPNAME}.libs)
do
if [ -f "${CORE_LIB_DIR}/${LIBRARY}" ] || grep $(echo $LIBRARY | cut -f1 -d"-") "${WHEEL_ROOT}/excluded.txt" ; then
echo "-- Removing ${LIBRARY} - already present in dependent wheel."
rm tmp/Kratos${APPNAME}.libs/${LIBRARY} # Try to remove from app dir
sed -i "/${LIBRARY}/d" tmp/*.dist-info/RECORD
else
echo "-- Keeping ${LIBRARY}"
fi
done
# Alson clean the possible copies done in the setup.py
rm tmp/KratosMultiphysics/.libs/libKratos*
cd tmp
zip -r ../${ARCHIVE_NAME} ./*
cd ..
rm -r tmp
}
# Buils the KratosXCore components for the kernel and applications
build_core () {
cd $KRATOS_ROOT
PYTHON_LOCATION=$1
PREFIX_LOCATION=$2
cp /workspace/kratos/Kratos/scripts/wheels/linux/configure.sh ./configure.sh
chmod +x configure.sh
./configure.sh $PYTHON_LOCATION $PREFIX_LOCATION
cmake --build "${KRATOS_ROOT}/build/Release" --target KratosKernel -- -j$(nproc)
}
# Buils the KratosXInterface components for the kernel and applications given an specific version of python
build_interface () {
cd $KRATOS_ROOT
PYTHON_LOCATION=$1
PREFIX_LOCATION=$2
cp /workspace/kratos/Kratos/scripts/wheels/linux/configure.sh ./configure.sh
chmod +x configure.sh
./configure.sh $PYTHON_LOCATION $PREFIX_LOCATION
cmake --build "${KRATOS_ROOT}/build/Release" --target KratosPythonInterface -- -j$(nproc)
cmake --build "${KRATOS_ROOT}/build/Release" --target install -- -j$(nproc)
}
# Core can be build independently of the python version.
# Install path should be useless here.
echo "Starting core build"
build_core python3.8 ${KRATOS_ROOT}/bin/core
echo "Finished core build"
for PYTHON_VERSION in "${PYTHONS[@]}"
do
PYTHON_TMP=$(ls /opt/python | grep $PYTHON_VERSION | cut -d "-" -f 2)
export PYTHON=${PYTHON_TMP#cp}
echo "Starting build for python${PYTHON_VERSION}"
PYTHON_LOCATION=/opt/python/$(ls /opt/python | grep $PYTHON_VERSION)/bin/python
PREFIX_LOCATION=$KRATOS_ROOT/bin/Release/python_$PYTHON
$PYTHON_LOCATION -m pip install mypy
build_interface $PYTHON_LOCATION $PREFIX_LOCATION
cd $KRATOS_ROOT
export HASH=$(git show -s --format=%h) # Used in version number
export LD_LIBRARY_PATH=${PREFIX_LOCATION}/libs:$BASE_LD_LIBRARY_PATH
echo $LD_LIBRARY_PATH
echo "Building Core Wheel"
build_core_wheel $PREFIX_LOCATION
echo "Building App Wheels"
for APPLICATION in $(ls -d ${PREFIX_LOCATION}/applications/*)
do
APPNAME=$(basename "$APPLICATION")
echo "Building ${APPNAME} Wheel"
build_application_wheel $APPNAME
done
echo "Building Bundle Wheel"
build_kratos_all_wheel $PREFIX_LOCATION
echo finished build for python${PYTHON_VERSION}
export LD_LIBRARY_PATH=$BASE_LD_LIBRARY_PATH
done