Title: [105697] trunk/Source/WebCore
Revision
105697
Author
[email protected]
Date
2012-01-23 23:09:47 -0800 (Mon, 23 Jan 2012)

Log Message

In CodeGeneratorObjC.pm, overwrite the output .h/.mm
only if the bytes differ
https://bugs.webkit.org/show_bug.cgi?id=76874

Reviewed by Adam Barth.

This is one of steps to stop rebuilding .h/.cpp/.mm files
generated by unchanged IDLs (bug 76836).
This patch makes a change on CodeGeneratorObjC.pm so that
it overwrites the output .h/.mm only if the bytes differ.

No tests. No change in behavior.
I manually confirmed that when I add a new attribute to Element.idl,
the time-stamps of unrelated DOM*.h and DOM*.mm do not change.

* bindings/scripts/CodeGenerator.pm:
(UpdateFileIfChanged): Added. This method writes data to a file
only if the data is different from the data in the current file.
* bindings/scripts/CodeGeneratorObjC.pm:
(WriteData): Used UpdateFileIfChanged().

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (105696 => 105697)


--- trunk/Source/WebCore/ChangeLog	2012-01-24 06:46:00 UTC (rev 105696)
+++ trunk/Source/WebCore/ChangeLog	2012-01-24 07:09:47 UTC (rev 105697)
@@ -1,3 +1,26 @@
+2012-01-23  Kentaro Hara  <[email protected]>
+
+        In CodeGeneratorObjC.pm, overwrite the output .h/.mm
+        only if the bytes differ
+        https://bugs.webkit.org/show_bug.cgi?id=76874
+
+        Reviewed by Adam Barth.
+
+        This is one of steps to stop rebuilding .h/.cpp/.mm files
+        generated by unchanged IDLs (bug 76836).
+        This patch makes a change on CodeGeneratorObjC.pm so that
+        it overwrites the output .h/.mm only if the bytes differ.
+
+        No tests. No change in behavior.
+        I manually confirmed that when I add a new attribute to Element.idl,
+        the time-stamps of unrelated DOM*.h and DOM*.mm do not change.
+
+        * bindings/scripts/CodeGenerator.pm:
+        (UpdateFileIfChanged): Added. This method writes data to a file
+        only if the data is different from the data in the current file.
+        * bindings/scripts/CodeGeneratorObjC.pm:
+        (WriteData): Used UpdateFileIfChanged().
+
 2012-01-23  Alexey Proskuryakov  <[email protected]>
 
         REGRESSION: Downloaded file name fallback encodings are not set correctly

Modified: trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm (105696 => 105697)


--- trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm	2012-01-24 06:46:00 UTC (rev 105696)
+++ trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm	2012-01-24 07:09:47 UTC (rev 105697)
@@ -163,6 +163,30 @@
     return $codeGenerator->FileNamePrefix();
 }
 
