1 # |
|
2 # Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: See the usage-method below. |
|
15 # |
|
16 # ----------------------------- |
|
17 # - Parses TBS build log file - |
|
18 # ----------------------------- |
|
19 # The script offers parsing functionality for build logs generated by Symbian TBS build tool. |
|
20 # It takes the build log file as an input and creates list of compiled binaries as an output. |
|
21 # The parser searches hard coded key words “-- abld –what” and “++ Finished” and parses the data between the key words. |
|
22 # Optionally you can also zip the binaries. The parser is configurable by giving filter, zipping etc. parameters as an argument. |
|
23 # You can get instructions by launching the script parse_what_log.pl –help |
|
24 # Note: Tested with Symbian TBS build logs only. |
|
25 # |
|
26 # INPUT: mandatory: '-i' name of the build log input file, multiple allowed |
|
27 # '-o' name of the parsed output file or '-zip' name of the zip file |
|
28 # '-filter' and '-pos' defines the string and position ( zero by default ) on the line, which we want to store |
|
29 # |
|
30 # optional: '-ex' defines a list of strings, which excludes lines containing one of these strings |
|
31 # '-zip_prefix' prefix for each secondary zip file name when "double" zipping method selected |
|
32 # '-zip2zip' enables the "double" zipping. Primary zip file name is defined in argument '-zip' |
|
33 # '-zip' full path for the primary zip file |
|
34 # |
|
35 # OUTPUT: mandatory: list of compiled binaries as an output file and/or single zip file named according '-zip' parameter |
|
36 # optional: separate zip files named according to prefix and component's name containing one's compiled binaries |
|
37 # |
|
38 |
|
39 use warnings; |
|
40 use strict; |
|
41 use Getopt::Long; |
|
42 Getopt::Long::Configure ("bundling_override","ignore_case_always"); |
|
43 |
|
44 my ($what_log, $filter_string) = ''; |
|
45 my ($start_found, $filter_position, $help, $i, $skip_line) = 0; |
|
46 my @build_log = (); |
|
47 my @lines = (); |
|
48 my @exclude_list = (); |
|
49 my $temp_folder = "\\temp_what_zip2zip\\"; # temporaly zip for zip2zip |
|
50 my ($app, @app_path, $zip_cmd, $zip_prefix, $zip2zip, $zip) = 0; |
|
51 my %components; |
|
52 |
|
53 my $parse_start_string = "^(-- abld .*-w)"; # defines the starting point for parsing |
|
54 my $parse_end_string = "++ Finished"; # defines the ending point for parsing |
|
55 my $app_key_word = "Chdir "; # defines the key word for finding the app name |
|
56 $filter_position = 0; #set default filter position to zero |
|
57 ############################################### |
|
58 # MAIN BEGIN # |
|
59 ############################################### |
|
60 |
|
61 initialize(); # checks arguments, opens input file etc. |
|
62 # parse_log(); # parses the input file |
|
63 handle_output(); # zips binaries and generates the output file |
|
64 |
|
65 |
|
66 ############################################### |
|
67 # MAIN END # |
|
68 ############################################### |
|
69 |
|
70 # Performs initialization |
|
71 sub initialize |
|
72 { |
|
73 handleArgs(); |
|
74 readLogFile(); |
|
75 } |
|
76 |
|
77 # Reads, stores and checks arguments |
|
78 sub handleArgs |
|
79 { |
|
80 my $ii = 0; |
|
81 my $result = GetOptions ( # read and store arguments |
|
82 'i=s' => \@build_log, # path for input file |
|
83 'o=s' => \$what_log, # path for output file |
|
84 'filter=s' => \$filter_string, # saves lines containing string in $filter_string and in position in $filter_position |
|
85 'pos:i' => \$filter_position, |
|
86 'ex=s' => \@exclude_list, # excludes lines containing one of these strings |
|
87 'zip=s' => \$zip, # name for zip file containing binaries from parsed lines |
|
88 'zip_prefix=s' => \$zip_prefix, # prefix for zip files named with each application's name if $zip2zip defined |
|
89 'zip2zip' => \$zip2zip, # double zipping |
|
90 'h' => \$help, # prints usage information |
|
91 'help' => \$help # prints usage information |
|
92 ); |
|
93 |
|
94 # check argumens are valid and prints usage if not |
|
95 if (!$result || !scalar(@build_log) || (!$what_log && !$zip) || (!$zip && $zip2zip) || |
|
96 !$filter_string || ($filter_position < 0) || $help ) { |
|
97 print "\nUSAGE:\n"; |
|
98 print "perl parse_what_log.pl\n". |
|
99 " -i\t'full path of the build log input file'\n". |
|
100 " -o\t'full path of the parsed output file'\n". |
|
101 " -filter\t'defines the string on the line, which we want to store'\n". |
|
102 " -pos\t'defines the position for filter string on the line, 0 index is used by default'\n". |
|
103 " -ex\t'defines a list of strings, which excludes lines containing one of these strings'\n". |
|
104 " -zip\t'full path for the primary zip file'\n". |
|
105 " -zip_prefix\t'prefix for each secondary zip file name when 'double' zipping method selected'\n". |
|
106 " -zip2zip\t'enables the 'double' zipping'\n\n"; |
|
107 |
|
108 print "Example1: Parse the build log\n"; |
|
109 print "perl parse_what_log.pl -i \\log\\S60_build.log -o \\Parsed_S60_build.log -filter \"epoc32\" -pos 1\n\n"; |
|
110 |
|
111 print "Example2: Parse the build log and zip binaries\n"; |
|
112 print "perl parse_what_log.pl -i \\log\\S60_build.log -o \\Parsed_S60_build.log -filter \"\\epoc32\" -pos -zip \\zip\\S60_binaries\n\n"; |
|
113 |
|
114 print "Example3: Parse the build log and double zip binaries\n"; |
|
115 print "perl parse_what_log.pl -i \\log\\S60_build.log -o \\Parsed_S60_build.log -filter \"\\epoc32\" -pos -zip \\zip\\S60_binaries -zip2zip\n\n"; |
|
116 |
|
117 print "Example4: Parse the build log with exclude list\n"; |
|
118 print "perl parse_what_log.pl -i \\log\\S60_build.log -o \\Parsed_S60_build.log -filter \"\\epoc32\" -pos -ex \"warning\" -ex \"\\build\"\n\n"; |
|
119 |
|
120 exit; |
|
121 } |
|
122 |
|
123 # disable the meaning of characters used in regular expressions |
|
124 # $parse_start_string = lc("\Q$parse_start_string\E"); |
|
125 $parse_end_string = lc("\Q$parse_end_string\E"); |
|
126 $filter_string = lc($filter_string); |
|
127 foreach $i (@exclude_list) { |
|
128 $i = lc("\Q$i\E"); |
|
129 $exclude_list[$ii++] = $i; |
|
130 } |
|
131 |
|
132 } |
|
133 |
|
134 # Opens and reads the log file to memory |
|
135 sub readLogFile |
|
136 { |
|
137 foreach my $log_file(@build_log) { |
|
138 |
|
139 open (IN,"$log_file") or die "Cannot open $log_file for reading: $!"; |
|
140 @lines=<IN>; |
|
141 parse_log(); |
|
142 close IN; |
|
143 } |
|
144 } |
|
145 |
|
146 # Parses the input file |
|
147 # Uses configuration according user input |
|
148 sub parse_log { |
|
149 foreach (@lines){ |
|
150 chomp $_; |
|
151 |
|
152 if ($_=~/$parse_start_string/i || $_=~/ACTION=what/i) { # find starting point for data |
|
153 $start_found = 1; |
|
154 } |
|
155 elsif ($start_found) { |
|
156 if ($_=~/$app_key_word/i) { # find the path for bld.inf file |
|
157 @app_path = split /[\\||\/]/,$_; |
|
158 $app = $app_path[scalar(@app_path)-2]; # store application's name |
|
159 } |
|
160 if ($_=~/$parse_end_string/i) { # stop fetching data |
|
161 $start_found = 0; |
|
162 next; |
|
163 } |
|
164 $_ =~ s/\"//g; |
|
165 my $f = $_; |
|
166 $f = lc $f; |
|
167 if (($filter_position == index $f,$filter_string,$filter_position) && $start_found) { # fetch valid data only |
|
168 foreach $i (@exclude_list) { # check if data is having illegal words |
|
169 if ($_=~/$i/i) { |
|
170 $skip_line = 1; |
|
171 } |
|
172 } |
|
173 if (!$skip_line) { |
|
174 $_ =~ s/ /\n/g; |
|
175 push @{$components{$app}}, $_."\n"; # store the data under each app's name |
|
176 } |
|
177 } |
|
178 $skip_line = 0; |
|
179 } |
|
180 } |
|
181 @lines = (); |
|
182 } |
|
183 |
|
184 # Creates output and zip files according arguements |
|
185 # Takes the list of binaries and applications fetched from input file as an input |
|
186 sub handle_output { |
|
187 my $zip_cmd; |
|
188 |
|
189 # prepares double zipping if zip2zip enabled by user |
|
190 if ($zip2zip) { |
|
191 mkdir $temp_folder; |
|
192 } |
|
193 if ($zip_prefix && $zip_prefix !~ /_$/) { # use the prefix from user input |
|
194 $zip_prefix .= "_"; |
|
195 } |
|
196 |
|
197 # generates zipping command if zip enabled by user |
|
198 if ($zip) { |
|
199 $zip_cmd ="zip -r "; |
|
200 if ($zip2zip) { |
|
201 $zip_cmd .="-j -m "; |
|
202 } |
|
203 if ($zip !~ /\.zip$/i) { |
|
204 $zip .= ".zip"; |
|
205 } |
|
206 $zip_cmd .="${zip} -@ "; |
|
207 |
|
208 open (ZIP, "| $zip_cmd"); |
|
209 } |
|
210 |
|
211 if ($what_log) { |
|
212 open (OUT_WHAT,">$what_log") or die "Cannot open $what_log for writing: $!"; # create or open output file |
|
213 } |
|
214 |
|
215 # goes through all apps and their binary lists |
|
216 foreach my $app (sort keys %components) { |
|
217 if ($zip2zip) { |
|
218 my $zip2zip_cmd = "call zip -r ${temp_folder}${zip_prefix}${app}.zip -@ "; # generate double zipping command |
|
219 open (ZIP2ZIP, "| $zip2zip_cmd"); |
|
220 print ZIP2ZIP @{$components{$app}}; # performs the zipping in temp folder |
|
221 close ZIP2ZIP; |
|
222 } |
|
223 elsif ($zip) { |
|
224 print ZIP @{$components{$app}}; # performs the normal zipping |
|
225 } |
|
226 if ($what_log) { |
|
227 print OUT_WHAT @{$components{$app}}; # prints the binary list to output file |
|
228 } |
|
229 } |
|
230 if ($what_log) { |
|
231 close OUT_WHAT; |
|
232 } |
|
233 |
|
234 if ($zip2zip && $zip) { |
|
235 print ZIP $temp_folder."*\n"; # zips the zip files in temp folder |
|
236 } |
|
237 if ($zip) { |
|
238 close ZIP; |
|
239 } |
|
240 if ($zip2zip) { |
|
241 rmdir $temp_folder; |
|
242 } |
|
243 } |
|
244 # EOF |
|