Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove old workaround.
[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 if type lsb_release >/dev/null 2>&1; then # recent versions of Debian/Ubuntu
47     # linuxbase.org
48     os=$(lsb_release -si)
49     ver="$(lsb_release -sr) ($(lsb_release -sc))"
50 elif [ -f /etc/lsb-release ]; then # For some versions of Debian/Ubuntu without lsb_release command
51     . /etc/lsb-release
52     os=$DISTRIB_ID
53     ver=$DISTRIB_RELEASE
54 elif [ -f /etc/debian_version ]; then # Older Debian/Ubuntu/etc.
55     os=Debian
56     ver=$(cat /etc/debian_version)
57 elif [ -f /etc/redhat-release ]; then #RH, Fedora, Centos
58     read -r os ver < /etc/redhat-release
59 elif [ -f /usr/bin/sw_vers ]; then #osx
60     os=$(sw_vers -productName)
61     ver=$(sw_vers -productVersion)
62 elif [ -f /bin/freebsd-version ]; then #freebsd
63     os=$(uname -s)
64     ver=$(freebsd-version -u)
65 elif [ -f /etc/release ]; then #openindiana
66     read -r os ver < /etc/release
67 elif [ -f /etc/os-release ]; then # freedesktop.org and systemd, put last as usually missing useful info
68     . /etc/os-release
69     os=$NAME
70     ver=$VERSION_ID
71 else
72     # Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
73     echo "fallback as OS name not found"
74     os=$(uname -s)
75     ver=$(uname -r)
76 fi
77
78 # Are we running on wsl ?
79 if [ -f /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe ]; then
80     #To identify the windows underneath the linux
81     PATH="/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:$PATH"
82     major=$(powershell.exe -command "[environment]::OSVersion.Version.Major" | sed 's/\r//g')
83     build=$(powershell.exe -command "[environment]::OSVersion.Version.Build"| sed 's/\r//g')
84     ver="$major v$build - WSL $os $ver"
85     os=Windows
86 fi
87
88 case $(uname -m) in
89 x86_64)
90     bits="64 bits"
91     ;;
92 i*86)
93     bits="32 bits"
94     ;;
95 *)
96     bits=""
97     ;;
98 esac
99 echo "OS Version : $os $ver $bits"
100
101
102 build_mode="$1"
103 echo "Build mode $build_mode on $(uname -np)" >&2
104 case "$build_mode" in
105   "Debug")
106       INSTALL="/builds/simgrid_install"
107   ;;
108
109   "ModelChecker")
110       INSTALL="/builds/mc_simgrid_install"
111   ;;
112
113   "DynamicAnalysis")
114       INSTALL=""
115   ;;
116
117   *)
118     die 1 "Unknown build_mode $build_mode"
119   ;;
120 esac
121
122 if [ "$2" = "" ]; then
123   branch_name="unknown"
124 else
125   branch_name="$2"
126 fi
127 echo "Branch built is $branch_name"
128
129 NUMBER_OF_PROCESSORS="$(nproc)" || NUMBER_OF_PROCESSORS=1
130 GENERATOR="Unix Makefiles"
131
132 ulimit -c 0 || true
133
134 echo "XX"
135 echo "XX Get out of the tree"
136 echo "XX"
137 if [ -d $WORKSPACE/build ]
138 then
139   # Windows cannot remove the directory if it's still used by the previous build
140   rm -rf $WORKSPACE/build || sleep 10 && rm -rf $WORKSPACE/build || sleep 10 && rm -rf $WORKSPACE/build
141 fi
142 mkdir $WORKSPACE/build
143 cd $WORKSPACE/build
144
145 have_NS3="no"
146 if dpkg -l libns3-dev 2>&1|grep -q "ii  libns3-dev" ; then
147   have_NS3="yes"
148 fi
149 echo "XX have_NS3: ${have_NS3}"
150
151 # This is for Windows:
152 PATH="$WORKSPACE/build/lib:$PATH"
153
154 echo "XX"
155 echo "XX Build the archive out of the tree"
156 echo "XX   pwd: "$(pwd)
157 echo "XX"
158
159 cmake -G"$GENERATOR" -Denable_documentation=OFF $WORKSPACE
160 make dist -j $NUMBER_OF_PROCESSORS
161 SIMGRID_VERSION=$(cat VERSION)
162
163 echo "XX"
164 echo "XX Open the resulting archive"
165 echo "XX"
166 gunzip ${SIMGRID_VERSION}.tar.gz
167 tar xf ${SIMGRID_VERSION}.tar
168 mkdir ${WORKSPACE}/build/${SIMGRID_VERSION}/build
169 cd ${WORKSPACE}/build/${SIMGRID_VERSION}/build
170 SRCFOLDER="${WORKSPACE}/build/${SIMGRID_VERSION}"
171
172 echo "XX"
173 echo "XX Configure and build SimGrid"
174 echo "XX   pwd: "$(pwd)
175 echo "XX"
176 set -x
177
178 if cmake --version | grep -q 3\.11 ; then
179   # -DCMAKE_DISABLE_SOURCE_CHANGES=ON is broken with java on CMake 3.11
180   # https://gitlab.kitware.com/cmake/cmake/issues/17933
181   MAY_DISABLE_SOURCE_CHANGE=""
182 else 
183   MAY_DISABLE_SOURCE_CHANGE="-DCMAKE_DISABLE_SOURCE_CHANGES=ON"
184 fi
185
186 cmake -G"$GENERATOR" ${INSTALL:+-DCMAKE_INSTALL_PREFIX=$INSTALL} \
187   -Denable_debug=ON -Denable_documentation=OFF -Denable_coverage=OFF \
188   -Denable_model-checking=$(onoff test "$build_mode" = "ModelChecker") \
189   -Denable_smpi_ISP_testsuite=$(onoff test "$build_mode" = "ModelChecker") \
190   -Denable_compile_optimizations=$(onoff test "$build_mode" != "DynamicAnalysis") \
191   -Denable_smpi_MPICH3_testsuite=$(onoff test "$build_mode" = "Debug") \
192   -Denable_mallocators=$(onoff test "$build_mode" != "DynamicAnalysis") \
193   -Denable_memcheck=$(onoff test "$build_mode" = "DynamicAnalysis") \
194   -Denable_compile_warnings=$(onoff test "$GENERATOR" != "MSYS Makefiles") -Denable_smpi=ON \
195   -Denable_ns3=$(onoff test "$have_NS3" = "yes" -a "$build_mode" = "Debug") \
196   -Denable_jedule=OFF -Denable_lua=OFF ${MAY_DISABLE_SOURCE_CHANGE} \
197   -Denable_java=$(onoff test "$build_mode" = "ModelChecker") \
198   -Denable_MSG=$(onoff test "$build_mode" = "ModelChecker") \
199   $SRCFOLDER
200 #  -Denable_lua=$(onoff test "$build_mode" != "DynamicAnalysis") \
201 set +x
202
203 make -j $NUMBER_OF_PROCESSORS VERBOSE=1 tests
204
205 echo "XX"
206 echo "XX Run the tests"
207 echo "XX   pwd: "$(pwd)
208 echo "XX"
209
210 ctest -T test --output-on-failure --no-compress-output || true
211
212 if test -n "$INSTALL" && [ ${branch_name} = "origin/master" ] ; then
213   echo "XX"
214   echo "XX Test done. Install everything since it's a regular build, not on a Windows."
215   echo "XX"
216
217   rm -rf "$INSTALL"
218
219   make install
220 fi
221
222 echo "XX"
223 echo "XX Done. Return the results to cmake"
224 echo "XX"