17417: Merge branch 'main' into 17417-add-arm64
[arvados.git] / build / run-library.sh
1 #!/bin/bash -xe
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 # A library of functions shared by the various scripts in this directory.
7
8 # This is the timestamp about when we merged changed to include licenses
9 # with Arvados packages.  We use it as a heuristic to add revisions for
10 # older packages.
11 LICENSE_PACKAGE_TS=20151208015500
12
13 if [[ -z "$ARVADOS_BUILDING_VERSION" ]]; then
14     RAILS_PACKAGE_ITERATION=1
15 else
16     RAILS_PACKAGE_ITERATION="$ARVADOS_BUILDING_ITERATION"
17 fi
18
19 debug_echo () {
20     echo "$@" >"$STDOUT_IF_DEBUG"
21 }
22
23 find_python_program() {
24     prog="$1"
25     shift
26     for prog in "$@"; do
27         if "$prog" --version >/dev/null 2>&1; then
28             echo "$prog"
29             return 0
30         fi
31     done
32     cat >&2 <<EOF
33 $helpmessage
34
35 Error: $prog (from Python setuptools module) not found
36
37 EOF
38     exit 1
39 }
40
41 format_last_commit_here() {
42     local format="$1"; shift
43     local dir="${1:-.}"; shift
44     TZ=UTC git log -n1 --first-parent "--format=format:$format" "$dir"
45 }
46
47 version_from_git() {
48     # Output the version being built, or if we're building a
49     # dev/prerelease, output a version number based on the git log for
50     # the given $subdir.
51     local subdir="$1"; shift
52     if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
53         echo "$ARVADOS_BUILDING_VERSION"
54         return
55     fi
56
57     local git_ts git_hash
58     declare $(format_last_commit_here "git_ts=%ct git_hash=%h" "$subdir")
59     ARVADOS_BUILDING_VERSION="$($WORKSPACE/build/version-at-commit.sh $git_hash)"
60     echo "$ARVADOS_BUILDING_VERSION"
61 }
62
63 nohash_version_from_git() {
64     local subdir="$1"; shift
65     if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
66         echo "$ARVADOS_BUILDING_VERSION"
67         return
68     fi
69     version_from_git $subdir | cut -d. -f1-4
70 }
71
72 timestamp_from_git() {
73     local subdir="$1"; shift
74     format_last_commit_here "%ct" "$subdir"
75 }
76
77 calculate_python_sdk_cwl_package_versions() {
78   python_sdk_version=$(cd sdk/python && python3 arvados_version.py)
79   cwl_runner_version=$(cd sdk/cwl && python3 arvados_version.py)
80 }
81
82 handle_ruby_gem() {
83     local gem_name="$1"; shift
84     local gem_version="$(nohash_version_from_git)"
85     local gem_src_dir="$(pwd)"
86
87     if [[ -n "$ONLY_BUILD" ]] && [[ "$gem_name" != "$ONLY_BUILD" ]] ; then
88         return 0
89     fi
90
91     if ! [[ -e "${gem_name}-${gem_version}.gem" ]]; then
92         find -maxdepth 1 -name "${gem_name}-*.gem" -delete
93
94         # -q appears to be broken in gem version 2.2.2
95         $GEM build "$gem_name.gemspec" $DASHQ_UNLESS_DEBUG >"$STDOUT_IF_DEBUG" 2>"$STDERR_IF_DEBUG"
96     fi
97 }
98
99 calculate_go_package_version() {
100   # $__returnvar has the nameref attribute set, which means it is a reference
101   # to another variable that is passed in as the first argument to this function.
102   # see https://www.gnu.org/software/bash/manual/html_node/Shell-Parameters.html
103   local -n __returnvar="$1"; shift
104   local oldpwd="$PWD"
105
106   cd "$WORKSPACE"
107   go mod download
108
109   # Update the version number and build a new package if the vendor
110   # bundle has changed, or the command imports anything from the
111   # Arvados SDK and the SDK has changed.
112   declare -a checkdirs=(go.mod go.sum)
113   while [ -n "$1" ]; do
114       checkdirs+=("$1")
115       shift
116   done
117   # Even our rails packages (version calculation happens here!) depend on a go component (arvados-server)
118   # Everything depends on the build directory.
119   checkdirs+=(sdk/go lib build)
120   local timestamp=0
121   for dir in ${checkdirs[@]}; do
122       cd "$WORKSPACE"
123       ts="$(timestamp_from_git "$dir")"
124       if [[ "$ts" -gt "$timestamp" ]]; then
125           version=$(version_from_git "$dir")
126           timestamp="$ts"
127       fi
128   done
129   cd "$oldpwd"
130   __returnvar="$version"
131 }
132
133 # Usage: package_go_binary services/foo arvados-foo "Compute foo to arbitrary precision" [apache-2.0.txt]
134 package_go_binary() {
135     local src_path="$1"; shift
136     local prog="$1"; shift
137     local description="$1"; shift
138     local license_file="${1:-agpl-3.0.txt}"; shift
139
140     if [[ -n "$ONLY_BUILD" ]] && [[ "$prog" != "$ONLY_BUILD" ]]; then
141       # arvados-workbench depends on arvados-server at build time, so even when
142       # only arvados-workbench is being built, we need to build arvados-server too
143       if [[ "$prog" != "arvados-server" ]] || [[ "$ONLY_BUILD" != "arvados-workbench" ]]; then
144         return 0
145       fi
146     fi
147
148     native_arch="amd64"
149     if [[ "$HOSTTYPE" == "aarch64" ]]; then
150         native_arch="arm64"
151     fi
152
153     if [[ -n "$ONLY_ARCH" ]]; then
154       if [[ "$native_arch" == "amd64" ]] || [[ "$native_arch" == "$ONLY_ARCH" ]]; then
155         package_go_binary_worker "$src_path" "$prog" "$description" "$native_arch" "$ONLY_ARCH" "$license_file"
156       else
157         echo "Error: no cross compilation support for Go on $native_arch yet, can not build $prog for $ONLY_ARCH"
158       fi
159     else
160       archs=($native_arch)
161       if [[ "$native_arch" == "amd64" ]]; then
162         archs=('amd64' 'arm64')
163       fi
164       for arch in $archs; do
165         package_go_binary_worker "$src_path" "$prog" "$description" "$native_arch" "$arch" "$license_file"
166       done
167     fi
168 }
169
170 # Usage: package_go_binary services/foo arvados-foo "Compute foo to arbitrary precision" [amd64/arm64] [apache-2.0.txt]
171 package_go_binary_worker() {
172     local src_path="$1"; shift
173     local prog="$1"; shift
174     local description="$1"; shift
175     local native_arch="${1:-amd64}"; shift
176     local arch="${1:-amd64}"; shift
177     local license_file="${1:-agpl-3.0.txt}"; shift
178
179     debug_echo "package_go_binary $src_path as $prog"
180     local basename="${src_path##*/}"
181     calculate_go_package_version go_package_version $src_path
182
183     cd $WORKSPACE/packages/$TARGET
184     test_package_presence "$prog" "$go_package_version" "go" "" "$arch"
185     if [[ "$?" != "0" ]]; then
186       return 1
187     fi
188
189     echo "BUILDING ${arch}"
190     if [[ "$arch" == "arm64" ]] && [[ "$native_arch" == "amd64" ]]; then
191       CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc GOARCH=${arch} go get -ldflags "-X git.arvados.org/arvados.git/lib/cmd.version=${go_package_version} -X main.version=${go_package_version}" "git.arvados.org/arvados.git/$src_path"
192     else
193       GOARCH=${arch} go get -ldflags "-X git.arvados.org/arvados.git/lib/cmd.version=${go_package_version} -X main.version=${go_package_version}" "git.arvados.org/arvados.git/$src_path"
194     fi
195
196     local -a switches=()
197
198     binpath=$GOPATH/bin/${basename}
199     if [[ "${arch}" != "${native_arch}" ]]; then
200       switches+=("-a${arch}")
201       binpath="$GOPATH/bin/linux_${arch}/${basename}"
202     fi
203
204     systemd_unit="$WORKSPACE/${src_path}/${prog}.service"
205     if [[ -e "${systemd_unit}" ]]; then
206         switches+=(
207             --after-install "${WORKSPACE}/build/go-python-package-scripts/postinst"
208             --before-remove "${WORKSPACE}/build/go-python-package-scripts/prerm"
209             "${systemd_unit}=/lib/systemd/system/${prog}.service")
210     fi
211     switches+=("$WORKSPACE/${license_file}=/usr/share/doc/$prog/${license_file}")
212
213     fpm_build "${WORKSPACE}/${src_path}" "$binpath=/usr/bin/${prog}" "${prog}" dir "${go_package_version}" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=${description}" "${switches[@]}"
214 }
215
216 # Usage: package_go_so lib/foo arvados_foo.so arvados-foo "Arvados foo library"
217 package_go_so() {
218     local src_path="$1"; shift
219     local sofile="$1"; shift
220     local pkg="$1"; shift
221     local description="$1"; shift
222
223     if [[ -n "$ONLY_BUILD" ]] && [[ "$pkg" != "$ONLY_BUILD" ]]; then
224       return 0
225     fi
226
227     debug_echo "package_go_so $src_path as $pkg"
228
229     calculate_go_package_version go_package_version $src_path
230     cd $WORKSPACE/packages/$TARGET
231     test_package_presence $pkg $go_package_version go || return 1
232     cd $WORKSPACE/$src_path
233     go build -buildmode=c-shared -o ${GOPATH}/bin/${sofile}
234     cd $WORKSPACE/packages/$TARGET
235     local -a fpmargs=(
236         "--url=https://arvados.org"
237         "--license=Apache License, Version 2.0"
238         "--description=${description}"
239         "$WORKSPACE/apache-2.0.txt=/usr/share/doc/$pkg/apache-2.0.txt"
240     )
241     if [[ -e "$WORKSPACE/$src_path/pam-configs-arvados" ]]; then
242         fpmargs+=("$WORKSPACE/$src_path/pam-configs-arvados=/usr/share/doc/$pkg/pam-configs-arvados-go")
243     fi
244     if [[ -e "$WORKSPACE/$src_path/README" ]]; then
245         fpmargs+=("$WORKSPACE/$src_path/README=/usr/share/doc/$pkg/README")
246     fi
247     fpm_build "${WORKSPACE}/${src_path}" "$GOPATH/bin/${sofile}=/usr/lib/${sofile}" "${pkg}" dir "${go_package_version}" "${fpmargs[@]}"
248 }
249
250 default_iteration() {
251     if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
252         echo "$ARVADOS_BUILDING_ITERATION"
253         return
254     fi
255     local package_name="$1"; shift
256     local package_version="$1"; shift
257     local package_type="$1"; shift
258     local iteration=1
259     if [[ $package_version =~ ^0\.1\.([0-9]{14})(\.|$) ]] && \
260            [[ ${BASH_REMATCH[1]} -le $LICENSE_PACKAGE_TS ]]; then
261         iteration=2
262     fi
263     echo $iteration
264 }
265
266 _build_rails_package_scripts() {
267     local pkgname="$1"; shift
268     local destdir="$1"; shift
269     local srcdir="$RUN_BUILD_PACKAGES_PATH/rails-package-scripts"
270     for scriptname in postinst prerm postrm; do
271         cat "$srcdir/$pkgname.sh" "$srcdir/step2.sh" "$srcdir/$scriptname.sh" \
272             >"$destdir/$scriptname" || return $?
273     done
274 }
275
276 rails_package_version() {
277     local pkgname="$1"; shift
278     local srcdir="$1"; shift
279     if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
280         echo "$ARVADOS_BUILDING_VERSION"
281         return
282     fi
283     local version="$(version_from_git)"
284     if [ $pkgname = "arvados-api-server" -o $pkgname = "arvados-workbench" ] ; then
285         calculate_go_package_version version cmd/arvados-server "$srcdir"
286     fi
287     echo $version
288 }
289
290 test_rails_package_presence() {
291   local pkgname="$1"; shift
292   local srcdir="$1"; shift
293
294   if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
295     return 1
296   fi
297
298   tmppwd=`pwd`
299
300   cd $srcdir
301
302   local version="$(rails_package_version "$pkgname" "$srcdir")"
303
304   cd $tmppwd
305
306   test_package_presence $pkgname $version rails "$RAILS_PACKAGE_ITERATION"
307 }
308
309 get_complete_package_name() {
310   # if the errexit flag is set, unset it until this function returns
311   # otherwise, the shift calls below will abort the program if optional arguments are not supplied
312   if [ -o errexit ]; then
313     set +e
314     trap 'set -e' RETURN
315   fi
316   # $__returnvar has the nameref attribute set, which means it is a reference
317   # to another variable that is passed in as the first argument to this function.
318   # see https://www.gnu.org/software/bash/manual/html_node/Shell-Parameters.html
319   local -n __returnvar="$1"; shift
320   local pkgname="$1"; shift
321   local version="$1"; shift
322   local pkgtype="$1"; shift
323   local iteration="$1"; shift
324   local arch="$1"; shift
325   if [[ "$iteration" == "" ]]; then
326       iteration="$(default_iteration "$pkgname" "$version" "$pkgtype")"
327   fi
328
329   if [[ "$arch" == "" ]]; then
330     native_arch="amd64"
331     rpm_native_arch="x86_64"
332     if [[ "$HOSTTYPE" == "aarch64" ]]; then
333       native_arch="arm64"
334       rpm_native_arch="arm64"
335     fi
336     rpm_architecture="$rpm_native_arch"
337     deb_architecture="$native_arch"
338
339     if [[ "$pkgtype" =~ ^(src)$ ]]; then
340       rpm_architecture="noarch"
341       deb_architecture="all"
342     fi
343
344     # These python packages have binary components
345     if [[ "$pkgname" =~ (ruamel|ciso|pycrypto|pyyaml) ]]; then
346       rpm_architecture="$rpm_native_arch"
347       deb_architecture="$native_arch"
348     fi
349   else
350     rpm_architecture=$arch
351     deb_architecture=$arch
352   fi
353
354   local complete_pkgname="${pkgname}_$version${iteration:+-$iteration}_$deb_architecture.deb"
355   if [[ "$FORMAT" == "rpm" ]]; then
356       # rpm packages get iteration 1 if we don't supply one
357       iteration=${iteration:-1}
358       complete_pkgname="$pkgname-$version-${iteration}.$rpm_architecture.rpm"
359   fi
360   __returnvar=${complete_pkgname}
361 }
362
363 # Test if the package already exists, if not return 0, if it does return 1
364 test_package_presence() {
365     local pkgname="$1"; shift
366     local version="$1"; shift
367     local pkgtype="$1"; shift
368     local iteration="$1"; shift
369     local arch="$1"; shift
370     if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
371       # arvados-workbench depends on arvados-server at build time, so even when
372       # only arvados-workbench is being built, we need to build arvados-server too
373       if [[ "$pkgname" != "arvados-server" ]] || [[ "$ONLY_BUILD" != "arvados-workbench" ]]; then
374         return 1
375       fi
376     fi
377
378     local full_pkgname
379     get_complete_package_name full_pkgname "$pkgname" "$version" "$pkgtype" "$iteration" "$arch"
380
381     # See if we can skip building the package, only if it already exists in the
382     # processed/ directory. If so, move it back to the packages directory to make
383     # sure it gets picked up by the test and/or upload steps.
384     # Get the list of packages from the repos
385
386     if [[ "$FORCE_BUILD" == "1" ]]; then
387       echo "Package $full_pkgname build forced with --force-build, building"
388     elif [[ "$FORMAT" == "deb" ]]; then
389       declare -A dd
390       dd[debian10]=buster
391       dd[debian11]=bullseye
392       dd[ubuntu1804]=bionic
393       dd[ubuntu2004]=focal
394       D=${dd[$TARGET]}
395       if [ ${pkgname:0:3} = "lib" ]; then
396         repo_subdir=${pkgname:0:4}
397       else
398         repo_subdir=${pkgname:0:1}
399       fi
400
401       repo_pkg_list=$(curl -s -o - http://apt.arvados.org/${D}/pool/main/${repo_subdir}/${pkgname}/)
402       echo "${repo_pkg_list}" |grep -q ${full_pkgname}
403       if [ $? -eq 0 ] ; then
404         echo "Package $full_pkgname exists upstream, not rebuilding, downloading instead!"
405         curl -s -o "$WORKSPACE/packages/$TARGET/${full_pkgname}" http://apt.arvados.org/${D}/pool/main/${repo_subdir}/${pkgname}/${full_pkgname}
406         return 1
407       elif test -f "$WORKSPACE/packages/$TARGET/processed/${full_pkgname}" ; then
408         echo "Package $full_pkgname exists, not rebuilding!"
409         return 1
410       else
411         echo "Package $full_pkgname not found, building"
412         return 0
413       fi
414     else
415       centos_repo="http://rpm.arvados.org/CentOS/7/dev/x86_64/"
416
417       repo_pkg_list=$(curl -s -o - ${centos_repo})
418       echo ${repo_pkg_list} |grep -q ${full_pkgname}
419       if [ $? -eq 0 ]; then
420         echo "Package $full_pkgname exists upstream, not rebuilding, downloading instead!"
421         curl -s -o "$WORKSPACE/packages/$TARGET/${full_pkgname}" ${centos_repo}${full_pkgname}
422         return 1
423       elif test -f "$WORKSPACE/packages/$TARGET/processed/${full_pkgname}" ; then
424         echo "Package $full_pkgname exists, not rebuilding!"
425         return 1
426       else
427         echo "Package $full_pkgname not found, building"
428         return 0
429       fi
430     fi
431 }
432
433 handle_rails_package() {
434     local pkgname="$1"; shift
435
436     if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
437         return 0
438     fi
439     local srcdir="$1"; shift
440     cd "$srcdir"
441     local license_path="$1"; shift
442     local version="$(rails_package_version "$pkgname" "$srcdir")"
443     echo "$version" >package-build.version
444     local scripts_dir="$(mktemp --tmpdir -d "$pkgname-XXXXXXXX.scripts")" && \
445     (
446         set -e
447         _build_rails_package_scripts "$pkgname" "$scripts_dir"
448         cd "$srcdir"
449         mkdir -p tmp
450         git rev-parse HEAD >git-commit.version
451         bundle package --all
452     )
453     if [[ 0 != "$?" ]] || ! cd "$WORKSPACE/packages/$TARGET"; then
454         echo "ERROR: $pkgname package prep failed" >&2
455         rm -rf "$scripts_dir"
456         EXITCODE=1
457         return 1
458     fi
459     local railsdir="/var/www/${pkgname%-server}/current"
460     local -a pos_args=("$srcdir/=$railsdir" "$pkgname" dir "$version")
461     local license_arg="$license_path=$railsdir/$(basename "$license_path")"
462     local -a switches=(--after-install "$scripts_dir/postinst"
463                        --before-remove "$scripts_dir/prerm"
464                        --after-remove "$scripts_dir/postrm")
465     if [[ -z "$ARVADOS_BUILDING_VERSION" ]]; then
466         switches+=(--iteration $RAILS_PACKAGE_ITERATION)
467     fi
468     # For some reason fpm excludes need to not start with /.
469     local exclude_root="${railsdir#/}"
470     local -a exclude_list=(tmp log coverage Capfile\* \
471                            config/deploy\* config/application.yml)
472     # for arvados-workbench, we need to have the (dummy) config/database.yml in the package
473     if  [[ "$pkgname" != "arvados-workbench" ]]; then
474       exclude_list+=('config/database.yml')
475     fi
476     for exclude in ${exclude_list[@]}; do
477         switches+=(-x "$exclude_root/$exclude")
478     done
479     fpm_build "${srcdir}" "${pos_args[@]}" "${switches[@]}" \
480               -x "$exclude_root/vendor/cache-*" \
481               -x "$exclude_root/vendor/bundle" "$@" "$license_arg"
482     rm -rf "$scripts_dir"
483 }
484
485 # Build python packages with a virtualenv built-in
486 fpm_build_virtualenv () {
487   PKG=$1
488   shift
489   PKG_DIR=$1
490   shift
491   PACKAGE_TYPE=${1:-python}
492   shift
493   native_arch="amd64"
494   if [[ "$HOSTTYPE" == "aarch64" ]]; then
495     native_arch="arm64"
496   fi
497
498   if [[ -n "$ONLY_ARCH" ]] && [[ "$ONLY_ARCH" == "$native_arch" ]]; then
499       fpm_build_virtualenv_worker "$PKG" "$PKG_DIR" "$PACKAGE_TYPE" "$ONLY_ARCH"
500   elif [[ -z "$ONLY_ARCH" ]]; then
501     for arch in $native_arch; do
502       fpm_build_virtualenv_worker "$PKG" "$PKG_DIR" "$PACKAGE_TYPE" "$arch"
503     done
504   else
505     echo "Error: no cross compilation support for Python yet, can not build $PKG for $ONLY_ARCH"
506   fi
507 }
508
509 # Build python packages with a virtualenv built-in
510 fpm_build_virtualenv_worker () {
511   PKG=$1
512   shift
513   PKG_DIR=$1
514   shift
515   PACKAGE_TYPE=${1:-python}
516   shift
517   arch=${1:-amd64}
518   shift
519
520   # Set up
521   STDOUT_IF_DEBUG=/dev/null
522   STDERR_IF_DEBUG=/dev/null
523   DASHQ_UNLESS_DEBUG=-q
524   if [[ "$DEBUG" != "0" ]]; then
525       STDOUT_IF_DEBUG=/dev/stdout
526       STDERR_IF_DEBUG=/dev/stderr
527       DASHQ_UNLESS_DEBUG=
528   fi
529   if [[ "$ARVADOS_BUILDING_ITERATION" == "" ]]; then
530     ARVADOS_BUILDING_ITERATION=1
531   fi
532
533   local python=""
534   case "$PACKAGE_TYPE" in
535     python3)
536         python=python3
537         pip=pip3
538         PACKAGE_PREFIX=$PYTHON3_PKG_PREFIX
539         ;;
540   esac
541
542   if [[ "$PKG" != "arvados-docker-cleaner" ]]; then
543     PYTHON_PKG=$PACKAGE_PREFIX-$PKG
544   else
545     # Exception to our package naming convention
546     PYTHON_PKG=$PKG
547   fi
548
549   # arvados-python-client sdist should always be built, to be available
550   # for other dependent packages.
551   if [[ -n "$ONLY_BUILD" ]] && [[ "arvados-python-client" != "$PKG" ]] && [[ "$PYTHON_PKG" != "$ONLY_BUILD" ]] && [[ "$PKG" != "$ONLY_BUILD" ]]; then
552     return 0
553   fi
554
555   cd $WORKSPACE/$PKG_DIR
556
557   rm -rf dist/*
558
559   # Get the latest setuptools
560   if ! $pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U 'setuptools<45'; then
561     echo "Error, unable to upgrade setuptools with"
562     echo "  $pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U 'setuptools<45'"
563     exit 1
564   fi
565   # filter a useless warning (when building the cwltest package) from the stderr output
566   if ! $python setup.py $DASHQ_UNLESS_DEBUG sdist 2> >(grep -v 'warning: no previously-included files matching'); then
567     echo "Error, unable to run $python setup.py sdist for $PKG"
568     exit 1
569   fi
570
571   PACKAGE_PATH=`(cd dist; ls *tar.gz)`
572
573   if [[ "arvados-python-client" == "$PKG" ]]; then
574     PYSDK_PATH=`pwd`/dist/
575   fi
576
577   if [[ -n "$ONLY_BUILD" ]] && [[ "$PYTHON_PKG" != "$ONLY_BUILD" ]] && [[ "$PKG" != "$ONLY_BUILD" ]]; then
578     return 0
579   fi
580
581   # Determine the package version from the generated sdist archive
582   if [[ -n "$ARVADOS_BUILDING_VERSION" ]] ; then
583       UNFILTERED_PYTHON_VERSION=$ARVADOS_BUILDING_VERSION
584       PYTHON_VERSION=$(echo -n $ARVADOS_BUILDING_VERSION | sed s/~dev/.dev/g | sed s/~rc/rc/g)
585   else
586       PYTHON_VERSION=$(awk '($1 == "Version:"){print $2}' *.egg-info/PKG-INFO)
587       UNFILTERED_PYTHON_VERSION=$(echo -n $PYTHON_VERSION | sed s/\.dev/~dev/g |sed 's/\([0-9]\)rc/\1~rc/g')
588   fi
589
590   # See if we actually need to build this package; does it exist already?
591   # We can't do this earlier than here, because we need PYTHON_VERSION...
592   # This isn't so bad; the sdist call above is pretty quick compared to
593   # the invocation of virtualenv and fpm, below.
594   if ! test_package_presence "$PYTHON_PKG" "$UNFILTERED_PYTHON_VERSION" "$PACKAGE_TYPE" "$ARVADOS_BUILDING_ITERATION" "$arch"; then
595     return 0
596   fi
597
598   echo "Building $FORMAT ($arch) package for $PKG from $PKG_DIR"
599
600   # Package the sdist in a virtualenv
601   echo "Creating virtualenv..."
602
603   cd dist
604
605   rm -rf build
606   rm -f $PYTHON_PKG*deb
607   echo "virtualenv version: `virtualenv --version`"
608   virtualenv_command="virtualenv --python `which $python` $DASHQ_UNLESS_DEBUG build/usr/share/$python/dist/$PYTHON_PKG"
609
610   if ! $virtualenv_command; then
611     echo "Error, unable to run"
612     echo "  $virtualenv_command"
613     exit 1
614   fi
615
616   if ! build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U pip; then
617     echo "Error, unable to upgrade pip with"
618     echo "  build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U pip"
619     exit 1
620   fi
621   echo "pip version:        `build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip --version`"
622
623   if ! build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U 'setuptools<45'; then
624     echo "Error, unable to upgrade setuptools with"
625     echo "  build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U 'setuptools<45'"
626     exit 1
627   fi
628   echo "setuptools version: `build/usr/share/$python/dist/$PYTHON_PKG/bin/$python -c 'import setuptools; print(setuptools.__version__)'`"
629
630   if ! build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U wheel; then
631     echo "Error, unable to upgrade wheel with"
632     echo "  build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U wheel"
633     exit 1
634   fi
635   echo "wheel version:      `build/usr/share/$python/dist/$PYTHON_PKG/bin/wheel version`"
636
637   if [[ "$TARGET" != "centos7" ]] || [[ "$PYTHON_PKG" != "python-arvados-fuse" ]]; then
638     build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -f $PYSDK_PATH $PACKAGE_PATH
639   else
640     # centos7 needs these special tweaks to install python-arvados-fuse
641     build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG docutils
642     PYCURL_SSL_LIBRARY=nss build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -f $PYSDK_PATH $PACKAGE_PATH
643   fi
644
645   if [[ "$?" != "0" ]]; then
646     echo "Error, unable to run"
647     echo "  build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -f $PYSDK_PATH $PACKAGE_PATH"
648     exit 1
649   fi
650
651   cd build/usr/share/$python/dist/$PYTHON_PKG/
652
653   # Replace the shebang lines in all python scripts, and handle the activate
654   # scripts too. This is a functional replacement of the 237 line
655   # virtualenv_tools.py script that doesn't work in python3 without serious
656   # patching, minus the parts we don't need (modifying pyc files, etc).
657   for binfile in `ls bin/`; do
658     if ! file --mime bin/$binfile |grep -q binary; then
659       # Not a binary file
660       if [[ "$binfile" =~ ^activate(.csh|.fish|)$ ]]; then
661         # these 'activate' scripts need special treatment
662         sed -i "s/VIRTUAL_ENV=\".*\"/VIRTUAL_ENV=\"\/usr\/share\/$python\/dist\/$PYTHON_PKG\"/" bin/$binfile
663         sed -i "s/VIRTUAL_ENV \".*\"/VIRTUAL_ENV \"\/usr\/share\/$python\/dist\/$PYTHON_PKG\"/" bin/$binfile
664       else
665         if grep -q -E '^#!.*/bin/python\d?' bin/$binfile; then
666           # Replace shebang line
667           sed -i "1 s/^.*$/#!\/usr\/share\/$python\/dist\/$PYTHON_PKG\/bin\/python/" bin/$binfile
668         fi
669       fi
670     fi
671   done
672
673   cd - >$STDOUT_IF_DEBUG
674
675   find build -iname '*.pyc' -exec rm {} \;
676   find build -iname '*.pyo' -exec rm {} \;
677
678   # Finally, generate the package
679   echo "Creating package..."
680
681   declare -a COMMAND_ARR=("fpm" "-s" "dir" "-t" "$FORMAT")
682
683   if [[ "${arch}" != "amd64" ]]; then
684     COMMAND_ARR+=("-a${arch}")
685   fi
686
687   if [[ "$MAINTAINER" != "" ]]; then
688     COMMAND_ARR+=('--maintainer' "$MAINTAINER")
689   fi
690
691   if [[ "$VENDOR" != "" ]]; then
692     COMMAND_ARR+=('--vendor' "$VENDOR")
693   fi
694
695   COMMAND_ARR+=('--url' 'https://arvados.org')
696
697   # Get description
698   DESCRIPTION=`grep '\sdescription' $WORKSPACE/$PKG_DIR/setup.py|cut -f2 -d=|sed -e "s/[',\\"]//g"`
699   COMMAND_ARR+=('--description' "$DESCRIPTION")
700
701   # Get license string
702   LICENSE_STRING=`grep license $WORKSPACE/$PKG_DIR/setup.py|cut -f2 -d=|sed -e "s/[',\\"]//g"`
703   COMMAND_ARR+=('--license' "$LICENSE_STRING")
704
705   if [[ "$FORMAT" == "rpm" ]]; then
706     # Make sure to conflict with the old rh-python36 packages we used to publish
707     COMMAND_ARR+=('--conflicts' "rh-python36-python-$PKG")
708   fi
709
710   if [[ "$DEBUG" != "0" ]]; then
711     COMMAND_ARR+=('--verbose' '--log' 'info')
712   fi
713
714   COMMAND_ARR+=('-v' $(echo -n "$PYTHON_VERSION" | sed s/.dev/~dev/g | sed s/rc/~rc/g))
715   COMMAND_ARR+=('--iteration' "$ARVADOS_BUILDING_ITERATION")
716   COMMAND_ARR+=('-n' "$PYTHON_PKG")
717   COMMAND_ARR+=('-C' "build")
718
719   systemd_unit="$WORKSPACE/$PKG_DIR/$PKG.service"
720   if [[ -e "${systemd_unit}" ]]; then
721     COMMAND_ARR+=('--after-install' "${WORKSPACE}/build/go-python-package-scripts/postinst")
722     COMMAND_ARR+=('--before-remove' "${WORKSPACE}/build/go-python-package-scripts/prerm")
723   fi
724
725   COMMAND_ARR+=('--depends' "$PYTHON3_PACKAGE")
726
727   # avoid warning
728   COMMAND_ARR+=('--deb-no-default-config-files')
729
730   # Append --depends X and other arguments specified by fpm-info.sh in
731   # the package source dir. These are added last so they can override
732   # the arguments added by this script.
733   declare -a fpm_args=()
734   declare -a fpm_depends=()
735
736   fpminfo="$WORKSPACE/$PKG_DIR/fpm-info.sh"
737   if [[ -e "$fpminfo" ]]; then
738     echo "Loading fpm overrides from $fpminfo"
739     if ! source "$fpminfo"; then
740       echo "Error, unable to source $WORKSPACE/$PKG_DIR/fpm-info.sh for $PKG"
741       exit 1
742     fi
743   fi
744
745   for i in "${fpm_depends[@]}"; do
746     COMMAND_ARR+=('--depends' "$i")
747   done
748
749   for i in "${fpm_depends[@]}"; do
750     COMMAND_ARR+=('--replaces' "python-$PKG")
751   done
752
753   # make sure the systemd service file ends up in the right place
754   # used by arvados-docker-cleaner
755   if [[ -e "${systemd_unit}" ]]; then
756     COMMAND_ARR+=("usr/share/$python/dist/$PKG/share/doc/$PKG/$PKG.service=/lib/systemd/system/$PKG.service")
757   fi
758
759   COMMAND_ARR+=("${fpm_args[@]}")
760
761   # Make sure to install all our package binaries in /usr/bin.
762   # We have to walk $WORKSPACE/$PKG_DIR/bin rather than
763   # $WORKSPACE/build/usr/share/$python/dist/$PYTHON_PKG/bin/ to get the list
764   # because the latter also includes all the python binaries for the virtualenv.
765   # We have to take the copies of our binaries from the latter directory, though,
766   # because those are the ones we rewrote the shebang line of, above.
767   if [[ -e "$WORKSPACE/$PKG_DIR/bin" ]]; then
768     for binary in `ls $WORKSPACE/$PKG_DIR/bin`; do
769       COMMAND_ARR+=("usr/share/$python/dist/$PYTHON_PKG/bin/$binary=/usr/bin/")
770     done
771   fi
772
773   # the python3-arvados-cwl-runner package comes with cwltool, expose that version
774   if [[ -e "$WORKSPACE/$PKG_DIR/dist/build/usr/share/$python/dist/$PYTHON_PKG/bin/cwltool" ]]; then
775     COMMAND_ARR+=("usr/share/$python/dist/$PYTHON_PKG/bin/cwltool=/usr/bin/")
776   fi
777
778   COMMAND_ARR+=(".")
779
780   debug_echo -e "\n${COMMAND_ARR[@]}\n"
781
782   FPM_RESULTS=$("${COMMAND_ARR[@]}")
783   FPM_EXIT_CODE=$?
784
785   # if something went wrong and debug is off, print out the fpm command that errored
786   if ! fpm_verify $FPM_EXIT_CODE $FPM_RESULTS && [[ "$STDOUT_IF_DEBUG" == "/dev/null" ]]; then
787     echo "fpm returned an error executing the command:"
788     echo
789     echo -e "\n${COMMAND_ARR[@]}\n"
790   else
791     echo `ls *$FORMAT`
792     mv $WORKSPACE/$PKG_DIR/dist/*$FORMAT $WORKSPACE/packages/$TARGET/
793   fi
794   echo
795 }
796
797 # build_metapackage builds meta packages that help with the python to python 3 package migration
798 build_metapackage() {
799   # base package name (e.g. arvados-python-client)
800   BASE_NAME=$1
801   shift
802   PKG_DIR=$1
803   shift
804
805   if [[ -n "$ONLY_BUILD" ]] && [[ "python-$BASE_NAME" != "$ONLY_BUILD" ]]; then
806     return 0
807   fi
808
809   if [[ "$ARVADOS_BUILDING_ITERATION" == "" ]]; then
810     ARVADOS_BUILDING_ITERATION=1
811   fi
812
813   if [[ -z "$ARVADOS_BUILDING_VERSION" ]]; then
814     cd $WORKSPACE/$PKG_DIR
815     pwd
816     rm -rf dist/*
817
818     # Get the latest setuptools
819     if ! pip3 install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U 'setuptools<45'; then
820       echo "Error, unable to upgrade setuptools with XY"
821       echo "  pip3 install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U 'setuptools<45'"
822       exit 1
823     fi
824     # filter a useless warning (when building the cwltest package) from the stderr output
825     if ! python3 setup.py $DASHQ_UNLESS_DEBUG sdist 2> >(grep -v 'warning: no previously-included files matching'); then
826       echo "Error, unable to run python3 setup.py sdist for $PKG"
827       exit 1
828     fi
829
830     PYTHON_VERSION=$(awk '($1 == "Version:"){print $2}' *.egg-info/PKG-INFO)
831     UNFILTERED_PYTHON_VERSION=$(echo -n $PYTHON_VERSION | sed s/\.dev/~dev/g |sed 's/\([0-9]\)rc/\1~rc/g')
832
833   else
834     UNFILTERED_PYTHON_VERSION=$ARVADOS_BUILDING_VERSION
835     PYTHON_VERSION=$(echo -n $ARVADOS_BUILDING_VERSION | sed s/~dev/.dev/g | sed s/~rc/rc/g)
836   fi
837
838   cd - >$STDOUT_IF_DEBUG
839   if [[ -d "$BASE_NAME" ]]; then
840     rm -rf $BASE_NAME
841   fi
842   mkdir $BASE_NAME
843   cd $BASE_NAME
844
845   if [[ "$FORMAT" == "deb" ]]; then
846     cat >ns-control <<EOF
847 Section: misc
848 Priority: optional
849 Standards-Version: 3.9.2
850
851 Package: python-${BASE_NAME}
852 Version: ${PYTHON_VERSION}-${ARVADOS_BUILDING_ITERATION}
853 Maintainer: Arvados Package Maintainers <packaging@arvados.org>
854 Depends: python3-${BASE_NAME}
855 Description: metapackage to ease the upgrade to the Pyhon 3 version of ${BASE_NAME}
856  This package is a metapackage that will automatically install the new version of
857  ${BASE_NAME} which is Python 3 based and has a different name.
858 EOF
859
860     /usr/bin/equivs-build ns-control
861     if [[ $? -ne 0 ]]; then
862       echo "Error running 'equivs-build ns-control', is the 'equivs' package installed?"
863       return 1
864     fi
865   elif [[ "$FORMAT" == "rpm" ]]; then
866     cat >meta.spec <<EOF
867 Summary: metapackage to ease the upgrade to the Python 3 version of ${BASE_NAME}
868 Name: python-${BASE_NAME}
869 Version: ${PYTHON_VERSION}
870 Release: ${ARVADOS_BUILDING_ITERATION}
871 License: distributable
872
873 Requires: python3-${BASE_NAME}
874
875 %description
876 This package is a metapackage that will automatically install the new version of
877 python-${BASE_NAME} which is Python 3 based and has a different name.
878
879 %prep
880
881 %build
882
883 %clean
884
885 %install
886
887 %post
888
889 %files
890
891
892 %changelog
893 * Mon Apr 12 2021 Arvados Package Maintainers <packaging@arvados.org>
894 - initial release
895 EOF
896
897     /usr/bin/rpmbuild -ba meta.spec
898     if [[ $? -ne 0 ]]; then
899       echo "Error running 'rpmbuild -ba meta.spec', is the 'rpm-build' package installed?"
900       return 1
901     else
902       mv /root/rpmbuild/RPMS/x86_64/python-${BASE_NAME}*.${FORMAT} .
903       if [[ $? -ne 0 ]]; then
904         echo "Error finding rpm file output of 'rpmbuild -ba meta.spec'"
905         return 1
906       fi
907     fi
908   else
909     echo "Unknown format"
910     return 1
911   fi
912
913   if [[ $EXITCODE -ne 0 ]]; then
914     return 1
915   else
916     echo `ls *$FORMAT`
917     mv *$FORMAT $WORKSPACE/packages/$TARGET/
918   fi
919
920   # clean up
921   cd - >$STDOUT_IF_DEBUG
922   if [[ -d "$BASE_NAME" ]]; then
923     rm -rf $BASE_NAME
924   fi
925 }
926
927 # Build packages for everything
928 fpm_build () {
929   # Source dir where fpm-info.sh (if any) will be found.
930   SRC_DIR=$1
931   shift
932   # The package source.  Depending on the source type, this can be a
933   # path, or the name of the package in an upstream repository (e.g.,
934   # pip).
935   PACKAGE=$1
936   shift
937   # The name of the package to build.
938   PACKAGE_NAME=$1
939   shift
940   # The type of source package.  Passed to fpm -s.  Default "dir".
941   PACKAGE_TYPE=${1:-dir}
942   shift
943   # Optional: the package version number.  Passed to fpm -v.
944   VERSION=$1
945   shift
946
947   if [[ -n "$ONLY_BUILD" ]] && [[ "$PACKAGE_NAME" != "$ONLY_BUILD" ]] && [[ "$PACKAGE" != "$ONLY_BUILD" ]] ; then
948     # arvados-workbench depends on arvados-server at build time, so even when
949     # only arvados-workbench is being built, we need to build arvados-server too
950     if [[ "$PACKAGE_NAME" != "arvados-server" ]] || [[ "$ONLY_BUILD" != "arvados-workbench" ]]; then
951       return 0
952     fi
953   fi
954
955   local default_iteration_value="$(default_iteration "$PACKAGE" "$VERSION" "$PACKAGE_TYPE")"
956
957   declare -a COMMAND_ARR=("fpm" "-s" "$PACKAGE_TYPE" "-t" "$FORMAT")
958   if [ python = "$PACKAGE_TYPE" ] && [ deb = "$FORMAT" ]; then
959       # Dependencies are built from setup.py.  Since setup.py will never
960       # refer to Debian package iterations, it doesn't make sense to
961       # enforce those in the .deb dependencies.
962       COMMAND_ARR+=(--deb-ignore-iteration-in-dependencies)
963   fi
964
965   if [[ "$DEBUG" != "0" ]]; then
966     COMMAND_ARR+=('--verbose' '--log' 'info')
967   fi
968
969   if [[ -n "$PACKAGE_NAME" ]]; then
970     COMMAND_ARR+=('-n' "$PACKAGE_NAME")
971   fi
972
973   if [[ "$MAINTAINER" != "" ]]; then
974     COMMAND_ARR+=('--maintainer' "$MAINTAINER")
975   fi
976
977   if [[ "$VENDOR" != "" ]]; then
978     COMMAND_ARR+=('--vendor' "$VENDOR")
979   fi
980
981   if [[ "$VERSION" != "" ]]; then
982     COMMAND_ARR+=('-v' "$VERSION")
983   fi
984   if [[ -n "$default_iteration_value" ]]; then
985       # We can always add an --iteration here.  If another one is specified in $@,
986       # that will take precedence, as desired.
987       COMMAND_ARR+=(--iteration "$default_iteration_value")
988   fi
989
990   # Append --depends X and other arguments specified by fpm-info.sh in
991   # the package source dir. These are added last so they can override
992   # the arguments added by this script.
993   declare -a fpm_args=()
994   declare -a build_depends=()
995   declare -a fpm_depends=()
996   declare -a fpm_conflicts=()
997   declare -a fpm_exclude=()
998   if [[ ! -d "$SRC_DIR" ]]; then
999       echo >&2 "BUG: looking in wrong dir for fpm-info.sh: $pkgdir"
1000       exit 1
1001   fi
1002   fpminfo="${SRC_DIR}/fpm-info.sh"
1003   if [[ -e "$fpminfo" ]]; then
1004       debug_echo "Loading fpm overrides from $fpminfo"
1005       source "$fpminfo"
1006   fi
1007   for pkg in "${build_depends[@]}"; do
1008       if [[ $TARGET =~ debian|ubuntu ]]; then
1009           pkg_deb=$(ls "$WORKSPACE/packages/$TARGET/$pkg_"*.deb | sort -rg | awk 'NR==1')
1010           if [[ -e $pkg_deb ]]; then
1011               echo "Installing build_dep $pkg from $pkg_deb"
1012               dpkg -i "$pkg_deb"
1013           else
1014               echo "Attemping to install build_dep $pkg using apt-get"
1015               apt-get install -y "$pkg"
1016           fi
1017           apt-get -y -f install
1018       else
1019           pkg_rpm=$(ls "$WORKSPACE/packages/$TARGET/$pkg"-[0-9]*.rpm | sort -rg | awk 'NR==1')
1020           if [[ -e $pkg_rpm ]]; then
1021               echo "Installing build_dep $pkg from $pkg_rpm"
1022               rpm -i "$pkg_rpm"
1023           else
1024               echo "Attemping to install build_dep $pkg"
1025               rpm -i "$pkg"
1026           fi
1027       fi
1028   done
1029   for i in "${fpm_depends[@]}"; do
1030     COMMAND_ARR+=('--depends' "$i")
1031   done
1032   for i in "${fpm_conflicts[@]}"; do
1033     COMMAND_ARR+=('--conflicts' "$i")
1034   done
1035   for i in "${fpm_exclude[@]}"; do
1036     COMMAND_ARR+=('--exclude' "$i")
1037   done
1038
1039   COMMAND_ARR+=("${fpm_args[@]}")
1040
1041   # Append remaining function arguments directly to fpm's command line.
1042   for i; do
1043     COMMAND_ARR+=("$i")
1044   done
1045
1046   COMMAND_ARR+=("$PACKAGE")
1047
1048   debug_echo -e "\n${COMMAND_ARR[@]}\n"
1049
1050   FPM_RESULTS=$("${COMMAND_ARR[@]}")
1051   FPM_EXIT_CODE=$?
1052
1053   fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
1054
1055   # if something went wrong and debug is off, print out the fpm command that errored
1056   if [[ 0 -ne $? ]] && [[ "$STDOUT_IF_DEBUG" == "/dev/null" ]]; then
1057     echo -e "\n${COMMAND_ARR[@]}\n"
1058   fi
1059 }
1060
1061 # verify build results
1062 fpm_verify () {
1063   FPM_EXIT_CODE=$1
1064   shift
1065   FPM_RESULTS=$@
1066
1067   FPM_PACKAGE_NAME=''
1068   if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\.-]*\.)(deb|rpm) ]]; then
1069     FPM_PACKAGE_NAME=${BASH_REMATCH[1]}${BASH_REMATCH[2]}
1070   fi
1071
1072   if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
1073     EXITCODE=1
1074     echo
1075     echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
1076     echo
1077     echo $FPM_RESULTS
1078     echo
1079     return 1
1080   elif [[ "$FPM_RESULTS" =~ "File already exists" ]]; then
1081     echo "Package $FPM_PACKAGE_NAME exists, not rebuilding"
1082     return 0
1083   elif [[ 0 -ne "$FPM_EXIT_CODE" ]]; then
1084     EXITCODE=1
1085     echo "Error building package for $1:\n $FPM_RESULTS"
1086     return 1
1087   fi
1088 }
1089
1090 install_package() {
1091   PACKAGES=$@
1092   if [[ "$FORMAT" == "deb" ]]; then
1093     $SUDO apt-get install $PACKAGES --yes
1094   elif [[ "$FORMAT" == "rpm" ]]; then
1095     $SUDO yum -q -y install $PACKAGES
1096   fi
1097 }
1098
1099 title() {
1100     printf '%s %s\n' "=======" "$1"
1101 }
1102
1103 checkexit() {
1104     if [[ "$1" != "0" ]]; then
1105         title "$2 -- FAILED"
1106         failures+=("$2 (`timer`)")
1107     else
1108         successes+=("$2 (`timer`)")
1109     fi
1110 }
1111
1112 timer_reset() {
1113     t0=$SECONDS
1114 }
1115
1116 timer() {
1117     if [[ -n "$t0" ]]; then
1118         echo -n "$(($SECONDS - $t0))s"
1119     fi
1120 }
1121
1122 report_outcomes() {
1123     for x in "${successes[@]}"
1124     do
1125         echo "Pass: $x"
1126     done
1127
1128     if [[ ${#failures[@]} == 0 ]]
1129     then
1130         if [[ ${#successes[@]} != 0 ]]; then
1131            echo "All test suites passed."
1132         fi
1133     else
1134         echo "Failures (${#failures[@]}):"
1135         for x in "${failures[@]}"
1136         do
1137             echo "Fail: $x"
1138         done
1139     fi
1140 }