-if [[ "$DEBUG" != 0 ]]; then
- echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
- echo "Workspace is $WORKSPACE"
-fi
-
-version_from_git() {
- # Generates a version number from the git log for the current working
- # directory, and writes it to stdout.
- local git_ts git_hash
- declare $(TZ=UTC git log -n1 --first-parent \
- --format=format:"git_ts=%ct git_hash=%h" .)
- echo "0.1.$(date -ud "@$git_ts" +%Y%m%d%H%M%S).$git_hash"
-}
-
-timestamp_from_git() {
- # Generates a version number from the git log for the current working
- # directory, and writes it to stdout.
- local git_ts git_hash
- declare $(TZ=UTC git log -n1 --first-parent \
- --format=format:"git_ts=%ct git_hash=%h" .)
- echo "$git_ts"
-}
-
-handle_python_package () {
- # This function assumes the current working directory is the python package directory
- if [[ "$UPLOAD" != 0 ]]; then
- # Make sure only to use sdist - that's the only format pip can deal with (sigh)
- if [[ "$DEBUG" != 0 ]]; then
- python setup.py sdist upload
- else
- python setup.py -q sdist upload
- fi
- else
- # Make sure only to use sdist - that's the only format pip can deal with (sigh)
- if [[ "$DEBUG" != 0 ]]; then
- python setup.py sdist
- else
- python setup.py -q sdist
- fi
- fi
-}
-
-# Build packages for everything
-fpm_build_and_scp () {
- # The package source. Depending on the source type, this can be a
- # path, or the name of the package in an upstream repository (e.g.,
- # pip).
- PACKAGE=$1
- shift
- # The name of the package to build. Defaults to $PACKAGE.
- PACKAGE_NAME=${1:-$PACKAGE}
- shift
- # Optional: the vendor of the package. Should be "Curoverse, Inc." for
- # packages of our own software. Passed to fpm --vendor.
- VENDOR=$1
- shift
- # The type of source package. Passed to fpm -s. Default "python".
- PACKAGE_TYPE=${1:-python}
- shift
- # Optional: the package version number. Passed to fpm -v.
- VERSION=$1
- shift
-
- case "$PACKAGE_TYPE" in
- python)
- # All Arvados Python2 packages depend on Python 2.7.
- # Make sure we build with that for consistency.
- set -- "$@" --python-bin python2.7 \
- --python-easyinstall "$EASY_INSTALL2" \
- --python-package-name-prefix "$PYTHON2_PKG_PREFIX" \
- --depends "$PYTHON2_PACKAGE"
- ;;
- python3)
- # fpm does not actually support a python3 package type. Instead
- # we recognize it as a convenience shortcut to add several
- # necessary arguments to fpm's command line later, after we're
- # done handling positional arguments.
- PACKAGE_TYPE=python
- set -- "$@" --python-bin python3 \
- --python-easyinstall "$EASY_INSTALL3" \
- --python-package-name-prefix "$PYTHON3_PKG_PREFIX" \
- --depends "$PYTHON3_PACKAGE"
- ;;
- esac
-
- declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "-s" "$PACKAGE_TYPE" "-t" "$FORMAT")
- if [ python = "$PACKAGE_TYPE" ]; then
- COMMAND_ARR+=(--exclude=\*/{dist,site}-packages/tests/\*)
- fi
-
- if [[ "$PACKAGE_NAME" != "$PACKAGE" ]]; then
- COMMAND_ARR+=('-n' "$PACKAGE_NAME")
- fi
-
- if [[ "$VENDOR" != "" ]]; then
- COMMAND_ARR+=('--vendor' "$VENDOR")
- fi
-
- if [[ "$VERSION" != "" ]]; then
- COMMAND_ARR+=('-v' "$VERSION")
- fi
-
- # Append remaining function arguments directly to fpm's command line.
- for i; do
- COMMAND_ARR+=("$i")
- done
-
- COMMAND_ARR+=("$PACKAGE")
-
- if [[ "$DEBUG" != 0 ]]; then
- echo
- echo "${COMMAND_ARR[@]}"
- echo
- fi
-
- FPM_RESULTS=$("${COMMAND_ARR[@]}")
- FPM_EXIT_CODE=$?
-
- fpm_verify_and_scp $FPM_EXIT_CODE $FPM_RESULTS
-}
-
-# verify build results and scp packages, if needed
-fpm_verify_and_scp () {
- FPM_EXIT_CODE=$1
- shift
- FPM_RESULTS=$@
-
- FPM_PACKAGE_NAME=''
- if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\.-]*\.)(deb|rpm) ]]; then
- FPM_PACKAGE_NAME=${BASH_REMATCH[1]}${BASH_REMATCH[2]}
- fi
-
- if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
- EXITCODE=1
- echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
- echo
- echo $FPM_RESULTS
- echo
- else
- if [[ ! $FPM_RESULTS =~ "File already exists" ]]; then
- if [[ "$FPM_EXIT_CODE" != "0" ]]; then
- echo "Error building package for $1:\n $FPM_RESULTS"
- else
- if [[ "$UPLOAD" != 0 ]]; then
- scp -P2222 $FPM_PACKAGE_NAME $SCPUSER@$SCPHOST:$FPM_OUTDIR/
- CALL_FREIGHT=1
- fi
- fi
- else
- echo "Package $FPM_PACKAGE_NAME exists, not rebuilding"
- fi
- fi
-}