WebKitTools/Scripts/do-webcore-rename
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 #!/usr/bin/perl -w
       
     2 
       
     3 # Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
       
     4 #
       
     5 # Redistribution and use in source and binary forms, with or without
       
     6 # modification, are permitted provided that the following conditions
       
     7 # are met:
       
     8 #
       
     9 # 1.  Redistributions of source code must retain the above copyright
       
    10 #     notice, this list of conditions and the following disclaimer. 
       
    11 # 2.  Redistributions in binary form must reproduce the above copyright
       
    12 #     notice, this list of conditions and the following disclaimer in the
       
    13 #     documentation and/or other materials provided with the distribution. 
       
    14 # 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
       
    15 #     its contributors may be used to endorse or promote products derived
       
    16 #     from this software without specific prior written permission. 
       
    17 #
       
    18 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
       
    19 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
       
    21 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
       
    22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
       
    24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
       
    25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
       
    27 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    28 
       
    29 # Script to do a rename in JavaScriptCore, WebCore, and WebKit.
       
    30 
       
    31 use strict;
       
    32 
       
    33 use File::Find;
       
    34 use FindBin;
       
    35 use Getopt::Long qw(:config pass_through);
       
    36 
       
    37 use lib $FindBin::Bin;
       
    38 use webkitdirs;
       
    39 use VCSUtils;
       
    40 
       
    41 setConfiguration();
       
    42 chdirWebKit();
       
    43 
       
    44 my $showHelp;
       
    45 my $verbose;
       
    46 
       
    47 my $programName = basename($0);
       
    48 my $usage = <<EOF;
       
    49 Usage: $programName [options]
       
    50   -h|--help                       Show this help message
       
    51   -v|--verbose                    More verbose output
       
    52 EOF
       
    53 
       
    54 my $getOptionsResult = GetOptions(
       
    55     'help|h' => \$showHelp,
       
    56     'verbose|v' => \$verbose,
       
    57 );
       
    58 
       
    59 if (!$getOptionsResult || $showHelp) {
       
    60     print STDERR $usage;
       
    61     exit 1;
       
    62 }
       
    63 
       
    64 my @directoriesToIgnoreList = (
       
    65     "icu",
       
    66 );
       
    67 my %directoriesToIgnore = map { $_ => 1 } @directoriesToIgnoreList;
       
    68 
       
    69 # find all files we want to process
       
    70 
       
    71 my @paths;
       
    72 find(\&wanted, "JavaScriptCore");
       
    73 find(\&wanted, "JavaScriptGlue");
       
    74 find(\&wanted, "WebCore");
       
    75 find(\&wanted, "WebKit");
       
    76 find(\&wanted, "WebKit2");
       
    77 
       
    78 sub wanted
       
    79 {
       
    80     my $file = $_;
       
    81 
       
    82     # Ignore excluded and hidden files/directories.
       
    83     if ($directoriesToIgnore{$file} or $file =~ /^\../ or $file =~ /^ChangeLog/) {
       
    84         print "Ignoring $File::Find::name\n" if $verbose;
       
    85         $File::Find::prune = 1;
       
    86         return;
       
    87     }
       
    88 
       
    89     return if -d $file;
       
    90 
       
    91     push @paths, $File::Find::name;
       
    92 }
       
    93 
       
    94 # Setting isDOMTypeRename to 1 rather than 0 expands the regexps used
       
    95 # below to handle custom JavaScript bindings.
       
    96 my $isDOMTypeRename = 0;
       
    97 my %renames = (
       
    98     # Renames go here in the form of:
       
    99     # "HTMLDocumentParser" => "LegacyHTMLDocumentParser",
       
   100 );
       
   101 
       
   102 my %renamesContemplatedForTheFuture = (
       
   103     "HTMLPlugInImageElement" => "HTMLEmbeddedObjectElement",
       
   104 
       
   105     "DOMObject" => "JSDOMObject",
       
   106 
       
   107     "runtimeObjectGetter" => "pluginElementGetter",
       
   108     "runtimeObjectPropertyGetter" => "pluginElementPropertyGetter",
       
   109     "runtimeObjectCustomGetOwnPropertySlot" => "pluginElementCustomGetOwnPropertySlot",
       
   110     "runtimeObjectCustomPut" => "pluginElementCustomPut",
       
   111     "runtimeObjectImplementsCall" => "pluginElementImplementsCall",
       
   112     "runtimeObjectCallAsFunction" => "pluginElementCallAsFunction",
       
   113 
       
   114     "CLONE_CONTENTS" => "Clone",
       
   115     "DELETE_CONTENTS" => "Delete",
       
   116     "EXTRACT_CONTENTS" => "Extract",
       
   117 
       
   118     "DateInstance" => "JSDate",
       
   119     "ErrorInstance" => "JSError",
       
   120 
       
   121     "KURL" => "URL",
       
   122     "KURLCFNet" => "URLCF",
       
   123     "KURLHash" => "URLHash",
       
   124     "KURLMac" => "URLMac",
       
   125     "KURL_h" => "URL_h",
       
   126 
       
   127     "ThreadSafeSharedBase" => "ThreadSafeRefCountedBase",
       
   128     "ThreadSafeShared" => "ThreadSafeRefCounted",
       
   129     "TreeShared" => "TreeRefCounted",
       
   130 
       
   131     "StringImpl" => "SharedString",
       
   132 
       
   133     "RenderView" => "RenderViewport",
       
   134 
       
   135     "ObjcFallbackObjectImp" => "ObjCFallbackObject",
       
   136     "RuntimeObjectImp" => "ForeignObject",
       
   137 
       
   138     "runtime_array" => "BridgedArray",
       
   139     "runtime_method" => "BridgedFunction",
       
   140     "runtime_object" => "BridgedObject",
       
   141     "objc_runtime" => "ObjCBridge",
       
   142 
       
   143     "equalIgnoringCase" => "equalFoldingCase",
       
   144 
       
   145     "FTPDirectoryTokenizer" => "FTPDirectoryDocumentBuilder",
       
   146     "HTMLTokenizer" => "HTMLDocumentBuilder",
       
   147     "ImageTokenizer" => "ImageDocumentBuilder",
       
   148     "PluginTokenizer" => "PluginDocumentBuilder",
       
   149     "TextTokenizer" => "TextDocumentBuilder",
       
   150     "Tokenizer" => "DocumentBuilder",
       
   151     "Tokenizer_h" => "DocumentBuilder_h",
       
   152     "XMLTokenizer" => "XMLDocumentBuilder",
       
   153     "isHTMLTokenizer" => "isHTMLDocumentBuilder",
       
   154     "m_tokenizer" => "m_builder",
       
   155     "createTokenizer" => "createBuilder",
       
   156     "tokenizerProcessedData" => "documentBuilderProcessedData",
       
   157 
       
   158     "WTF_UNICODE_H" => "Unicode_h",
       
   159     "WTF_UNICODE_ICU_H" => "UnicodeICU_h",
       
   160     "WTF_UNICODE_QT4_H" => "UnicodeQt4_h",
       
   161     "UnicodeIcu" => "UnicodeICU",
       
   162 
       
   163     "m_invertibleCTM" => "m_transformIsInvertible",
       
   164 
       
   165     "NativeFunctionWrapper_h" => "JSHostFunction_h",
       
   166     "NativeFunctionWrapper" => "JSHostFunction",
       
   167     "nativeFunctionThunk" => "hostFunctionThunk",
       
   168     "nativeFunction" => "hostFunction",
       
   169     "NativeFunction" => "HostFunction",
       
   170 );
       
   171 
       
   172 # Sort the keys of the renames hash in order of decreasing length. This
       
   173 # handles the case where some of the renames are substrings of others;
       
   174 # i.e., "Foo" => "Bar" and "FooBuffer" => "BarBuffer".
       
   175 my @sortedRenameKeys = sort { length($b) - length($a) } keys %renames;
       
   176 
       
   177 # rename files
       
   178 
       
   179 sub renameFile
       
   180 {
       
   181     my $file = shift;
       
   182 
       
   183     if ($isDOMTypeRename) {
       
   184         # Find the longest key in %renames which matches this more permissive regexp.
       
   185         # (The old regexp would match ".../Foo.cpp" but not ".../JSFooCustom.cpp".)
       
   186         # This handles renaming of custom JavaScript bindings even when some of the
       
   187         # renames are substrings of others. The only reason we don't do this all the
       
   188         # time is to avoid accidental file renamings for short, non-DOM renames.
       
   189         for my $key (@sortedRenameKeys) {
       
   190             my $newFile = "";
       
   191             $newFile = "$1$renames{$2}$3" if $file =~ /^(.*\/\w*)($key)(\w*\.\w+)$/;
       
   192             if ($newFile ne "") {
       
   193                 return $newFile;
       
   194             }
       
   195         }
       
   196     } else {
       
   197        $file = "$1$renames{$2}$3" if $file =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2};
       
   198     }
       
   199     return $file;
       
   200 }
       
   201 
       
   202 my %newFile;
       
   203 for my $file (sort @paths) {
       
   204     my $f = renameFile($file);
       
   205     if ($f ne $file) {
       
   206         $newFile{$file} = $f;
       
   207     }
       
   208 }
       
   209 
       
   210 
       
   211 my $isGit = isGit();
       
   212 
       
   213 for my $file (sort @paths) {
       
   214     if ($newFile{$file}) {
       
   215         my $newFile = $newFile{$file};
       
   216         print "Renaming $file to $newFile\n";
       
   217         if ($isGit) {
       
   218             system "git mv $file $newFile";
       
   219         } else {
       
   220             system "svn move $file $newFile";
       
   221         }
       
   222     }
       
   223 }
       
   224 
       
   225 # change all file contents
       
   226 
       
   227 for my $file (sort @paths) {
       
   228     $file = $newFile{$file} if $newFile{$file};
       
   229     my $contents;
       
   230     {
       
   231         local $/;
       
   232         open FILE, $file or die "Failed to open $file";
       
   233         $contents = <FILE>;
       
   234         close FILE;
       
   235     }
       
   236     my $newContents = $contents;
       
   237 
       
   238     if ($isDOMTypeRename) {
       
   239         for my $from (@sortedRenameKeys) {
       
   240             # Handle JavaScript custom bindings.
       
   241             $newContents =~ s/\b(JS|V8|to|)$from/$1$renames{$from}/g;
       
   242         }
       
   243     } else {
       
   244         for my $from (@sortedRenameKeys) {
       
   245             $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
       
   246         }
       
   247     }
       
   248 
       
   249     if ($newContents ne $contents) {
       
   250         open FILE, ">", $file or die "Failed to open $file";
       
   251         print FILE $newContents;
       
   252         close FILE;
       
   253     }
       
   254 }