From 8675fa834bf1435430ebe3783cc05ac26d71f129 Mon Sep 17 00:00:00 2001 From: "haraken@chromium.org" Date: Tue, 24 Jan 2012 07:09:47 +0000 Subject: [PATCH] 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(). git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105697 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/ChangeLog | 23 ++++++++ Source/WebCore/bindings/scripts/CodeGenerator.pm | 24 ++++++++ .../WebCore/bindings/scripts/CodeGeneratorObjC.pm | 65 ++++++++-------------- 3 files changed, 70 insertions(+), 42 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index d9d98e7..c115554 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,26 @@ +2012-01-23 Kentaro Hara + + 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 REGRESSION: Downloaded file name fallback encodings are not set correctly diff --git a/Source/WebCore/bindings/scripts/CodeGenerator.pm b/Source/WebCore/bindings/scripts/CodeGenerator.pm index f94c0b2..44fefde 100644 --- a/Source/WebCore/bindings/scripts/CodeGenerator.pm +++ b/Source/WebCore/bindings/scripts/CodeGenerator.pm @@ -163,6 +163,30 @@ sub FileNamePrefix 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 = ; + $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; diff --git a/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm b/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm index 93739da..6cb1fcb 100644 --- a/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm +++ b/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm @@ -1776,25 +1776,15 @@ sub WriteData 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; - - close(HEADER); + $contents .= "\n" if $hasForwardDeclarations; + $contents .= join "", @headerContent; + $codeGenerator->UpdateFileIfChanged($headerFileName, $contents); @headerContentHeader = (); @headerContent = (); @@ -1802,17 +1792,14 @@ sub WriteData %headerForwardDeclarationsForProtocols = (); if (@privateHeaderContent > 0) { - open(PRIVATE_HEADER, ">$privateHeaderFileName") or die "Couldn't open file $privateHeaderFileName"; - - print PRIVATE_HEADER @privateHeaderContentHeader; - print PRIVATE_HEADER map { "\@class $_;\n" } sort keys(%privateHeaderForwardDeclarations); - print PRIVATE_HEADER map { "\@protocol $_;\n" } sort keys(%privateHeaderForwardDeclarationsForProtocols); + $contents = join "", @privateHeaderContentHeader; + map { $contents .= "\@class $_;\n" } sort keys(%privateHeaderForwardDeclarations); + map { $contents .= "\@protocol $_;\n" } sort keys(%privateHeaderForwardDeclarationsForProtocols); $hasForwardDeclarations = keys(%privateHeaderForwardDeclarations) + keys(%privateHeaderForwardDeclarationsForProtocols); - print PRIVATE_HEADER "\n" if $hasForwardDeclarations; - print PRIVATE_HEADER @privateHeaderContent; - - close(PRIVATE_HEADER); + $contents .= "\n" if $hasForwardDeclarations; + $contents .= join "", @privateHeaderContent; + $codeGenerator->UpdateFileIfChanged($privateHeaderFileName, $contents); @privateHeaderContentHeader = (); @privateHeaderContent = (); @@ -1822,34 +1809,28 @@ sub WriteData # Write implementation file. unless ($noImpl) { - open(IMPL, ">$implFileName") or die "Couldn't open file $implFileName"; - - print IMPL @implContentHeader; - print IMPL map { "#import \"$_\"\n" } sort keys(%implIncludes); - print IMPL @implContent; - - close(IMPL); + $contents = join "", @implContentHeader; + map { $contents .= "#import \"$_\"\n" } sort keys(%implIncludes); + $contents .= join "", @implContent; + $codeGenerator->UpdateFileIfChanged($implFileName, $contents); @implContentHeader = (); @implContent = (); %implIncludes = (); } - - if (@internalHeaderContent > 0) { - open(INTERNAL_HEADER, ">$internalHeaderFileName") or die "Couldn't open file $internalHeaderFileName"; - print INTERNAL_HEADER @internalHeaderContent; - - close(INTERNAL_HEADER); + if (@internalHeaderContent > 0) { + $contents = join "", @internalHeaderContent; + $codeGenerator->UpdateFileIfChanged($internalHeaderFileName, $contents); - @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 = (); } } -- 2.7.4