1 # |
|
2 # Copyright (c) 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 # Module for TraceCompiler. parse the mmp file and prepare an object to be re-used by tracecompiler.pl and tracecompiler_perse_mmp.pl |
|
17 # |
|
18 package tracecompiler_mmp_data; |
|
19 |
|
20 use strict; |
|
21 use warnings; |
|
22 use File::Basename; |
|
23 use tracecompiler; |
|
24 sub readMmp($); |
|
25 |
|
26 |
|
27 my $component_name; |
|
28 |
|
29 |
|
30 sub new |
|
31 { |
|
32 my $pkg = shift; |
|
33 my $self = {}; |
|
34 bless $self,$pkg; |
|
35 my $mmp = shift; |
|
36 if (defined($mmp) and -e $mmp) { |
|
37 tracecompiler::debugMsg("Starting to parse MMP file: $mmp"); |
|
38 my $file_path = $mmp; |
|
39 $component_name = basename $mmp; |
|
40 |
|
41 # Take the module name from the MMP file path. e.g. "X:/temp/mycomponent.mmp" would create "mycomponent" |
|
42 $component_name =~ s/([^\.]*).*/$1/; |
|
43 |
|
44 $self->{mmpName} = $mmp; |
|
45 $self->readMmp($mmp); |
|
46 } else |
|
47 { |
|
48 tracecompiler::debugMsg("tracecompiler_mmp_data :: Valid MMP file must be provided ...\n"); |
|
49 } |
|
50 |
|
51 return $self; |
|
52 } |
|
53 |
|
54 # parse mmp and get the infos we need. This method moved from tracecompiler_parse_mmp.pl to here with some add-on |
|
55 sub readMmp($) |
|
56 { |
|
57 my $self = shift; |
|
58 my $file = shift; |
|
59 if (-e $file) |
|
60 { |
|
61 tracecompiler::debugMsg("Starting to parse file: $file"); |
|
62 my @sources; |
|
63 my @tracesfolders; |
|
64 my $in_comment_block = 0; |
|
65 |
|
66 # Get file path (remove file + extension) |
|
67 my $file_path = dirname $file; |
|
68 |
|
69 # Change "//" to "/" |
|
70 $file_path =~ s/\/\//\//g; |
|
71 |
|
72 my $current_src_path = $file_path; |
|
73 |
|
74 # Go through lines |
|
75 open FILE, "<$file" or die $!; |
|
76 foreach my $line (<FILE>) |
|
77 { |
|
78 # Check if contains includes |
|
79 if ($line =~ /#include.+\"(.*)?\"/i) |
|
80 { |
|
81 my $includedFile = $1; |
|
82 |
|
83 # Get absolute path if the first character is not "\" or b"/" |
|
84 if ($includedFile =~ /^[^\\\/]/) |
|
85 { |
|
86 $includedFile = tracecompiler::concatenatePath($file_path, $includedFile); |
|
87 } |
|
88 else |
|
89 { |
|
90 $includedFile = substr($file_path, 0, 2) . $includedFile; |
|
91 } |
|
92 |
|
93 if (defined $includedFile) |
|
94 { |
|
95 tracecompiler::debugMsg("Found #include from $file. Start parsing it..\n"); |
|
96 $self->readMmp($includedFile); |
|
97 } |
|
98 } |
|
99 |
|
100 # Check if in comment block |
|
101 if ($in_comment_block > 0) |
|
102 { |
|
103 if ($line =~ /\*\/(.*)/) |
|
104 { |
|
105 $line = $1; |
|
106 $in_comment_block--; |
|
107 } |
|
108 if ($in_comment_block == 0) |
|
109 { |
|
110 # Comment block ended, continue parsing the line |
|
111 } |
|
112 else |
|
113 { |
|
114 # We are still in comment block, jump to next line |
|
115 next; |
|
116 } |
|
117 } |
|
118 |
|
119 # Delete possible comments in one line |
|
120 $line =~ s/\/\/.*//; # // |
|
121 $line =~ s/\/\*.*\*\///; # /* */ |
|
122 |
|
123 if ($line =~ /(.*?)\/\*/) |
|
124 { |
|
125 $line = $1; |
|
126 $in_comment_block++; |
|
127 } |
|
128 |
|
129 # Find uid |
|
130 if ($line =~ /uid.+0x([a-fA-F0-9]+)?/i) |
|
131 { |
|
132 $self->{uid} = $1; |
|
133 |
|
134 tracecompiler::debugMsg("Found Uid: $self->{uid}"); |
|
135 } |
|
136 |
|
137 #Find target |
|
138 if($line =~ /target\s+(\S+)\.(\S+)/i) |
|
139 { |
|
140 $self->{target} = $1; |
|
141 $self->{ext} = $2; |
|
142 } |
|
143 |
|
144 #Find target type |
|
145 if($line =~ /targettype\s+(\S+)/i) |
|
146 { |
|
147 $self->{type} = $1; |
|
148 } |
|
149 |
|
150 # Find source path |
|
151 if ($line =~ /sourcepath\s+([^\s]+)/i) |
|
152 { |
|
153 my $src_path = $1; |
|
154 |
|
155 # Get absolute path if the first character is not "\" or "/" |
|
156 if ($src_path =~ /^[^\\\/]/) |
|
157 { |
|
158 $current_src_path = tracecompiler::concatenatePath($file_path, $src_path . "/"); |
|
159 } |
|
160 else |
|
161 { |
|
162 $current_src_path = substr($file_path, 0, 2) . $src_path; |
|
163 } |
|
164 |
|
165 tracecompiler::debugMsg("Source path changed to: $current_src_path"); |
|
166 } |
|
167 |
|
168 # Find sources |
|
169 while ($line =~ /source\s+([^\s]+)/i) |
|
170 { |
|
171 my $src = $1; |
|
172 |
|
173 my $src_path = tracecompiler::concatenatePath($current_src_path, $src); |
|
174 |
|
175 if (-e $src_path) |
|
176 { |
|
177 push(@sources, $src_path); |
|
178 |
|
179 tracecompiler::debugMsg("Found source: $src_path"); |
|
180 } |
|
181 else |
|
182 { |
|
183 tracecompiler::debugMsg("Source doesn't exist!: $src_path"); |
|
184 } |
|
185 |
|
186 $line =~ s/\Q$src//; |
|
187 } |
|
188 |
|
189 #Find unserincludes |
|
190 if ($line =~ /userinclude\s+([^\s]+)/i) |
|
191 { |
|
192 tracecompiler::debugMsg("Found userinclude: $line"); |
|
193 my $userinclude = $1; |
|
194 $userinclude =~ s/\\/\//g; |
|
195 my $tmp1 = $self->{target} . "_" . $self->{ext}; |
|
196 my $tmp2 = $self->{target} . "_" . $self->{type}; |
|
197 if ( $userinclude =~ /.*\/traces\/$tmp1$/i |
|
198 or $userinclude =~ /.*\/traces_$tmp2$/i |
|
199 or $userinclude =~ /.*\/traces_$component_name$/i |
|
200 or $userinclude =~ /.*\/traces$/i) |
|
201 { |
|
202 tracecompiler::debugMsg("Found traces userinclude: $userinclude"); |
|
203 push(@tracesfolders, $userinclude); |
|
204 } |
|
205 } |
|
206 } |
|
207 if (scalar @sources > 0) |
|
208 { |
|
209 $self->{sources} = [@sources]; |
|
210 } |
|
211 if (scalar @tracesfolders > 0) |
|
212 { |
|
213 $self->{tracespaths} = [@tracesfolders]; |
|
214 } |
|
215 close FILE; |
|
216 |
|
217 tracecompiler::debugMsg("Ending the parsing of MMP file: $file\n"); |
|
218 } else |
|
219 { |
|
220 tracecompiler::debugMsg("Could not find file: $file\n"); |
|
221 } |
|
222 |
|
223 } |
|
224 |
|
225 1; |
|