You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by sa...@apache.org on 2016/09/16 06:41:41 UTC

[2/2] incubator-impala git commit: Make gen_build_version.py resilient to a failing git rev-parse

Make gen_build_version.py resilient to a failing git rev-parse

It was noticed that some build processes did not checkout Impala and
instead built it from a tarball. This would cause our gen_build_version
script to write a blank version info everytime to the version.info file.

This patch takes care of the case where if there is an already existing
version.info file and we cannot get the git rev-parse output, we use
the old file instead. Blank version info is written only when we don't
have an old version.info file and we cannot do a git rev-parse.

Change-Id: Id7af33502bbb70185dc15ffca6219436a616f25b
Reviewed-on: http://gerrit.cloudera.org:8080/4411
Reviewed-by: Sailesh Mukil <sa...@cloudera.com>
Tested-by: Sailesh Mukil <sa...@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/3904d309
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/3904d309
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/3904d309

Branch: refs/heads/master
Commit: 3904d3091dbbeb5c75c1154736955970a99350d7
Parents: a301ff4
Author: Sailesh Mukil <sa...@cloudera.com>
Authored: Tue Sep 13 21:16:19 2016 -0700
Committer: Sailesh Mukil <sa...@cloudera.com>
Committed: Fri Sep 16 06:40:27 2016 +0000

----------------------------------------------------------------------
 bin/gen_build_version.py | 43 +++++++++++++++++++++++++++++--------------
 bin/save-version.sh      | 11 +++++++----
 2 files changed, 36 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/3904d309/bin/gen_build_version.py
----------------------------------------------------------------------
diff --git a/bin/gen_build_version.py b/bin/gen_build_version.py
index e27507e..7dcce87 100755
--- a/bin/gen_build_version.py
+++ b/bin/gen_build_version.py
@@ -23,6 +23,7 @@
 import os
 import time;
 import filecmp
+from subprocess import PIPE, call
 from commands import getstatusoutput
 from time import localtime, strftime
 
@@ -31,17 +32,34 @@ SAVE_VERSION_SCRIPT = os.path.join(IMPALA_HOME, 'bin/save-version.sh')
 VERSION_FILE_NAME = os.path.join(IMPALA_HOME, 'bin/version.info')
 VERSION_CC_FILE_NAME = os.path.join(IMPALA_HOME, 'be/src/common/version.cc')
 
-# Remove existing version files only if they exist.
-# TODO: Might be useful to make a common utility function remove_if_clean.
-if os.path.isfile(VERSION_FILE_NAME):
-  print 'Removing existing file: %s' % (VERSION_FILE_NAME)
-  os.remove(VERSION_FILE_NAME)
-if os.path.isfile(VERSION_CC_FILE_NAME):
-  print 'Removing existing file: %s' % (VERSION_CC_FILE_NAME)
-  os.remove(VERSION_CC_FILE_NAME)
-
-# Generate a new version file.
-os.system(SAVE_VERSION_SCRIPT)
+# Redirecting stdout and stderr to os.devnull as we don't want unnecessary output.
+devnull = open(os.devnull, 'w')
+try:
+  can_obtain_git_hash = \
+      call(['git', 'rev-parse', 'HEAD'], stdout=devnull, stderr=devnull) == 0
+finally:
+  devnull.close()
+
+version_file_exists = os.path.isfile(VERSION_FILE_NAME)
+
+# If we have a version file and cannot obtain a git hash, skip generating a new
+# version file.
+if version_file_exists and not can_obtain_git_hash:
+  print "Cannot obtain git hash, using existing version file."
+else:
+  # Remove existing version files only if they exist.
+  # TODO: Might be useful to make a common utility function remove_if_clean.
+  if version_file_exists:
+    print 'Removing existing file: %s' % (VERSION_FILE_NAME)
+    os.remove(VERSION_FILE_NAME)
+  if os.path.isfile(VERSION_CC_FILE_NAME):
+    print 'Removing existing file: %s' % (VERSION_CC_FILE_NAME)
+    os.remove(VERSION_CC_FILE_NAME)
+
+  # SAVE_VERSION_SCRIPT will generate a dummy version.info file if we cannot obtain the
+  # git hash.
+  # Generate a new version file.
+  os.system(SAVE_VERSION_SCRIPT)
 
 # version.info file has the format:
 # VERSION: <version>
@@ -57,9 +75,6 @@ finally:
 
 print '\n'.join([version, git_hash, build_time])
 
-# construct the build time (e.g. Thu, 04 Oct 2012 11:53:17 PST)
-build_time = "%s %s" % (strftime("%a, %d %b %Y %H:%M:%S", localtime()), time.tzname[0])
-
 file_contents = """
 //
 // Licensed to the Apache Software Foundation (ASF) under one

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/3904d309/bin/save-version.sh
----------------------------------------------------------------------
diff --git a/bin/save-version.sh b/bin/save-version.sh
index 64359a0..978222e 100755
--- a/bin/save-version.sh
+++ b/bin/save-version.sh
@@ -21,12 +21,15 @@
 # Note: for internal (aka pre-release) versions, the version should have
 # "-INTERNAL" appended. Parts of the code will look for this to distinguish
 # between released and internal versions.
-VERSION=2.7.0
-GIT_HASH=$(git rev-parse HEAD)
+VERSION=2.8.0-cdh5-INTERNAL
+GIT_HASH=$(git rev-parse HEAD 2> /dev/null)
+if [ -z $GIT_HASH ]
+then
+  GIT_HASH="Could not obtain git hash"
+fi
+
 BUILD_TIME=`date`
 HEADER="# Generated version information from save-version.sh"
 echo -e \
 "${HEADER}\nVERSION: ${VERSION}\nGIT_HASH: ${GIT_HASH}\nBUILD_TIME: ${BUILD_TIME}"\
 > $IMPALA_HOME/bin/version.info
-
-cat $IMPALA_HOME/bin/version.info