blob: b74c8df5108d8338bc6740a3426a9ba8a5e90e52 [file] [log] [blame]
#!/bin/bash
# Exit on error.
set -e
# $BUCK_BIN_DIRECTORY is the directory that hosts this script. Solution taken from:
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
SOURCE="${BASH_SOURCE[0]}"
DIR="$( dirname "$SOURCE" )"
while [ -h "$SOURCE" ]
do
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
BUCK_BIN_DIRECTORY=$DIR
# Set environment and update buck if required.
# TODO(user): refactor buck_common in to functions rather than sourcing
source "${BUCK_BIN_DIRECTORY}/buck_common"
# If a buck daemon is running, use it.
BUCK_CLIENT="${BUCK_DIRECTORY}/build/ng"
if [ $BUCKD_RUNNING -eq 0 ] && [ -e "$BUCK_CLIENT" ]; then
echo "Using buckd." 1>&2
BUCKD_PORT=`cat ${BUCKD_DIR}/buckd.port`
# Tell buckd whether the client is talking to a tty.
if [ -t 1 ]; then
export BUCKD_COLOR_DEFAULT="always"
else
export BUCKD_COLOR_DEFAULT="never"
fi
# Disable exit on error as exit code 2 is used to indicate the daemon is busy.
set +e
$BUCK_CLIENT --nailgun-port $BUCKD_PORT com.facebook.buck.cli.Main "$@"
BUCKD_STATUS=$?
set -e
# If buck daemon is not busy, return exit code.
if [ $BUCKD_STATUS -ne 2 ]; then
exit $BUCKD_STATUS
fi
echo "Daemon is busy, starting new buck process." 1>&2
fi
# Daemon is not running, or is busy so start buck process.
java \
$BUCK_JAVA_ARGS \
-classpath \
$BUCK_JAVA_CLASSPATH \
com.facebook.buck.cli.Main "$@"