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