Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[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 VERBOSE_BUILD="VERBOSE=1"
134 if which ninja 2>/dev/null >/dev/null ; then
135   GENERATOR=Ninja
136   BUILDER=ninja
137   VERBOSE_BUILD="-v"
138 fi
139
140 ulimit -c 0 || true
141
142 echo "XX"
143 echo "XX Get out of the tree"
144 echo "XX"
145 if [ -d "$WORKSPACE"/build ]
146 then
147   # Windows cannot remove the directory if it's still used by the previous build
148   rm -rf "$WORKSPACE"/build || sleep 10 && rm -rf "$WORKSPACE"/build || sleep 10 && rm -rf "$WORKSPACE"/build
149 fi
150 mkdir "$WORKSPACE"/build
151 cd "$WORKSPACE"/build
152
153 have_NS3="no"
154 if [ "$os" = "Debian" ] ; then
155   if dpkg --compare-versions "$(dpkg-query -f '${Version}' -W libns3-dev)" ge 3.28; then
156     have_NS3="yes"
157   fi
158 fi
159 if [ "$os" = "nixos" ] ; then
160   have_NS3="yes"
161 fi
162 echo "XX have_NS3: ${have_NS3}"
163
164 SIMGRID_PYTHON_LIBDIR=""
165 if [ "$os" = "nixos" ] ; then
166   SIMGRID_PYTHON_LIBDIR="/home/ci/simgrid_install/lib64"
167 fi
168 echo "XX SIMGRID_PYTHON_LIBDIR: ${SIMGRID_PYTHON_LIBDIR}"
169
170 # This is for Windows:
171 PATH="$WORKSPACE/build/lib:$PATH"
172
173 echo "XX"
174 echo "XX Build the archive out of the tree"
175 echo "XX   pwd: $(pwd)"
176 echo "XX"
177
178 cmake -G"$GENERATOR" -Denable_documentation=OFF "$WORKSPACE"
179 ${BUILDER} dist -j $NUMBER_OF_PROCESSORS
180 SIMGRID_VERSION=$(cat VERSION)
181
182 echo "XX"
183 echo "XX Open the resulting archive"
184 echo "XX"
185 gunzip "${SIMGRID_VERSION}".tar.gz
186 tar xf "${SIMGRID_VERSION}".tar
187 mkdir "${WORKSPACE}"/build/"${SIMGRID_VERSION}"/build
188 cd "${WORKSPACE}"/build/"${SIMGRID_VERSION}"/build
189 SRCFOLDER="${WORKSPACE}/build/${SIMGRID_VERSION}"
190
191 echo "XX"
192 echo "XX Configure and build SimGrid"
193 echo "XX   pwd: $(pwd)"
194 echo "XX"
195 set -x
196
197 if [ "$os" = "CentOS" ]; then
198     if [ "$(ld -v | cut -d\  -f4 | cut -c1-4)" = "2.30" ]; then
199         echo "Temporary disable LTO, believed to be broken on this system."
200         MAY_DISABLE_LTO=-Denable_lto=OFF
201     else
202         MAY_DISABLE_LTO=
203     fi
204 fi
205
206 if [ $NODE_NAME = "armv8" ]; then
207     echo "disable LTO, believed to be too heavy for this particular system"
208     MAY_DISABLE_LTO=-Denable_lto=OFF
209 fi
210
211 cmake -G"$GENERATOR" ${INSTALL:+-DCMAKE_INSTALL_PREFIX=$INSTALL} \
212   -Denable_debug=ON -Denable_documentation=OFF -Denable_coverage=OFF \
213   -Denable_model-checking=$(onoff test "$build_mode" = "ModelChecker") \
214   -Denable_testsuite_smpi_MBI=OFF -Denable_testsuite_McMini=ON \
215   -Denable_compile_optimizations=$(onoff test "$build_mode" != "DynamicAnalysis") \
216   -Denable_testsuite_smpi_MPICH3=$(onoff test "$build_mode" = "Debug") \
217   -Denable_mallocators=$(onoff test "$build_mode" != "DynamicAnalysis") \
218   -Denable_memcheck=$(onoff test "$build_mode" = "DynamicAnalysis") \
219   -Denable_compile_warnings=$(onoff test "$GENERATOR" != "MSYS Makefiles") -Denable_smpi=ON \
220   -Denable_ns3=$(onoff test "$have_NS3" = "yes" -a "$build_mode" = "Debug") \
221   -DSIMGRID_PYTHON_LIBDIR=${SIMGRID_PYTHON_LIBDIR} \
222   -DCMAKE_DISABLE_SOURCE_CHANGES=ON ${MAY_DISABLE_LTO} \
223   -DLTO_EXTRA_FLAG="auto" \
224   -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
225   "$SRCFOLDER"
226
227 ${BUILDER} -j $NUMBER_OF_PROCESSORS ${VERBOSE_BUILD} tests
228
229 echo "XX"
230 echo "XX Run the tests"
231 echo "XX   pwd: "$(pwd)
232 echo "XX"
233
234 ctest -T test --output-on-failure --no-compress-output -j $NUMBER_OF_PROCESSORS || true
235
236 if test -n "$INSTALL" && [ "${branch_name}" = "origin/master" ] ; then
237   echo "XX"
238   echo "XX Test done. Install everything since it's a regular build, not on a Windows."
239   echo "XX"
240
241   rm -rf "$INSTALL"
242
243   ${BUILDER} install
244 fi
245
246 echo "XX"
247 echo "XX Done. Return the results to cmake"
248 echo "XX"