Logo AND Algorithmique Numérique Distribuée

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