Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid looping over single, constant value (codefactor.io/ShellCheck).
[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 set -e
9
10 # ensure that the locales are set, so that perl keeps its nerves
11 export LC_ALL=C
12
13 echo "XXXX Cleanup previous attempts. Remaining content of /tmp:"
14 rm -rf /tmp/simgrid-java*
15 rm -rf /var/tmp/simgrid-java*
16 rm -rf /tmp/jvm-*
17 find /builds/workspace/SimGrid/ -name "hs_err_pid*.log" -exec rm -f {} +
18 ls /tmp
19 df -h
20 echo "XXXX Let's go"
21
22 # Help older cmakes
23 if [ -e /usr/lib/jvm/java-7-openjdk-amd64 ] ;
24 then
25   export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
26 fi
27
28 # usage: die status message...
29 die () {
30   status=${1:-1}
31   shift
32   [ $# -gt 0 ] || set -- "Error - Halting"
33   echo "$@" >&2
34   exit $status
35 }
36
37 # Get an ON/OFF string from a command:
38 onoff() {
39   if "$@" > /dev/null ; then
40     echo ON
41   else
42     echo OFF
43   fi
44 }
45
46 # Check that we have what we need, or die quickly.
47 # The paths are not the same on all platforms, unfortunately.
48 #test -e /bin/tar  || die 1 "I need tar to compile. Please fix your slave."
49 #test -e /bin/gzip || die 1 "I need gzip to compile. Please fix your slave."
50 #test -e /usr/include/libunwind.h || die 1 "I need libunwind to compile. Please fix your slave."
51 #test -e /usr/include/valgrind/valgrind.h || die 1 "I need valgrind to compile. Please fix your slave."
52
53 if type lsb_release >/dev/null 2>&1; then
54   if [ -f /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe ]; then
55     #To identify the windows underneath the winbuntu
56     PATH="/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:$PATH"
57     major=$(powershell.exe -command "[environment]::OSVersion.Version.Major" | sed 's/\r//g')
58     build=$(powershell.exe -command "[environment]::OSVersion.Version.Build"| sed 's/\r//g')
59     os=Windows
60     ver="$major v$build - WSL $(lsb_release -sd)"
61   else
62     # linuxbase.org
63     os=$(lsb_release -si)
64     ver="$(lsb_release -sr) ($(lsb_release -sc))"
65   fi
66 elif [ -f /etc/lsb-release ]; then
67     # For some versions of Debian/Ubuntu without lsb_release command
68     . /etc/lsb-release
69     os=$DISTRIB_ID
70     ver=$DISTRIB_RELEASE
71 elif [ -f /etc/debian_version ]; then
72     # Older Debian/Ubuntu/etc.
73     os=Debian
74     ver=$(cat /etc/debian_version)
75 elif [ -f /etc/redhat-release ]; then
76     read -r os ver < /etc/redhat-release
77 elif [ -f /usr/bin/sw_vers ]; then
78     os=$(sw_vers -productName)
79     ver=$(sw_vers -productVersion)
80 elif [ -f /bin/freebsd-version ]; then
81     os=$(uname -s)
82     ver=$(freebsd-version -u)
83 elif [ -f /etc/version ]; then
84     read -r os ver < /etc/release
85 elif [ -f /etc/os-release ]; then
86     # freedesktop.org and systemd, put last as usually missing useful info
87     . /etc/os-release
88     os=$NAME
89     ver=$VERSION_ID
90 else
91     # Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
92     echo "fallback as OS name not found"
93     os=$(uname -s)
94     ver=$(uname -r)
95 fi
96 case $(uname -m) in
97 x86_64)
98     bits="64 bits"
99     ;;
100 i*86)
101     bits="32 bits"
102     ;;
103 *)
104     bits=""
105     ;;
106 esac
107 echo "OS Version : $os $ver $bits"
108
109
110 build_mode="$1"
111 echo "Build mode $build_mode on $(uname -np)" >&2
112 case "$build_mode" in
113   "Debug")
114       INSTALL="/builds/simgrid_install"
115   ;;
116
117   "ModelChecker")
118       INSTALL="/builds/mc_simgrid_install"
119   ;;
120
121   "DynamicAnalysis")
122       INSTALL=""
123   ;;
124
125   *)
126     die 1 "Unknown build_mode $build_mode"
127   ;;
128 esac
129
130 if [ "$2" = "" ]; then
131   branch_name="unknown"
132 else
133   branch_name="$2"
134 fi
135 echo "Branch built is $branch_name"
136
137 NUMBER_OF_PROCESSORS="$(nproc)" || NUMBER_OF_PROCESSORS=1
138 GENERATOR="Unix Makefiles"
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 dpkg -l libns3-dev 2>&1|grep -q "ii  libns3-dev" ; then
155   have_NS3="yes"
156 fi
157 echo "XX have_NS3: ${have_NS3}"
158
159 # This is for Windows:
160 PATH="$WORKSPACE/build/lib:$PATH"
161
162 echo "XX"
163 echo "XX Build the archive out of the tree"
164 echo "XX   pwd: "$(pwd)
165 echo "XX"
166
167 cmake -G"$GENERATOR" -Denable_documentation=OFF $WORKSPACE
168 make dist -j $NUMBER_OF_PROCESSORS
169 SIMGRID_VERSION=$(cat VERSION)
170
171 echo "XX"
172 echo "XX Open the resulting archive"
173 echo "XX"
174 gunzip ${SIMGRID_VERSION}.tar.gz
175 tar xf ${SIMGRID_VERSION}.tar
176 mkdir ${WORKSPACE}/build/${SIMGRID_VERSION}/build
177 cd ${WORKSPACE}/build/${SIMGRID_VERSION}/build
178 SRCFOLDER="${WORKSPACE}/build/${SIMGRID_VERSION}"
179
180 echo "XX"
181 echo "XX Configure and build SimGrid"
182 echo "XX   pwd: "$(pwd)
183 echo "XX"
184 set -x
185
186 if cmake --version | grep -q 3\.11 ; then
187   # -DCMAKE_DISABLE_SOURCE_CHANGES=ON is broken with java on CMake 3.11
188   # https://gitlab.kitware.com/cmake/cmake/issues/17933
189   MAY_DISABLE_SOURCE_CHANGE=""
190 else 
191   MAY_DISABLE_SOURCE_CHANGE="-DCMAKE_DISABLE_SOURCE_CHANGES=ON"
192 fi
193
194 if [ "$os" = "NixOS" ] && [ "$(gcc -dumpversion)" = "7.4.0" ]; then
195     echo "Temporary disable LTO, believed to be broken on this system."
196     MAY_DISABLE_LTO=-Denable_lto=OFF
197 else
198     MAY_DISABLE_LTO=
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_ISP_testsuite=$(onoff test "$build_mode" = "ModelChecker") \
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   -Denable_jedule=OFF -Denable_java=ON -Denable_lua=OFF ${MAY_DISABLE_SOURCE_CHANGE} ${MAY_DISABLE_LTO} \
212   $SRCFOLDER
213 #  -Denable_lua=$(onoff test "$build_mode" != "DynamicAnalysis") \
214 set +x
215
216 make -j $NUMBER_OF_PROCESSORS VERBOSE=1 tests
217
218 echo "XX"
219 echo "XX Run the tests"
220 echo "XX   pwd: "$(pwd)
221 echo "XX"
222
223 ctest -T test --output-on-failure --no-compress-output || true
224 if [ -f Testing/TAG ] ; then
225    xsltproc $WORKSPACE/tools/jenkins/ctest2junit.xsl Testing/$( head -n 1 < Testing/TAG )/Test.xml > CTestResults.xml
226    mv CTestResults.xml $WORKSPACE
227 fi
228
229 if test -n "$INSTALL" && [ ${branch_name} = "origin/master" ] ; then
230   echo "XX"
231   echo "XX Test done. Install everything since it's a regular build, not on a Windows."
232   echo "XX"
233
234   rm -rf "$INSTALL"
235
236   make install
237 fi
238
239 echo "XX"
240 echo "XX Done. Return the results to cmake"
241 echo "XX"