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

Unified Diff: tools/grit/grit/tool/build.py

Issue 53028: GRIT rules improvements on windows (Closed)
Patch Set: Created 11 years, 9 months 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 | « tools/grit/grit/format/rc_header.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/grit/tool/build.py
diff --git a/tools/grit/grit/tool/build.py b/tools/grit/grit/tool/build.py
index a2683fd562c584d4814cc8643a2a7d1b6e5bed0c..5fe234868a1af14c1ceeb59c38d597f1c4d8d9f1 100644
--- a/tools/grit/grit/tool/build.py
+++ b/tools/grit/grit/tool/build.py
@@ -7,10 +7,12 @@
SCons build system.
'''
-import os
+import filecmp
import getopt
-import types
+import os
+import shutil
import sys
+import types
from grit import grd_reader
from grit import util
@@ -169,7 +171,9 @@ are exported to translation interchange files (e.g. XMB files), etc.
outdir = os.path.split(output.GetOutputFilename())[0]
if not os.path.exists(outdir):
os.makedirs(outdir)
- outfile = self.fo_create(output.GetOutputFilename(), 'wb')
+ # Write the results to a temporary file and only overwrite the original
+ # if the file changed. This avoids unnecessary rebuilds.
+ outfile = self.fo_create(output.GetOutputFilename() + '.tmp', 'wb')
if output.GetType() != 'data_package':
outfile = util.WrapOutputStream(outfile, encoding)
@@ -186,6 +190,21 @@ are exported to translation interchange files (e.g. XMB files), etc.
self.ProcessNode(self.res, output, outfile)
outfile.close()
+ # Now copy from the temp file back to the real output, but only if the
+ # real output doesn't exist or the contents of the file changed. This
+ # prevents identical headers from being written and .cc files from
+ # recompiling.
+ if not os.path.exists(output.GetOutputFilename()):
+ os.rename(output.GetOutputFilename() + '.tmp',
+ output.GetOutputFilename())
+ else:
+ files_match = filecmp.cmp(output.GetOutputFilename(),
+ output.GetOutputFilename() + '.tmp')
+ if output.GetType() != 'rc_header' or not files_match:
+ shutil.copy2(output.GetOutputFilename() + '.tmp',
+ output.GetOutputFilename())
+ os.remove(output.GetOutputFilename() + '.tmp')
+
self.VerboseOut(' done.\n')
# Print warnings if there are any duplicate shortcuts.
« no previous file with comments | « tools/grit/grit/format/rc_header.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698