Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of github.com:simgrid/simgrid into dev_10
[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 dpkg -l libns3-dev 2>&1|grep -q "ii  libns3-dev" ; then
149   have_NS3="yes"
150 fi
151 echo "XX have_NS3: ${have_NS3}"
152
153 # This is for Windows:
154 PATH="$WORKSPACE/build/lib:$PATH"
155
156 echo "XX"
157 echo "XX Build the archive out of the tree"
158 echo "XX   pwd: $(pwd)"
159 echo "XX"
160
161 cmake -G"$GENERATOR" -Denable_documentation=OFF "$WORKSPACE"
162 make dist -j $NUMBER_OF_PROCESSORS
163 SIMGRID_VERSION=$(cat VERSION)
164
165 echo "XX"
166 echo "XX Open the resulting archive"
167 echo "XX"
168 gunzip "${SIMGRID_VERSION}".tar.gz
169 tar xf "${SIMGRID_VERSION}".tar
170 mkdir "${WORKSPACE}"/build/"${SIMGRID_VERSION}"/build
171 cd "${WORKSPACE}"/build/"${SIMGRID_VERSION}"/build
172 SRCFOLDER="${WORKSPACE}/build/${SIMGRID_VERSION}"
173
174 echo "XX"
175 echo "XX Configure and build SimGrid"
176 echo "XX   pwd: $(pwd)"
177 echo "XX"
178 set -x
179
180 if cmake --version | grep -q 3\.11 ; then
181   # -DCMAKE_DISABLE_SOURCE_CHANGES=ON is broken with java on CMake 3.11
182   # https://gitlab.kitware.com/cmake/cmake/issues/17933
183   MAY_DISABLE_SOURCE_CHANGE=""
184 else 
185   MAY_DISABLE_SOURCE_CHANGE="-DCMAKE_DISABLE_SOURCE_CHANGES=ON"
186 fi
187
188 cmake -G"$GENERATOR" ${INSTALL:+-DCMAKE_INSTALL_PREFIX=$INSTALL} \
189   -Denable_debug=ON -Denable_documentation=OFF -Denable_coverage=OFF \
190   -Denable_model-checking=$(onoff test "$build_mode" = "ModelChecker") \
191   -Denable_smpi_ISP_testsuite=$(onoff test "$build_mode" = "ModelChecker") \
192   -Denable_compile_optimizations=$(onoff test "$build_mode" != "DynamicAnalysis") \
193   -Denable_smpi_MPICH3_testsuite=$(onoff test "$build_mode" = "Debug") \
194   -Denable_mallocators=$(onoff test "$build_mode" != "DynamicAnalysis") \
195   -Denable_memcheck=$(onoff test "$build_mode" = "DynamicAnalysis") \
196   -Denable_compile_warnings=$(onoff test "$GENERATOR" != "MSYS Makefiles") -Denable_smpi=ON \
197   -Denable_ns3=$(onoff test "$have_NS3" = "yes" -a "$build_mode" = "Debug") \
198   -Denable_jedule=OFF -Denable_lua=OFF ${MAY_DISABLE_SOURCE_CHANGE} \
199   -Denable_java=$(onoff test "$build_mode" = "ModelChecker") \
200   -Denable_msg=$(onoff test "$build_mode" = "ModelChecker") \
201   -DLTO_EXTRA_FLAG="auto" \
202   "$SRCFOLDER"
203 #  -Denable_lua=$(onoff test "$build_mode" != "DynamicAnalysis") \
204 set +x
205
206 make -j $NUMBER_OF_PROCESSORS VERBOSE=1 tests
207
208 echo "XX"
209 echo "XX Run the tests"
210 echo "XX   pwd: "$(pwd)
211 echo "XX"
212
213 ctest -T test --output-on-failure --no-compress-output || true
214
215 if test -n "$INSTALL" && [ "${branch_name}" = "origin/master" ] ; then
216   echo "XX"
217   echo "XX Test done. Install everything since it's a regular build, not on a Windows."
218   echo "XX"
219
220   rm -rf "$INSTALL"
221
222   make install
223 fi
224
225 echo "XX"
226 echo "XX Done. Return the results to cmake"
227 echo "XX"