Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Unified Diff: Source/build/scripts/in_generator.py

Issue 688443007: Only write .in outputs if they have changed. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rename function (per dpranke) Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/build/scripts/in_generator.py
diff --git a/Source/build/scripts/in_generator.py b/Source/build/scripts/in_generator.py
index 9ba9eebc3f426489d017cf32ffd84e4cd0dc5a66..fcd5f0166d758df55b277ab59a1e6766ab4fe602 100644
--- a/Source/build/scripts/in_generator.py
+++ b/Source/build/scripts/in_generator.py
@@ -55,28 +55,25 @@ class Writer(object):
return string
return "#if ENABLE(%(condition)s)\n%(string)s\n#endif" % { 'condition' : condition, 'string' : string }
- def _forcibly_create_text_file_at_path_with_contents(self, file_path, contents):
- # FIXME: This method can be made less force-full anytime after 6/1/2013.
- # A gyp error was briefly checked into the tree, causing
- # a directory to have been generated in place of one of
- # our output files. Clean up after that error so that
- # all users don't need to clobber their output directories.
- shutil.rmtree(file_path, ignore_errors=True)
+ def _write_file_if_changed(self, output_dir, contents, file_name):
+ path = os.path.join(output_dir, file_name)
+
# The build system should ensure our output directory exists, but just in case.
- directory = os.path.dirname(file_path)
+ directory = os.path.dirname(path)
if not os.path.exists(directory):
os.makedirs(directory)
- with open(file_path, "w") as file_to_write:
- file_to_write.write(contents)
-
- def _write_file(self, output_dir, contents, file_name):
- path = os.path.join(output_dir, file_name)
- self._forcibly_create_text_file_at_path_with_contents(path, contents)
+ # Only write the file if the contents have changed. This allows ninja to
+ # skip rebuilding targets which depend on the output.
+ with open(path, "a+") as output_file:
+ output_file.seek(0)
+ if output_file.read() != contents:
+ output_file.truncate(0)
+ output_file.write(contents)
def write_files(self, output_dir):
for file_name, generator in self._outputs.items():
- self._write_file(output_dir, generator(), file_name)
+ self._write_file_if_changed(output_dir, generator(), file_name)
def set_gperf_path(self, gperf_path):
self.gperf_path = gperf_path
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698