|
1 # |
|
2 # Copyright (c) 2009-2010 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: |
|
15 # |
|
16 # Parses UID and source files from given MMP files. Starts TraceCompiler Java application. |
|
17 # |
|
18 #!perl -w |
|
19 use FindBin; |
|
20 my $trace_compiler_path; |
|
21 |
|
22 |
|
23 BEGIN |
|
24 { |
|
25 # Get current directory as TraceCompiler path |
|
26 $trace_compiler_path = $FindBin::Bin; # e.g. X:/epoc32/tools |
|
27 $trace_compiler_path =~ s/\\/\//g; # Replace all "\" with "/" |
|
28 $trace_compiler_path =~ s/\/$//; # Remove possible trailing slash |
|
29 } |
|
30 |
|
31 use lib $trace_compiler_path; |
|
32 |
|
33 use strict; |
|
34 use warnings; |
|
35 use env; |
|
36 use FileHandle; |
|
37 use IPC::Open3; |
|
38 use tracecompiler; |
|
39 use tracecompiler_mmp_data; |
|
40 |
|
41 my $java_command = tracecompiler::getJavaCommand(); |
|
42 |
|
43 if (not defined $java_command) |
|
44 { |
|
45 print STDERR "Java 1.5 or newer required!\n"; |
|
46 exit; |
|
47 } |
|
48 |
|
49 # Global variables |
|
50 my $project_name; |
|
51 my $traces_folder = ""; |
|
52 |
|
53 |
|
54 # run from class files |
|
55 |
|
56 my $command = "$java_command -classpath $trace_compiler_path/tracecompiler com.nokia.tracecompiler.TraceCompilerMain"; |
|
57 |
|
58 # run from jar file |
|
59 #my $command = "$java_command -jar $trace_compiler_path/tracecompiler/tracecompiler.jar"; |
|
60 |
|
61 # Open MMP file |
|
62 foreach my $mmp_file (@ARGV) |
|
63 { |
|
64 $traces_folder = ""; |
|
65 $project_name = $mmp_file; |
|
66 |
|
67 # Take the module name from the MMP file path. e.g. "X:/temp/mycomponent.mmp" would create "mycomponent" |
|
68 $project_name =~ s/.*\/([^\.]*).*/$1/; |
|
69 |
|
70 tracecompiler::debugMsg("Module name: $project_name"); |
|
71 |
|
72 # Parse sources in an own function |
|
73 my $mmpObject = tracecompiler_mmp_data->new($mmp_file); |
|
74 |
|
75 # There must be UID |
|
76 if (!$mmpObject->{uid}) |
|
77 { |
|
78 tracecompiler::debugMsg("UID is not defined, don't call TraceCompiler!"); |
|
79 exit; |
|
80 } |
|
81 if (!$mmpObject->{target}) |
|
82 { |
|
83 tracecompiler::debugMsg("Target not defined, don't call TraceCompiler!"); |
|
84 exit; |
|
85 } |
|
86 if (!$mmpObject->{type}) |
|
87 { |
|
88 tracecompiler::debugMsg("Target type not defined, don't call TraceCompiler!"); |
|
89 exit; |
|
90 } |
|
91 if (!$mmpObject->{ext}) |
|
92 { |
|
93 tracecompiler::debugMsg("Target extension not defined, don't call TraceCompiler!"); |
|
94 exit; |
|
95 } |
|
96 |
|
97 # find out the right traces folder to use if ther is more than one and set the project name accordingly. |
|
98 # the following order of the code is very important. |
|
99 my $tmp; |
|
100 if ($mmpObject->{tracespaths}) |
|
101 { |
|
102 #Check if there is one of the expected format |
|
103 |
|
104 #search for /trace/<target>_<ext> |
|
105 $tmp = $mmpObject->{target} ."_" . $mmpObject->{ext}; |
|
106 my @list = grep(/.*\/traces\/$tmp\s*$/i, @{$mmpObject->{tracespaths}}); |
|
107 |
|
108 if (scalar @list > 0) |
|
109 { |
|
110 $traces_folder = pop(@list); |
|
111 $project_name = $mmpObject->{target} ."_" . $mmpObject->{ext}; |
|
112 tracecompiler::debugMsg("Found traces folder 1: $traces_folder" ); |
|
113 } |
|
114 |
|
115 if ($traces_folder eq "" ) |
|
116 { |
|
117 #search for /traces_<target>_<type> |
|
118 $tmp = $mmpObject->{target} ."_" . $mmpObject->{type}; |
|
119 @list = grep(/.*\/traces_$tmp\s*$/i, @{$mmpObject->{tracespaths}}); |
|
120 if (scalar @list > 0) |
|
121 { |
|
122 $traces_folder = pop(@list); |
|
123 $project_name = $mmpObject->{target} . "_" . $mmpObject->{type}; |
|
124 tracecompiler::debugMsg("Found traces folder 2: $traces_folder" ); |
|
125 } |
|
126 } |
|
127 |
|
128 if ($traces_folder eq "" ) |
|
129 { |
|
130 #search for /traces_<mmpname> |
|
131 @list = grep(/.*\/traces_$project_name\s*$/i, @{$mmpObject->{tracespaths}}); |
|
132 if (scalar @list > 0) |
|
133 { |
|
134 $traces_folder = pop(@list); |
|
135 tracecompiler::debugMsg("Found traces folder 3: $traces_folder" ); |
|
136 } |
|
137 } |
|
138 |
|
139 if ($traces_folder eq "" ) |
|
140 { |
|
141 #search for /traces |
|
142 @list = grep(/.*\/traces\s*$/i, @{$mmpObject->{tracespaths}}); |
|
143 if (scalar @list > 0) |
|
144 { |
|
145 $traces_folder = pop(@list); |
|
146 tracecompiler::debugMsg("Found traces folder 4: $traces_folder" ); |
|
147 } |
|
148 } |
|
149 } |
|
150 else |
|
151 { |
|
152 tracecompiler::debugMsg("No Traces folder was found in userinclude, don't call TraceCompiler!"); |
|
153 exit; |
|
154 } |
|
155 |
|
156 if (!$mmpObject->{sources}) |
|
157 { |
|
158 tracecompiler::debugMsg("No sources found!"); |
|
159 exit; |
|
160 } |
|
161 |
|
162 |
|
163 # IMPORTANT NOTE: |
|
164 # please note that IPC::open3() is the only suitable api available in the perl version 5.6.1 used in ONB |
|
165 # but it has a limit. If the size of the command is more than 264, perl will crash and it seems to be a windows limit |
|
166 # rather perl. |
|
167 # Therefore we have to parse the mmp and the traces folder from the stdin (*WRITER in this case) and |
|
168 # relax the new TraceCompiler API to allow this if they are not specified on the command line. |
|
169 # It's not an issue in Raptor as it calls TraceCompiler directly. |
|
170 # |
|
171 $command .= " --uid=" . $mmpObject->{uid} . " --project=" . $project_name; |
|
172 |
|
173 tracecompiler::debugMsg("\nCall the Java TraceCompiler. Command: $command\n"); |
|
174 |
|
175 # Create TraceCompiler process |
|
176 local (*READER, *WRITER); |
|
177 my $ pid = open3(\*WRITER, \*READER, \*READER, $command); |
|
178 |
|
179 # Remove duplicates from the sources list |
|
180 my %seen = (); |
|
181 my @uniqueSources = (); |
|
182 foreach my $item (@{$mmpObject->{sources}}) |
|
183 { |
|
184 push(@uniqueSources, $item) unless $seen{$item}++; |
|
185 } |
|
186 |
|
187 tracecompiler::debugMsg("Send mmp file: $mmp_file"); |
|
188 print WRITER "--mmp=$mmp_file\n"; |
|
189 |
|
190 tracecompiler::debugMsg("Send traces folder path: $traces_folder"); |
|
191 print WRITER "--traces=$traces_folder\n"; |
|
192 |
|
193 |
|
194 # Send sources to the TraceCompiler |
|
195 foreach my $source (@uniqueSources) |
|
196 { |
|
197 tracecompiler::debugMsg("Send source: $source"); |
|
198 print WRITER "$source\n"; |
|
199 } |
|
200 |
|
201 # Send the end of the source files tag |
|
202 print WRITER "*ENDOFSOURCEFILES*\n"; |
|
203 WRITER->autoflush(1); |
|
204 |
|
205 # Gather up the response from the TraceCompiler |
|
206 my $compilerReturn = ""; |
|
207 foreach my $line (<READER>) |
|
208 { |
|
209 tracecompiler::debugMsg("Response line from TraceCompiler: $line"); |
|
210 $compilerReturn .= $line; |
|
211 } |
|
212 |
|
213 # If Compiler doesn't return anything or we get no class found error from Java, don't print anything |
|
214 if ($compilerReturn ne "" and $compilerReturn !~ /NoClassDefFoundError/) |
|
215 { |
|
216 tracecompiler::debugMsg("TraceCompiler succeeded! Returned: $compilerReturn"); |
|
217 print "\n******************* TRACECOMPILER STARTS *******************\n\n"; |
|
218 print "Building traces for component $project_name. Component UID: 0x$mmpObject->{uid}.\n"; |
|
219 print $compilerReturn . "\n"; |
|
220 print "\n******************* TRACECOMPILER ENDS *********************\n\n"; |
|
221 } |
|
222 else |
|
223 { |
|
224 tracecompiler::debugMsg("No traces were generated. Returned:\n$compilerReturn\n"); |
|
225 } |
|
226 } |