diff --git a/conda/conda-build.sh b/conda/conda-build.sh index 2e528695f94da90d8e5c389cb6ed1f00f6aa796b..d08420da99af639324bfe3c34efeacf2b51e123e 100755 --- a/conda/conda-build.sh +++ b/conda/conda-build.sh @@ -1,27 +1,90 @@ #!/usr/bin/env bash -if [ $# = 0 ]; then - echo "Script wrapping conda-build to build Bob packages with defaults" - echo "usage: $0 <recipe-dir> [<python-version>]" - echo "example: $0 conda 3.6" - echo "example: $0 dependencies/libblitz" +# Checks whether to use "date" or "gdate" +gnudate() { + if hash gdate 2>/dev/null; then + echo gdate + else + echo date + fi +} +DATE=`gnudate` + + +# datetime prefix for logging +log_datetime() { + echo "($(${DATE} +%T.%3N))" +} + +# Functions for coloring echo commands +log_debug() { + echo -e "$(log_datetime) \033[1;32m${@}\033[0m" +} + + +log_info() { + echo -e "$(log_datetime) \033[1;34m${@}\033[0m" +} + + +log_warn() { + echo -e "$(log_datetime) \033[1;35mWarning: ${@}\033[0m" >&2 +} + + +log_error() { + echo -e "$(log_datetime) \033[1;31mError: ${@}\033[0m" >&2 +} + + +# Function for running command and echoing results +run_cmd() { + log_info "$ ${@}" + ${@} + local status=$? + if [ ${status} != 0 ]; then + log_error "Command Failed \"${@}\"" + exit ${status} + fi +} + +usage() { + + echo "Script wrapping conda-build to build Bob packages with defaults" 1>&2; + echo "" 1>&2; + echo "Usage: $0 [conda-build-options] <recipe-dir>" 1>&2; + echo "" 1>&2; + echo "Examples:" 1>&2; + echo "" 1>&2; + echo " Builds recipe from one of our build dependencies:" 1>&2; + echo "" 1>&2; + echo " $ $0 conda/libblitz" 1>&2; + echo "" 1>&2; + echo " Builds recipe from one of our packages, for Python 3.6:" 1>&2; + echo "" 1>&2; + echo " $ $0 --python=3.6 conda" 1>&2; + echo "" 1>&2; + echo " Builds recipe from one of our packages, for Python 3.6," 1>&2; + echo " merging host/build recipe sections:" 1>&2; + echo "" 1>&2; + echo " $ $0 --merge-build-host --python=3.6 conda" 1>&2; + echo "" 1>&2; exit 1 -fi + +} + +if [ $# = 0 ]; then usage; fi DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" export CONDARC=${DIR}/build-condarc -echo "Using CONDARC from \`${CONDARC}'..." +log_info "Using CONDARC from \`${CONDARC}'..." BUILD_OPTIONS="--no-anaconda-upload --skip-existing --variant-config-files ${DIR}/../gitlab/conda_build_config.yaml" -if [ $# = 2 ]; then - BUILD_OPTIONS="${BUILD_OPTIONS} --python=${2}"; -fi - # Exclusively for Bob packages, we also set the package version if [ -e ${1}/../version.txt ]; then export BOB_PACKAGE_VERSION=$(cat ${1}/../version.txt) echo "Setting package version to \`${BOB_PACKAGE_VERSION}'..." fi -conda build ${BUILD_OPTIONS} ${1} +run_cmd conda build ${BUILD_OPTIONS} ${*}