Commit 7f19c2ea authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Reland "Grit: Avoid rebuilding all pak files when ID ranges do not change"

This reverts commit 9e9a0e96.

Reason for reland: Closing file before moving it to appease windows

Change-Id: Iaa9b51861232c98ef4bf7210f868dbe20544c5c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2040950
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739122}
parent efd04a6d
...@@ -69,7 +69,9 @@ from __future__ import print_function ...@@ -69,7 +69,9 @@ from __future__ import print_function
import collections import collections
import getopt import getopt
import os import os
import shutil
import sys import sys
import tempfile
from grit.tool import interface from grit.tool import interface
from grit.tool.update_resource_ids import assigner, common, parser, reader from grit.tool.update_resource_ids import assigner, common, parser, reader
...@@ -106,12 +108,20 @@ def _MultiReplace(data, repl): ...@@ -106,12 +108,20 @@ def _MultiReplace(data, repl):
return ''.join(res) return ''.join(res)
def _WriteFile(output, new_data): def _WriteFileIfChanged(output, new_data):
if output: if not output:
with open(output, 'wt') as fh:
fh.write(new_data)
else:
sys.stdout.write(new_data) sys.stdout.write(new_data)
return
# Avoid touching outputs if file contents has not changed so that ninja
# does not rebuild dependent when not necessary.
if os.path.exists(output) and _ReadData(output)[0] == new_data:
return
# Write to a temporary file to ensure atomic changes.
with tempfile.NamedTemporaryFile('wt', delete=False) as f:
f.write(new_data)
shutil.move(f.name, output)
class _Args: class _Args:
...@@ -288,8 +298,8 @@ Other options: ...@@ -288,8 +298,8 @@ Other options:
header.append('# Edit %s instead.' % rel_input_dir) header.append('# Edit %s instead.' % rel_input_dir)
header.append('#' * 80) header.append('#' * 80)
new_data = '\n'.join(header + ['']) + new_data new_data = '\n'.join(header + ['']) + new_data
_WriteFile(args.output, new_data) _WriteFileIfChanged(args.output, new_data)
if args.depfile: if args.depfile:
deps_data = '{}: {}'.format(args.output, ' '.join(sorted(seen_files))) deps_data = '{}: {}'.format(args.output, ' '.join(sorted(seen_files)))
_WriteFile(args.depfile, deps_data) _WriteFileIfChanged(args.depfile, deps_data)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment