From 0a662afd73d75e68c7e908631a2dc8c6494f5a35 Mon Sep 17 00:00:00 2001 From: Joel Linn Date: Mon, 3 May 2021 22:26:05 +0200 Subject: [PATCH] [xb] Only write version.h when changed --- xenia-build | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/xenia-build b/xenia-build index 4fcf03f44..998748955 100755 --- a/xenia-build +++ b/xenia-build @@ -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)