From f3184a24c15409fe65b398be61c69422d1936f78 Mon Sep 17 00:00:00 2001 From: Yuanming Hu Date: Sun, 26 Apr 2020 00:06:32 -0400 Subject: [PATCH] [misc] Avoid unnecessary linking when git commit hash not changed (#871) * [misc] Avoid unnecessary linking when git commit hash not changed * fix ci * apply review --- misc/generate_commit_hash.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/misc/generate_commit_hash.py b/misc/generate_commit_hash.py index a560c3cc457cb..45477b72150c7 100644 --- a/misc/generate_commit_hash.py +++ b/misc/generate_commit_hash.py @@ -6,5 +6,16 @@ print(f"Building commit {commit_hash}") output_fn = os.path.join(repo_dir, 'taichi/common/commit_hash.h') +content = f"#define TI_COMMIT_HASH \"{commit_hash}\"\n" + +# First read the file to see if an update is needed +# This reduces unnecessary file changes/linkings +if os.path.exists(output_fn): + with open(output_fn, 'r') as f: + old_content = f.read() + if old_content == content: + # No update needed + exit(0) + with open(output_fn, 'w') as f: - f.write(f"#define TI_COMMIT_HASH \"{commit_hash}\"\n") + f.write(content)