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 <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2021-03-23 19:06:02 +00:00 committed by Commit Bot service account
parent 266bce86b4
commit c48e487998
1 changed files with 9 additions and 0 deletions

View File

@ -27,9 +27,18 @@ if __name__ == "__main__":
for (name, content) in files.items(): for (name, content) in files.items():
output_file = output_dir + os.path.sep + name output_file = output_dir + os.path.sep + name
# Create the output directory if needed.
directory = os.path.dirname(output_file) directory = os.path.dirname(output_file)
if not os.path.exists(directory): if not os.path.exists(directory):
os.makedirs(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: with open(output_file, 'w') as outfile:
outfile.write(content) outfile.write(content)