X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=bin%2Fgit_sha1_gen.py;h=c6fbf4903020b1b1f292468f313a983c356ca340;hb=5993f13b27f0e0a1ba17e8411148e30b03eb48f4;hp=7b9267b59e9d1d897cc46b9b5779ab5334bba368;hpb=7088622e5fb506b64c906b673a9af0feb9a5ba14;p=mesa.git diff --git a/bin/git_sha1_gen.py b/bin/git_sha1_gen.py old mode 100755 new mode 100644 index 7b9267b59e9..c6fbf490302 --- a/bin/git_sha1_gen.py +++ b/bin/git_sha1_gen.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - """ Generate the contents of the git_sha1.h file. The output of this script goes to stdout. @@ -28,20 +26,25 @@ def get_git_sha1(): git_sha1 = '' return git_sha1 +def write_if_different(contents): + """ + Avoid touching the output file if it doesn't need modifications + Useful to avoid triggering rebuilds when nothing has changed. + """ + if os.path.isfile(args.output): + with open(args.output, 'r') as file: + if file.read() == contents: + return + with open(args.output, 'w') as file: + file.write(contents) + parser = argparse.ArgumentParser() parser.add_argument('--output', help='File to write the #define in', - required=True) + required=True) args = parser.parse_args() git_sha1 = os.environ.get('MESA_GIT_SHA1_OVERRIDE', get_git_sha1())[:10] if git_sha1: - git_sha1_h_in_path = os.path.join(os.path.dirname(sys.argv[0]), - '..', 'src', 'git_sha1.h.in') - with open(git_sha1_h_in_path , 'r') as git_sha1_h_in: - new_sha1 = git_sha1_h_in.read().replace('@VCS_TAG@', git_sha1) - if os.path.isfile(args.output): - with open(args.output, 'r') as git_sha1_h: - if git_sha1_h.read() == new_sha1: - quit() - with open(args.output, 'w') as git_sha1_h: - git_sha1_h.write(new_sha1) + write_if_different('#define MESA_GIT_SHA1 " (git-' + git_sha1 + ')"') +else: + write_if_different('#define MESA_GIT_SHA1 ""')