Logo AND Algorithmique Numérique Distribuée

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