3 # A library of functions shared by the various scripts in this directory.
6 echo "$@" >"$STDOUT_IF_DEBUG"
10 for version_suffix in "$@"; do
11 if "easy_install$version_suffix" --version >/dev/null 2>&1; then
12 echo "easy_install$version_suffix"
19 Error: easy_install$1 (from Python setuptools module) not found
25 format_last_commit_here() {
26 local format=$1; shift
27 TZ=UTC git log -n1 --first-parent "--format=format:$format" .
31 # Generates a version number from the git log for the current working
32 # directory, and writes it to stdout.
34 declare $(format_last_commit_here "git_ts=%ct git_hash=%h")
35 echo "0.1.$(date -ud "@$git_ts" +%Y%m%d%H%M%S).$git_hash"
38 nohash_version_from_git() {
39 version_from_git | cut -d. -f1-3
42 timestamp_from_git() {
43 format_last_commit_here "%ct"
46 handle_python_package () {
47 # This function assumes the current working directory is the python package directory
48 if [ -n "$(find dist -name "*-$(nohash_version_from_git).tar.gz" -print -quit)" ]; then
49 # This package doesn't need rebuilding.
52 # Make sure only to use sdist - that's the only format pip can deal with (sigh)
53 python setup.py $DASHQ_UNLESS_DEBUG sdist
57 local gem_name=$1; shift
58 local gem_version=$(nohash_version_from_git)
59 local gem_src_dir="$(pwd)"
61 if ! [[ -e "${gem_name}-${gem_version}.gem" ]]; then
62 find -maxdepth 1 -name "${gem_name}-*.gem" -delete
64 # -q appears to be broken in gem version 2.2.2
65 $GEM build "$gem_name.gemspec" $DASHQ_UNLESS_DEBUG >"$STDOUT_IF_DEBUG" 2>"$STDERR_IF_DEBUG"
69 # Build packages for everything
71 # The package source. Depending on the source type, this can be a
72 # path, or the name of the package in an upstream repository (e.g.,
76 # The name of the package to build. Defaults to $PACKAGE.
77 PACKAGE_NAME=${1:-$PACKAGE}
79 # Optional: the vendor of the package. Should be "Curoverse, Inc." for
80 # packages of our own software. Passed to fpm --vendor.
83 # The type of source package. Passed to fpm -s. Default "python".
84 PACKAGE_TYPE=${1:-python}
86 # Optional: the package version number. Passed to fpm -v.
90 case "$PACKAGE_TYPE" in
92 # All Arvados Python2 packages depend on Python 2.7.
93 # Make sure we build with that for consistency.
94 set -- "$@" --python-bin python2.7 \
95 --python-easyinstall "$EASY_INSTALL2" \
96 --python-package-name-prefix "$PYTHON2_PKG_PREFIX" \
97 --depends "$PYTHON2_PACKAGE"
100 # fpm does not actually support a python3 package type. Instead
101 # we recognize it as a convenience shortcut to add several
102 # necessary arguments to fpm's command line later, after we're
103 # done handling positional arguments.
105 set -- "$@" --python-bin python3 \
106 --python-easyinstall "$EASY_INSTALL3" \
107 --python-package-name-prefix "$PYTHON3_PKG_PREFIX" \
108 --depends "$PYTHON3_PACKAGE"
112 declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "-s" "$PACKAGE_TYPE" "-t" "$FORMAT")
113 if [ python = "$PACKAGE_TYPE" ]; then
114 COMMAND_ARR+=(--exclude=\*/{dist,site}-packages/tests/\*)
117 if [[ "$PACKAGE_NAME" != "$PACKAGE" ]]; then
118 COMMAND_ARR+=('-n' "$PACKAGE_NAME")
121 if [[ "$VENDOR" != "" ]]; then
122 COMMAND_ARR+=('--vendor' "$VENDOR")
125 if [[ "$VERSION" != "" ]]; then
126 COMMAND_ARR+=('-v' "$VERSION")
129 # Append remaining function arguments directly to fpm's command line.
134 # Append --depends X and other arguments specified by fpm-info.sh in
135 # the package source dir. These are added last so they can override
136 # the arguments added by this script.
137 declare -a fpm_args=()
138 declare -a fpm_depends=()
139 if [[ -d "$PACKAGE" ]]; then
140 FPM_INFO="$PACKAGE/fpm-info.sh"
142 FPM_INFO="${WORKSPACE}/backports/${PACKAGE_TYPE}-${PACKAGE}/fpm-info.sh"
144 if [[ -e "$FPM_INFO" ]]; then
145 debug_echo "Loading fpm overrides from $FPM_INFO"
148 for i in "${fpm_depends[@]}"; do
149 COMMAND_ARR+=('--depends' "$i")
151 COMMAND_ARR+=("${fpm_args[@]}")
153 COMMAND_ARR+=("$PACKAGE")
155 debug_echo -e "\n${COMMAND_ARR[@]}\n"
157 FPM_RESULTS=$("${COMMAND_ARR[@]}")
160 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
163 # verify build results
170 if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\.-]*\.)(deb|rpm) ]]; then
171 FPM_PACKAGE_NAME=${BASH_REMATCH[1]}${BASH_REMATCH[2]}
174 if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
176 echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
180 elif [[ "$FPM_RESULTS" =~ "File already exists" ]]; then
181 echo "Package $FPM_PACKAGE_NAME exists, not rebuilding"
182 elif [[ 0 -ne "$FPM_EXIT_CODE" ]]; then
183 echo "Error building package for $1:\n $FPM_RESULTS"