Home | History | Annotate | Download | only in Scripts
      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, "Source/JavaScriptCore");
     73 find(\&wanted, "Source/JavaScriptGlue");
     74 find(\&wanted, "Source/WebCore");
     75 find(\&wanted, "Source/WebKit");
     76 find(\&wanted, "Source/WebKit2");
     77 find(\&wanted, "Tools/DumpRenderTree");
     78 
     79 sub wanted
     80 {
     81     my $file = $_;
     82 
     83     # Ignore excluded and hidden files/directories.
     84     if ($directoriesToIgnore{$file} or $file =~ /^\../ or $file =~ /^ChangeLog/) {
     85         print "Ignoring $File::Find::name\n" if $verbose;
     86         $File::Find::prune = 1;
     87         return;
     88     }
     89 
     90     return if -d $file;
     91 
     92     push @paths, $File::Find::name;
     93 }
     94 
     95 # Setting isDOMTypeRename to 1 rather than 0 expands the regexps used
     96 # below to handle custom JavaScript bindings.
     97 my $isDOMTypeRename = 0;
     98 my %renames = (
     99     # Renames go here in the form of:
    100     "MediaControls" => "MediaControlRootElement",
    101 );
    102 
    103 my %renamesContemplatedForTheFuture = (
    104     "HTMLPlugInImageElement" => "HTMLEmbeddedObjectElement",
    105 
    106     "DOMObject" => "JSDOMObject",
    107 
    108     "runtimeObjectGetter" => "pluginElementGetter",
    109     "runtimeObjectPropertyGetter" => "pluginElementPropertyGetter",
    110     "runtimeObjectCustomGetOwnPropertySlot" => "pluginElementCustomGetOwnPropertySlot",
    111     "runtimeObjectCustomPut" => "pluginElementCustomPut",
    112     "runtimeObjectImplementsCall" => "pluginElementImplementsCall",
    113     "runtimeObjectCallAsFunction" => "pluginElementCallAsFunction",
    114 
    115     "CLONE_CONTENTS" => "Clone",
    116     "DELETE_CONTENTS" => "Delete",
    117     "EXTRACT_CONTENTS" => "Extract",
    118 
    119     "DateInstance" => "JSDate",
    120     "ErrorInstance" => "JSError",
    121 
    122     "KURL" => "URL",
    123     "KURLCFNet" => "URLCF",
    124     "KURLHash" => "URLHash",
    125     "KURLMac" => "URLMac",
    126     "KURL_h" => "URL_h",
    127 
    128     "TreeShared" => "TreeRefCounted",
    129 
    130     "StringImpl" => "SharedString",
    131 
    132     "RenderView" => "RenderViewport",
    133 
    134     "ObjcFallbackObjectImp" => "ObjCFallbackObject",
    135     "RuntimeObjectImp" => "ForeignObject",
    136 
    137     "runtime_array" => "BridgedArray",
    138     "runtime_method" => "BridgedFunction",
    139     "runtime_object" => "BridgedObject",
    140     "objc_runtime" => "ObjCBridge",
    141 
    142     "equalIgnoringCase" => "equalFoldingCase",
    143 
    144     "FTPDirectoryTokenizer" => "FTPDirectoryDocumentBuilder",
    145     "HTMLTokenizer" => "HTMLDocumentBuilder",
    146     "ImageTokenizer" => "ImageDocumentBuilder",
    147     "PluginTokenizer" => "PluginDocumentBuilder",
    148     "TextTokenizer" => "TextDocumentBuilder",
    149     "Tokenizer" => "DocumentBuilder",
    150     "Tokenizer_h" => "DocumentBuilder_h",
    151     "XMLTokenizer" => "XMLDocumentBuilder",
    152     "isHTMLTokenizer" => "isHTMLDocumentBuilder",
    153     "m_tokenizer" => "m_builder",
    154     "createTokenizer" => "createBuilder",
    155     "tokenizerProcessedData" => "documentBuilderProcessedData",
    156 
    157     "WTF_UNICODE_H" => "Unicode_h",
    158     "WTF_UNICODE_ICU_H" => "UnicodeICU_h",
    159     "WTF_UNICODE_QT4_H" => "UnicodeQt4_h",
    160     "UnicodeIcu" => "UnicodeICU",
    161 
    162     "m_invertibleCTM" => "m_transformIsInvertible",
    163 
    164     "NativeFunctionWrapper_h" => "JSHostFunction_h",
    165     "NativeFunctionWrapper" => "JSHostFunction",
    166     "nativeFunctionThunk" => "hostFunctionThunk",
    167     "nativeFunction" => "hostFunction",
    168     "NativeFunction" => "HostFunction",
    169 );
    170 
    171 # Sort the keys of the renames hash in order of decreasing length. This
    172 # handles the case where some of the renames are substrings of others;
    173 # i.e., "Foo" => "Bar" and "FooBuffer" => "BarBuffer".
    174 my @sortedRenameKeys = sort { length($b) - length($a) } keys %renames;
    175 
    176 # rename files
    177 
    178 sub renameFile
    179 {
    180     my $file = shift;
    181 
    182     if ($isDOMTypeRename) {
    183         # Find the longest key in %renames which matches this more permissive regexp.
    184         # (The old regexp would match ".../Foo.cpp" but not ".../JSFooCustom.cpp".)
    185         # This handles renaming of custom JavaScript bindings even when some of the
    186         # renames are substrings of others. The only reason we don't do this all the
    187         # time is to avoid accidental file renamings for short, non-DOM renames.
    188         for my $key (@sortedRenameKeys) {
    189             my $newFile = "";
    190             $newFile = "$1$renames{$2}$3" if $file =~ /^(.*\/\w*)($key)(\w*\.\w+)$/;
    191             if ($newFile ne "") {
    192                 return $newFile;
    193             }
    194         }
    195     } else {
    196        $file = "$1$renames{$2}$3" if $file =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2};
    197     }
    198     return $file;
    199 }
    200 
    201 my %newFile;
    202 for my $file (sort @paths) {
    203     my $f = renameFile($file);
    204     if ($f ne $file) {
    205         $newFile{$file} = $f;
    206     }
    207 }
    208 
    209 for my $file (sort @paths) {
    210     if ($newFile{$file}) {
    211         my $newFile = $newFile{$file};
    212         print "Renaming $file to $newFile\n";
    213         scmMoveOrRenameFile($file, $newFile);
    214     }
    215 }
    216 
    217 # change all file contents
    218 
    219 for my $file (sort @paths) {
    220     $file = $newFile{$file} if $newFile{$file};
    221     my $contents;
    222     {
    223         local $/;
    224         open FILE, $file or die "Failed to open $file";
    225         $contents = <FILE>;
    226         close FILE;
    227     }
    228     my $newContents = $contents;
    229 
    230     if ($isDOMTypeRename) {
    231         for my $from (@sortedRenameKeys) {
    232             # Handle JavaScript custom bindings.
    233             $newContents =~ s/\b(JS|V8|to|)$from/$1$renames{$from}/g;
    234         }
    235     } else {
    236         for my $from (@sortedRenameKeys) {
    237             $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
    238         }
    239     }
    240 
    241     if ($newContents ne $contents) {
    242         open FILE, ">", $file or die "Failed to open $file";
    243         print FILE $newContents;
    244         close FILE;
    245     }
    246 }
    247