| # 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_COMMIT_HASH_AND_BRANCH=`cat ${PROJECT_ROOT}/.buckversion` | |
| BUCK_REQUIRED_VERSION=`echo ${BUCK_COMMIT_HASH_AND_BRANCH} | awk -F':' '{print $1}'` | |
| BUCK_REQUIRED_BRANCH=`echo ${BUCK_COMMIT_HASH_AND_BRANCH} | awk -F':' '{print $2}'` | |
| # If the hash is in not in the user's repository, do a `git fetch`. | |
| if ! git cat-file -e "$BUCK_REQUIRED_VERSION"; then | |
| if [ -e "${BUCK_REQUIRED_BRANCH}" ]; then | |
| git fetch --all | |
| else | |
| git fetch origin $BUCK_REQUIRED_BRANCH | |
| fi | |
| fi | |
| BUCK_CURRENT_VERSION=`git rev-parse HEAD` | |
| function restartBuck() | |
| { | |
| # Rerun command with new version of buck. | |
| cd "$ORIGINAL_WORKING_DIRECTORY" | |
| "$SOURCE" "$@" | |
| exit $? | |
| } | |
| # 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 | |
| # Rerun this script after checking out the new version. | |
| restartBuck $@ | |
| fi | |
| fi | |
| # Get current buck version. | |
| # Whether or not the repo is dirty (contains untracked files or modified | |
| # tracked files). | |
| BUCK_REPOSITORY_DIRTY=0 | |
| # Whether or not the repo contains changes to tracked files. | |
| BUCK_REPOSITORY_LOCAL_CHANGES=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 | |
| # If the output of "git ls-files -m" is non-empty, buck has local changes to | |
| # tracked files that can't be cleaned automatically with `git clean -fd`. | |
| if [ -n "`git ls-files -m`" ]; then | |
| BUCK_REPOSITORY_LOCAL_CHANGES=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 [ "${BUCK_REPOSITORY_DIRTY}" = "0" ] ; then | |
| BUCK_VERSION_UID="${BUCK_CURRENT_VERSION}" | |
| else | |
| if [ -d ".git" ] ; then | |
| function computeLocalHash() | |
| { | |
| # 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}" | |
| } | |
| if [ -e "${PROJECT_ROOT}/.nobuckcheck" ] || [ ! -e "${PROJECT_ROOT}/.buckversion" ]; then | |
| computeLocalHash | |
| else | |
| if [ "${BUCK_REPOSITORY_LOCAL_CHANGES}" = "1" ] ; then | |
| # If the buck repo is dirty but has local changes, warn the user, but we | |
| # can't clean the repo for them. | |
| echo ":: Your buck directory has local modifications, and therefore" | |
| echo ":: builds will not be able to use a distributed cache." | |
| echo ":: The following files must be either reverted or committed:" | |
| git ls-files -m | |
| BUCK_CLEAN_REPO_IF_DIRTY=N | |
| fi | |
| if [ -z "$BUCK_CLEAN_REPO_IF_DIRTY" ]; then | |
| echo ":: Your local buck directory is dirty, and therefore builds will" | |
| echo ":: not be able to use a distributed cache." | |
| echo ":: Do you want to clean your buck directory? [y/N]" | |
| read BUCK_CLEAN_REPO_IF_DIRTY | |
| fi | |
| if [[ "$(echo $BUCK_CLEAN_REPO_IF_DIRTY | tr '[:lower:]' '[:upper:]')" =~ ^Y.* ]]; then | |
| git clean -fd | |
| # Restart buck just in case the files we just deleted in any way | |
| # affected this file. | |
| restartBuck $@ | |
| else | |
| computeLocalHash | |
| fi | |
| fi | |
| else | |
| BUCK_VERSION_UID="N/A" | |
| 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 | |
| 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" | |
| BUCK_PATH_TO_CUSTOM_DX="" | |
| # 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-2.0.26.jar:\ | |
| ${BUCK_DIRECTORY}/lib/ddmlib-r21.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/nailgun-server-0.9.2-SNAPSHOT.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/gson/gson-2.2.4.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/neo4j/geronimo-jta_1.1_spec-1.1.1.jar:\ | |
| ${BUCK_DIRECTORY}/third-party/java/neo4j/lucene-core-3.6.2.jar:\ | |
| ${BUCK_DIRECTORY}/third-party/java/neo4j/neo4j-kernel-2.0.0-M05.jar:\ | |
| ${BUCK_DIRECTORY}/third-party/java/neo4j/neo4j-lucene-index-2.0.0-M05.jar:\ | |
| ${BUCK_DIRECTORY}/third-party/java/xz-java-1.3/xz-1.3.jar:\ | |
| " | |
| BUCK_PROJECT_JAVA_ARGS_FILE="${PROJECT_ROOT}/.buckjavaargs" | |
| if [[ -r ${BUCK_PROJECT_JAVA_ARGS_FILE} ]]; then | |
| BUCK_PROJECT_JAVA_ARGS=$(cat ${BUCK_PROJECT_JAVA_ARGS_FILE}) | |
| else | |
| BUCK_PROJECT_JAVA_ARGS= | |
| fi | |
| BUCK_JAVA_ARGS="\ | |
| -XX:MaxPermSize=256m \ | |
| -Xmx1000m \ | |
| -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.quickstart_origin_dir=${BUCK_DIRECTORY}/src/com/facebook/buck/cli/quickstart/android \ | |
| -Dbuck.version_uid=${BUCK_VERSION_UID} \ | |
| -Dbuck.dx=${BUCK_PATH_TO_CUSTOM_DX} \ | |
| -Dbuck.buckd_dir=${BUCKD_DIR} \ | |
| -Dlog4j.configuration=file:${BUCK_DIRECTORY}/config/log4j.properties \ | |
| ${BUCK_PROJECT_JAVA_ARGS} \ | |
| ${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 |