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 "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
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
149 if [[ "$HOSTTYPE" == "aarch64" ]]; then
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"
157 echo "Error: no cross compilation support for Go on $native_arch yet, can not build $prog for $ARCH"
161 if [[ "$native_arch" == "amd64" ]]; then
162 archs=('amd64' 'arm64')
164 for arch in $archs; do
165 package_go_binary_worker "$src_path" "$prog" "$description" "$native_arch" "$arch" "$license_file"
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
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
183 cd $WORKSPACE/packages/$TARGET
184 test_package_presence "$prog" "$go_package_version" "go" "" "$arch"
185 if [[ "$?" != "0" ]]; then
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"
194 echo "Error: no cross compilation support for Go on $native_arch ($FORMAT), can not build $prog for $ARCH"
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"
203 binpath=$GOPATH/bin/${basename}
204 if [[ "${arch}" != "${native_arch}" ]]; then
205 switches+=("-a${arch}")
206 binpath="$GOPATH/bin/linux_${arch}/${basename}"
209 systemd_unit="$WORKSPACE/${src_path}/${prog}.service"
210 if [[ -e "${systemd_unit}" ]]; then
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")
216 switches+=("$WORKSPACE/${license_file}=/usr/share/doc/$prog/${license_file}")
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[@]}"
221 # Usage: package_go_so lib/foo arvados_foo.so arvados-foo "Arvados foo library"
223 local src_path="$1"; shift
224 local sofile="$1"; shift
225 local pkg="$1"; shift
226 local description="$1"; shift
228 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkg" != "$ONLY_BUILD" ]]; then
232 debug_echo "package_go_so $src_path as $pkg"
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
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"
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")
249 if [[ -e "$WORKSPACE/$src_path/README" ]]; then
250 fpmargs+=("$WORKSPACE/$src_path/README=/usr/share/doc/$pkg/README")
252 fpm_build "${WORKSPACE}/${src_path}" "$GOPATH/bin/${sofile}=/usr/lib/${sofile}" "${pkg}" dir "${go_package_version}" "${fpmargs[@]}"
255 default_iteration() {
256 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
257 echo "$ARVADOS_BUILDING_ITERATION"
260 local package_name="$1"; shift
261 local package_version="$1"; shift
262 local package_type="$1"; shift
264 if [[ $package_version =~ ^0\.1\.([0-9]{14})(\.|$) ]] && \
265 [[ ${BASH_REMATCH[1]} -le $LICENSE_PACKAGE_TS ]]; then
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 $?
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"
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"
295 test_rails_package_presence() {
296 local pkgname="$1"; shift
297 local srcdir="$1"; shift
299 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
307 local version="$(rails_package_version "$pkgname" "$srcdir")"
311 test_package_presence $pkgname $version rails "$RAILS_PACKAGE_ITERATION"
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
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")"
334 if [[ "$arch" == "" ]]; then
336 rpm_native_arch="x86_64"
337 if [[ "$HOSTTYPE" == "aarch64" ]]; then
339 rpm_native_arch="arm64"
341 rpm_architecture="$rpm_native_arch"
342 deb_architecture="$native_arch"
344 if [[ "$pkgtype" =~ ^(src)$ ]]; then
345 rpm_architecture="noarch"
346 deb_architecture="all"
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"
355 rpm_architecture=$arch
356 deb_architecture=$arch
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"
365 __returnvar=${complete_pkgname}
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
384 get_complete_package_name full_pkgname "$pkgname" "$version" "$pkgtype" "$iteration" "$arch"
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
391 if [[ "$FORCE_BUILD" == "1" ]]; then
392 echo "Package $full_pkgname build forced with --force-build, building"
393 elif [[ "$FORMAT" == "deb" ]]; then
396 dd[debian11]=bullseye
397 dd[ubuntu1804]=bionic
400 if [ ${pkgname:0:3} = "lib" ]; then
401 repo_subdir=${pkgname:0:4}
403 repo_subdir=${pkgname:0:1}
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}
412 elif test -f "$WORKSPACE/packages/$TARGET/processed/${full_pkgname}" ; then
413 echo "Package $full_pkgname exists, not rebuilding!"
416 echo "Package $full_pkgname not found, building"
420 centos_repo="http://rpm.arvados.org/CentOS/7/dev/x86_64/"
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}
428 elif test -f "$WORKSPACE/packages/$TARGET/processed/${full_pkgname}" ; then
429 echo "Package $full_pkgname exists, not rebuilding!"
432 echo "Package $full_pkgname not found, building"
438 handle_rails_package() {
439 local pkgname="$1"; shift
441 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
444 local srcdir="$1"; shift
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")" && \
452 _build_rails_package_scripts "$pkgname" "$scripts_dir"
455 git rev-parse HEAD >git-commit.version
458 if [[ 0 != "$?" ]] || ! cd "$WORKSPACE/packages/$TARGET"; then
459 echo "ERROR: $pkgname package prep failed" >&2
460 rm -rf "$scripts_dir"
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)
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')
481 for exclude in ${exclude_list[@]}; do
482 switches+=(-x "$exclude_root/$exclude")
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"
490 # Build python packages with a virtualenv built-in
491 fpm_build_virtualenv () {
496 PACKAGE_TYPE=${1:-python}
499 if [[ "$HOSTTYPE" == "aarch64" ]]; then
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"
510 echo "Error: no cross compilation support for Python yet, can not build $PKG for $ARCH"
514 # Build python packages with a virtualenv built-in
515 fpm_build_virtualenv_worker () {
520 PACKAGE_TYPE=${1:-python}
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
534 if [[ "$ARVADOS_BUILDING_ITERATION" == "" ]]; then
535 ARVADOS_BUILDING_ITERATION=1
539 case "$PACKAGE_TYPE" in
543 PACKAGE_PREFIX=$PYTHON3_PKG_PREFIX
547 if [[ "$PKG" != "arvados-docker-cleaner" ]]; then
548 PYTHON_PKG=$PACKAGE_PREFIX-$PKG
550 # Exception to our package naming convention
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
560 cd $WORKSPACE/$PKG_DIR
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'"
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"
576 PACKAGE_PATH=`(cd dist; ls *tar.gz)`
578 if [[ "arvados-python-client" == "$PKG" ]]; then
579 PYSDK_PATH=`pwd`/dist/
582 if [[ -n "$ONLY_BUILD" ]] && [[ "$PYTHON_PKG" != "$ONLY_BUILD" ]] && [[ "$PKG" != "$ONLY_BUILD" ]]; then
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)
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')
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
603 echo "Building $FORMAT ($arch) package for $PKG from $PKG_DIR"
605 # Package the sdist in a virtualenv
606 echo "Creating virtualenv..."
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"
615 if ! $virtualenv_command; then
616 echo "Error, unable to run"
617 echo " $virtualenv_command"
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"
626 echo "pip version: `build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip --version`"
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'"
633 echo "setuptools version: `build/usr/share/$python/dist/$PYTHON_PKG/bin/$python -c 'import setuptools; print(setuptools.__version__)'`"
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"
640 echo "wheel version: `build/usr/share/$python/dist/$PYTHON_PKG/bin/wheel version`"
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
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
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"
656 cd build/usr/share/$python/dist/$PYTHON_PKG/
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
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
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
678 cd - >$STDOUT_IF_DEBUG
680 find build -iname '*.pyc' -exec rm {} \;
681 find build -iname '*.pyo' -exec rm {} \;
683 # Finally, generate the package
684 echo "Creating package..."
686 declare -a COMMAND_ARR=("fpm" "-s" "dir" "-t" "$FORMAT")
688 if [[ "${arch}" != "amd64" ]]; then
689 COMMAND_ARR+=("-a${arch}")
692 if [[ "$MAINTAINER" != "" ]]; then
693 COMMAND_ARR+=('--maintainer' "$MAINTAINER")
696 if [[ "$VENDOR" != "" ]]; then
697 COMMAND_ARR+=('--vendor' "$VENDOR")
700 COMMAND_ARR+=('--url' 'https://arvados.org')
703 DESCRIPTION=`grep '\sdescription' $WORKSPACE/$PKG_DIR/setup.py|cut -f2 -d=|sed -e "s/[',\\"]//g"`
704 COMMAND_ARR+=('--description' "$DESCRIPTION")
707 LICENSE_STRING=`grep license $WORKSPACE/$PKG_DIR/setup.py|cut -f2 -d=|sed -e "s/[',\\"]//g"`
708 COMMAND_ARR+=('--license' "$LICENSE_STRING")
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")
715 if [[ "$DEBUG" != "0" ]]; then
716 COMMAND_ARR+=('--verbose' '--log' 'info')
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")
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")
730 COMMAND_ARR+=('--depends' "$PYTHON3_PACKAGE")
733 COMMAND_ARR+=('--deb-no-default-config-files')
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=()
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"
750 for i in "${fpm_depends[@]}"; do
751 COMMAND_ARR+=('--depends' "$i")
754 for i in "${fpm_depends[@]}"; do
755 COMMAND_ARR+=('--replaces' "python-$PKG")
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")
764 COMMAND_ARR+=("${fpm_args[@]}")
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/")
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/")
785 debug_echo -e "\n${COMMAND_ARR[@]}\n"
787 FPM_RESULTS=$("${COMMAND_ARR[@]}")
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:"
794 echo -e "\n${COMMAND_ARR[@]}\n"
797 mv $WORKSPACE/$PKG_DIR/dist/*$FORMAT $WORKSPACE/packages/$TARGET/
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)
810 if [[ -n "$ONLY_BUILD" ]] && [[ "python-$BASE_NAME" != "$ONLY_BUILD" ]]; then
814 if [[ "$ARVADOS_BUILDING_ITERATION" == "" ]]; then
815 ARVADOS_BUILDING_ITERATION=1
818 if [[ -z "$ARVADOS_BUILDING_VERSION" ]]; then
819 cd $WORKSPACE/$PKG_DIR
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'"
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"
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')
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)
843 cd - >$STDOUT_IF_DEBUG
844 if [[ -d "$BASE_NAME" ]]; then
850 if [[ "$FORMAT" == "deb" ]]; then
851 cat >ns-control <<EOF
854 Standards-Version: 3.9.2
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.
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?"
870 elif [[ "$FORMAT" == "rpm" ]]; then
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
878 Requires: python3-${BASE_NAME}
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.
898 * Mon Apr 12 2021 Arvados Package Maintainers <packaging@arvados.org>
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?"
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'"
914 echo "Unknown format"
918 if [[ $EXITCODE -ne 0 ]]; then
922 mv *$FORMAT $WORKSPACE/packages/$TARGET/
926 cd - >$STDOUT_IF_DEBUG
927 if [[ -d "$BASE_NAME" ]]; then
932 # Build packages for everything
934 # Source dir where fpm-info.sh (if any) will be found.
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.,
942 # The name of the package to build.
945 # The type of source package. Passed to fpm -s. Default "dir".
946 PACKAGE_TYPE=${1:-dir}
948 # Optional: the package version number. Passed to fpm -v.
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
960 local default_iteration_value="$(default_iteration "$PACKAGE" "$VERSION" "$PACKAGE_TYPE")"
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)
970 if [[ "$DEBUG" != "0" ]]; then
971 COMMAND_ARR+=('--verbose' '--log' 'info')
974 if [[ -n "$PACKAGE_NAME" ]]; then
975 COMMAND_ARR+=('-n' "$PACKAGE_NAME")
978 if [[ "$MAINTAINER" != "" ]]; then
979 COMMAND_ARR+=('--maintainer' "$MAINTAINER")
982 if [[ "$VENDOR" != "" ]]; then
983 COMMAND_ARR+=('--vendor' "$VENDOR")
986 if [[ "$VERSION" != "" ]]; then
987 COMMAND_ARR+=('-v' "$VERSION")
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")
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"
1007 fpminfo="${SRC_DIR}/fpm-info.sh"
1008 if [[ -e "$fpminfo" ]]; then
1009 debug_echo "Loading fpm overrides from $fpminfo"
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"
1019 echo "Attemping to install build_dep $pkg using apt-get"
1020 apt-get install -y "$pkg"
1022 apt-get -y -f install
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"
1029 echo "Attemping to install build_dep $pkg"
1034 for i in "${fpm_depends[@]}"; do
1035 COMMAND_ARR+=('--depends' "$i")
1037 for i in "${fpm_conflicts[@]}"; do
1038 COMMAND_ARR+=('--conflicts' "$i")
1040 for i in "${fpm_exclude[@]}"; do
1041 COMMAND_ARR+=('--exclude' "$i")
1044 COMMAND_ARR+=("${fpm_args[@]}")
1046 # Append remaining function arguments directly to fpm's command line.
1051 COMMAND_ARR+=("$PACKAGE")
1053 debug_echo -e "\n${COMMAND_ARR[@]}\n"
1055 FPM_RESULTS=$("${COMMAND_ARR[@]}")
1058 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
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"
1066 # verify build results
1073 if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\.-]*\.)(deb|rpm) ]]; then
1074 FPM_PACKAGE_NAME=${BASH_REMATCH[1]}${BASH_REMATCH[2]}
1077 if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
1080 echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
1085 elif [[ "$FPM_RESULTS" =~ "File already exists" ]]; then
1086 echo "Package $FPM_PACKAGE_NAME exists, not rebuilding"
1088 elif [[ 0 -ne "$FPM_EXIT_CODE" ]]; then
1090 echo "Error building package for $1:\n $FPM_RESULTS"
1097 if [[ "$FORMAT" == "deb" ]]; then
1098 $SUDO apt-get install $PACKAGES --yes
1099 elif [[ "$FORMAT" == "rpm" ]]; then
1100 $SUDO yum -q -y install $PACKAGES
1105 printf '%s %s\n' "=======" "$1"
1109 if [[ "$1" != "0" ]]; then
1110 title "$2 -- FAILED"
1111 failures+=("$2 (`timer`)")
1113 successes+=("$2 (`timer`)")
1122 if [[ -n "$t0" ]]; then
1123 echo -n "$(($SECONDS - $t0))s"
1128 for x in "${successes[@]}"
1133 if [[ ${#failures[@]} == 0 ]]
1135 if [[ ${#successes[@]} != 0 ]]; then
1136 echo "All test suites passed."
1139 echo "Failures (${#failures[@]}):"
1140 for x in "${failures[@]}"