blob: 57d55424516096389354dd171b412031d006416c [file] [log] [blame]
if [ -f "/etc/buck.conf" ] ; then
. /etc/buck.conf
fi
if [ -f "$HOME/.buck/buck.conf" ] ; then
. $HOME/.buck/buck.conf
fi
if [ -f "$HOME/.buckrc" ] ; then
. "$HOME/.buckrc"
fi
if [ -z "$BUCK_EXTRA_JAVA_ARGS" ] ; then
BUCK_EXTRA_JAVA_ARGS="-XX:MaxPermSize=256m -Xmx1000m"
fi
# Set TMPDIR to a reasonable default if it isn't already set, so that mktmp(1) can be
# succinctly and portably used.
if [ "x${TMPDIR}" = "x" ] ; then
TMPDIR="/tmp"
fi
# Record the directory from which this script was run in case
# we need to re-run it as part of the autoupdate.
ORIGINAL_WORKING_DIRECTORY="$PWD"
# Keep track of the project root directory.
PROJECT_ROOT="$PWD"
# Test for running buck daemon.
BUCKD_DIR="${PROJECT_ROOT}/.buckd"
BUCKD_LOG_FILE="${BUCKD_DIR}/buckd.log"
BUCKD_PID_FILE="${BUCKD_DIR}/buckd.pid"
BUCKD_PORT_FILE="${BUCKD_DIR}/buckd.port"
BUCKD_RUNNING=0
kill -0 `cat "$BUCKD_PID_FILE" 2> /dev/null` &> /dev/null || BUCKD_RUNNING=1
# Navigate to the root of the Buck project.
pushd "$BUCK_BIN_DIRECTORY" > /dev/null
pushd .. > /dev/null
BUCK_DIRECTORY="$PWD"
# If there is a .buckversion file in the project root, then make sure that Buck is at that version.
# The only way to override this is to include a .nobuckcheck file in the project root.
if [ -e "${PROJECT_ROOT}/.nobuckcheck" ]; then
echo >&2 ":::"
echo >&2 "::: '.nobuckcheck' file is present. Not updating buck"
echo >&2 ":::"
elif [ -e "${PROJECT_ROOT}/.buckversion" ]; then
BUCK_REQUIRED_VERSION=`cat ${PROJECT_ROOT}/.buckversion`
# If the hash is in not in the user's repository, do a `git fetch`.
if ! git cat-file -e "$BUCK_REQUIRED_VERSION"; then
git fetch --all
fi
BUCK_CURRENT_VERSION=`git rev-parse HEAD`
# Note that this test succeeds if you have local changes in your Buck repository that have not
# been committed.
if [ "$BUCK_REQUIRED_VERSION" != "$BUCK_CURRENT_VERSION" ]; then
echo "Buck is at ${BUCK_CURRENT_VERSION},"
echo "but should be ${BUCK_REQUIRED_VERSION}."
echo "Buck is updating itself."
echo "To disable this, add a '.nobuckcheck' file to your project root."
echo "In general, you should only disable this if you are developing Buck."
# Now that the version is guaranteed to be in the user's repository,
# checkout that hash.
git checkout $BUCK_REQUIRED_VERSION
# Now that we have updated the repository, we should rebuild Buck.
ant clean
fi
fi
# Make sure that Buck has been built.
if [ ! -e "build/buck.jar" ]; then
if [ $BUCKD_RUNNING -eq 0 ] && [ -e "$BUCKD_PID_FILE" ]; then
echo "Killing buckd before building buck"
kill `cat "$BUCKD_PID_FILE"` || true
fi
echo "No sign of buck.jar -- building Buck!"
# Note the jar file will not be used,
# but serves to represent whether everything has been built.
ant clean && ant
if [ $BUCKD_RUNNING -eq 0 ] && [ -e "${BUCK_BIN_DIRECTORY}/buckd" ]; then
echo "Restarting buckd after building buck"
"${BUCK_BIN_DIRECTORY}/buckd"
fi
# Rerun command with new version of buck.
cd "$ORIGINAL_WORKING_DIRECTORY"
"$SOURCE" "$@"
exit $?
fi
# Get current buck version.
BUCK_REPOSITORY_DIRTY=0
BUCK_CURRENT_VERSION="N/A"
BUCK_VERSION_TIMESTAMP=-1
if [ -d ".git" ]; then
# Make sure buck gets passed the right version.
BUCK_CURRENT_VERSION=`git rev-parse HEAD`
BUCK_VERSION_TIMESTAMP=`git log --pretty=format:%ct -1 HEAD`
# if the output of "git status -s" is non-empty.
if [ -n "`git status -s`" ]; then
BUCK_REPOSITORY_DIRTY=1
fi
fi
# Compute a version string that uniquely incorporates the current git revision
# and local modifications (if any) to managed files that are relevant to
# building/running the buck application.
if [ "x${BUCK_REPOSITORY_DIRTY}" = "x0" ] ; then
BUCK_VERSION_UID="${BUCK_CURRENT_VERSION}"
else
if [ -d ".git" ] ; then
# Get git tree for current revision.
git_tree_in=`git log -n1 --pretty=format:%T HEAD`
# Generate git tree as it would exist if current local changes were
# committed.
git_tree_out=$(
git_index_file=`mktemp ${TMPDIR}/buck-git-index.XXXXXX` || exit 1
export GIT_INDEX_FILE="${git_index_file}"
git read-tree ${git_tree_in} || exit 1
git update-index --add --remove `git diff --name-only HEAD` || exit 1
git write-tree || exit 1
rm -f "${git_index_file}"
)
# Compute UID based on relevant portions of the output git tree.
buck_version_uid_input=`mktemp "${TMPDIR}/buck-version-uid-input.XXXXXX"` || exit 1
git ls-tree --full-tree ${git_tree_out} > ${buck_version_uid_input} || exit 1
BUCK_VERSION_UID=`git hash-object ${buck_version_uid_input}` || exit 1
rm -f "${buck_version_uid_input}"
else
BUCK_VERSION_UID="N/A"
fi
fi
# Pop back to the original directory.
popd > /dev/null
popd > /dev/null
# Path to Python interpreter will be tried to find. If not found, Jython will be used.
PYTHON_INTERP_FALLBACK=${BUCK_DIRECTORY}/bin/jython
# Note that if $RELATIVE_PATH_TO_BUCK_PY changes, then the default value of
# com.facebook.buck.json.BuildFileToJsonParser#PATH_TO_BUCK_PY
# needs to be updated.
RELATIVE_PATH_TO_BUCK_PY=src/com/facebook/buck/parser/buck.py
PATH_TO_BUCK_PY="${BUCK_DIRECTORY}/$RELATIVE_PATH_TO_BUCK_PY"
# Run Buck "unpacked": specifying its individual classpath elements rather than from a
# single monolithic JAR file that includes all of its dependencies. This speeds up Buck development
# because `ant compile` takes much less time to rebuild Buck than `ant jar` does.
BUCK_JAVA_CLASSPATH="${BUCK_DIRECTORY}/src:\
${BUCK_DIRECTORY}/build/classes:\
${BUCK_DIRECTORY}/lib/args4j.jar:\
${BUCK_DIRECTORY}/lib/guava-15.0.jar:\
${BUCK_DIRECTORY}/lib/ini4j-0.5.2.jar:\
${BUCK_DIRECTORY}/lib/jackson-annotations-2.0.5.jar:\
${BUCK_DIRECTORY}/lib/jackson-core-2.0.5.jar:\
${BUCK_DIRECTORY}/lib/jackson-databind-2.0.5.jar:\
${BUCK_DIRECTORY}/lib/jsr305.jar:\
${BUCK_DIRECTORY}/lib/sdklib.jar:\
${BUCK_DIRECTORY}/lib/ddmlib-r21.jar:\
${BUCK_DIRECTORY}/lib/sdklib.jar:\
${BUCK_DIRECTORY}/third-party/java/asm/asm-debug-all-4.1.jar:\
${BUCK_DIRECTORY}/third-party/java/astyanax/astyanax-cassandra-1.56.38.jar:\
${BUCK_DIRECTORY}/third-party/java/astyanax/astyanax-core-1.56.38.jar:\
${BUCK_DIRECTORY}/third-party/java/astyanax/astyanax-thrift-1.56.38.jar:\
${BUCK_DIRECTORY}/third-party/java/astyanax/cassandra-1.2.3.jar:\
${BUCK_DIRECTORY}/third-party/java/astyanax/cassandra-thrift-1.2.3.jar:\
${BUCK_DIRECTORY}/third-party/java/astyanax/commons-cli-1.1.jar:\
${BUCK_DIRECTORY}/third-party/java/astyanax/commons-codec-1.2.jar:\
${BUCK_DIRECTORY}/third-party/java/astyanax/commons-lang-2.6.jar:\
${BUCK_DIRECTORY}/third-party/java/astyanax/high-scale-lib-1.1.2.jar:\
${BUCK_DIRECTORY}/third-party/java/astyanax/joda-time-2.2.jar:\
${BUCK_DIRECTORY}/third-party/java/astyanax/libthrift-0.7.0.jar:\
${BUCK_DIRECTORY}/third-party/java/astyanax/log4j-1.2.16.jar:\
${BUCK_DIRECTORY}/third-party/java/astyanax/slf4j-api-1.7.2.jar:\
${BUCK_DIRECTORY}/third-party/java/astyanax/slf4j-log4j12-1.7.2.jar:\
${BUCK_DIRECTORY}/third-party/java/jetty/jetty-all-9.0.4.v20130625.jar:\
${BUCK_DIRECTORY}/third-party/java/jetty/servlet-api.jar:\
${BUCK_DIRECTORY}/third-party/java/xz-java-1.3/xz-1.3.jar"
BUCK_JAVA_ARGS="\
-Djava.awt.headless=true \
-Dbuck.testrunner_classes=${BUCK_DIRECTORY}/build/testrunner/classes \
-Dbuck.abi_processor_classes=${BUCK_DIRECTORY}/build/abi_processor/classes \
-Dbuck.path_to_emma_jar=${BUCK_DIRECTORY}/third-party/java/emma-2.0.5312/out/emma-2.0.5312.jar \
-Dbuck.test_util_no_tests_dir=true \
-Dbuck.path_to_python_interp=${PYTHON_INTERP_FALLBACK} \
-Dbuck.path_to_buck_py=${PATH_TO_BUCK_PY} \
-Dbuck.path_to_intellij_py=${BUCK_DIRECTORY}/src/com/facebook/buck/command/intellij.py \
-Dbuck.git_commit=${BUCK_CURRENT_VERSION} \
-Dbuck.git_commit_timestamp=${BUCK_VERSION_TIMESTAMP} \
-Dbuck.git_dirty=${BUCK_REPOSITORY_DIRTY} \
-Dbuck.version_uid=${BUCK_VERSION_UID} \
-Dbuck.buckd_dir=${BUCKD_DIR} \
-Dlog4j.configuration=file:${BUCK_DIRECTORY}/config/log4j.properties \
${BUCK_EXTRA_JAVA_ARGS}"
# To debug BUCK, set BUCK_DEBUG_MODE in your environment to anything non-empty,
# then connect to port 8888.
if [ "$BUCK_DEBUG_MODE" ]; then
arg="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8888"
BUCK_JAVA_ARGS="$BUCK_JAVA_ARGS $arg"
fi