ci: Missing source dir when parsing configure.ac version
[tor.git] / scripts / ci / ci-driver.sh
blobf99e45e6f25a79483421c7691195df732b10d3fa
1 #!/bin/bash
3 ####
4 # DO NOT EDIT THIS FILE IN MASTER. ONLY EDIT IT IN THE OLDEST SUPPORTED
5 # BRANCH, THEN MERGE FORWARD.
6 ####
8 # This script is used to build Tor for continuous integration. It should
9 # be kept the same for all supported Tor versions.
11 # It's subject to the regular Tor license; see LICENSE for copying
12 # information.
14 set -o errexit
15 set -o nounset
17 # Options for this script.
18 DEBUG_CI="${DEBUG_CI:-no}"
19 COLOR_CI="${COLOR_CI:-yes}"
21 # Options for which CI system this is.
22 ON_GITLAB="${ON_GITLAB:-yes}"
24 # Options for things we usually won't want to skip.
25 RUN_STAGE_CONFIGURE="${RUN_STAGE_CONFIGURE:-yes}"
26 RUN_STAGE_BUILD="${RUN_STAGE_BUILD:-yes}"
27 RUN_STAGE_TEST="${RUN_STAGE_TEST:-yes}"
29 # Options for how to build Tor. All should be yes/no.
30 FATAL_WARNINGS="${FATAL_WARNINGS:-yes}"
31 HARDENING="${HARDENING:-no}"
32 COVERAGE="${COVERAGE:-no}"
33 RUST="${RUST:-no}"
34 DOXYGEN="${DOXYGEN:-no}"
35 ASCIIDOC="${ASCIIDOC:-no}"
36 TRACING="${TRACING:-no}"
37 ALL_BUGS_ARE_FATAL="${ALL_BUGS_ARE_FATAL:-no}"
38 DISABLE_DIRAUTH="${DISABLE_DIRAUTH:-no}"
39 DISABLE_RELAY="${DISABLE_RELAY:-no}"
40 NSS="${NSS:-no}"
42 # Options for which tests to run. All should be yes/no.
43 CHECK="${CHECK:-yes}"
44 STEM="${STEM:-no}"
45 CHUTNEY="${CHUTNEY:-no}"
46 DISTCHECK="${DISTCHECK:-no}"
48 # Options for where the Tor source is.
49 CI_SRCDIR="${CI_SRCDIR:-.}"
51 # Options for where to build.
52 CI_BUILDDIR="${CI_BUILDDIR:-./build}"
54 # How parallel should we run make?
55 MAKE_J_OPT="${MAKE_J_OPT:--j4}"
56 # Should we stop after make finds an error?
57 MAKE_K_OPT="${MAKE_K_OPT:--k}"
59 # What make target should we use for chutney?
60 CHUTNEY_MAKE_TARGET="${CHUTNEY_MAKE_TARGET:-test-network}"
62 # Where do we find our additional testing tools?
63 CHUTNEY_PATH="${CHUTNEY_PATH:-}"
64 STEM_PATH="${STEM_PATH:-}"
66 #############################################################################
67 # Preliminary functions.
69 # Terminal coloring/emphasis stuff.
70 if [[ "${COLOR_CI}" == "yes" ]]; then
71 T_RED=$(tput setaf 1 || true)
72 T_GREEN=$(tput setaf 2 || true)
73 T_YELLOW=$(tput setaf 3 || true)
74 T_DIM=$(tput dim || true)
75 T_BOLD=$(tput bold || true)
76 T_RESET=$(tput sgr0 || true)
77 else
78 T_RED=
79 T_GREEN=
80 T_YELLOW=
81 T_DIM=
82 T_BOLD=
83 T_RESET=
86 function error()
88 echo "${T_BOLD}${T_RED}ERROR:${T_RESET} $*" 1>&2
90 function die()
92 echo "${T_BOLD}${T_RED}FATAL ERROR:${T_RESET} $*" 1>&2
93 exit 1
96 function skipping()
98 echo "${T_BOLD}${T_YELLOW}Skipping $*${T_RESET}"
101 function hooray()
103 echo "${T_BOLD}${T_GREEN}$*${T_RESET}"
106 if [[ "${DEBUG_CI}" == "yes" ]]; then
107 function debug()
109 echo "${T_DIM}(debug): $*${T_RESET}"
111 else
112 function debug()
118 function yes_or_no()
120 local varname="$1"
121 local value="${!varname}"
122 debug "${varname} is ${value}"
123 if [[ "${value}" != 'yes' && "${value}" != 'no' ]]; then
124 die "${varname} must be 'yes' or 'no'. Got unexpected value ${value}".
128 function incompatible()
130 local varname1="$1"
131 local varname2="$2"
132 local val1="${!varname1}"
133 local val2="${!varname2}"
134 if [[ "${val1}" = 'yes' && "${val2}" = 'yes' ]]; then
135 die "Cannot set both ${varname1} and ${varname2}: they are incompatible."
139 function runcmd()
141 echo "${T_BOLD}\$ $*${T_RESET}"
142 if ! "$@" ; then
143 error "command '$*' has failed."
144 return 1
148 function show_git_version()
150 local tool="$1"
151 local dir="$2"
152 local version="?????"
153 if [[ -e "$dir/.git" ]] ; then
154 version=$(cd "$dir"; git rev-parse HEAD)
156 echo "${T_BOLD}$tool:${T_RESET} $version"
159 if [[ "${ON_GITLAB}" == "yes" ]]; then
160 function start_section()
162 local label="$1"
163 local stamp
164 stamp=$(date +%s)
165 printf "section_start:%s:%s\r\e[0K" "$stamp" "$label"
166 echo "${T_BOLD}${T_GREEN}========= $label${T_RESET}"
168 function end_section()
170 local label="$1"
171 local stamp
172 stamp=$(date +%s)
173 printf "section_end:%s:%s\r\e[0K" "$stamp" "$label"
175 else
176 function start_section()
178 true
180 function end_section()
182 true
186 #############################################################################
187 # Validate inputs.
189 debug Validating inputs
190 yes_or_no DEBUG_CI
191 yes_or_no COLOR_CI
192 yes_or_no ON_GITLAB
193 yes_or_no FATAL_WARNINGS
194 yes_or_no HARDENING
195 yes_or_no COVERAGE
196 yes_or_no RUST
197 yes_or_no DOXYGEN
198 yes_or_no ASCIIDOC
199 yes_or_no TRACING
200 yes_or_no ALL_BUGS_ARE_FATAL
201 yes_or_no DISABLE_DIRAUTH
202 yes_or_no DISABLE_RELAY
203 yes_or_no NSS
205 yes_or_no RUN_STAGE_CONFIGURE
206 yes_or_no RUN_STAGE_BUILD
207 yes_or_no RUN_STAGE_TEST
209 yes_or_no CHECK
210 yes_or_no STEM
211 yes_or_no DISTCHECK
213 incompatible DISTCHECK CHECK
214 incompatible DISTCHECK CHUTNEY
215 incompatible DISTCHECK STEM
216 incompatible DISTCHECK COVERAGE
217 incompatible DISTCHECK DOXYGEN
219 if [[ "${CHUTNEY}" = yes && "${CHUTNEY_PATH}" = '' ]] ; then
220 die "CHUTNEY is set to 'yes', but CHUTNEY_PATH was not specified."
223 if [[ "${STEM}" = yes && "${STEM_PATH}" = '' ]] ; then
224 die "STEM is set to 'yes', but STEM_PATH was not specified."
227 #############################################################################
228 # Set up options for make and configure.
230 make_options=()
231 if [[ "$MAKE_J_OPT" != "" ]]; then
232 make_options+=("$MAKE_J_OPT")
234 if [[ "$MAKE_K_OPT" != "" ]]; then
235 make_options+=("$MAKE_K_OPT")
238 configure_options=()
239 if [[ "$FATAL_WARNINGS" == "yes" ]]; then
240 configure_options+=("--enable-fatal-warnings")
242 if [[ "$HARDENING" == "yes" ]]; then
243 configure_options+=("--enable-fragile-hardening")
245 if [[ "$COVERAGE" == "yes" ]]; then
246 configure_options+=("--enable-coverage")
248 if [[ "$RUST" == "yes" ]]; then
249 configure_options+=("--enable-rust")
251 if [[ "$ASCIIDOC" != "yes" ]]; then
252 configure_options+=("--disable-asciidoc")
254 if [[ "$TRACING" == "yes" ]]; then
255 configure_options+=("--enable-tracing-instrumentation-lttng")
257 if [[ "$ALL_BUGS_ARE_FATAL" == "yes" ]]; then
258 configure_options+=("--enable-all-bugs-are-fatal")
260 if [[ "$DISABLE_DIRAUTH" == "yes" ]]; then
261 configure_options+=("--disable-module-dirauth")
263 if [[ "$DISABLE_RELAY" == "yes" ]]; then
264 configure_options+=("--disable-module-relay")
266 if [[ "$NSS" == "yes" ]]; then
267 configure_options+=("--enable-nss")
270 #############################################################################
271 # Tell the user about our versions of different tools and packages.
273 uname -a
274 printf "python: "
275 python -V || echo "no 'python' binary."
276 printf "python3: "
277 python3 -V || echo "no 'python3' binary."
279 show_git_version Tor "${CI_SRCDIR}"
280 if [[ "${STEM}" = "yes" ]]; then
281 show_git_version Stem "${STEM_PATH}"
283 if [[ "${CHUTNEY}" = "yes" ]]; then
284 show_git_version Chutney "${CHUTNEY_PATH}"
287 #############################################################################
288 # Determine the version of Tor.
290 TOR_VERSION=$(grep -m 1 AC_INIT ${CI_SRCDIR}/configure.ac | sed -e 's/.*\[//; s/\].*//;')
292 # Use variables like these when we need to behave differently depending on
293 # Tor version. Only create the variables we need.
294 TOR_VER_AT_LEAST_043=no
295 TOR_VER_AT_LEAST_044=no
297 # These are the currently supported Tor versions; no need to work with anything
298 # ancient in this script.
299 case "$TOR_VERSION" in
300 0.3.*)
301 TOR_VER_AT_LEAST_043=no
302 TOR_VER_AT_LEAST_044=no
304 0.4.[012].*)
305 TOR_VER_AT_LEAST_043=no
306 TOR_VER_AT_LEAST_044=no
308 0.4.3.*)
309 TOR_VER_AT_LEAST_043=yes
310 TOR_VER_AT_LEAST_044=no
313 TOR_VER_AT_LEAST_043=yes
314 TOR_VER_AT_LEAST_044=yes
316 esac
318 #############################################################################
319 # Make sure the directories are all there.
321 # Make sure CI_SRCDIR exists and has a file we expect.
322 if [[ ! -d "$CI_SRCDIR" ]] ; then
323 die "CI_SRCDIR=${CI_SRCDIR} is not a directory"
325 if [[ ! -f "$CI_SRCDIR/src/core/or/or.h" ]] ; then
326 die "CI_SRCDIR=${CI_SRCDIR} does not look like a Tor directory."
329 # Make CI_SRCDIR absolute.
330 CI_SRCDIR=$(cd "$CI_SRCDIR" && pwd)
332 # Create an "artifacts" directory to copy artifacts into.
333 mkdir -p ./artifacts
335 if [[ "$RUN_STAGE_CONFIGURE" = "yes" ]]; then
337 start_section "Autogen"
338 runcmd cd "${CI_SRCDIR}"
339 runcmd ./autogen.sh
340 runcmd mkdir -p "${CI_BUILDDIR}"
341 runcmd cd "${CI_BUILDDIR}"
342 end_section "Autogen"
344 # make the builddir absolute too.
345 CI_BUILDDIR=$(pwd)
347 start_section "Configure"
348 if ! runcmd "${CI_SRCDIR}"/configure "${configure_options[@]}" ; then
349 error "Here is the end of config.log:"
350 runcmd tail config.log
351 die "Unable to continue"
353 end_section "Configure"
354 else
355 debug "Skipping configure stage. Making sure that ${CI_BUILDDIR}/config.log exists."
356 if [[ ! -d "${CI_BUILDDIR}" ]]; then
357 die "Build directory ${CI_BUILDDIR} did not exist!";
359 if [[ ! -f "${CI_BUILDDIR}/config.log" ]]; then
360 die "Tor was not configured in ${CI_BUILDDIR}!";
363 cp config.log "${CI_SRCDIR}"/artifacts
365 runcmd cd "${CI_BUILDDIR}"
366 CI_BUILDDIR=$(pwd)
369 ###############################
370 # Build Tor.
372 if [[ "$RUN_STAGE_BUILD" = "yes" ]] ; then
373 if [[ "$DISTCHECK" = "no" ]]; then
374 start_section "Build"
375 runcmd make "${make_options[@]}" all
376 cp src/app/tor "${CI_SRCDIR}"/artifacts
377 end_section "Build"
378 else
379 export DISTCHECK_CONFIGURE_FLAGS="${configure_options[*]}"
380 # XXXX Set make options?
381 start_section Distcheck
382 if runcmd make "${make_options[@]}" distcheck ; then
383 hooray "Distcheck was successful. Nothing further will be done."
384 # We have to exit early here, since we can't do any other tests.
385 cp tor-*.tar.gz "${CI_SRCDIR}"/artifacts
386 exit 0
387 else
388 error "Diagnostics:"
389 runcmd make show-distdir-testlog || true
390 runcmd make show-distdir-core || true
391 die "Unable to continue."
393 end_section Distcheck
397 ##############################
398 # Run tests.
400 if [[ "$RUN_STAGE_TEST" == "no" ]]; then
401 echo "Skipping tests. Exiting now."
402 exit 0
405 FAILED_TESTS=""
407 if [[ "${DOXYGEN}" = 'yes' ]]; then
408 start_section Doxygen
409 if [[ "${TOR_VER_AT_LEAST_043}" = 'yes' ]]; then
410 if runcmd make doxygen; then
411 hooray "make doxygen has succeeded."
412 else
413 FAILED_TESTS="${FAILED_TESTS} doxygen"
415 else
416 skipping "make doxygen: doxygen is broken for Tor < 0.4.3"
418 end_section Doxygen
421 if [[ "${ASCIIDOC}" = 'yes' ]]; then
422 start_section Asciidoc
423 if runcmd make manpages; then
424 hooray "make manpages has succeeded."
425 else
426 FAILED_TESTS="${FAILED_TESTS} asciidoc"
428 end_section Asciidoc
431 if [[ "${CHECK}" = "yes" ]]; then
432 start_section "Check"
433 if runcmd make "${make_options[@]}" check; then
434 hooray "make check has succeeded."
435 else
436 error "Here are the contents of the test suite output:"
437 runcmd cat test-suite.log || true
438 FAILED_TESTS="${FAILED_TESTS} check"
440 end_section "Check"
443 if [[ "${CHUTNEY}" = "yes" ]]; then
444 start_section "Chutney"
445 export CHUTNEY_TOR_SANDBOX=0
446 export CHUTNEY_ALLOW_FAILURES=2
447 if runcmd make "${CHUTNEY_MAKE_TARGET}"; then
448 hooray "Chutney tests have succeeded"
449 else
450 error "Chutney says:"
451 export CHUTNEY_DATA_DIR="${CHUTNEY_PATH}/net"
452 runcmd "${CHUTNEY_PATH}"/tools/diagnostics.sh || true
453 # XXXX These next two should be part of a make target.
454 runcmd ls test_network_log || true
455 runcmd cat test_network_log || true
456 FAILED_TESTS="${FAILED_TESTS} chutney"
458 end_section "Chutney"
461 if [[ "${STEM}" = "yes" ]]; then
462 start_section "Stem"
463 if [[ "${TOR_VER_AT_LEAST_044}" = 'yes' ]]; then
464 # XXXX This shold probably be part some test-stem make target.
465 if runcmd timelimit -p -t 520 -s USR1 -T 30 -S ABRT \
466 python3 "${STEM_PATH}/run_tests.py" \
467 --tor src/app/tor \
468 --integ --test control.controller \
469 --test control.base_controller \
470 --test process \
471 --log TRACE \
472 --log-file stem.log ; then
473 hooray "Stem tests have succeeded"
474 else
475 error "Stem output:"
476 runcmd tail -1000 "${STEM_PATH}"/test/data/tor_log
477 runcmd grep -v "SocketClosed" stem.log | tail -1000
478 FAILED_TESTS="${FAILED_TESTS} stem"
480 else
481 skipping "Stem: broken with <= 0.4.3. See bug tor#40077"
483 end_section "Stem"
486 # TODO: Coverage
488 if [[ "${FAILED_TESTS}" != "" ]]; then
489 die "Failed tests: ${FAILED_TESTS}"
492 hooray "Everything seems fine."