Web Inspector: CodeGeneratorInspector.py: fix output write logic to support increment...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Jul 2012 18:10:58 +0000 (18:10 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Jul 2012 18:10:58 +0000 (18:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90642

Patch by Peter Rybin <peter.rybin@gmail.com> on 2012-07-16
Reviewed by Yury Semikhatsky.

A small intermediate writer is added. It handles comparing old and new source before actual writing.

* inspector/CodeGeneratorInspector.py:
(flatten_list):
(SmartOutput):
(SmartOutput.__init__):
(SmartOutput.write):
(SmartOutput.close):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@122739 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/CodeGeneratorInspector.py

index 85bd894..b2cab8e 100644 (file)
@@ -1,3 +1,19 @@
+2012-07-16  Peter Rybin  <peter.rybin@gmail.com>
+
+        Web Inspector: CodeGeneratorInspector.py: fix output write logic to support incremental build
+        https://bugs.webkit.org/show_bug.cgi?id=90642
+
+        Reviewed by Yury Semikhatsky.
+
+        A small intermediate writer is added. It handles comparing old and new source before actual writing.
+
+        * inspector/CodeGeneratorInspector.py:
+        (flatten_list):
+        (SmartOutput):
+        (SmartOutput.__init__):
+        (SmartOutput.write):
+        (SmartOutput.close):
+
 2012-07-16  Dana Jansens  <danakj@chromium.org>
 
         [chromium] Incorrect assertion: Replicas will cause a RenderPass to be removed twice
index b3a5f41..ed1f2bf 100755 (executable)
@@ -2953,18 +2953,45 @@ def flatten_list(input):
     return res
 
 
+# A writer that only updates file if it actually changed to better support incremental build.
+class SmartOutput:
+    def __init__(self, file_name):
+        self.file_name_ = file_name
+        self.output_ = ""
+
+    def write(self, text):
+        self.output_ += text
+
+    def close(self):
+        text_changed = True
+
+        try:
+            read_file = open(self.file_name_, "r")
+            old_text = read_file.read()
+            read_file.close()
+            text_changed = old_text != self.output_
+        except:
+            # Ignore, just overwrite by default
+            pass
+
+        if text_changed:
+            out_file = open(self.file_name_, "w")
+            out_file.write(self.output_)
+            out_file.close()
+
+
 Generator.go()
 
-backend_h_file = open(output_header_dirname + "/InspectorBackendDispatcher.h", "w")
-backend_cpp_file = open(output_cpp_dirname + "/InspectorBackendDispatcher.cpp", "w")
+backend_h_file = SmartOutput(output_header_dirname + "/InspectorBackendDispatcher.h")
+backend_cpp_file = SmartOutput(output_cpp_dirname + "/InspectorBackendDispatcher.cpp")
 
-frontend_h_file = open(output_header_dirname + "/InspectorFrontend.h", "w")
-frontend_cpp_file = open(output_cpp_dirname + "/InspectorFrontend.cpp", "w")
+frontend_h_file = SmartOutput(output_header_dirname + "/InspectorFrontend.h")
+frontend_cpp_file = SmartOutput(output_cpp_dirname + "/InspectorFrontend.cpp")
 
-typebuilder_h_file = open(output_header_dirname + "/InspectorTypeBuilder.h", "w")
-typebuilder_cpp_file = open(output_cpp_dirname + "/InspectorTypeBuilder.cpp", "w")
+typebuilder_h_file = SmartOutput(output_header_dirname + "/InspectorTypeBuilder.h")
+typebuilder_cpp_file = SmartOutput(output_cpp_dirname + "/InspectorTypeBuilder.cpp")
 
-backend_js_file = open(output_cpp_dirname + "/InspectorBackendCommands.js", "w")
+backend_js_file = SmartOutput(output_cpp_dirname + "/InspectorBackendCommands.js")
 
 
 backend_h_file.write(Templates.backend_h.substitute(None,