Pin gen_build_version's git handling to typical git dir.

gen_build_version.py now specifies --git-dir explicitly, to avoid
fetching the revision of a containing git directory that's not an Impala
checkout.

This came up when building Impala without a git directory, but within a
build system that happens to have a git directory higher up in the
directory tree.

I tested this by running the script manually and observing
it works identically in the normal case.

Change-Id: I98870a1cb2073ddcf9ba1620e3801e1964930edd
Reviewed-on: http://gerrit.cloudera.org:8080/8500
Reviewed-by: Joe McDonnell <joemcdonnell@cloudera.com>
Tested-by: Impala Public Jenkins
This commit is contained in:
Philip Zeyliger
2017-11-08 11:33:23 -08:00
committed by Impala Public Jenkins
parent b840137c94
commit 1128e1a44f

View File

@@ -21,11 +21,7 @@
# on the git hash.
import os
import time;
import filecmp
from subprocess import PIPE, call
from commands import getstatusoutput
from time import localtime, strftime
from subprocess import call
IMPALA_HOME = os.environ['IMPALA_HOME']
SAVE_VERSION_SCRIPT = os.path.join(IMPALA_HOME, 'bin/save-version.sh')
@@ -35,8 +31,11 @@ VERSION_CC_FILE_NAME = os.path.join(IMPALA_HOME, 'be/src/common/version.cc')
# Redirecting stdout and stderr to os.devnull as we don't want unnecessary output.
devnull = open(os.devnull, 'w')
try:
# Force git to look at a git directory relative to IMPALA_HOME,
# so as to avoid accidentally getting another repo's git hashes.
can_obtain_git_hash = \
call(['git', 'rev-parse', 'HEAD'], stdout=devnull, stderr=devnull) == 0
call(['git', '--git-dir', os.path.join(IMPALA_HOME, ".git"), 'rev-parse', 'HEAD'],
stdout=devnull, stderr=devnull) == 0
finally:
devnull.close()