Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
36c17be64b2f5dee419710f3d1ac87f2796d671f
[simgrid.git] / tools / jenkins / build.sh
1 #!/usr/bin/env sh
2
3 # This script is used by various build projects on Jenkins
4
5 # See https://ci.inria.fr/simgrid/job/SimGrid/configure
6 # See https://ci.inria.fr/simgrid/job/Simgrid-Windows/configure
7
8 # ensure that the locales are set, so that perl keeps its nerves
9 export LC_ALL=C
10
11 echo "XXXX Cleanup previous attempts. Remaining content of /tmp:"
12 rm -f /tmp/cc*
13 rm -f /tmp/*.so
14 rm -f /tmp/*.so.*
15 rm -rf /tmp/simgrid-java*
16 rm -rf /var/tmp/simgrid-java*
17 rm -rf /tmp/jvm-*
18 find $WORKSPACE -name "hs_err_pid*.log" -exec rm -f {} +
19 ls /tmp
20 df -h
21 echo "XXXX Let's go"
22
23 set -e
24
25 # usage: die status message...
26 die () {
27   status=${1:-1}
28   shift
29   [ $# -gt 0 ] || set -- "Error - Halting"
30   echo "$@" >&2
31   exit "$status"
32 }
33
34 # Get an ON/OFF string from a command:
35 onoff() {
36   if "$@" > /dev/null ; then
37     echo ON
38   else
39     echo OFF
40   fi
41 }
42
43 if type lsb_release >/dev/null 2>&1; then # recent versions of Debian/Ubuntu
44     # linuxbase.org
45     os=$(lsb_release -si)
46     ver="$(lsb_release -sr) ($(lsb_release -sc))"
47 elif [ -f /etc/lsb-release ]; then # For some versions of Debian/Ubuntu without lsb_release command
48     . /etc/lsb-release
49     os=$DISTRIB_ID
50     ver=$DISTRIB_RELEASE
51 elif [ -f /etc/debian_version ]; then # Older Debian/Ubuntu/etc.
52     os=Debian
53     ver=$(cat /etc/debian_version)
54 elif [ -f /etc/redhat-release ]; then #RH, Fedora, Centos
55     read -r os ver < /etc/redhat-release
56 elif [ -f /usr/bin/sw_vers ]; then #osx
57     os=$(sw_vers -productName)
58     ver=$(sw_vers -productVersion)
59 elif [ -f /bin/freebsd-version ]; then #freebsd
60     os=$(uname -s)
61     ver=$(freebsd-version -u)
62 elif [ -f /etc/release ]; then #openindiana
63     read -r os ver < /etc/release
64 elif [ -f /etc/os-release ]; then # freedesktop.org and systemd, put last as usually missing useful info
65     . /etc/os-release
66     os=$NAME
67     ver=$VERSION_ID
68 else
69     # Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
70     echo "fallback as OS name not found"
71     os=$(uname -s)
72     ver=$(uname -r)
73 fi
74
75 # Are we running on wsl ?
76 if [ -f /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe ]; then
77     #To identify the windows underneath the linux
78     PATH="/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:$PATH"
79     major=$(powershell.exe -command "[environment]::OSVersion.Version.Major" | sed 's/\r//g')
80     build=$(powershell.exe -command "[environment]::OSVersion.Version.Build"| sed 's/\r//g')
81     ver="$major v$build - WSL $os $ver"
82     os=Windows
83 fi
84
85 case $(uname -m) in
86 x86_64)
87     bits="64 bits"
88     ;;
89 i*86)
90     bits="32 bits"
91     ;;
92 *)
93     bits=""
94     ;;
95 esac
96 echo "OS Version : $os $ver $bits"
97
98
99 build_mode="$1"
100 echo "Build mode $build_mode on $(uname -np)" >&2
101 case "$build_mode" in
102   "Debug")
103       INSTALL="$HOME/simgrid_install"
104   ;;
105
106   "ModelChecker")
107       INSTALL="$HOME/mc_simgrid_install"
108   ;;
109
110   "DynamicAnalysis")
111       INSTALL=""
112   ;;
113
114   *)
115     die 1 "Unknown build_mode $build_mode"
116   ;;
117 esac
118
119 if [ "$2" = "" ]; then
120   branch_name="unknown"
121 else
122   branch_name="$2"
123 fi
124 echo "Branch built is $branch_name"
125
126 NUMBER_OF_PROCESSORS="$(nproc)" || NUMBER_OF_PROCESSORS=1
127 GENERATOR="Unix Makefiles"
128
129 ulimit -c 0 || true
130
131 echo "XX"
132 echo "XX Get out of the tree"
133 echo "XX"
134 if [ -d "$WORKSPACE"/build ]
135 then
136   # Windows cannot remove the directory if it's still used by the previous build
137   rm -rf "$WORKSPACE"/build || sleep 10 && rm -rf "$WORKSPACE"/build || sleep 10 && rm -rf "$WORKSPACE"/build
138 fi
139 mkdir "$WORKSPACE"/build
140 cd "$WORKSPACE"/build
141
142 have_NS3="no"
143 if [ "$os" = "Debian" ] ; then
144   if dpkg --compare-versions "$(dpkg-query -f '${Version}' -W libns3-dev)" ge 3.28; then
145     have_NS3="yes"
146   fi
147 fi
148 MAY_HINT_AT_NS3=""
149 if [ $NODE_NAME = "ubuntu-lts" ] ; then
150   MAY_HINT_AT_NS3="-DNS3_HINT=/builds/ns-3-dev/build/"
151   have_NS3="yes"
152 fi
153 if [ "$os" = "nixos" ] ; then
154   have_NS3="yes"
155 fi
156 echo "XX have_NS3: ${have_NS3}"
157
158 SIMGRID_PYTHON_LIBDIR=""
159 if [ "$os" = "nixos" ] ; then
160   SIMGRID_PYTHON_LIBDIR="/home/ci/simgrid_install/lib64"
161 fi
162 echo "XX SIMGRID_PYTHON_LIBDIR: ${SIMGRID_PYTHON_LIBDIR}"
163
164 # This is for Windows:
165 PATH="$WORKSPACE/build/lib:$PATH"
166
167 echo "XX"
168 echo "XX Build the archive out of the tree"
169 echo "XX   pwd: $(pwd)"
170 echo "XX"
171
172 cmake -G"$GENERATOR" -Denable_documentation=OFF "$WORKSPACE"
173 make dist -j $NUMBER_OF_PROCESSORS
174 SIMGRID_VERSION=$(cat VERSION)
175
176 echo "XX"
177 echo "XX Open the resulting archive"
178 echo "XX"
179 gunzip "${SIMGRID_VERSION}".tar.gz
180 tar xf "${SIMGRID_VERSION}".tar
181 mkdir "${WORKSPACE}"/build/"${SIMGRID_VERSION}"/build
182 cd "${WORKSPACE}"/build/"${SIMGRID_VERSION}"/build
183 SRCFOLDER="${WORKSPACE}/build/${SIMGRID_VERSION}"
184
185 echo "XX"
186 echo "XX Configure and build SimGrid"
187 echo "XX   pwd: $(pwd)"
188 echo "XX"
189 set -x
190
191 if cmake --version | grep -q 3\.11 ; then
192   # -DCMAKE_DISABLE_SOURCE_CHANGES=ON is broken with java on CMake 3.11
193   # https://gitlab.kitware.com/cmake/cmake/issues/17933
194   MAY_DISABLE_SOURCE_CHANGE=""
195 else
196   MAY_DISABLE_SOURCE_CHANGE="-DCMAKE_DISABLE_SOURCE_CHANGES=ON"
197 fi
198
199 if [ "$os" = "CentOS" ]; then
200     if [ "$(ld -v | cut -d\  -f4 | cut -c1-4)" = "2.30" ]; then
201         echo "Temporary disable LTO, believed to be broken on this system."
202         MAY_DISABLE_LTO=-Denable_lto=OFF
203     else
204         MAY_DISABLE_LTO=
205     fi
206 fi
207
208 if [ $NODE_NAME = "armv8" ]; then
209     echo "disable LTO, believed to be too heavy for this particular system"
210     MAY_DISABLE_LTO=-Denable_lto=OFF
211 fi
212
213 cmake -G"$GENERATOR" ${INSTALL:+-DCMAKE_INSTALL_PREFIX=$INSTALL} \
214   -Denable_debug=ON -Denable_documentation=OFF -Denable_coverage=OFF \
215   -Denable_model-checking=$(onoff test "$build_mode" = "ModelChecker") \
216   -Denable_smpi_MBI_testsuite=OFF \
217   -Denable_compile_optimizations=$(onoff test "$build_mode" != "DynamicAnalysis") \
218   -Denable_smpi_MPICH3_testsuite=$(onoff test "$build_mode" = "Debug") \
219   -Denable_mallocators=$(onoff test "$build_mode" != "DynamicAnalysis") \
220   -Denable_memcheck=$(onoff test "$build_mode" = "DynamicAnalysis") \
221   -Denable_compile_warnings=$(onoff test "$GENERATOR" != "MSYS Makefiles") -Denable_smpi=ON \
222   -Denable_ns3=$(onoff test "$have_NS3" = "yes" -a "$build_mode" = "Debug") \
223   -DSIMGRID_PYTHON_LIBDIR=${SIMGRID_PYTHON_LIBDIR} \
224   ${MAY_DISABLE_SOURCE_CHANGE} ${MAY_DISABLE_LTO} ${MAY_HINT_AT_NS3} \
225   -Denable_java=$(onoff test "$build_mode" = "ModelChecker") \
226   -Denable_msg=$(onoff test "$build_mode" = "ModelChecker") \
227   -DLTO_EXTRA_FLAG="auto" \
228   -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
229   "$SRCFOLDER"
230 set +x
231
232 make -j $NUMBER_OF_PROCESSORS VERBOSE=1 tests
233
234 echo "XX"
235 echo "XX Run the tests"
236 echo "XX   pwd: "$(pwd)
237 echo "XX"
238
239 ctest -T test --output-on-failure --no-compress-output -j $NUMBER_OF_PROCESSORS || true
240
241 if test -n "$INSTALL" && [ "${branch_name}" = "origin/master" ] ; then
242   echo "XX"
243   echo "XX Test done. Install everything since it's a regular build, not on a Windows."
244   echo "XX"
245
246   rm -rf "$INSTALL"
247
248   make install
249 fi
250
251 echo "XX"
252 echo "XX Done. Return the results to cmake"
253 echo "XX"