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 generate HTML wrappers for JavaScript tests from templates 30 31use strict; 32 33use FindBin; 34use lib $FindBin::Bin; 35 36use File::Basename; 37use File::Find; 38use Getopt::Long; 39use webkitdirs; 40 41sub directoryFilter; 42sub findTemplateFiles(@); 43 44my $showHelp; 45 46my $result = GetOptions( 47 "help" => \$showHelp, 48); 49 50if (!$result || $showHelp) { 51 print STDERR basename($0) . " [-h|--help] [path ...]\n"; 52 exit 1; 53} 54 55setConfiguration(); 56my $productDir = productDir(); 57 58chdirWebKit(); 59 60my @templates = findTemplateFiles(@ARGV); 61 62for my $tfile (@templates) { 63 64 my $tpath = $tfile; 65 $tpath =~ s:/resources/TEMPLATE.html$::; 66 67 print "${tpath}\n"; 68 69 chdirWebKit(); 70 chdir($tpath); 71 72 my @files; 73 my $fileFilter = sub { 74 push @files, $File::Find::name if substr($_, -3) eq ".js"; 75 }; 76 find({ preprocess => \&directoryFilter, wanted => $fileFilter }, "resources"); 77 78 open TEMPLATE, "<resources/TEMPLATE.html"; 79 my $template = do { local $/; <TEMPLATE> }; 80 close TEMPLATE; 81 82 my $templateNegative = $template; 83 if (-e "resources/TEMPLATE-n.html") { 84 open TEMPLATE, "<resources/TEMPLATE-n.html"; 85 $templateNegative = do { local $/; <TEMPLATE> }; 86 close TEMPLATE; 87 } 88 89 for my $file (@files) { 90 next if $file =~ /js-test-.*\.js$/; 91 next if $file =~ /cookies-test-(post|pre)\.js$/; 92 next if $file =~ /standalone-.*\.js$/; 93 next if $file =~ /SVGTestCase\.js/; 94 next if $file =~ /WMLTestCase\.js/; 95 96 next if $file =~ m:resources/bom-in-file-retains-correct-offset\.js$:; # has a custom template 97 next if $file =~ m:resources/NSResolver-exceptions\.js$:; 98 next if $file =~ m:resources/WindowProperties\.js$:; 99 next if $file =~ m:resources/altGlyph-dom\.js$:; 100 next if $file =~ m:resources/attr-case-sensitivity\.js$:; 101 next if $file =~ m:resources/box-shadow-overflow-scroll\.js$:; 102 next if $file =~ m:resources/codegen-temporaries-multiple-global-blocks-1\.js$:; 103 next if $file =~ m:resources/codegen-temporaries-multiple-global-blocks-2\.js$:; 104 next if $file =~ m:resources/constructors-cached-navigate\.js$:; 105 next if $file =~ m:resources/frame-loading-via-document-write\.js$:; 106 next if $file =~ m:resources/id-fastpath-almost-strict\.js$:; 107 next if $file =~ m:resources/id-fastpath-strict\.js$:; 108 next if $file =~ m:resources/intersectsNode\.js$:; 109 next if $file =~ m:resources/p-in-scope\.js$:; 110 next if $file =~ m:resources/paste-blockquote-before-blockquote\.js$:; 111 next if $file =~ m:resources/reflection-overflow-scroll\.js$:; 112 next if $file =~ m:resources/script-element-gc\.js$:; 113 next if $file =~ m:resources/script-element-gc\.js$:; 114 next if $file =~ m:resources/script3\.js$:; 115 next if $file =~ m:resources/script4\.js$:; 116 next if $file =~ m:resources/script5\.js$:; 117 next if $file =~ m:resources/scripted-random\.js$:; 118 next if $file =~ m:resources/select-options-remove\.js$:; 119 next if $file =~ m:resources/shadow-offset\.js$:; 120 next if $file =~ m:resources/tabindex-focus-blur-all\.js$:; 121 next if $file =~ m:resources/use-instanceRoot-event-bubbling\.js$:; 122 next if $file =~ m:resources/use-instanceRoot-event-listeners\.js$:; 123 next if $file =~ m:resources/window-properties\.js$:; 124 next if $file =~ m:resources/wrapper-identity-base\.js$:; 125 next if $file =~ m:resources/xhtml-scripts\.js$:; 126 next if $file =~ m:resources/instanceof-operator-dummy-worker\.js$:; 127 next if $file =~ m:resources/json2-es5-compat\.js$:; 128 next if $file =~ m:resources/JSON-stringify\.js$:; 129 next if $file =~ m:resources/JSON-parse\.js$:; 130 next if $file =~ m:resources/textarea-input-event\.js$:; 131 132 my $html = $file; 133 $html =~ s:resources/(.*)\.js:$1.html:; 134 next if -f "$html-disabled"; 135 136 system("grep -q 'successfullyParsed =' $file"); 137 if ($? != 0) { 138 `echo "" >> "${file}"`; 139 `echo "var successfullyParsed = true;" >> "${file}"`; 140 } 141 142 print " ${html}\n"; 143 open HTML, ">$html"; 144 my $output = ($file =~ /-n\.js/) ? $templateNegative : $template; 145 $output =~ s:YOUR_JS_FILE_HERE:$file:; 146 print HTML $output; 147 148 close HTML; 149 } 150} 151 152exit 0; 153 154sub directoryFilter 155{ 156 return () if basename($File::Find::dir) eq ".svn"; 157 return @_; 158} 159 160sub findTemplateFiles(@) { 161 my @args = @_; 162 my @templateFiles; 163 164 push @args, "LayoutTests" if scalar(@args) == 0; 165 166 my @paths = map { -f $_ ? dirname($_) : $_ } @args; 167 168 my $fileFilter = sub { 169 push @templateFiles, $File::Find::name if $_ eq "TEMPLATE.html"; 170 }; 171 172 find({ preprocess => \&directoryFilter, wanted => $fileFilter }, @paths); 173 174 return @templateFiles; 175} 176