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 # Usage: package_go_binary services/foo arvados-foo "Compute foo to arbitrary precision"
71 local src_path="$1"; shift
72 local prog="$1"; shift
73 local description="$1"; shift
75 debug_echo "package_go_binary $src_path as $prog"
77 local basename="${src_path##*/}"
79 mkdir -p "$GOPATH/src/git.curoverse.com"
80 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
82 cd "$GOPATH/src/git.curoverse.com/arvados.git/$src_path"
83 local version=$(version_from_git)
84 local timestamp=$(timestamp_from_git)
86 # If the command imports anything from the Arvados SDK, bump the
87 # version number and build a new package whenever the SDK changes.
88 if grep -qr git.curoverse.com/arvados .; then
89 cd "$GOPATH/src/git.curoverse.com/arvados.git/sdk/go"
90 if [[ $(timestamp_from_git) -gt "$timestamp" ]]; then
91 version=$(version_from_git)
95 cd $WORKSPACE/packages/$TARGET
96 go get "git.curoverse.com/arvados.git/$src_path"
97 fpm_build "$GOPATH/bin/$basename=/usr/bin/$prog" "$prog" 'Curoverse, Inc.' dir "$version" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=$description"
100 # Build packages for everything
102 # The package source. Depending on the source type, this can be a
103 # path, or the name of the package in an upstream repository (e.g.,
107 # The name of the package to build. Defaults to $PACKAGE.
108 PACKAGE_NAME=${1:-$PACKAGE}
110 # Optional: the vendor of the package. Should be "Curoverse, Inc." for
111 # packages of our own software. Passed to fpm --vendor.
114 # The type of source package. Passed to fpm -s. Default "python".
115 PACKAGE_TYPE=${1:-python}
117 # Optional: the package version number. Passed to fpm -v.
121 case "$PACKAGE_TYPE" in
123 # All Arvados Python2 packages depend on Python 2.7.
124 # Make sure we build with that for consistency.
125 set -- "$@" --python-bin python2.7 \
126 --python-easyinstall "$EASY_INSTALL2" \
127 --python-package-name-prefix "$PYTHON2_PKG_PREFIX" \
128 --depends "$PYTHON2_PACKAGE"
131 # fpm does not actually support a python3 package type. Instead
132 # we recognize it as a convenience shortcut to add several
133 # necessary arguments to fpm's command line later, after we're
134 # done handling positional arguments.
136 set -- "$@" --python-bin python3 \
137 --python-easyinstall "$EASY_INSTALL3" \
138 --python-package-name-prefix "$PYTHON3_PKG_PREFIX" \
139 --depends "$PYTHON3_PACKAGE"
143 declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "-s" "$PACKAGE_TYPE" "-t" "$FORMAT")
144 if [ python = "$PACKAGE_TYPE" ]; then
145 COMMAND_ARR+=(--exclude=\*/{dist,site}-packages/tests/\*)
148 if [[ "$PACKAGE_NAME" != "$PACKAGE" ]]; then
149 COMMAND_ARR+=('-n' "$PACKAGE_NAME")
152 if [[ "$VENDOR" != "" ]]; then
153 COMMAND_ARR+=('--vendor' "$VENDOR")
156 if [[ "$VERSION" != "" ]]; then
157 COMMAND_ARR+=('-v' "$VERSION")
160 # Append remaining function arguments directly to fpm's command line.
165 # Append --depends X and other arguments specified by fpm-info.sh in
166 # the package source dir. These are added last so they can override
167 # the arguments added by this script.
168 declare -a fpm_args=()
169 declare -a fpm_depends=()
170 if [[ -d "$PACKAGE" ]]; then
171 FPM_INFO="$PACKAGE/fpm-info.sh"
173 FPM_INFO="${WORKSPACE}/backports/${PACKAGE_TYPE}-${PACKAGE}/fpm-info.sh"
175 if [[ -e "$FPM_INFO" ]]; then
176 debug_echo "Loading fpm overrides from $FPM_INFO"
179 for i in "${fpm_depends[@]}"; do
180 COMMAND_ARR+=('--depends' "$i")
182 COMMAND_ARR+=("${fpm_args[@]}")
184 COMMAND_ARR+=("$PACKAGE")
186 debug_echo -e "\n${COMMAND_ARR[@]}\n"
188 FPM_RESULTS=$("${COMMAND_ARR[@]}")
191 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
194 # verify build results
201 if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\.-]*\.)(deb|rpm) ]]; then
202 FPM_PACKAGE_NAME=${BASH_REMATCH[1]}${BASH_REMATCH[2]}
205 if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
207 echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
211 elif [[ "$FPM_RESULTS" =~ "File already exists" ]]; then
212 echo "Package $FPM_PACKAGE_NAME exists, not rebuilding"
213 elif [[ 0 -ne "$FPM_EXIT_CODE" ]]; then
214 echo "Error building package for $1:\n $FPM_RESULTS"
220 if [[ "$FORMAT" == "deb" ]]; then
221 $SUDO apt-get install $PACKAGES --yes
222 elif [[ "$FORMAT" == "rpm" ]]; then
223 $SUDO yum -q -y install $PACKAGES