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 TZ=UTC git log -n1 --first-parent "--format=format:$format" .
47 # Output the version being built, or if we're building a
48 # dev/prerelease, output a version number based on the git log for
49 # the current working directory.
50 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
51 echo "$ARVADOS_BUILDING_VERSION"
55 local git_ts git_hash prefix
56 if [[ -n "$1" ]] ; then
62 declare $(format_last_commit_here "git_ts=%ct git_hash=%h")
63 ARVADOS_BUILDING_VERSION="$(git tag -l |sort -V -r |head -n1).$(date -ud "@$git_ts" +%Y%m%d%H%M%S)"
64 echo "$ARVADOS_BUILDING_VERSION"
67 nohash_version_from_git() {
68 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
69 echo "$ARVADOS_BUILDING_VERSION"
72 version_from_git $1 | cut -d. -f1-4
75 timestamp_from_git() {
76 format_last_commit_here "%ct"
79 handle_python_package () {
80 # This function assumes the current working directory is the python package directory
81 if [ -n "$(find dist -name "*-$(nohash_version_from_git).tar.gz" -print -quit)" ]; then
82 # This package doesn't need rebuilding.
85 # Make sure only to use sdist - that's the only format pip can deal with (sigh)
86 python setup.py $DASHQ_UNLESS_DEBUG sdist
90 local gem_name="$1"; shift
91 local gem_version="$(nohash_version_from_git)"
92 local gem_src_dir="$(pwd)"
94 if [[ -n "$ONLY_BUILD" ]] && [[ "$gem_name" != "$ONLY_BUILD" ]] ; then
98 if ! [[ -e "${gem_name}-${gem_version}.gem" ]]; then
99 find -maxdepth 1 -name "${gem_name}-*.gem" -delete
101 # -q appears to be broken in gem version 2.2.2
102 $GEM build "$gem_name.gemspec" $DASHQ_UNLESS_DEBUG >"$STDOUT_IF_DEBUG" 2>"$STDERR_IF_DEBUG"
106 # Usage: package_go_binary services/foo arvados-foo "Compute foo to arbitrary precision"
107 package_go_binary() {
108 local src_path="$1"; shift
109 local prog="$1"; shift
110 local description="$1"; shift
111 local license_file="${1:-agpl-3.0.txt}"; shift
113 if [[ -n "$ONLY_BUILD" ]] && [[ "$prog" != "$ONLY_BUILD" ]] ; then
117 debug_echo "package_go_binary $src_path as $prog"
119 local basename="${src_path##*/}"
121 mkdir -p "$GOPATH/src/git.curoverse.com"
122 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
123 (cd "$GOPATH/src/git.curoverse.com/arvados.git" && "$GOPATH/bin/govendor" sync -v)
125 cd "$GOPATH/src/git.curoverse.com/arvados.git/$src_path"
126 local version="$(version_from_git)"
127 local timestamp="$(timestamp_from_git)"
129 # Update the version number and build a new package if the vendor
130 # bundle has changed, or the command imports anything from the
131 # Arvados SDK and the SDK has changed.
132 declare -a checkdirs=(vendor)
133 if grep -qr git.curoverse.com/arvados .; then
134 checkdirs+=(sdk/go lib)
136 for dir in ${checkdirs[@]}; do
137 cd "$GOPATH/src/git.curoverse.com/arvados.git/$dir"
138 ts="$(timestamp_from_git)"
139 if [[ "$ts" -gt "$timestamp" ]]; then
140 version=$(version_from_git)
145 cd $WORKSPACE/packages/$TARGET
146 test_package_presence $prog $version go
148 if [[ "$?" != "0" ]]; then
152 go get -ldflags "-X main.version=${version}" "git.curoverse.com/arvados.git/$src_path"
155 systemd_unit="$WORKSPACE/${src_path}/${prog}.service"
156 if [[ -e "${systemd_unit}" ]]; then
158 --after-install "${WORKSPACE}/build/go-python-package-scripts/postinst"
159 --before-remove "${WORKSPACE}/build/go-python-package-scripts/prerm"
160 "${systemd_unit}=/lib/systemd/system/${prog}.service")
162 switches+=("$WORKSPACE/${license_file}=/usr/share/doc/$prog/${license_file}")
164 fpm_build "$GOPATH/bin/${basename}=/usr/bin/${prog}" "${prog}" dir "${version}" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=${description}" "${switches[@]}"
167 default_iteration() {
168 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
169 echo "$ARVADOS_BUILDING_ITERATION"
172 local package_name="$1"; shift
173 local package_version="$1"; shift
174 local package_type="$1"; shift
176 if [[ $package_version =~ ^0\.1\.([0-9]{14})(\.|$) ]] && \
177 [[ ${BASH_REMATCH[1]} -le $LICENSE_PACKAGE_TS ]]; then
180 if [[ $package_type =~ ^python ]]; then
181 # Fix --iteration for #9242.
187 _build_rails_package_scripts() {
188 local pkgname="$1"; shift
189 local destdir="$1"; shift
190 local srcdir="$RUN_BUILD_PACKAGES_PATH/rails-package-scripts"
191 for scriptname in postinst prerm postrm; do
192 cat "$srcdir/$pkgname.sh" "$srcdir/step2.sh" "$srcdir/$scriptname.sh" \
193 >"$destdir/$scriptname" || return $?
197 test_rails_package_presence() {
198 local pkgname="$1"; shift
199 local srcdir="$1"; shift
201 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
209 local version="$(version_from_git)"
213 test_package_presence $pkgname $version rails "$RAILS_PACKAGE_ITERATION"
216 test_package_presence() {
217 local pkgname="$1"; shift
218 local version="$1"; shift
219 local pkgtype="$1"; shift
220 local iteration="$1"; shift
221 local arch="$1"; shift
223 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
227 if [[ "$iteration" == "" ]]; then
228 iteration="$(default_iteration "$pkgname" "$version" "$pkgtype")"
231 if [[ "$arch" == "" ]]; then
232 rpm_architecture="x86_64"
233 deb_architecture="amd64"
235 if [[ "$pkgtype" =~ ^(src)$ ]]; then
236 rpm_architecture="noarch"
237 deb_architecture="all"
240 # These python packages have binary components
241 if [[ "$pkgname" =~ (ruamel|ciso|pycrypto|pyyaml) ]]; then
242 rpm_architecture="x86_64"
243 deb_architecture="amd64"
246 rpm_architecture=$arch
247 deb_architecture=$arch
250 if [[ "$FORMAT" == "deb" ]]; then
251 local complete_pkgname="${pkgname}_$version${iteration:+-$iteration}_$deb_architecture.deb"
253 # rpm packages get iteration 1 if we don't supply one
254 iteration=${iteration:-1}
255 local complete_pkgname="$pkgname-$version-${iteration}.$rpm_architecture.rpm"
258 # See if we can skip building the package, only if it already exists in the
259 # processed/ directory. If so, move it back to the packages directory to make
260 # sure it gets picked up by the test and/or upload steps.
261 # Get the list of packages from the repos
263 if [[ "$FORMAT" == "deb" ]]; then
268 dd[ubuntu1404]=trusty
269 dd[ubuntu1604]=xenial
270 dd[ubuntu1804]=bionic
272 if [ ${pkgname:0:3} = "lib" ]; then
273 repo_subdir=${pkgname:0:4}
275 repo_subdir=${pkgname:0:1}
278 repo_pkg_list=$(curl -s -o - http://apt.arvados.org/pool/${D}/main/${repo_subdir}/)
279 echo ${repo_pkg_list} |grep -q ${complete_pkgname}
280 if [ $? -eq 0 ] ; then
281 echo "Package $complete_pkgname exists, not rebuilding!"
282 curl -s -o ./${complete_pkgname} http://apt.arvados.org/pool/${D}/main/${repo_subdir}/${complete_pkgname}
284 elif test -f "$WORKSPACE/packages/$TARGET/processed/${complete_pkgname}" ; then
285 echo "Package $complete_pkgname exists, not rebuilding!"
288 echo "Package $complete_pkgname not found, building"
292 centos_repo="http://rpm.arvados.org/CentOS/7/dev/x86_64/"
294 repo_pkg_list=$(curl -s -o - ${centos_repo})
295 echo ${repo_pkg_list} |grep -q ${complete_pkgname}
296 if [ $? -eq 0 ]; then
297 echo "Package $complete_pkgname exists, not rebuilding!"
298 curl -s -o ./${complete_pkgname} ${centos_repo}${complete_pkgname}
300 elif test -f "$WORKSPACE/packages/$TARGET/processed/${complete_pkgname}" ; then
301 echo "Package $complete_pkgname exists, not rebuilding!"
304 echo "Package $complete_pkgname not found, building"
310 handle_rails_package() {
311 local pkgname="$1"; shift
313 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
316 local srcdir="$1"; shift
318 local license_path="$1"; shift
319 local version="$(version_from_git)"
320 echo "$version" >package-build.version
321 local scripts_dir="$(mktemp --tmpdir -d "$pkgname-XXXXXXXX.scripts")" && \
324 _build_rails_package_scripts "$pkgname" "$scripts_dir"
327 git rev-parse HEAD >git-commit.version
330 if [[ 0 != "$?" ]] || ! cd "$WORKSPACE/packages/$TARGET"; then
331 echo "ERROR: $pkgname package prep failed" >&2
332 rm -rf "$scripts_dir"
336 local railsdir="/var/www/${pkgname%-server}/current"
337 local -a pos_args=("$srcdir/=$railsdir" "$pkgname" dir "$version")
338 local license_arg="$license_path=$railsdir/$(basename "$license_path")"
339 local -a switches=(--after-install "$scripts_dir/postinst"
340 --before-remove "$scripts_dir/prerm"
341 --after-remove "$scripts_dir/postrm")
342 if [[ -z "$ARVADOS_BUILDING_VERSION" ]]; then
343 switches+=(--iteration $RAILS_PACKAGE_ITERATION)
345 # For some reason fpm excludes need to not start with /.
346 local exclude_root="${railsdir#/}"
347 # .git and packages are for the SSO server, which is built from its
349 local -a exclude_list=(.git packages tmp log coverage Capfile\* \
350 config/deploy\* config/application.yml)
351 # for arvados-workbench, we need to have the (dummy) config/database.yml in the package
352 if [[ "$pkgname" != "arvados-workbench" ]]; then
353 exclude_list+=('config/database.yml')
355 # for arvados-api-server, we need to dereference the
356 # config/config.default.yml file. There is no fpm way to do that, sadly
357 # (excluding the existing symlink and then adding the file from its source
358 # path doesn't work, sadly.
359 if [[ "$pkgname" == "arvados-api-server" ]]; then
360 mv /arvados/services/api/config/config.default.yml /arvados/services/api/config/config.default.yml.bu
361 cp -p /arvados/lib/config/config.default.yml /arvados/services/api/config/
362 exclude_list+=('config/config.default.yml.bu')
364 for exclude in ${exclude_list[@]}; do
365 switches+=(-x "$exclude_root/$exclude")
367 fpm_build "${pos_args[@]}" "${switches[@]}" \
368 -x "$exclude_root/vendor/cache-*" \
369 -x "$exclude_root/vendor/bundle" "$@" "$license_arg"
370 rm -rf "$scripts_dir"
371 # Undo the deferencing we did above
372 if [[ "$pkgname" == "arvados-api-server" ]]; then
373 rm -f /arvados/services/api/config/config.default.yml
374 mv /arvados/services/api/config/config.default.yml.bu /arvados/services/api/config/config.default.yml
378 # Build python packages with a virtualenv built-in
379 fpm_build_virtualenv () {
384 PACKAGE_TYPE=${1:-python}
388 STDOUT_IF_DEBUG=/dev/null
389 STDERR_IF_DEBUG=/dev/null
390 DASHQ_UNLESS_DEBUG=-q
391 if [[ "$DEBUG" != "0" ]]; then
392 STDOUT_IF_DEBUG=/dev/stdout
393 STDERR_IF_DEBUG=/dev/stderr
396 if [[ "$ARVADOS_BUILDING_ITERATION" == "" ]]; then
397 ARVADOS_BUILDING_ITERATION=1
401 case "$PACKAGE_TYPE" in
404 if [[ "$FORMAT" != "rpm" ]]; then
407 # In CentOS, we use a different mechanism to get the right version of pip
410 PACKAGE_PREFIX=$PYTHON3_PKG_PREFIX
413 # All Arvados Python2 packages depend on Python 2.7.
414 # Make sure we build with that for consistency.
417 PACKAGE_PREFIX=$PYTHON2_PKG_PREFIX
421 if [[ "$PKG" != "libpam-arvados" ]] &&
422 [[ "$PKG" != "arvados-node-manager" ]] &&
423 [[ "$PKG" != "arvados-docker-cleaner" ]]; then
424 PYTHON_PKG=$PACKAGE_PREFIX-$PKG
426 # Exception to our package naming convention
430 # arvados-python-client sdist should always be built, to be available
431 # for other dependant packages.
432 if [[ -n "$ONLY_BUILD" ]] && [[ "arvados-python-client" != "$PKG" ]] && [[ "$PYTHON_PKG" != "$ONLY_BUILD" ]] && [[ "$PKG" != "$ONLY_BUILD" ]]; then
436 cd $WORKSPACE/$PKG_DIR
440 # Get the latest setuptools
441 if ! $pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U setuptools; then
442 echo "Error, unable to upgrade setuptools with"
443 echo " $pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U setuptools"
446 # filter a useless warning (when building the cwltest package) from the stderr output
447 if ! $python setup.py $DASHQ_UNLESS_DEBUG sdist 2> >(grep -v 'warning: no previously-included files matching'); then
448 echo "Error, unable to run $python setup.py sdist for $PKG"
452 PACKAGE_PATH=`(cd dist; ls *tar.gz)`
454 if [[ "arvados-python-client" == "$PKG" ]]; then
455 PYSDK_PATH=`pwd`/dist/
458 if [[ -n "$ONLY_BUILD" ]] && [[ "$PYTHON_PKG" != "$ONLY_BUILD" ]] && [[ "$PKG" != "$ONLY_BUILD" ]]; then
462 # Determine the package version from the generated sdist archive
463 PYTHON_VERSION=${ARVADOS_BUILDING_VERSION:-$(awk '($1 == "Version:"){print $2}' *.egg-info/PKG-INFO)}
465 # See if we actually need to build this package; does it exist already?
466 # We can't do this earlier than here, because we need PYTHON_VERSION...
467 # This isn't so bad; the sdist call above is pretty quick compared to
468 # the invocation of virtualenv and fpm, below.
469 if ! test_package_presence "$PYTHON_PKG" $PYTHON_VERSION $PACKAGE_TYPE $ARVADOS_BUILDING_ITERATION; then
473 echo "Building $FORMAT package for $PKG from $PKG_DIR"
475 # Package the sdist in a virtualenv
476 echo "Creating virtualenv..."
481 rm -f $PYTHON_PKG*deb
482 echo "virtualenv version: `virtualenv --version`"
483 virtualenv_command="virtualenv --python `which $python` $DASHQ_UNLESS_DEBUG build/usr/share/$python/dist/$PYTHON_PKG"
485 if ! $virtualenv_command; then
486 echo "Error, unable to run"
487 echo " $virtualenv_command"
491 if ! build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U pip; then
492 echo "Error, unable to upgrade pip with"
493 echo " build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U pip"
496 echo "pip version: `build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip --version`"
498 if ! build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U setuptools; then
499 echo "Error, unable to upgrade setuptools with"
500 echo " build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U setuptools"
503 echo "setuptools version: `build/usr/share/$python/dist/$PYTHON_PKG/bin/$python -c 'import setuptools; print(setuptools.__version__)'`"
505 if ! build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U wheel; then
506 echo "Error, unable to upgrade wheel with"
507 echo " build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U wheel"
510 echo "wheel version: `build/usr/share/$python/dist/$PYTHON_PKG/bin/wheel version`"
512 if [[ "$TARGET" != "centos7" ]] || [[ "$PYTHON_PKG" != "python-arvados-fuse" ]]; then
513 build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -f $PYSDK_PATH $PACKAGE_PATH
515 # centos7 needs these special tweaks to install python-arvados-fuse
516 build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG docutils
517 PYCURL_SSL_LIBRARY=nss build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -f $PYSDK_PATH $PACKAGE_PATH
520 if [[ "$?" != "0" ]]; then
521 echo "Error, unable to run"
522 echo " build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -f $PYSDK_PATH $PACKAGE_PATH"
526 cd build/usr/share/$python/dist/$PYTHON_PKG/
528 # Replace the shebang lines in all python scripts, and handle the activate
529 # scripts too This is a functional replacement of the 237 line
530 # virtualenv_tools.py script that doesn't work in python3 without serious
531 # patching, minus the parts we don't need (modifying pyc files, etc).
532 for binfile in `ls bin/`; do
533 if ! file --mime bin/$binfile |grep -q binary; then
535 if [[ "$binfile" =~ ^activate(.csh|.fish|)$ ]]; then
536 # these 'activate' scripts need special treatment
537 sed -i "s/VIRTUAL_ENV=\".*\"/VIRTUAL_ENV=\"\/usr\/share\/$python\/dist\/$PYTHON_PKG\"/" bin/$binfile
538 sed -i "s/VIRTUAL_ENV \".*\"/VIRTUAL_ENV \"\/usr\/share\/$python\/dist\/$PYTHON_PKG\"/" bin/$binfile
540 if grep -q -E '^#!.*/bin/python\d?' bin/$binfile; then
541 # Replace shebang line
542 sed -i "1 s/^.*$/#!\/usr\/share\/$python\/dist\/$PYTHON_PKG\/bin\/python/" bin/$binfile
548 cd - >$STDOUT_IF_DEBUG
550 find build -iname '*.pyc' -exec rm {} \;
551 find build -iname '*.pyo' -exec rm {} \;
553 # Finally, generate the package
554 echo "Creating package..."
556 declare -a COMMAND_ARR=("fpm" "-s" "dir" "-t" "$FORMAT")
558 if [[ "$MAINTAINER" != "" ]]; then
559 COMMAND_ARR+=('--maintainer' "$MAINTAINER")
562 if [[ "$VENDOR" != "" ]]; then
563 COMMAND_ARR+=('--vendor' "$VENDOR")
566 COMMAND_ARR+=('--url' 'https://arvados.org')
569 DESCRIPTION=`grep '\sdescription' $WORKSPACE/$PKG_DIR/setup.py|cut -f2 -d=|sed -e "s/[',\\"]//g"`
570 COMMAND_ARR+=('--description' "$DESCRIPTION")
573 LICENSE_STRING=`grep license $WORKSPACE/$PKG_DIR/setup.py|cut -f2 -d=|sed -e "s/[',\\"]//g"`
574 COMMAND_ARR+=('--license' "$LICENSE_STRING")
576 # 12271 - As FPM-generated packages don't include scripts by default, the
577 # packages cleanup on upgrade depends on files being listed on the %files
578 # section in the generated SPEC files. To remove DIRECTORIES, they need to
579 # be listed in that sectiontoo, so we need to add this parameter to properly
580 # remove lingering dirs. But this only works for python2: if used on
581 # python33, it includes dirs like /opt/rh/python33 that belong to
583 if [[ "$FORMAT" == "rpm" ]] && [[ "$python" == "python2.7" ]]; then
584 COMMAND_ARR+=('--rpm-auto-add-directories')
587 if [[ "$PKG" == "arvados-python-client" ]]; then
588 if [[ "$python" == "python2.7" ]]; then
589 COMMAND_ARR+=('--conflicts' "$PYTHON3_PKG_PREFIX-$PKG")
591 COMMAND_ARR+=('--conflicts' "$PYTHON2_PKG_PREFIX-$PKG")
595 if [[ "$DEBUG" != "0" ]]; then
596 COMMAND_ARR+=('--verbose' '--log' 'info')
599 COMMAND_ARR+=('-v' "$PYTHON_VERSION")
600 COMMAND_ARR+=('--iteration' "$ARVADOS_BUILDING_ITERATION")
601 COMMAND_ARR+=('-n' "$PYTHON_PKG")
602 COMMAND_ARR+=('-C' "build")
604 if [[ -e "$WORKSPACE/$PKG_DIR/$PKG.service" ]]; then
605 COMMAND_ARR+=('--after-install' "${WORKSPACE}/build/go-python-package-scripts/postinst")
606 COMMAND_ARR+=('--before-remove' "${WORKSPACE}/build/go-python-package-scripts/prerm")
609 if [[ "$python" == "python2.7" ]]; then
610 COMMAND_ARR+=('--depends' "$PYTHON2_PACKAGE")
612 COMMAND_ARR+=('--depends' "$PYTHON3_PACKAGE")
616 COMMAND_ARR+=('--deb-no-default-config-files')
618 # Append --depends X and other arguments specified by fpm-info.sh in
619 # the package source dir. These are added last so they can override
620 # the arguments added by this script.
621 declare -a fpm_args=()
622 declare -a fpm_depends=()
624 fpminfo="$WORKSPACE/$PKG_DIR/fpm-info.sh"
625 if [[ -e "$fpminfo" ]]; then
626 echo "Loading fpm overrides from $fpminfo"
627 if ! source "$fpminfo"; then
628 echo "Error, unable to source $WORKSPACE/$PKG_DIR/fpm-info.sh for $PKG"
633 for i in "${fpm_depends[@]}"; do
634 COMMAND_ARR+=('--depends' "$i")
637 COMMAND_ARR+=("${fpm_args[@]}")
639 # Make sure to install all our package binaries in /usr/bin.
640 # We have to walk $WORKSPACE/$PKG_DIR/bin rather than
641 # $WORKSPACE/build/usr/share/$python/dist/$PYTHON_PKG/bin/ to get the list
642 # because the latter also includes all the python binaries for the virtualenv.
643 # We have to take the copies of our binaries from the latter directory, though,
644 # because those are the ones we rewrote the shebang line of, above.
645 if [[ -e "$WORKSPACE/$PKG_DIR/bin" ]]; then
646 for binary in `ls $WORKSPACE/$PKG_DIR/bin`; do
647 COMMAND_ARR+=("usr/share/$python/dist/$PYTHON_PKG/bin/$binary=/usr/bin/")
651 # the libpam module should place a few files in the correct place for the pam
653 if [[ -e "$WORKSPACE/$PKG_DIR/dist/build/usr/share/$python/dist/$PYTHON_PKG/lib/security/libpam_arvados.py" ]]; then
654 COMMAND_ARR+=("usr/share/$python/dist/$PYTHON_PKG/lib/security/libpam_arvados.py=/usr/lib/security/")
656 if [[ -e "$WORKSPACE/$PKG_DIR/dist/build/usr/share/$python/dist/$PYTHON_PKG/share/pam-configs/arvados" ]]; then
657 COMMAND_ARR+=("usr/share/$python/dist/$PYTHON_PKG/share/pam-configs/arvados=/usr/share/pam-configs/")
660 # the python-arvados-cwl-runner package comes with cwltool, expose that version
661 if [[ -e "$WORKSPACE/$PKG_DIR/dist/build/usr/share/python2.7/dist/python-arvados-cwl-runner/bin/cwltool" ]]; then
662 COMMAND_ARR+=("usr/share/python2.7/dist/python-arvados-cwl-runner/bin/cwltool=/usr/bin/")
667 FPM_RESULTS=$("${COMMAND_ARR[@]}")
670 # if something went wrong and debug is off, print out the fpm command that errored
671 if ! fpm_verify $FPM_EXIT_CODE $FPM_RESULTS && [[ "$STDOUT_IF_DEBUG" == "/dev/null" ]]; then
672 echo "fpm returned an error executing the command:"
674 echo -e "\n${COMMAND_ARR[@]}\n"
677 mv $WORKSPACE/$PKG_DIR/dist/*$FORMAT $WORKSPACE/packages/$TARGET/
682 # Build packages for everything
684 # The package source. Depending on the source type, this can be a
685 # path, or the name of the package in an upstream repository (e.g.,
689 # The name of the package to build.
692 # The type of source package. Passed to fpm -s. Default "dir".
693 PACKAGE_TYPE=${1:-dir}
695 # Optional: the package version number. Passed to fpm -v.
699 if [[ -n "$ONLY_BUILD" ]] && [[ "$PACKAGE_NAME" != "$ONLY_BUILD" ]] && [[ "$PACKAGE" != "$ONLY_BUILD" ]] ; then
703 local default_iteration_value="$(default_iteration "$PACKAGE" "$VERSION" "$PACKAGE_TYPE")"
705 declare -a COMMAND_ARR=("fpm" "-s" "$PACKAGE_TYPE" "-t" "$FORMAT")
706 if [ python = "$PACKAGE_TYPE" ] && [ deb = "$FORMAT" ]; then
707 # Dependencies are built from setup.py. Since setup.py will never
708 # refer to Debian package iterations, it doesn't make sense to
709 # enforce those in the .deb dependencies.
710 COMMAND_ARR+=(--deb-ignore-iteration-in-dependencies)
713 # 12271 - As FPM-generated packages don't include scripts by default, the
714 # packages cleanup on upgrade depends on files being listed on the %files
715 # section in the generated SPEC files. To remove DIRECTORIES, they need to
716 # be listed in that section too, so we need to add this parameter to properly
717 # remove lingering dirs. But this only works for python2: if used on
718 # python33, it includes dirs like /opt/rh/python33 that belong to
720 if [[ "$FORMAT" = rpm ]] && [[ "$python" = python2.7 ]]; then
721 COMMAND_ARR+=('--rpm-auto-add-directories')
724 if [[ "$DEBUG" != "0" ]]; then
725 COMMAND_ARR+=('--verbose' '--log' 'info')
728 if [[ -n "$PACKAGE_NAME" ]]; then
729 COMMAND_ARR+=('-n' "$PACKAGE_NAME")
732 if [[ "$MAINTAINER" != "" ]]; then
733 COMMAND_ARR+=('--maintainer' "$MAINTAINER")
736 if [[ "$VENDOR" != "" ]]; then
737 COMMAND_ARR+=('--vendor' "$VENDOR")
740 if [[ "$VERSION" != "" ]]; then
741 COMMAND_ARR+=('-v' "$VERSION")
743 if [[ -n "$default_iteration_value" ]]; then
744 # We can always add an --iteration here. If another one is specified in $@,
745 # that will take precedence, as desired.
746 COMMAND_ARR+=(--iteration "$default_iteration_value")
749 # Append --depends X and other arguments specified by fpm-info.sh in
750 # the package source dir. These are added last so they can override
751 # the arguments added by this script.
752 declare -a fpm_args=()
753 declare -a build_depends=()
754 declare -a fpm_depends=()
755 declare -a fpm_exclude=()
756 declare -a fpm_dirs=(
757 # source dir part of 'dir' package ("/source=/dest" => "/source"):
759 for pkgdir in "${fpm_dirs[@]}"; do
760 fpminfo="$pkgdir/fpm-info.sh"
761 if [[ -e "$fpminfo" ]]; then
762 debug_echo "Loading fpm overrides from $fpminfo"
767 for pkg in "${build_depends[@]}"; do
768 if [[ $TARGET =~ debian|ubuntu ]]; then
769 pkg_deb=$(ls "$WORKSPACE/packages/$TARGET/$pkg_"*.deb | sort -rg | awk 'NR==1')
770 if [[ -e $pkg_deb ]]; then
771 echo "Installing build_dep $pkg from $pkg_deb"
774 echo "Attemping to install build_dep $pkg using apt-get"
775 apt-get install -y "$pkg"
777 apt-get -y -f install
779 pkg_rpm=$(ls "$WORKSPACE/packages/$TARGET/$pkg"-[0-9]*.rpm | sort -rg | awk 'NR==1')
780 if [[ -e $pkg_rpm ]]; then
781 echo "Installing build_dep $pkg from $pkg_rpm"
784 echo "Attemping to install build_dep $pkg"
789 for i in "${fpm_depends[@]}"; do
790 COMMAND_ARR+=('--depends' "$i")
792 for i in "${fpm_exclude[@]}"; do
793 COMMAND_ARR+=('--exclude' "$i")
796 # Append remaining function arguments directly to fpm's command line.
801 COMMAND_ARR+=("${fpm_args[@]}")
803 COMMAND_ARR+=("$PACKAGE")
805 debug_echo -e "\n${COMMAND_ARR[@]}\n"
807 FPM_RESULTS=$("${COMMAND_ARR[@]}")
810 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
812 # if something went wrong and debug is off, print out the fpm command that errored
813 if [[ 0 -ne $? ]] && [[ "$STDOUT_IF_DEBUG" == "/dev/null" ]]; then
814 echo -e "\n${COMMAND_ARR[@]}\n"
818 # verify build results
825 if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\.-]*\.)(deb|rpm) ]]; then
826 FPM_PACKAGE_NAME=${BASH_REMATCH[1]}${BASH_REMATCH[2]}
829 if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
832 echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
837 elif [[ "$FPM_RESULTS" =~ "File already exists" ]]; then
838 echo "Package $FPM_PACKAGE_NAME exists, not rebuilding"
840 elif [[ 0 -ne "$FPM_EXIT_CODE" ]]; then
842 echo "Error building package for $1:\n $FPM_RESULTS"
849 if [[ "$FORMAT" == "deb" ]]; then
850 $SUDO apt-get install $PACKAGES --yes
851 elif [[ "$FORMAT" == "rpm" ]]; then
852 $SUDO yum -q -y install $PACKAGES
857 printf '%s %s\n' "=======" "$1"
861 if [[ "$1" != "0" ]]; then
863 failures+=("$2 (`timer`)")
865 successes+=("$2 (`timer`)")
874 echo -n "$(($SECONDS - $t0))s"
878 for x in "${successes[@]}"
883 if [[ ${#failures[@]} == 0 ]]
885 if [[ ${#successes[@]} != 0 ]]; then
886 echo "All test suites passed."
889 echo "Failures (${#failures[@]}):"
890 for x in "${failures[@]}"