You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by to...@apache.org on 2016/01/28 03:09:38 UTC

[3/3] incubator-kudu git commit: thirdparty: allow build-if-necessary to work outside of git

thirdparty: allow build-if-necessary to work outside of git

This adds a timestamp-based approach to determining if thirdparty
has changed since the last build. This is used instead of git
if running outside of the git repo.

The purpose here is to allow this script to be used from a
source release tarball.

Change-Id: Iada72f9c93a357d37c41386afb4d0587813bf2f7
Reviewed-on: http://gerrit.cloudera.org:8080/1932
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Tested-by: Kudu Jenkins


Project: http://git-wip-us.apache.org/repos/asf/incubator-kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kudu/commit/143826e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/143826e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/143826e8

Branch: refs/heads/master
Commit: 143826e88c26ed4347177453caecdf193e6f8b7a
Parents: fefa29c
Author: Todd Lipcon <to...@apache.org>
Authored: Wed Jan 27 16:19:33 2016 -0800
Committer: Todd Lipcon <to...@apache.org>
Committed: Thu Jan 28 02:08:24 2016 +0000

----------------------------------------------------------------------
 thirdparty/build-if-necessary.sh | 70 +++++++++++++++++++++++++----------
 1 file changed, 50 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/143826e8/thirdparty/build-if-necessary.sh
----------------------------------------------------------------------
diff --git a/thirdparty/build-if-necessary.sh b/thirdparty/build-if-necessary.sh
index 8f48ea6..8239b85 100755
--- a/thirdparty/build-if-necessary.sh
+++ b/thirdparty/build-if-necessary.sh
@@ -16,10 +16,12 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
+
 # Script which downloads and builds the thirdparty dependencies
-# only if necessary (i.e if they have changed or the local repository
-# is dirty).
+# only if necessary.
+#
+# In a git repo, this uses git checksum information on the thirdparty
+# tree. Otherwise, it uses a 'stamp file' approach.
 
 set -e
 set -o pipefail
@@ -29,28 +31,56 @@ cd $TP_DIR
 
 NEEDS_BUILD=
 
-# Determine whether this subtree in the git repo has changed since thirdparty
-# was last built
-CUR_THIRDPARTY_HASH=$(cd .. && git ls-tree -d HEAD thirdparty | awk '{print $3}')
-LAST_BUILD_HASH=$(cat .build-hash || :)
-if [ "$CUR_THIRDPARTY_HASH" != "$LAST_BUILD_HASH" ]; then
-  echo "Rebuilding thirdparty: the repository has changed since thirdparty was last built."
-  echo "Old git hash: $LAST_BUILD_HASH"
-  echo "New build hash: $CUR_THIRDPARTY_HASH"
-  NEEDS_BUILD=1
+IS_IN_GIT=$(test -d ../.git && echo true || :)
+
+if [ -n "$IS_IN_GIT" ]; then
+  # Determine whether this subtree in the git repo has changed since thirdparty
+  # was last built
+
+  CUR_THIRDPARTY_HASH=$(cd .. && git ls-tree -d HEAD thirdparty | awk '{print $3}')
+  LAST_BUILD_HASH=$(cat .build-hash || :)
+  if [ "$CUR_THIRDPARTY_HASH" != "$LAST_BUILD_HASH" ]; then
+    echo "Rebuilding thirdparty: the repository has changed since thirdparty was last built."
+    echo "Old git hash: $LAST_BUILD_HASH"
+    echo "New build hash: $CUR_THIRDPARTY_HASH"
+    NEEDS_BUILD=1
+  else
+    # Determine whether the developer has any local changes
+    if ! ( git diff --quiet .  && git diff --cached --quiet . ) ; then
+      echo "Rebuilding thirdparty: There are local changes in the repository."
+      NEEDS_BUILD=1
+    else
+      echo Not rebuilding thirdparty. No changes since last build.
+    fi
+  fi
 else
-  # Determine whether the developer has any local changes
-  if ! ( git diff --quiet .  && git diff --cached --quiet . ) ; then
-    echo "Rebuilding thirdparty: There are local changes in the repository."
+  # If we aren't inside running inside a git repository (e.g. we are
+  # part of a source distribution tarball) then we can't use git to find
+  # out whether the build is clean. Instead, use a .build-stamp file, and
+  # see if any files inside this directory have been modified since then.
+  if [ -f .build-stamp ]; then
+    CHANGED_FILE_COUNT=$(find . -cnewer .build-stamp | wc -l)
+    echo "$CHANGED_FILE_COUNT file(s) been modified since thirdparty was last built."
+    if [ $CHANGED_FILE_COUNT -gt 0 ]; then
+      echo "Rebuilding."
+      echo NEEDS_BUILD=1
+    fi
+  else
+    echo "It appears that thirdparty was never built. Building."
     NEEDS_BUILD=1
   fi
 fi
 
-if [ -n "$NEEDS_BUILD" ]; then
-  rm -f .build-hash
-  ./download-thirdparty.sh
-  ./build-thirdparty.sh
+if [ -z "$NEEDS_BUILD" ]; then
+  exit 0
+fi
+
+rm -f .build-hash .build-stamp
+./download-thirdparty.sh
+./build-thirdparty.sh
+
+if [ -n "$IS_IN_GIT" ]; then
   echo $CUR_THIRDPARTY_HASH > .build-hash
 else
-  echo Not rebuilding thirdparty. No changes since last build.
+  touch .build-stamp
 fi