make-script-test-wrappers 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/usr/bin/perl -w
  2. # Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions
  6. # are met:
  7. #
  8. # 1. Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # 2. Redistributions in binary form must reproduce the above copyright
  11. # notice, this list of conditions and the following disclaimer in the
  12. # documentation and/or other materials provided with the distribution.
  13. # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  14. # its contributors may be used to endorse or promote products derived
  15. # from this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  18. # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  21. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. # Script to generate HTML wrappers for JavaScript tests from templates
  28. use strict;
  29. use FindBin;
  30. use lib $FindBin::Bin;
  31. use File::Basename;
  32. use File::Find;
  33. use Getopt::Long;
  34. use webkitdirs;
  35. sub directoryFilter;
  36. sub findTemplateFiles(@);
  37. my $showHelp;
  38. my $result = GetOptions(
  39. "help" => \$showHelp,
  40. );
  41. if (!$result || $showHelp) {
  42. print STDERR basename($0) . " [-h|--help]\n";
  43. exit 1;
  44. }
  45. setConfiguration();
  46. my $productDir = productDir();
  47. chdirWebKit();
  48. my @templates = findTemplateFiles(@ARGV);
  49. for my $tfile (@templates) {
  50. my $tpath = $tfile;
  51. my $templateDirectory;
  52. my $templateRelativePath;
  53. if ($tpath =~ s:/(script-tests)/TEMPLATE.html$::) {
  54. $templateDirectory = $1;
  55. $templateRelativePath = $1 . "/TEMPLATE.html";
  56. } else {
  57. print "Inappropriate position of a template: ${tpath}\n";
  58. next;
  59. }
  60. print "${tpath}\n";
  61. chdirWebKit();
  62. chdir($tpath);
  63. my @files;
  64. my $fileFilter = sub {
  65. push @files, $File::Find::name if substr($_, -3) eq ".js";
  66. };
  67. find({ preprocess => \&directoryFilter, wanted => $fileFilter }, $templateDirectory);
  68. open TEMPLATE, "<${templateRelativePath}";
  69. my $template = do { local $/; <TEMPLATE> };
  70. close TEMPLATE;
  71. my $templateNegative = $template;
  72. if (-e "${templateDirectory}/TEMPLATE-n.html") {
  73. open TEMPLATE, "<${templateDirectory}/TEMPLATE-n.html";
  74. $templateNegative = do { local $/; <TEMPLATE> };
  75. close TEMPLATE;
  76. }
  77. for my $file (@files) {
  78. my $html = $file;
  79. $html =~ s:${templateDirectory}/(.*)\.js:$1.html:;
  80. next if -f "$html-disabled";
  81. system("cat ${file} | tr '\\0' ' ' | grep -q 'successfullyParsed ='");
  82. if ($? != 0) {
  83. `echo "" >> "${file}"`;
  84. `echo "var successfullyParsed = true;" >> "${file}"`;
  85. }
  86. print " ${html}\n";
  87. open HTML, ">$html";
  88. my $output = ($file =~ /-n\.js/) ? $templateNegative : $template;
  89. $output =~ s:YOUR_JS_FILE_HERE:$file:;
  90. print HTML $output;
  91. close HTML;
  92. }
  93. }
  94. exit 0;
  95. sub directoryFilter
  96. {
  97. return () if basename($File::Find::dir) eq ".svn";
  98. return @_;
  99. }
  100. sub findTemplateFiles(@) {
  101. my @templateFiles;
  102. my $fileFilter = sub {
  103. push @templateFiles, $File::Find::name if $_ eq "TEMPLATE.html";
  104. };
  105. find({ preprocess => \&directoryFilter, wanted => $fileFilter }, "LayoutTests/fast/js");
  106. return @templateFiles;
  107. }