|
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 # Finds MMP paths from component makefiles and forwards them to MMP parser |
|
17 # |
|
18 #!perl -w |
|
19 use FindBin; |
|
20 my $trace_compiler_path; |
|
21 |
|
22 BEGIN |
|
23 { |
|
24 # Get current directory as TraceCompiler path |
|
25 $trace_compiler_path = $FindBin::Bin; # e.g. X:/epoc32/tools |
|
26 $trace_compiler_path =~ s/\\/\//g; # Replace all "\" with "/" |
|
27 $trace_compiler_path =~ s/\/$//; # Remove possible trailing slash |
|
28 } |
|
29 |
|
30 use lib $trace_compiler_path; |
|
31 |
|
32 use strict; |
|
33 use env; |
|
34 use Cwd; |
|
35 use tracecompiler; |
|
36 use tracecompiler_mmp_data; |
|
37 |
|
38 # EPOC root is two levels down from TraceCompiler level |
|
39 my $epocroot = tracecompiler::concatenatePath($trace_compiler_path, "../../"); |
|
40 $epocroot =~ s/\/$//; # Remove possible trailing slash |
|
41 my $drive = substr($epocroot, 0, 2); |
|
42 my $build_target; |
|
43 my $project_name; |
|
44 my $action = "RUN"; |
|
45 |
|
46 # Get Java command or EXIT if not found |
|
47 my $java_command = tracecompiler::getJavaCommand(); |
|
48 |
|
49 if (not defined $java_command) |
|
50 { |
|
51 print STDERR "Java 1.5 or newer required!\n"; |
|
52 exit; |
|
53 } |
|
54 |
|
55 #------------------------------------------------------- |
|
56 # Go through command line arguments |
|
57 #------------------------------------------------------- |
|
58 while ( @ARGV ) |
|
59 { |
|
60 my $arg = shift(@ARGV); |
|
61 |
|
62 # Print version information |
|
63 if ($arg eq "-v") |
|
64 { |
|
65 my $version = tracecompiler::getTraceCompilerVersion(); |
|
66 print $version; |
|
67 exit; |
|
68 } |
|
69 # Clean TraceCompiler generated files |
|
70 elsif ($arg eq "-clean") |
|
71 { |
|
72 $action = "CLEAN"; |
|
73 } |
|
74 # Finalize TraceCompiler running |
|
75 elsif ($arg eq "-final") |
|
76 { |
|
77 $action = "FINAL"; |
|
78 } |
|
79 # Build target (e.g. armv5) |
|
80 elsif (not defined $build_target) |
|
81 { |
|
82 $build_target = $arg; |
|
83 } |
|
84 # Project name (e.g. MyComponent) |
|
85 else |
|
86 { |
|
87 $project_name = $arg; |
|
88 } |
|
89 } |
|
90 |
|
91 #------------------------------------------------------- |
|
92 # Build target must now be defined or print usage info |
|
93 #------------------------------------------------------- |
|
94 if (not defined $build_target) |
|
95 { |
|
96 my $version = tracecompiler::getTraceCompilerVersion(); |
|
97 print $version; |
|
98 print "\nUsage: tracecompiler.pl build_target in the folder containing bld.inf. bldmake bldfiles must be run before this.\n"; |
|
99 print "Example: tracecompiler.pl armv5\n"; |
|
100 exit; |
|
101 } |
|
102 |
|
103 my $return_string = ""; |
|
104 |
|
105 #------------------------------------------------------- |
|
106 # Find component makefile path from abld.bat |
|
107 #------------------------------------------------------- |
|
108 tracecompiler::debugTraceCompilerVersion(); |
|
109 tracecompiler::debugMsg("Find component makefile path from abld.bat"); |
|
110 open(ABLD, "<abld.bat") or die $!; |
|
111 my $makefile; |
|
112 while (<ABLD>) |
|
113 { |
|
114 if (/ABLD.PL/) |
|
115 { |
|
116 my $makefilepath = $_; |
|
117 $makefilepath =~ s/perl -S ABLD.PL "(.*)\\" .*$/$1/; |
|
118 chop($makefilepath); |
|
119 |
|
120 # Change all "\" characters to "/" |
|
121 $makefilepath =~ s/\\/\//g; |
|
122 |
|
123 $makefilepath = "$epocroot/epoc32/build".$makefilepath; |
|
124 $makefile = $makefilepath.$build_target.".MAKE"; |
|
125 } |
|
126 } |
|
127 close ABLD or die $!; |
|
128 |
|
129 #------------------------------------------------------- |
|
130 # Find project makefile paths from component makefile |
|
131 #------------------------------------------------------- |
|
132 my @projectmakefiles; |
|
133 my $mmps; |
|
134 |
|
135 tracecompiler::debugMsg("Find project makefile paths from component makefile $makefile"); |
|
136 |
|
137 open(MAKEFILE, "<$makefile") or (print STDERR "Cannot open makefile $makefile\n" and exit); |
|
138 while (<MAKEFILE>) |
|
139 { |
|
140 my $line = $_; |
|
141 |
|
142 if ($line =~ /\"([^\"]+?)\"\s+\"PRJ_.*MMPFILES\s+MMP\"\s+\"([^\"]+?)\"/i) |
|
143 { |
|
144 my $bldinf = $1; |
|
145 my $mmp = $2; |
|
146 |
|
147 tracecompiler::debugMsg("Found BLD file: $bldinf"); |
|
148 |
|
149 # Remove bld.inf from the end of the path |
|
150 $bldinf =~ s/(.*)[\\\/].*/$1\//; |
|
151 |
|
152 my $mmp_file = tracecompiler::concatenatePath($bldinf, $mmp); |
|
153 |
|
154 # Change all "//" to "/" |
|
155 $mmp_file =~ s/\/\//\//g; |
|
156 |
|
157 # If .mmp is missing from the end, add it |
|
158 if ($mmp_file !~ /\.mmp$/i) |
|
159 { |
|
160 $mmp_file .= ".mmp"; |
|
161 } |
|
162 |
|
163 tracecompiler::debugMsg("Found MMP file: $drive$mmp_file\n"); |
|
164 |
|
165 # If project name is defined, only add that MMP to the list of mmp files |
|
166 if (defined $project_name) |
|
167 { |
|
168 if ($mmp_file =~ /($project_name.mmp)$/i) |
|
169 { |
|
170 $mmps .= $drive . $mmp_file . " "; |
|
171 } |
|
172 } |
|
173 else |
|
174 { |
|
175 $mmps .= $drive . $mmp_file . " "; |
|
176 } |
|
177 } |
|
178 |
|
179 } |
|
180 close MAKEFILE or die $!; |
|
181 |
|
182 #------------------------------------------------------- |
|
183 # Call the MMP parser for each MMP (or clean / final) |
|
184 #------------------------------------------------------- |
|
185 if (defined $mmps) |
|
186 { |
|
187 foreach my $mmp (split(" ", $mmps)) |
|
188 { |
|
189 # Pass MMP file path to Parse MMP |
|
190 if ($action eq "RUN") |
|
191 { |
|
192 my $command = "perl $trace_compiler_path/tracecompiler_parse_mmp.pl $mmp"; |
|
193 tracecompiler::debugMsg("Call the MMP parser. Command: $command\n"); |
|
194 print qx($command); |
|
195 } |
|
196 |
|
197 # Clean files using this MMP |
|
198 elsif ($action eq "CLEAN") |
|
199 { |
|
200 my $mmpObject = tracecompiler_mmp_data->new($mmp); |
|
201 cleanTraceCompilerFiles($mmpObject); |
|
202 } |
|
203 |
|
204 # Finalize files using this MMP |
|
205 elsif ($action eq "FINAL") |
|
206 { |
|
207 my $mmpObject = tracecompiler_mmp_data->new($mmp); |
|
208 finalizeTraceCompilerRun($mmpObject); |
|
209 } |
|
210 } |
|
211 } |
|
212 else |
|
213 { |
|
214 tracecompiler::debugMsg("Could not find any MMP files!"); |
|
215 } |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 #-------------------------------------------------------# |
|
222 #-------------------------------------------------------# |
|
223 #--------------------SUBROUTINES------------------------# |
|
224 #-------------------------------------------------------# |
|
225 #-------------------------------------------------------# |
|
226 |
|
227 #------------------------------------------------------- |
|
228 # Cleans TraceCompiler generated files |
|
229 #------------------------------------------------------- |
|
230 sub cleanTraceCompilerFiles |
|
231 { |
|
232 tracecompiler::debugMsg("Clean TraceCompiler Files"); |
|
233 my $mmpObj = $_[0]; |
|
234 if($mmpObj->{tracespaths}) { |
|
235 foreach my $tracesFolder (@{$mmpObj->{tracespaths}}) |
|
236 { |
|
237 if (-e $tracesFolder and opendir(DIR, $tracesFolder)) |
|
238 { |
|
239 while (defined(my $file = readdir(DIR))) |
|
240 { |
|
241 # Delete files ending with *Traces.h |
|
242 if ($file =~ /Traces\.h$/i) |
|
243 { |
|
244 print "Cleaning: " . $tracesFolder . "/" . $file . "\n"; |
|
245 unlink $tracesFolder . "/" . $file || print $!; |
|
246 } |
|
247 # Delete cache files |
|
248 elsif ($file =~ /\.cache$/i) |
|
249 { |
|
250 print "Cleaning: " . $tracesFolder . "/" . $file . "\n"; |
|
251 unlink $tracesFolder . "/" . $file || print $!; |
|
252 } |
|
253 } |
|
254 closedir(DIR); |
|
255 } |
|
256 } |
|
257 } |
|
258 |
|
259 tracecompiler::debugMsg("Cleaning TraceCompiler Files ready\n"); |
|
260 |
|
261 # Finalize TraceCompiler run |
|
262 finalizeTraceCompilerRun($mmpObj); |
|
263 } |
|
264 |
|
265 #------------------------------------------------------- |
|
266 # Finalizes TraceCompiler run |
|
267 #------------------------------------------------------- |
|
268 sub finalizeTraceCompilerRun |
|
269 { |
|
270 tracecompiler::debugMsg("Finalize TraceCompiler Run"); |
|
271 my $mmpObj = $_[0]; |
|
272 if($mmpObj->{tracespaths}) { |
|
273 foreach my $tracesFolder (@{$mmpObj->{tracespaths}}) |
|
274 { |
|
275 my $defFile = $tracesFolder . "/" . "OstTraceDefinitions.h"; |
|
276 # Open OstTraceDefinitions.h and read stuff to array |
|
277 if (-e $defFile and open(FILE,"<$defFile")) |
|
278 { |
|
279 my @lines = <FILE>; |
|
280 close(FILE); |
|
281 |
|
282 # Write stuff back to OstTraceDefinitions.h |
|
283 open(FILE,">$defFile") || exit; |
|
284 foreach my $line (@lines) |
|
285 { |
|
286 # Comment out the define |
|
287 $line =~ s/(.*)#define OST_TRACE_COMPILER_IN_USE/\/\/ #define OST_TRACE_COMPILER_IN_USE/; |
|
288 print FILE $line; |
|
289 } |
|
290 close(FILE); |
|
291 } |
|
292 } |
|
293 } |
|
294 |
|
295 tracecompiler::debugMsg("Finalizing TraceCompiler Run ready\n"); |
|
296 } |