2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 # A library of functions shared by the various scripts in this directory.
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
11 LICENSE_PACKAGE_TS=20151208015500
13 if [[ -z "$ARVADOS_BUILDING_VERSION" ]]; then
14 RAILS_PACKAGE_ITERATION=1
16 RAILS_PACKAGE_ITERATION="$ARVADOS_BUILDING_ITERATION"
20 echo "$@" >"$STDOUT_IF_DEBUG"
23 find_python_program() {
27 if "$prog" --version >/dev/null 2>&1; then
35 Error: $prog (from Python setuptools module) not found
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"
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
51 local subdir="$1"; shift
52 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
53 echo "$ARVADOS_BUILDING_VERSION"
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"
63 nohash_version_from_git() {
64 local subdir="$1"; shift
65 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
66 echo "$ARVADOS_BUILDING_VERSION"
69 version_from_git $subdir | cut -d. -f1-4
72 timestamp_from_git() {
73 local subdir="$1"; shift
74 format_last_commit_here "%ct" "$subdir"
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)
83 local gem_name="$1"; shift
84 local gem_version="$(nohash_version_from_git)"
85 local gem_src_dir="$(pwd)"
87 if [[ -n "$ONLY_BUILD" ]] && [[ "$gem_name" != "$ONLY_BUILD" ]] ; then
91 if ! [[ -e "${gem_name}-${gem_version}.gem" ]]; then
92 find -maxdepth 1 -name "${gem_name}-*.gem" -delete
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"
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
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
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)
121 for dir in ${checkdirs[@]}; do
123 ts="$(timestamp_from_git "$dir")"
124 if [[ "$ts" -gt "$timestamp" ]]; then
125 version=$(version_from_git "$dir")
130 __returnvar="$version"
133 # Usage: package_go_binary services/foo arvados-foo [deb|rpm] [amd64|arm64] "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 package_format="$1"; shift
138 local target_arch="$1"; shift
139 local description="$1"; shift
140 local license_file="${1:-agpl-3.0.txt}"; shift
142 if [[ -n "$ONLY_BUILD" ]] && [[ "$prog" != "$ONLY_BUILD" ]]; then
143 # arvados-workbench depends on arvados-server at build time, so even when
144 # only arvados-workbench is being built, we need to build arvados-server too
145 if [[ "$prog" != "arvados-server" ]] || [[ "$ONLY_BUILD" != "arvados-workbench" ]]; then
150 # Only amd64 and aarch64 are supported
152 if [[ "$HOSTTYPE" == "aarch64" ]]; then
156 if [[ "$native_arch" != "amd64" ]] && [[ -n "$target_arch" ]] && [[ "$native_arch" != "$target_arch" ]]; then
157 echo "Error: no cross compilation support for Go on $native_arch yet, can not build $prog for $target_arch"
161 if [[ -n "$target_arch" ]]; then
162 # A target architecture has been specified
163 package_go_binary_worker "$src_path" "$prog" "$package_format" "$description" "$native_arch" "$target_arch" "$license_file"
166 # No target architecture specified, default to native target. When on amd64 also crosscompile arm64
167 # but only when building deb packages (centos does not have support for crosscompiling userspace).
169 if [[ "$native_arch" == "amd64" ]] && [[ "$package_format" == "deb" ]]; then
170 archs=('amd64' 'arm64')
173 package_go_binary_worker "$src_path" "$prog" "$package_format" "$description" "$native_arch" "$ta" "$license_file"
175 if [[ "$retval" != 0 ]]; then
182 # Usage: package_go_binary services/foo arvados-foo deb "Compute foo to arbitrary precision" [amd64/arm64] [amd64/arm64] [apache-2.0.txt]
183 package_go_binary_worker() {
184 local src_path="$1"; shift
185 local prog="$1"; shift
186 local package_format="$1"; shift
187 local description="$1"; shift
188 local native_arch="${1:-amd64}"; shift
189 local target_arch="${1:-amd64}"; shift
190 local license_file="${1:-agpl-3.0.txt}"; shift
192 if [[ "$native_arch" != "$target_arch" ]] && [[ "$package_format" == "rpm" ]]; then
193 echo "Error: no cross compilation support for Go on $native_arch ($package_format), can not build $prog for $target_arch"
197 debug_echo "package_go_binary $src_path as $prog (native arch: $native_arch, target arch: $target_arch)"
198 local basename="${src_path##*/}"
199 calculate_go_package_version go_package_version $src_path
201 cd $WORKSPACE/packages/$TARGET
202 test_package_presence "$prog" "$go_package_version" "go" "" "$target_arch"
203 if [[ "$?" != "0" ]]; then
207 echo "Building $pachage_format ($target_arch) package for $prog from $src_path"
208 if [[ "$native_arch" == "amd64" ]] && [[ "$target_arch" == "arm64" ]]; then
209 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc GOARCH=${target_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"
211 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"
216 binpath=$GOPATH/bin/${basename}
217 if [[ "${target_arch}" != "${native_arch}" ]]; then
218 switches+=("-a${target_arch}")
219 binpath="$GOPATH/bin/linux_${target_arch}/${basename}"
222 systemd_unit="$WORKSPACE/${src_path}/${prog}.service"
223 if [[ -e "${systemd_unit}" ]]; then
225 --after-install "${WORKSPACE}/build/go-python-package-scripts/postinst"
226 --before-remove "${WORKSPACE}/build/go-python-package-scripts/prerm"
227 "${systemd_unit}=/lib/systemd/system/${prog}.service")
229 switches+=("$WORKSPACE/${license_file}=/usr/share/doc/$prog/${license_file}")
231 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[@]}"
234 # Usage: package_go_so lib/foo arvados_foo.so arvados-foo deb amd64 "Arvados foo library"
236 local src_path="$1"; shift
237 local sofile="$1"; shift
238 local pkg="$1"; shift
239 local package_format="$1"; shift
240 local target_arch="$1"; shift # supported: amd64, arm64
241 local description="$1"; shift
243 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkg" != "$ONLY_BUILD" ]]; then
247 debug_echo "package_go_so $src_path as $pkg"
249 calculate_go_package_version go_package_version $src_path
250 cd $WORKSPACE/packages/$TARGET
251 test_package_presence $pkg $go_package_version go || return 1
252 cd $WORKSPACE/$src_path
253 go build -buildmode=c-shared -o ${GOPATH}/bin/${sofile}
254 cd $WORKSPACE/packages/$TARGET
256 "--url=https://arvados.org"
257 "--license=Apache License, Version 2.0"
258 "--description=${description}"
259 "$WORKSPACE/apache-2.0.txt=/usr/share/doc/$pkg/apache-2.0.txt"
261 if [[ -e "$WORKSPACE/$src_path/pam-configs-arvados" ]]; then
262 fpmargs+=("$WORKSPACE/$src_path/pam-configs-arvados=/usr/share/doc/$pkg/pam-configs-arvados-go")
264 if [[ -e "$WORKSPACE/$src_path/README" ]]; then
265 fpmargs+=("$WORKSPACE/$src_path/README=/usr/share/doc/$pkg/README")
267 fpm_build "${WORKSPACE}/${src_path}" "$GOPATH/bin/${sofile}=/usr/lib/${sofile}" "${pkg}" dir "${go_package_version}" "${fpmargs[@]}"
270 default_iteration() {
271 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
272 echo "$ARVADOS_BUILDING_ITERATION"
275 local package_name="$1"; shift
276 local package_version="$1"; shift
277 local package_type="$1"; shift
279 if [[ $package_version =~ ^0\.1\.([0-9]{14})(\.|$) ]] && \
280 [[ ${BASH_REMATCH[1]} -le $LICENSE_PACKAGE_TS ]]; then
286 _build_rails_package_scripts() {
287 local pkgname="$1"; shift
288 local destdir="$1"; shift
289 local srcdir="$RUN_BUILD_PACKAGES_PATH/rails-package-scripts"
290 for scriptname in postinst prerm postrm; do
291 cat "$srcdir/$pkgname.sh" "$srcdir/step2.sh" "$srcdir/$scriptname.sh" \
292 >"$destdir/$scriptname" || return $?
296 rails_package_version() {
297 local pkgname="$1"; shift
298 local srcdir="$1"; shift
299 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
300 echo "$ARVADOS_BUILDING_VERSION"
303 local version="$(version_from_git)"
304 if [ $pkgname = "arvados-api-server" -o $pkgname = "arvados-workbench" ] ; then
305 calculate_go_package_version version cmd/arvados-server "$srcdir"
310 test_rails_package_presence() {
311 local pkgname="$1"; shift
312 local srcdir="$1"; shift
314 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
322 local version="$(rails_package_version "$pkgname" "$srcdir")"
326 test_package_presence $pkgname $version rails "$RAILS_PACKAGE_ITERATION"
329 get_complete_package_name() {
330 # if the errexit flag is set, unset it until this function returns
331 # otherwise, the shift calls below will abort the program if optional arguments are not supplied
332 if [ -o errexit ]; then
336 # $__returnvar has the nameref attribute set, which means it is a reference
337 # to another variable that is passed in as the first argument to this function.
338 # see https://www.gnu.org/software/bash/manual/html_node/Shell-Parameters.html
339 local -n __returnvar="$1"; shift
340 local pkgname="$1"; shift
341 local version="$1"; shift
342 local pkgtype="$1"; shift
343 local iteration="$1"; shift
344 local arch="$1"; shift
345 if [[ "$iteration" == "" ]]; then
346 iteration="$(default_iteration "$pkgname" "$version" "$pkgtype")"
349 if [[ "$arch" == "" ]]; then
351 rpm_native_arch="x86_64"
352 if [[ "$HOSTTYPE" == "aarch64" ]]; then
354 rpm_native_arch="arm64"
356 rpm_architecture="$rpm_native_arch"
357 deb_architecture="$native_arch"
359 if [[ "$pkgtype" =~ ^(src)$ ]]; then
360 rpm_architecture="noarch"
361 deb_architecture="all"
364 # These python packages have binary components
365 if [[ "$pkgname" =~ (ruamel|ciso|pycrypto|pyyaml) ]]; then
366 rpm_architecture="$rpm_native_arch"
367 deb_architecture="$native_arch"
370 rpm_architecture=$arch
371 deb_architecture=$arch
374 local complete_pkgname="${pkgname}_$version${iteration:+-$iteration}_$deb_architecture.deb"
375 if [[ "$FORMAT" == "rpm" ]]; then
376 # rpm packages get iteration 1 if we don't supply one
377 iteration=${iteration:-1}
378 complete_pkgname="$pkgname-$version-${iteration}.$rpm_architecture.rpm"
380 __returnvar=${complete_pkgname}
383 # Test if the package already exists, if not return 0, if it does return 1
384 test_package_presence() {
385 local pkgname="$1"; shift
386 local version="$1"; shift
387 local pkgtype="$1"; shift
388 local iteration="$1"; shift
389 local arch="$1"; shift
390 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
391 # arvados-workbench depends on arvados-server at build time, so even when
392 # only arvados-workbench is being built, we need to build arvados-server too
393 if [[ "$pkgname" != "arvados-server" ]] || [[ "$ONLY_BUILD" != "arvados-workbench" ]]; then
399 get_complete_package_name full_pkgname "$pkgname" "$version" "$pkgtype" "$iteration" "$arch"
401 # See if we can skip building the package, only if it already exists in the
402 # processed/ directory. If so, move it back to the packages directory to make
403 # sure it gets picked up by the test and/or upload steps.
404 # Get the list of packages from the repos
406 if [[ "$FORCE_BUILD" == "1" ]]; then
407 echo "Package $full_pkgname build forced with --force-build, building"
408 elif [[ "$FORMAT" == "deb" ]]; then
411 dd[debian11]=bullseye
412 dd[ubuntu1804]=bionic
415 if [ ${pkgname:0:3} = "lib" ]; then
416 repo_subdir=${pkgname:0:4}
418 repo_subdir=${pkgname:0:1}
421 repo_pkg_list=$(curl -s -o - http://apt.arvados.org/${D}/pool/main/${repo_subdir}/${pkgname}/)
422 echo "${repo_pkg_list}" |grep -q ${full_pkgname}
423 if [ $? -eq 0 ] ; then
424 echo "Package $full_pkgname exists upstream, not rebuilding, downloading instead!"
425 curl -s -o "$WORKSPACE/packages/$TARGET/${full_pkgname}" http://apt.arvados.org/${D}/pool/main/${repo_subdir}/${pkgname}/${full_pkgname}
427 elif test -f "$WORKSPACE/packages/$TARGET/processed/${full_pkgname}" ; then
428 echo "Package $full_pkgname exists, not rebuilding!"
431 echo "Package $full_pkgname not found, building"
435 centos_repo="http://rpm.arvados.org/CentOS/7/dev/x86_64/"
437 repo_pkg_list=$(curl -s -o - ${centos_repo})
438 echo ${repo_pkg_list} |grep -q ${full_pkgname}
439 if [ $? -eq 0 ]; then
440 echo "Package $full_pkgname exists upstream, not rebuilding, downloading instead!"
441 curl -s -o "$WORKSPACE/packages/$TARGET/${full_pkgname}" ${centos_repo}${full_pkgname}
443 elif test -f "$WORKSPACE/packages/$TARGET/processed/${full_pkgname}" ; then
444 echo "Package $full_pkgname exists, not rebuilding!"
447 echo "Package $full_pkgname not found, building"
453 handle_rails_package() {
454 local pkgname="$1"; shift
456 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
459 local srcdir="$1"; shift
461 local license_path="$1"; shift
462 local version="$(rails_package_version "$pkgname" "$srcdir")"
463 echo "$version" >package-build.version
464 local scripts_dir="$(mktemp --tmpdir -d "$pkgname-XXXXXXXX.scripts")" && \
467 _build_rails_package_scripts "$pkgname" "$scripts_dir"
470 git rev-parse HEAD >git-commit.version
473 if [[ 0 != "$?" ]] || ! cd "$WORKSPACE/packages/$TARGET"; then
474 echo "ERROR: $pkgname package prep failed" >&2
475 rm -rf "$scripts_dir"
479 local railsdir="/var/www/${pkgname%-server}/current"
480 local -a pos_args=("$srcdir/=$railsdir" "$pkgname" dir "$version")
481 local license_arg="$license_path=$railsdir/$(basename "$license_path")"
482 local -a switches=(--after-install "$scripts_dir/postinst"
483 --before-remove "$scripts_dir/prerm"
484 --after-remove "$scripts_dir/postrm")
485 if [[ -z "$ARVADOS_BUILDING_VERSION" ]]; then
486 switches+=(--iteration $RAILS_PACKAGE_ITERATION)
488 # For some reason fpm excludes need to not start with /.
489 local exclude_root="${railsdir#/}"
490 local -a exclude_list=(tmp log coverage Capfile\* \
491 config/deploy\* config/application.yml)
492 # for arvados-workbench, we need to have the (dummy) config/database.yml in the package
493 if [[ "$pkgname" != "arvados-workbench" ]]; then
494 exclude_list+=('config/database.yml')
496 for exclude in ${exclude_list[@]}; do
497 switches+=(-x "$exclude_root/$exclude")
499 fpm_build "${srcdir}" "${pos_args[@]}" "${switches[@]}" \
500 -x "$exclude_root/vendor/cache-*" \
501 -x "$exclude_root/vendor/bundle" "$@" "$license_arg"
502 rm -rf "$scripts_dir"
505 # Build python packages with a virtualenv built-in
506 fpm_build_virtualenv () {
511 PACKAGE_TYPE=${1:-python}
514 if [[ "$HOSTTYPE" == "aarch64" ]]; then
518 if [[ -n "$ARCH" ]] && [[ "$ARCH" == "$native_arch" ]]; then
519 fpm_build_virtualenv_worker "$PKG" "$PKG_DIR" "$PACKAGE_TYPE" "$ARCH"
520 elif [[ -z "$ARCH" ]]; then
521 for arch in $native_arch; do
522 fpm_build_virtualenv_worker "$PKG" "$PKG_DIR" "$PACKAGE_TYPE" "$arch"
525 echo "Error: no cross compilation support for Python yet, can not build $PKG for $ARCH"
529 # Build python packages with a virtualenv built-in
530 fpm_build_virtualenv_worker () {
535 PACKAGE_TYPE=${1:-python}
541 STDOUT_IF_DEBUG=/dev/null
542 STDERR_IF_DEBUG=/dev/null
543 DASHQ_UNLESS_DEBUG=-q
544 if [[ "$DEBUG" != "0" ]]; then
545 STDOUT_IF_DEBUG=/dev/stdout
546 STDERR_IF_DEBUG=/dev/stderr
549 if [[ "$ARVADOS_BUILDING_ITERATION" == "" ]]; then
550 ARVADOS_BUILDING_ITERATION=1
554 case "$PACKAGE_TYPE" in
558 PACKAGE_PREFIX=$PYTHON3_PKG_PREFIX
562 if [[ "$PKG" != "arvados-docker-cleaner" ]]; then
563 PYTHON_PKG=$PACKAGE_PREFIX-$PKG
565 # Exception to our package naming convention
569 # arvados-python-client sdist should always be built, to be available
570 # for other dependent packages.
571 if [[ -n "$ONLY_BUILD" ]] && [[ "arvados-python-client" != "$PKG" ]] && [[ "$PYTHON_PKG" != "$ONLY_BUILD" ]] && [[ "$PKG" != "$ONLY_BUILD" ]]; then
575 cd $WORKSPACE/$PKG_DIR
579 # Get the latest setuptools
580 if ! $pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U 'setuptools<45'; then
581 echo "Error, unable to upgrade setuptools with"
582 echo " $pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U 'setuptools<45'"
585 # filter a useless warning (when building the cwltest package) from the stderr output
586 if ! $python setup.py $DASHQ_UNLESS_DEBUG sdist 2> >(grep -v 'warning: no previously-included files matching'); then
587 echo "Error, unable to run $python setup.py sdist for $PKG"
591 PACKAGE_PATH=`(cd dist; ls *tar.gz)`
593 if [[ "arvados-python-client" == "$PKG" ]]; then
594 PYSDK_PATH=`pwd`/dist/
597 if [[ -n "$ONLY_BUILD" ]] && [[ "$PYTHON_PKG" != "$ONLY_BUILD" ]] && [[ "$PKG" != "$ONLY_BUILD" ]]; then
601 # Determine the package version from the generated sdist archive
602 if [[ -n "$ARVADOS_BUILDING_VERSION" ]] ; then
603 UNFILTERED_PYTHON_VERSION=$ARVADOS_BUILDING_VERSION
604 PYTHON_VERSION=$(echo -n $ARVADOS_BUILDING_VERSION | sed s/~dev/.dev/g | sed s/~rc/rc/g)
606 PYTHON_VERSION=$(awk '($1 == "Version:"){print $2}' *.egg-info/PKG-INFO)
607 UNFILTERED_PYTHON_VERSION=$(echo -n $PYTHON_VERSION | sed s/\.dev/~dev/g |sed 's/\([0-9]\)rc/\1~rc/g')
610 # See if we actually need to build this package; does it exist already?
611 # We can't do this earlier than here, because we need PYTHON_VERSION...
612 # This isn't so bad; the sdist call above is pretty quick compared to
613 # the invocation of virtualenv and fpm, below.
614 if ! test_package_presence "$PYTHON_PKG" "$UNFILTERED_PYTHON_VERSION" "$PACKAGE_TYPE" "$ARVADOS_BUILDING_ITERATION" "$arch"; then
618 echo "Building $FORMAT ($arch) package for $PKG from $PKG_DIR"
620 # Package the sdist in a virtualenv
621 echo "Creating virtualenv..."
626 rm -f $PYTHON_PKG*deb
627 echo "virtualenv version: `virtualenv --version`"
628 virtualenv_command="virtualenv --python `which $python` $DASHQ_UNLESS_DEBUG build/usr/share/$python/dist/$PYTHON_PKG"
630 if ! $virtualenv_command; then
631 echo "Error, unable to run"
632 echo " $virtualenv_command"
636 if ! build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U pip; then
637 echo "Error, unable to upgrade pip with"
638 echo " build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U pip"
641 echo "pip version: `build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip --version`"
643 if ! build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U 'setuptools<45'; then
644 echo "Error, unable to upgrade setuptools with"
645 echo " build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U 'setuptools<45'"
648 echo "setuptools version: `build/usr/share/$python/dist/$PYTHON_PKG/bin/$python -c 'import setuptools; print(setuptools.__version__)'`"
650 if ! build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U wheel; then
651 echo "Error, unable to upgrade wheel with"
652 echo " build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U wheel"
655 echo "wheel version: `build/usr/share/$python/dist/$PYTHON_PKG/bin/wheel version`"
657 if [[ "$TARGET" != "centos7" ]] || [[ "$PYTHON_PKG" != "python-arvados-fuse" ]]; then
658 build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -f $PYSDK_PATH $PACKAGE_PATH
660 # centos7 needs these special tweaks to install python-arvados-fuse
661 build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG docutils
662 PYCURL_SSL_LIBRARY=nss build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -f $PYSDK_PATH $PACKAGE_PATH
665 if [[ "$?" != "0" ]]; then
666 echo "Error, unable to run"
667 echo " build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -f $PYSDK_PATH $PACKAGE_PATH"
671 cd build/usr/share/$python/dist/$PYTHON_PKG/
673 # Replace the shebang lines in all python scripts, and handle the activate
674 # scripts too. This is a functional replacement of the 237 line
675 # virtualenv_tools.py script that doesn't work in python3 without serious
676 # patching, minus the parts we don't need (modifying pyc files, etc).
677 for binfile in `ls bin/`; do
678 if ! file --mime bin/$binfile |grep -q binary; then
680 if [[ "$binfile" =~ ^activate(.csh|.fish|)$ ]]; then
681 # these 'activate' scripts need special treatment
682 sed -i "s/VIRTUAL_ENV=\".*\"/VIRTUAL_ENV=\"\/usr\/share\/$python\/dist\/$PYTHON_PKG\"/" bin/$binfile
683 sed -i "s/VIRTUAL_ENV \".*\"/VIRTUAL_ENV \"\/usr\/share\/$python\/dist\/$PYTHON_PKG\"/" bin/$binfile
685 if grep -q -E '^#!.*/bin/python\d?' bin/$binfile; then
686 # Replace shebang line
687 sed -i "1 s/^.*$/#!\/usr\/share\/$python\/dist\/$PYTHON_PKG\/bin\/python/" bin/$binfile
693 cd - >$STDOUT_IF_DEBUG
695 find build -iname '*.pyc' -exec rm {} \;
696 find build -iname '*.pyo' -exec rm {} \;
698 # Finally, generate the package
699 echo "Creating package..."
701 declare -a COMMAND_ARR=("fpm" "-s" "dir" "-t" "$FORMAT")
703 if [[ "${arch}" != "amd64" ]]; then
704 COMMAND_ARR+=("-a${arch}")
707 if [[ "$MAINTAINER" != "" ]]; then
708 COMMAND_ARR+=('--maintainer' "$MAINTAINER")
711 if [[ "$VENDOR" != "" ]]; then
712 COMMAND_ARR+=('--vendor' "$VENDOR")
715 COMMAND_ARR+=('--url' 'https://arvados.org')
718 DESCRIPTION=`grep '\sdescription' $WORKSPACE/$PKG_DIR/setup.py|cut -f2 -d=|sed -e "s/[',\\"]//g"`
719 COMMAND_ARR+=('--description' "$DESCRIPTION")
722 LICENSE_STRING=`grep license $WORKSPACE/$PKG_DIR/setup.py|cut -f2 -d=|sed -e "s/[',\\"]//g"`
723 COMMAND_ARR+=('--license' "$LICENSE_STRING")
725 if [[ "$FORMAT" == "rpm" ]]; then
726 # Make sure to conflict with the old rh-python36 packages we used to publish
727 COMMAND_ARR+=('--conflicts' "rh-python36-python-$PKG")
730 if [[ "$DEBUG" != "0" ]]; then
731 COMMAND_ARR+=('--verbose' '--log' 'info')
734 COMMAND_ARR+=('-v' $(echo -n "$PYTHON_VERSION" | sed s/.dev/~dev/g | sed s/rc/~rc/g))
735 COMMAND_ARR+=('--iteration' "$ARVADOS_BUILDING_ITERATION")
736 COMMAND_ARR+=('-n' "$PYTHON_PKG")
737 COMMAND_ARR+=('-C' "build")
739 systemd_unit="$WORKSPACE/$PKG_DIR/$PKG.service"
740 if [[ -e "${systemd_unit}" ]]; then
741 COMMAND_ARR+=('--after-install' "${WORKSPACE}/build/go-python-package-scripts/postinst")
742 COMMAND_ARR+=('--before-remove' "${WORKSPACE}/build/go-python-package-scripts/prerm")
745 COMMAND_ARR+=('--depends' "$PYTHON3_PACKAGE")
748 COMMAND_ARR+=('--deb-no-default-config-files')
750 # Append --depends X and other arguments specified by fpm-info.sh in
751 # the package source dir. These are added last so they can override
752 # the arguments added by this script.
753 declare -a fpm_args=()
754 declare -a fpm_depends=()
756 fpminfo="$WORKSPACE/$PKG_DIR/fpm-info.sh"
757 if [[ -e "$fpminfo" ]]; then
758 echo "Loading fpm overrides from $fpminfo"
759 if ! source "$fpminfo"; then
760 echo "Error, unable to source $WORKSPACE/$PKG_DIR/fpm-info.sh for $PKG"
765 for i in "${fpm_depends[@]}"; do
766 COMMAND_ARR+=('--depends' "$i")
769 for i in "${fpm_depends[@]}"; do
770 COMMAND_ARR+=('--replaces' "python-$PKG")
773 # make sure the systemd service file ends up in the right place
774 # used by arvados-docker-cleaner
775 if [[ -e "${systemd_unit}" ]]; then
776 COMMAND_ARR+=("usr/share/$python/dist/$PKG/share/doc/$PKG/$PKG.service=/lib/systemd/system/$PKG.service")
779 COMMAND_ARR+=("${fpm_args[@]}")
781 # Make sure to install all our package binaries in /usr/bin.
782 # We have to walk $WORKSPACE/$PKG_DIR/bin rather than
783 # $WORKSPACE/build/usr/share/$python/dist/$PYTHON_PKG/bin/ to get the list
784 # because the latter also includes all the python binaries for the virtualenv.
785 # We have to take the copies of our binaries from the latter directory, though,
786 # because those are the ones we rewrote the shebang line of, above.
787 if [[ -e "$WORKSPACE/$PKG_DIR/bin" ]]; then
788 for binary in `ls $WORKSPACE/$PKG_DIR/bin`; do
789 COMMAND_ARR+=("usr/share/$python/dist/$PYTHON_PKG/bin/$binary=/usr/bin/")
793 # the python3-arvados-cwl-runner package comes with cwltool, expose that version
794 if [[ -e "$WORKSPACE/$PKG_DIR/dist/build/usr/share/$python/dist/$PYTHON_PKG/bin/cwltool" ]]; then
795 COMMAND_ARR+=("usr/share/$python/dist/$PYTHON_PKG/bin/cwltool=/usr/bin/")
800 debug_echo -e "\n${COMMAND_ARR[@]}\n"
802 FPM_RESULTS=$("${COMMAND_ARR[@]}")
805 # if something went wrong and debug is off, print out the fpm command that errored
806 if ! fpm_verify $FPM_EXIT_CODE $FPM_RESULTS && [[ "$STDOUT_IF_DEBUG" == "/dev/null" ]]; then
807 echo "fpm returned an error executing the command:"
809 echo -e "\n${COMMAND_ARR[@]}\n"
812 mv $WORKSPACE/$PKG_DIR/dist/*$FORMAT $WORKSPACE/packages/$TARGET/
817 # build_metapackage builds meta packages that help with the python to python 3 package migration
818 build_metapackage() {
819 # base package name (e.g. arvados-python-client)
825 if [[ -n "$ONLY_BUILD" ]] && [[ "python-$BASE_NAME" != "$ONLY_BUILD" ]]; then
829 if [[ "$ARVADOS_BUILDING_ITERATION" == "" ]]; then
830 ARVADOS_BUILDING_ITERATION=1
833 if [[ -z "$ARVADOS_BUILDING_VERSION" ]]; then
834 cd $WORKSPACE/$PKG_DIR
838 # Get the latest setuptools
839 if ! pip3 install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U 'setuptools<45'; then
840 echo "Error, unable to upgrade setuptools with XY"
841 echo " pip3 install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U 'setuptools<45'"
844 # filter a useless warning (when building the cwltest package) from the stderr output
845 if ! python3 setup.py $DASHQ_UNLESS_DEBUG sdist 2> >(grep -v 'warning: no previously-included files matching'); then
846 echo "Error, unable to run python3 setup.py sdist for $PKG"
850 PYTHON_VERSION=$(awk '($1 == "Version:"){print $2}' *.egg-info/PKG-INFO)
851 UNFILTERED_PYTHON_VERSION=$(echo -n $PYTHON_VERSION | sed s/\.dev/~dev/g |sed 's/\([0-9]\)rc/\1~rc/g')
854 UNFILTERED_PYTHON_VERSION=$ARVADOS_BUILDING_VERSION
855 PYTHON_VERSION=$(echo -n $ARVADOS_BUILDING_VERSION | sed s/~dev/.dev/g | sed s/~rc/rc/g)
858 cd - >$STDOUT_IF_DEBUG
859 if [[ -d "$BASE_NAME" ]]; then
865 if [[ "$FORMAT" == "deb" ]]; then
866 cat >ns-control <<EOF
869 Standards-Version: 3.9.2
871 Package: python-${BASE_NAME}
872 Version: ${PYTHON_VERSION}-${ARVADOS_BUILDING_ITERATION}
873 Maintainer: Arvados Package Maintainers <packaging@arvados.org>
874 Depends: python3-${BASE_NAME}
875 Description: metapackage to ease the upgrade to the Pyhon 3 version of ${BASE_NAME}
876 This package is a metapackage that will automatically install the new version of
877 ${BASE_NAME} which is Python 3 based and has a different name.
880 /usr/bin/equivs-build ns-control
881 if [[ $? -ne 0 ]]; then
882 echo "Error running 'equivs-build ns-control', is the 'equivs' package installed?"
885 elif [[ "$FORMAT" == "rpm" ]]; then
887 Summary: metapackage to ease the upgrade to the Python 3 version of ${BASE_NAME}
888 Name: python-${BASE_NAME}
889 Version: ${PYTHON_VERSION}
890 Release: ${ARVADOS_BUILDING_ITERATION}
891 License: distributable
893 Requires: python3-${BASE_NAME}
896 This package is a metapackage that will automatically install the new version of
897 python-${BASE_NAME} which is Python 3 based and has a different name.
913 * Mon Apr 12 2021 Arvados Package Maintainers <packaging@arvados.org>
917 /usr/bin/rpmbuild -ba meta.spec
918 if [[ $? -ne 0 ]]; then
919 echo "Error running 'rpmbuild -ba meta.spec', is the 'rpm-build' package installed?"
922 mv /root/rpmbuild/RPMS/x86_64/python-${BASE_NAME}*.${FORMAT} .
923 if [[ $? -ne 0 ]]; then
924 echo "Error finding rpm file output of 'rpmbuild -ba meta.spec'"
929 echo "Unknown format"
933 if [[ $EXITCODE -ne 0 ]]; then
937 mv *$FORMAT $WORKSPACE/packages/$TARGET/
941 cd - >$STDOUT_IF_DEBUG
942 if [[ -d "$BASE_NAME" ]]; then
947 # Build packages for everything
949 # Source dir where fpm-info.sh (if any) will be found.
952 # The package source. Depending on the source type, this can be a
953 # path, or the name of the package in an upstream repository (e.g.,
957 # The name of the package to build.
960 # The type of source package. Passed to fpm -s. Default "dir".
961 PACKAGE_TYPE=${1:-dir}
963 # Optional: the package version number. Passed to fpm -v.
967 if [[ -n "$ONLY_BUILD" ]] && [[ "$PACKAGE_NAME" != "$ONLY_BUILD" ]] && [[ "$PACKAGE" != "$ONLY_BUILD" ]] ; then
968 # arvados-workbench depends on arvados-server at build time, so even when
969 # only arvados-workbench is being built, we need to build arvados-server too
970 if [[ "$PACKAGE_NAME" != "arvados-server" ]] || [[ "$ONLY_BUILD" != "arvados-workbench" ]]; then
975 local default_iteration_value="$(default_iteration "$PACKAGE" "$VERSION" "$PACKAGE_TYPE")"
977 declare -a COMMAND_ARR=("fpm" "-s" "$PACKAGE_TYPE" "-t" "$FORMAT")
978 if [ python = "$PACKAGE_TYPE" ] && [ deb = "$FORMAT" ]; then
979 # Dependencies are built from setup.py. Since setup.py will never
980 # refer to Debian package iterations, it doesn't make sense to
981 # enforce those in the .deb dependencies.
982 COMMAND_ARR+=(--deb-ignore-iteration-in-dependencies)
985 if [[ "$DEBUG" != "0" ]]; then
986 COMMAND_ARR+=('--verbose' '--log' 'info')
989 if [[ -n "$PACKAGE_NAME" ]]; then
990 COMMAND_ARR+=('-n' "$PACKAGE_NAME")
993 if [[ "$MAINTAINER" != "" ]]; then
994 COMMAND_ARR+=('--maintainer' "$MAINTAINER")
997 if [[ "$VENDOR" != "" ]]; then
998 COMMAND_ARR+=('--vendor' "$VENDOR")
1001 if [[ "$VERSION" != "" ]]; then
1002 COMMAND_ARR+=('-v' "$VERSION")
1004 if [[ -n "$default_iteration_value" ]]; then
1005 # We can always add an --iteration here. If another one is specified in $@,
1006 # that will take precedence, as desired.
1007 COMMAND_ARR+=(--iteration "$default_iteration_value")
1010 # Append --depends X and other arguments specified by fpm-info.sh in
1011 # the package source dir. These are added last so they can override
1012 # the arguments added by this script.
1013 declare -a fpm_args=()
1014 declare -a build_depends=()
1015 declare -a fpm_depends=()
1016 declare -a fpm_conflicts=()
1017 declare -a fpm_exclude=()
1018 if [[ ! -d "$SRC_DIR" ]]; then
1019 echo >&2 "BUG: looking in wrong dir for fpm-info.sh: $pkgdir"
1022 fpminfo="${SRC_DIR}/fpm-info.sh"
1023 if [[ -e "$fpminfo" ]]; then
1024 debug_echo "Loading fpm overrides from $fpminfo"
1027 for pkg in "${build_depends[@]}"; do
1028 if [[ $TARGET =~ debian|ubuntu ]]; then
1029 pkg_deb=$(ls "$WORKSPACE/packages/$TARGET/$pkg_"*.deb | sort -rg | awk 'NR==1')
1030 if [[ -e $pkg_deb ]]; then
1031 echo "Installing build_dep $pkg from $pkg_deb"
1034 echo "Attemping to install build_dep $pkg using apt-get"
1035 apt-get install -y "$pkg"
1037 apt-get -y -f install
1039 pkg_rpm=$(ls "$WORKSPACE/packages/$TARGET/$pkg"-[0-9]*.rpm | sort -rg | awk 'NR==1')
1040 if [[ -e $pkg_rpm ]]; then
1041 echo "Installing build_dep $pkg from $pkg_rpm"
1044 echo "Attemping to install build_dep $pkg"
1049 for i in "${fpm_depends[@]}"; do
1050 COMMAND_ARR+=('--depends' "$i")
1052 for i in "${fpm_conflicts[@]}"; do
1053 COMMAND_ARR+=('--conflicts' "$i")
1055 for i in "${fpm_exclude[@]}"; do
1056 COMMAND_ARR+=('--exclude' "$i")
1059 COMMAND_ARR+=("${fpm_args[@]}")
1061 # Append remaining function arguments directly to fpm's command line.
1066 COMMAND_ARR+=("$PACKAGE")
1068 debug_echo -e "\n${COMMAND_ARR[@]}\n"
1070 FPM_RESULTS=$("${COMMAND_ARR[@]}")
1073 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
1075 # if something went wrong and debug is off, print out the fpm command that errored
1076 if [[ 0 -ne $? ]] && [[ "$STDOUT_IF_DEBUG" == "/dev/null" ]]; then
1077 echo -e "\n${COMMAND_ARR[@]}\n"
1081 # verify build results
1088 if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\.-]*\.)(deb|rpm) ]]; then
1089 FPM_PACKAGE_NAME=${BASH_REMATCH[1]}${BASH_REMATCH[2]}
1092 if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
1095 echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
1100 elif [[ "$FPM_RESULTS" =~ "File already exists" ]]; then
1101 echo "Package $FPM_PACKAGE_NAME exists, not rebuilding"
1103 elif [[ 0 -ne "$FPM_EXIT_CODE" ]]; then
1105 echo "Error building package for $1:\n $FPM_RESULTS"
1112 if [[ "$FORMAT" == "deb" ]]; then
1113 $SUDO apt-get install $PACKAGES --yes
1114 elif [[ "$FORMAT" == "rpm" ]]; then
1115 $SUDO yum -q -y install $PACKAGES
1120 printf '%s %s\n' "=======" "$1"
1124 if [[ "$1" != "0" ]]; then
1125 title "$2 -- FAILED"
1126 failures+=("$2 (`timer`)")
1128 successes+=("$2 (`timer`)")
1137 if [[ -n "$t0" ]]; then
1138 echo -n "$(($SECONDS - $t0))s"
1143 for x in "${successes[@]}"
1148 if [[ ${#failures[@]} == 0 ]]
1150 if [[ ${#successes[@]} != 0 ]]; then
1151 echo "All test suites passed."
1154 echo "Failures (${#failures[@]}):"
1155 for x in "${failures[@]}"