From c48e4879986dbb99972ba1b3d355d230910e2f45 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Tue, 23 Mar 2021 19:06:02 +0000 Subject: [PATCH] Avoid unnecessary recompiles with code generators. Previously code generators would unconditionally write the generated files even if they didn't change, causing all many more files to be rebuilt than necessary. Make extract_json.py check the file content to skip writing if it can to fix this. Bug: None Change-Id: I22389444179c9b16a7ccc03ea133a973d419fad3 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/45761 Auto-Submit: Corentin Wallez Reviewed-by: Austin Eng Commit-Queue: Austin Eng --- generator/extract_json.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/generator/extract_json.py b/generator/extract_json.py index 4afefae946..67114bf4fb 100644 --- a/generator/extract_json.py +++ b/generator/extract_json.py @@ -27,9 +27,18 @@ if __name__ == "__main__": for (name, content) in files.items(): output_file = output_dir + os.path.sep + name + # Create the output directory if needed. directory = os.path.dirname(output_file) if not os.path.exists(directory): os.makedirs(directory) + # Skip writing to the file if it already has the correct content. + try: + with open(output_file, 'r') as outfile: + if outfile.read() == content: + continue + except (OSError, EnvironmentError): + pass + with open(output_file, 'w') as outfile: outfile.write(content)