+sub UpdateFileIfChanged
+{
+    my $object = shift;
+    my $fileName = shift;
+    my $contents = shift;
+
+    my $shouldUpdate = 0;
+
+    if (open FH, $fileName) {
+        local $/ = undef;
+        my $oldContents = <FH>;
+        $shouldUpdate = 1 if $oldContents ne $contents;
+        close FH;
+    } else {
+        $shouldUpdate = 1;
+    }
+
+    if ($shouldUpdate) {
+        open FH, "> $fileName" or die "Couldn't open $fileName: $!\n";
+        print FH $contents;
+        close FH;
+    }
+}
+
 sub ForAllParents
 {
     my $object = shift;

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm (105696 => 105697)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm	2012-01-24 06:46:00 UTC (rev 105696)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm	2012-01-24 07:09:47 UTC (rev 105697)
@@ -1776,44 +1776,31 @@
     my $internalHeaderFileName = "$outputDir/" . $name . "Internal.h";
     my $depsFileName = "$outputDir/" . $name . ".dep";
 
-    # Remove old files.
-    unlink($headerFileName);
-    unlink($privateHeaderFileName);
-    unlink($implFileName);
-    unlink($internalHeaderFileName);
-    unlink($depsFileName);
-
     # Write public header.
-    open(HEADER, ">$headerFileName") or die "Couldn't open file $headerFileName";
-    
-    print HEADER @headerContentHeader;
-    print HEADER map { "\@class $_;\n" } sort keys(%headerForwardDeclarations);
-    print HEADER map { "\@protocol $_;\n" } sort keys(%headerForwardDeclarationsForProtocols);
+    my $contents = join "", @headerContentHeader;
+    map { $contents .= "\@class $_;\n" } sort keys(%headerForwardDeclarations);
+    map { $contents .= "\@protocol $_;\n" } sort keys(%headerForwardDeclarationsForProtocols);
 
     my $hasForwardDeclarations = keys(%headerForwardDeclarations) + keys(%headerForwardDeclarationsForProtocols);
-    print HEADER "\n" if $hasForwardDeclarations;
-    print HEADER @headerContent;
+    $contents .= "\n" if $hasForwardDeclarations;
+    $contents .= join "", @headerContent;
+    $codeGenerator->UpdateFileIfChanged($headerFileName, $contents);
 
-    close(HEADER);
-
     @headerContentHeader = ();
     @headerContent = ();
     %headerForwardDeclarations = ();
     %headerForwardDeclarationsForProtocols = ();
 
     if (@privateHeaderContent > 0) {
-        open(PRIVATE_HEADER, ">$privateHeaderFileName") or die "Couldn't open file $privateHeaderFileName";
+        $contents = join "", @privateHeaderContentHeader;
+        map { $contents .= "\@class $_;\n" } sort keys(%privateHeaderForwardDeclarations);
+        map { $contents .= "\@protocol $_;\n" } sort keys(%privateHeaderForwardDeclarationsForProtocols);
 
-        print PRIVATE_HEADER @privateHeaderContentHeader;
-        print PRIVATE_HEADER map { "\@class $_;\n" } sort keys(%privateHeaderForwardDeclarations);
-        print PRIVATE_HEADER map { "\@protocol $_;\n" } sort keys(%privateHeaderForwardDeclarationsForProtocols);
-
         $hasForwardDeclarations = keys(%privateHeaderForwardDeclarations) + keys(%privateHeaderForwardDeclarationsForProtocols);
-        print PRIVATE_HEADER "\n" if $hasForwardDeclarations;
-        print PRIVATE_HEADER @privateHeaderContent;
+        $contents .= "\n" if $hasForwardDeclarations;
+        $contents .= join "", @privateHeaderContent;
+        $codeGenerator->UpdateFileIfChanged($privateHeaderFileName, $contents);
 
-        close(PRIVATE_HEADER);
-
         @privateHeaderContentHeader = ();
         @privateHeaderContent = ();
         %privateHeaderForwardDeclarations = ();
@@ -1822,34 +1809,28 @@
 
     # Write implementation file.
     unless ($noImpl) {
-        open(IMPL, ">$implFileName") or die "Couldn't open file $implFileName";
+        $contents = join "", @implContentHeader;
+        map { $contents .= "#import \"$_\"\n" } sort keys(%implIncludes);
+        $contents .= join "", @implContent;
+        $codeGenerator->UpdateFileIfChanged($implFileName, $contents);
 
-        print IMPL @implContentHeader;
-        print IMPL map { "#import \"$_\"\n" } sort keys(%implIncludes);
-        print IMPL @implContent;
-
-        close(IMPL);
-
         @implContentHeader = ();
         @implContent = ();
         %implIncludes = ();
     }
-    
+
     if (@internalHeaderContent > 0) {
-       open(INTERNAL_HEADER, ">$internalHeaderFileName") or die "Couldn't open file $internalHeaderFileName";
+        $contents = join "", @internalHeaderContent;
+        $codeGenerator->UpdateFileIfChanged($internalHeaderFileName, $contents);
 
-       print INTERNAL_HEADER @internalHeaderContent;
-
-       close(INTERNAL_HEADER);
-
-       @internalHeaderContent = ();
+        @internalHeaderContent = ();
     }
 
     # Write dependency file.
     if (@depsContent) {
-        open(DEPS, ">$depsFileName") or die "Couldn't open file $depsFileName";
-        print DEPS @depsContent;
-        close(DEPS);
+        $contents = join "", @depsContent;
+        $codeGenerator->UpdateFileIfChanged($depsFileName, $contents);
+
         @depsContent = ();
     }
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to