[Release] Webkit2-efl-123997_0.11.85
[framework/web/webkit-efl.git] / Tools / Scripts / filter-build-webkit
1 #!/usr/bin/perl -w
2
3 # Copyright (C) 2011 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 # 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
14 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
15 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 # DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
25 # Filters the output of build-webkit into a more human-readable format.
26
27 use strict;
28 use warnings;
29
30 use CGI qw(escapeHTML);
31 use File::Basename;
32 use FindBin;
33 use lib $FindBin::Bin;
34 use Getopt::Long;
35 use VCSUtils;
36
37 use constant {
38     STYLE_PLAIN => 0,
39     STYLE_HEADER => 1,
40     STYLE_SUCCESS => 2,
41     STYLE_ALERT => 3,
42
43     HTML_HEADER =><<HTMLHEADER,
44 <html>
45     <head>
46         <title>Build Log</title>
47         <style>
48             body { font-family: Monaco, monospace; font-size: 10px; color: #666; line-height: 1.5em; }
49             h2 { margin: 1.5em 0 0 0; font-size: 1.0em; font-weight: bold; color: blue; }
50             p { margin: 0; padding-left: 1.5em; border-left: 3px solid #fff; }
51             p.alert { border-left-color: red; color: red; margin: 1.5em 0 0 0; }
52             p.alert + p { margin: 1.5em 0 0 0; }
53             p.alert + p.alert { margin: 0; }
54             p.success { color: green; }
55         </style>
56     </head>
57     <body>
58 HTMLHEADER
59
60     HTML_FOOTER =><<HTMLFOOTER,
61     </body>
62 </html>
63 HTMLFOOTER
64 };
65
66 sub printLine($$);
67 sub setLogfileOption($$);
68 sub setOutputFormatOption($$);
69 sub usageAndExit();
70
71 # Defined in VCSUtils.
72 sub possiblyColored($$);
73
74 my $showHelp;
75 my $outputPath = "&STDOUT";
76 my $outputFormat = "text";
77 my $useColor = -t STDOUT;
78 my $unfilteredOutputPath = "build.log";
79 my $logUnfilteredOutput;
80
81 sub usageAndExit()
82 {
83     print STDERR <<__END__;
84 Usage: @{[ basename($0) ]} [options] buildlog1 [buildlog2 ...]
85        build-webkit | @{[ basename($0) ]} [options]
86   -h|--help     Show this help message
87 Output Options:
88   -o|--output   Path for output (default: STDOUT)
89   -f|--format   Output format (default: $outputFormat)
90                   text: Plain text
91                   html: Standalone HTML document
92   --[no-]color  ANSI color output for text (default: on, if -o is STDOUT)
93 Unfiltered Logging Options:
94   -l|--log      Save unfiltered output to file (see --log-file)
95   --logfile     Path to save unfiltered output (implies --log, default: $unfilteredOutputPath)
96 __END__
97     exit 1;
98 }
99
100 my $getOptionsResult = GetOptions(
101     'h|help'                => \$showHelp,
102     'o|output=s'            => \$outputPath,
103     'f|format=s'            => \&setOutputFormatOption,
104     'color!'                => \$useColor,
105     'l|log'                 => \$logUnfilteredOutput,
106     'logfile=s'             => \&setLogfileOption,
107 );
108
109 if (-t STDIN || $showHelp || !$getOptionsResult) {
110     usageAndExit();
111 }
112
113 open(OUTPUT_HANDLE, ">$outputPath") or die "Failed to open $outputPath : $!";
114 if ($logUnfilteredOutput) {
115     open(UNFILTERED_OUTPUT_HANDLE, ">$unfilteredOutputPath") or die "Failed to open $unfilteredOutputPath : $!";
116 }
117
118 print OUTPUT_HANDLE HTML_HEADER if ($outputFormat eq "html");
119
120 my $buildFinished;
121 my $buildFailed = 0;
122 while (my $line = <>) {
123     print UNFILTERED_OUTPUT_HANDLE $line if $logUnfilteredOutput;
124
125     chomp($line);
126
127     next if $line =~ /^\s*$/;
128     next if $line =~ /^Build settings from command line:/;
129     next if $line =~ /make: Nothing to be done for `all'\./;
130     next if $line =~ /^JavaScriptCore\/create_hash_table/;
131     next if $line =~ /JavaScriptCore.framework\/PrivateHeaders\/create_hash_table/;
132     next if $line =~ /^JavaScriptCore\/pcre\/dftables/;
133     next if $line =~ /^Creating hashtable for /;
134     next if $line =~ /^Wrote output to /;
135     next if $line =~ /^(touch|perl|cat|rm -f|bison|flex|python|\/usr\/bin\/g\+\+|gperf|echo|sed|if \[ \-f|WebCore\/generate-export-file) /;
136     next if $line =~ /^UNDOCUMENTED: /;
137     next if $line =~ /libtool.*has no symbols/;
138     next if $line =~ /^# Lower case all the values, as CSS values are case-insensitive$/;
139     next if $line =~ /^if sort /;
140     next if $line =~ /^    /;
141     next if $line =~ /^printf /;
142     next if $line =~ /^offlineasm: Nothing changed/;
143     next if $line =~ /^Showing first/;
144
145     if ($line =~ /^={10}/) {
146         printLine($line, STYLE_SUCCESS);
147         $buildFinished = 1;
148     } elsif ($line =~ /^===/) {
149         printLine($line, STYLE_HEADER);
150     } elsif ($line =~ /Checking Dependencies|Check dependencies/) {
151         printLine($line, STYLE_PLAIN);
152     } elsif ($line =~ /\*\* BUILD SUCCEEDED \*\*/) {
153         printLine("Build Succeeded", STYLE_SUCCESS);
154     } elsif ($line =~ /^(PhaseScriptExecution|CompileC|Distributed-CompileC|Ld|PBXCp|CpResource|CopyPNGFile|CopyTiffFile|CpHeader|Processing|ProcessInfoPlistFile|ProcessPCH|ProcessPCH\+\+|Touch|Libtool|CopyStringsFile|Mig|CreateUniversalBinary|Analyze|ProcessProductPackaging|CodeSign|SymLink|Updating|CompileXIB|StripNIB|CopyPlistFile|GenerateDSYMFile) ("[^"]+"|\S+)?/) {
155         my ($command, $path) = ($1, basename($2));
156         $path =~ s/"//g;
157         printLine("$command $path", STYLE_PLAIN);
158     } elsif ($line =~ /^\/\S+?(strip|WebCoreExportFileGenerator) .*?(\/|\> )(\S+)/) {
159         my ($command, $path) = (basename($1), basename($3));
160         printLine("$command $path", STYLE_PLAIN);
161     } elsif ($line =~ /^offlineasm\: /) {
162         printLine($line, STYLE_PLAIN);
163     } elsif ($line =~ /^Generating message.*(header|receiver) for (\S+)\.\.\./) {
164         my ($command, $path) = ($1, basename($2));
165         printLine("Generating message $command $path", STYLE_PLAIN);
166     } elsif ($line =~ /^(\S+\/cc).*?(\S+)\.(out|exp)/) {
167         my ($command, $path) = (basename($1), basename($2));
168         printLine("$command $path", STYLE_PLAIN);
169     } else {
170         # This only gets hit if stderr is redirected to stdout.
171         if ($line =~ /\*\* BUILD FAILED \*\*/) {
172             $buildFailed = 1;
173         }
174         printLine($line, $buildFinished ? STYLE_SUCCESS : STYLE_ALERT);
175     }
176 }
177
178 print OUTPUT_HANDLE HTML_FOOTER if ($outputFormat eq "html");
179
180 close(OUTPUT_HANDLE);
181 close(UNFILTERED_OUTPUT_HANDLE) if ($logUnfilteredOutput);
182
183 exit $buildFailed;
184
185 sub printLine($$)
186 {
187     my ($line, $style) = @_;
188
189     if ($outputFormat eq "html") {
190         $line = escapeHTML($line);
191         if    ($style == STYLE_HEADER)  { print OUTPUT_HANDLE "<h2>$line</h2>"; }
192         elsif ($style == STYLE_SUCCESS) { print OUTPUT_HANDLE "<p class=\"success\">$line</p>"; }
193         elsif ($style == STYLE_ALERT)   { print OUTPUT_HANDLE "<p class=\"alert\">$line</p>"; }
194         else                            { print OUTPUT_HANDLE "<p>$line</p>"; }
195     } else {
196         if ($useColor) {
197             my $colors = "reset";
198             if ($style == STYLE_HEADER)  { $colors = "blue"; }
199             if ($style == STYLE_SUCCESS) { $colors = "green"; }
200             if ($style == STYLE_ALERT)   { $colors = "red"; }
201             print OUTPUT_HANDLE possiblyColored($colors, $line);
202         } else {
203             print OUTPUT_HANDLE $line;
204         }
205     }
206     print OUTPUT_HANDLE "\n";
207 }
208
209 sub setLogfileOption($$)
210 {
211     my ($opt, $value) = @_;
212     $unfilteredOutputPath = $value;
213     $logUnfilteredOutput = 1;
214 }
215
216 sub setOutputFormatOption($$)
217 {
218     my ($opt, $value) = @_;
219     $value = lc($value);
220     if ($value ne "html" && $value ne "text") {
221         die "The $opt option must be either \"html\" or \"text\"";
222     }
223     $outputFormat = $value;
224 }