#!/bin/bash EXEC_PATH=$(dirname "${BASH_SOURCE[0]}") source "$EXEC_PATH/cbc_functions.inc" # declare $OS and $ARCH (don't touch) get_os_info LOGFILE="monolith.log" LOGFILE_PREV="$LOGFILE.prev" TMPDIR=/tmp start_pos= PYTHON_VERSION="3.4" NUMPY_VERSION="1.9" BRANCH="" BRANCH_MANIFEST="" function usage { echo "usage: $(basename $0) {manifest} [-pnco] manifest List of recipes to build (in order) --python -p Version to pass to conda-build --numpy -n Version to pass to conda-build --branch -b Build from a branch (or tag) --branch-manifest List containing git_url patterns --cbc-recipes -c Path to CBC recipes directory --cbc-output-dir -o Path to CONDA recipes " } function build_restart { if [ -f "$LOGFILE" ]; then echo "Build restarting..." cp -av "$LOGFILE" $LOGFILE.prev sync export start_pos=$(tail -n 1 "$LOGFILE_PREV" | tr -d ' ') fi } function build_prepare { echo "Translating CBC recipes..." cbc_build --no-build $(echo $CBC_RECIPES/*/*.ini) _OK=`success` if [ $_OK -ne 0 ]; then echo "Something went wrong with cbc_build..." exit 1 fi if [ -n "$BRANCH" ]; then build_prepare_branch fi } function build_prepare_branch() { echo Building from branch: $BRANCH CBC_HOME_ORIG="$CBC_HOME" mktemp_args= case "$OS" in osx) export mktemp_args="-d -u -t $(basename $0)" ;; linux) export mktemp_args="-u -d" ;; *) ;; esac export CBC_HOME="$(mktemp $mktemp_args)" mkdir -pv "$CBC_HOME" echo "CBC_HOME=$CBC_HOME" rsync -a "$CBC_HOME_ORIG/" "$CBC_HOME" _OK=`success` if [ $_OK -ne 0 ]; then echo "Failed to transfer: $CBC_HOME_ORIG -> $CBC_HOME" echo "Aborting..." exit 1 fi # Redundant code alert... ugh (WILL FIX) is_osx= if [[ $OS == "osx" ]]; then export is_osx=".orig" fi if [ -n "$BRANCH_MANIFEST" ]; then while read pattern do for f in `find $CBC_HOME -type f -name "*.yaml"` do grep "$pattern" "$f" >/dev/null _OK=`success` if [ $_OK -eq 0 ]; then echo "Applying branch: $BRANCH -> $(dirname $f)" sed -i$is_osx 's|git_tag|#git_tag|g' "$f" >/dev/null sed -i$is_osx "/git_url/ a \ \ \ \ git_tag: '$BRANCH'" "$f" >/dev/null fi done done < "$BRANCH_MANIFEST" else for f in `find $CBC_HOME -type f -name "*.yaml"` do grep "git_url" "$f" >/dev/null _OK=`success` if [ $_OK -eq 0 ]; then echo "Applying branch $BRANCH -> $(dirname $f)" sed -i$is_osx 's|git_tag|#git_tag|g' "$f" >/dev/null sed -i$is_osx "/git_url/ a \ \ \ \ git_tag: '$BRANCH'" "$f" >/dev/null fi done fi } function build_cleanup { if [ -n "$BRANCH" ]; then if [[ $CBC_RECIPES == *$TMPDIR* ]]; then echo "Removing temporary branch data..." rm -rf "$CBC_RECIPES" fi fi } function build() { CWD=`pwd` while read recipe do if [ -n "$start_pos" ]; then if [[ $recipe != $start_pos ]]; then echo "Skipping: $recipe" continue else # Iterate through remaining recipes unset start_pos fi fi cd "$CBC_HOME" conda build \ --no-binstar-upload \ --python $PYTHON_VERSION \ --numpy $NUMPY_VERSION \ --override-channels -c defaults "$recipe" _OK=`success` if [ $_OK -ne 0 ]; then echo echo "Monolithic build failure..." echo "Cause:" echo " $recipe" cd "$CWD" exit $_OK fi done < "$MANIFEST" cd "$CWD" } function bad_arg { usage echo "Bad argument: $@" exit 1 } ARGC="${#}" if [[ ${ARGC} < 1 ]]; then usage exit 1 fi MANIFEST="$1" if [ ! -f "$MANIFEST" ]; then echo "\"$MANIFEST\" does not exist." exit 1 fi # MAIN shift while [ $# -gt 0 ]; do case "$1" in '') usage exit 1 ;; --python|-p) PYTHON_VERSION="$2" if [ -z "$PYTHON_VERSION" ]; then bad_arg "Missing python version." fi export PYTHON_VERSION shift ;; --numpy|-n) NUMPY_VERSION="$2" if [ -z "$NUMPY_VERSION" ]; then bad_arg "Missing numpy version." fi export NUMPY_VERSION shift ;; --branch|-b) BRANCH="$2" if [ -z "$BRANCH" ]; then bad_arg "Missing branch name." fi export BRANCH shift ;; --branch-manifest) BRANCH_MANIFEST="$2" if [ -z "$BRANCH_MANIFEST" ]; then bad_arg "Missing branch manifest filename." fi export BRANCH_MANIFEST shift ;; --cbc-recipes|-c) CBC_RECIPES="$2" if [ -z "$CBC_RECIPES" ]; then bad_arg "Missing recipe directory." fi export CBC_RECIPES shift ;; --cbc-output-dir|-o) CBC_HOME="$2" if [ -z "$CBC_HOME" ]; then bad_arg "Missing conda recipe directory." fi export CBC_HOME shift ;; *) echo "Unknown option: $1" usage exit 1 ;; esac shift done # DO NOT LOG THIS... build_prepare build_restart # LOG THIS ( build ) 2>&1 | tee "$LOGFILE" build_cleanup