From 469c870e37211533aa1c226a4065121a401ec390 Mon Sep 17 00:00:00 2001 From: Gautam Korlam Date: Mon, 10 Jul 2017 13:44:37 -0400 Subject: [PATCH] Add logic to buckw to update buck and build it if needed (#469) --- .buckversion | 2 +- buckw | 22 ++++++++++++++++++- .../okbuck/core/util/wrapper/BUCKW_TEMPLATE | 20 +++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/.buckversion b/.buckversion index 154c1b4f5..09e97f554 100644 --- a/.buckversion +++ b/.buckversion @@ -1 +1 @@ -bd7dec472d385279ea961789eaf72bc655ca9213 +f685044b764341d952491529c167403e3c3adba6 diff --git a/buckw b/buckw index d91b51fa2..11c4475ac 100755 --- a/buckw +++ b/buckw @@ -4,7 +4,7 @@ ## ## Buck wrapper script to invoke okbuck when needed, before running buck ## -## Created by OkBuck Gradle Plugin on : Wed Apr 19 21:13:00 PDT 2017 +## Created by OkBuck Gradle Plugin on : Mon Jul 10 10:22:56 PDT 2017 ## ######################################################################### @@ -162,6 +162,26 @@ setupBuckBinary ( ) { cd - fi + # Check for current buck version + BUCK_VERSION=$(cat .buckversion) + if [[ ! -z "$BUCK_VERSION" ]]; then + pushd "$BUCK_HOME" >/dev/null + CURRENT_BUCK_VERSION=$(git rev-parse HEAD) + if [[ "$BUCK_VERSION" != "$CURRENT_BUCK_VERSION" ]]; then + info "BUCK VERSION IS AT $CURRENT_BUCK_VERSION , BUT IT SHOULD BE $BUCK_VERSION. UPDATING BUCK" + git clean -fdx --quiet && git reset --hard --quiet && git fetch --all && git checkout "$BUCK_VERSION" --quiet + fi + popd >/dev/null + fi + + # Build buck if needed + if [[ ! -f "$BUCK_HOME/build/successful-build" ]]; then + echo "Buck does not appear to have been built -- building Buck!" + pushd "$BUCK_HOME" >/dev/null + mkdir -p build && ant > build/ant.log && success "BUCK BUILT SUCCESFULLY" || die "FAILED TO BUILD BUCK" + popd >/dev/null + fi + BUCK_BINARY="$BUCK_HOME/bin/buck" fi } diff --git a/buildSrc/src/main/resources/com/uber/okbuck/core/util/wrapper/BUCKW_TEMPLATE b/buildSrc/src/main/resources/com/uber/okbuck/core/util/wrapper/BUCKW_TEMPLATE index 7e35b67dc..f7750e61f 100644 --- a/buildSrc/src/main/resources/com/uber/okbuck/core/util/wrapper/BUCKW_TEMPLATE +++ b/buildSrc/src/main/resources/com/uber/okbuck/core/util/wrapper/BUCKW_TEMPLATE @@ -153,6 +153,26 @@ setupBuckBinary ( ) { cd - fi + # Check for current buck version + BUCK_VERSION=$(cat .buckversion) + if [[ ! -z "$BUCK_VERSION" ]]; then + pushd "$BUCK_HOME" >/dev/null + CURRENT_BUCK_VERSION=$(git rev-parse HEAD) + if [[ "$BUCK_VERSION" != "$CURRENT_BUCK_VERSION" ]]; then + info "BUCK VERSION IS AT $CURRENT_BUCK_VERSION , BUT IT SHOULD BE $BUCK_VERSION. UPDATING BUCK" + git clean -fdx --quiet && git reset --hard --quiet && git fetch --all && git checkout "$BUCK_VERSION" --quiet + fi + popd >/dev/null + fi + + # Build buck if needed + if [[ ! -f "$BUCK_HOME/build/successful-build" ]]; then + echo "Buck does not appear to have been built -- building Buck!" + pushd "$BUCK_HOME" >/dev/null + mkdir -p build && ant > build/ant.log && success "BUCK BUILT SUCCESFULLY" || die "FAILED TO BUILD BUCK" + popd >/dev/null + fi + BUCK_BINARY="$BUCK_HOME/bin/buck" fi }