Logo AND Algorithmique Numérique Distribuée

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