[xb] Only write version.h when changed

This commit is contained in:
Joel Linn 2021-05-03 22:26:05 +02:00 committed by Rick Gibbed
parent 48bd08a11b
commit 0a662afd73

View File

@ -252,6 +252,7 @@ def shell_call(command, throw_on_error=True, stdout_path=None, stderr_path=None,
def generate_version_h():
"""Generates a build/version.h file that contains current git info.
"""
header_file = 'build/version.h'
if git_is_repository():
(branch_name, commit, commit_short) = git_get_head_info()
else:
@ -259,17 +260,25 @@ def generate_version_h():
commit = ':(-dont-do-this'
commit_short = ':('
contents = '''// Autogenerated by `xb premake`.
#ifndef GENERATED_VERSION_H_
#define GENERATED_VERSION_H_
#define XE_BUILD_BRANCH "%s"
#define XE_BUILD_COMMIT "%s"
#define XE_BUILD_COMMIT_SHORT "%s"
#define XE_BUILD_DATE __DATE__
#endif // GENERATED_VERSION_H_
''' % (branch_name, commit, commit_short)
with open('build/version.h', 'w') as f:
f.write(contents)
contents_new = '''// Autogenerated by `xb premake`.
#ifndef GENERATED_VERSION_H_
#define GENERATED_VERSION_H_
#define XE_BUILD_BRANCH "{}"
#define XE_BUILD_COMMIT "{}"
#define XE_BUILD_COMMIT_SHORT "{}"
#define XE_BUILD_DATE __DATE__
#endif // GENERATED_VERSION_H_
'''.format(branch_name, commit, commit_short)
contents_old = None
if os.path.exists(header_file) and os.path.getsize(header_file) < 1024:
with open(header_file, 'r') as f:
contents_old = f.read()
if contents_old != contents_new:
with open(header_file, 'w') as f:
f.write(contents_new)
def generate_source_class(path):
header_path = '{}.h'.format(path)