Logo AND Algorithmique Numérique Distribuée

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