Chromium Code Reviews| 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..b33972849f7c3e472627bbe1965923c5f985b892 100644 |
| --- a/Source/build/scripts/in_generator.py |
| +++ b/Source/build/scripts/in_generator.py |
| @@ -55,24 +55,21 @@ 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(self, output_dir, contents, file_name): |
|
Dirk Pranke
2014/11/10 22:04:56
I'd probably rename this to _write_file_if_changed
jbroman
2014/11/11 15:30:54
Done.
|
| + 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(): |