Return str in describe() as said by the blurb.

This commit is contained in:
Lei Zhang 2016-03-11 15:24:41 -05:00
Родитель 9149a66ca4
Коммит 476989e7b7
1 изменённых файлов: 10 добавлений и 10 удалений

Просмотреть файл

@ -57,13 +57,18 @@ def describe(dir):
Runs 'git describe', or alternately 'git rev-parse HEAD', in dir. If
successful, returns the output; otherwise returns 'unknown hash, <date>'."""
try:
return command_output(['git', 'describe'], dir).rstrip()
# decode() is needed here for Python3 compatibility. In Python2,
# str and bytes are the same type, but not in Python3.
# Popen.communicate() returns a bytes instance, which needs to be
# decoded into text data first in Python3. And this decode() won't
# hurt Python2.
return command_output(['git', 'describe'], dir).rstrip().decode()
except:
try:
return command_output(['git', 'rev-parse', 'HEAD'], dir).rstrip()
return command_output(
['git', 'rev-parse', 'HEAD'], dir).rstrip().decode()
except:
return 'unknown hash, {}'.format(
datetime.date.today().isoformat()).encode('ascii')
return 'unknown hash, {}'.format(datetime.date.today().isoformat())
def main():
@ -72,12 +77,7 @@ def main():
sys.exit(1)
new_content = '"spirv-tools {}\\n"\n'.format(
# decode() is needed here for Python3 compatibility. In Python2,
# str and bytes are the same type, but not in Python3.
# Popen.communicate() returns a bytes instance, which needs to be
# decoded into text data first in Python3. And this decode() won't
# hurt Python2.
describe(sys.argv[1]).decode('ascii').replace('"', '\\"'))
describe(sys.argv[1]).replace('"', '\\"'))
if os.path.isfile(OUTFILE) and new_content == open(OUTFILE, 'r').read():
sys.exit(0)
open(OUTFILE, 'w').write(new_content)