602
|
1 |
# Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
# All rights reserved.
|
|
3 |
# This component and the accompanying materials are made available
|
|
4 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
# which accompanies this distribution, and is available
|
|
6 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
#
|
|
8 |
# Initial Contributors:
|
|
9 |
# Nokia Corporation - initial contribution.
|
|
10 |
#
|
|
11 |
# Contributors:
|
|
12 |
#
|
|
13 |
# Description:
|
|
14 |
#
|
|
15 |
#
|
|
16 |
# Description:
|
|
17 |
# Symbian::CBR::MRP
|
|
18 |
#
|
|
19 |
|
|
20 |
package Symbian::CBR::MRP;
|
|
21 |
|
|
22 |
use strict;
|
|
23 |
use Carp;
|
|
24 |
use File::Spec;
|
|
25 |
use base qw(Symbian::CBR::MRPInterface);
|
|
26 |
|
|
27 |
|
|
28 |
sub new {
|
|
29 |
my $pkg = shift;
|
|
30 |
my $mrpName = shift;
|
|
31 |
my $verbose = shift;
|
|
32 |
|
|
33 |
if (!$mrpName || shift) {
|
|
34 |
# caller(0))[3] gives the package and the method called, e.g. Symbian::CBR::MRP::new
|
|
35 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n";
|
|
36 |
}
|
|
37 |
|
|
38 |
my $self = {
|
|
39 |
'mrpName' => $mrpName,
|
|
40 |
'verbose' => $verbose};
|
|
41 |
|
|
42 |
bless $self, $pkg;
|
|
43 |
|
|
44 |
return $self;
|
|
45 |
}
|
|
46 |
|
|
47 |
sub SetIPR {
|
|
48 |
my $self = shift;
|
|
49 |
my $category = shift;
|
|
50 |
my $path = lc(shift) || 'default';
|
|
51 |
my $exportRestricted = (shift) ? 1 : 0;
|
|
52 |
|
|
53 |
if (!$category || shift) {
|
|
54 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n";
|
|
55 |
}
|
|
56 |
|
|
57 |
if ($category !~ /^[a-z]$/i) {
|
|
58 |
#Check that the IPR category specified is indeed a valid category
|
|
59 |
croak "Error: IPR category $category is invalid\n";
|
|
60 |
}
|
|
61 |
|
|
62 |
$path = File::Spec->canonpath($path); # Normalise the path
|
|
63 |
|
|
64 |
# remove trailing slashes
|
|
65 |
$path =~ s/[\\\/]$//;
|
|
66 |
|
|
67 |
if (exists $self->{unresolvedIPR}->{$path}) {
|
|
68 |
return 0;
|
|
69 |
}
|
|
70 |
|
|
71 |
$self->{unresolvedIPR}->{$path} = {
|
|
72 |
category => uc($category),
|
|
73 |
exportRestricted => $exportRestricted};
|
|
74 |
|
|
75 |
return 1;
|
|
76 |
}
|
|
77 |
|
|
78 |
sub SetComponent {
|
|
79 |
my $self = shift;
|
|
80 |
my $operand = shift;
|
|
81 |
|
|
82 |
if (!$operand || shift) {
|
|
83 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n";
|
|
84 |
}
|
|
85 |
|
|
86 |
if (exists $self->{componentName}) {
|
|
87 |
return 0;
|
|
88 |
}
|
|
89 |
|
|
90 |
$self->{componentName} = $operand;
|
|
91 |
|
|
92 |
return 1;
|
|
93 |
}
|
|
94 |
|
|
95 |
sub SetNotesSource {
|
|
96 |
my $self = shift;
|
|
97 |
my $operand = shift;
|
|
98 |
|
|
99 |
if (!$operand || shift) {
|
|
100 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n";
|
|
101 |
}
|
|
102 |
|
|
103 |
if (exists $self->{notesSource}) {
|
|
104 |
return 0;
|
|
105 |
}
|
|
106 |
|
|
107 |
$operand = File::Spec->canonpath($operand); # Normalise the path
|
|
108 |
|
|
109 |
if (!-f $operand) {
|
|
110 |
croak "Error: Notes source \"$operand\" does not exist\n";
|
|
111 |
}
|
|
112 |
|
|
113 |
$self->{notesSource} = $operand;
|
|
114 |
|
|
115 |
return 1;
|
|
116 |
}
|
|
117 |
|
|
118 |
sub SetSource {
|
|
119 |
my $self = shift;
|
|
120 |
my $operand = shift;
|
|
121 |
|
|
122 |
if (!$operand || shift) {
|
|
123 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n";
|
|
124 |
}
|
|
125 |
|
|
126 |
$operand = File::Spec->canonpath($operand); # Normalise the path
|
|
127 |
|
|
128 |
#remove trailing slashes
|
|
129 |
$operand =~ s/[\\\/]$//;
|
|
130 |
|
|
131 |
if (!-e $operand) {
|
|
132 |
croak "Error: Source \"$operand\" does not exist\n";
|
|
133 |
}
|
|
134 |
|
|
135 |
if (exists $self->{sourceItems}->{$operand}) {
|
|
136 |
return 0;
|
|
137 |
}
|
|
138 |
|
|
139 |
$self->{sourceItems}->{$operand} = 1;
|
|
140 |
|
|
141 |
return 1;
|
|
142 |
}
|
|
143 |
|
|
144 |
sub SetBinary {
|
|
145 |
my $self = shift;
|
|
146 |
my @operand = @{shift()} if (ref $_[0] eq 'ARRAY');
|
|
147 |
my $test = (shift) ? 1 : 0;
|
|
148 |
my $remove = (shift) ? 1 : 0;
|
|
149 |
|
|
150 |
if (!scalar(@operand) || shift) {
|
|
151 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n";
|
|
152 |
}
|
|
153 |
|
|
154 |
my $path = shift @operand;
|
|
155 |
|
|
156 |
$path = File::Spec->canonpath($path); # Normalise the path
|
|
157 |
|
|
158 |
push @{$self->{binary}}, {
|
|
159 |
path => $path,
|
|
160 |
test => $test,
|
|
161 |
remove => $remove,
|
|
162 |
words => [@operand]};
|
|
163 |
}
|
|
164 |
|
|
165 |
sub SetExports {
|
|
166 |
my $self = shift;
|
|
167 |
my $operand = shift;
|
|
168 |
my $test = (shift) ? 1 : 0;
|
|
169 |
my $dependantComponent = shift;
|
|
170 |
|
|
171 |
if (!$operand || shift) {
|
|
172 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n";
|
|
173 |
}
|
|
174 |
|
|
175 |
if (exists $self->{exports}->{$operand}) {
|
|
176 |
croak "Error: 'exports' entry for \"$operand\" defined more than once in $self->{mrpName}\n";
|
|
177 |
}
|
|
178 |
|
|
179 |
$operand = File::Spec->canonpath($operand); # Normalise the path
|
|
180 |
|
|
181 |
if (!-e $operand) {
|
|
182 |
croak "Error: Exports path \"$operand\" does not exist\n";
|
|
183 |
}
|
|
184 |
|
|
185 |
$self->{exports}->{$operand} = $test;
|
|
186 |
|
|
187 |
if ($dependantComponent) {
|
|
188 |
push (@{$self->{exports}->{_dependantComponent}}, $dependantComponent);
|
|
189 |
}
|
|
190 |
}
|
|
191 |
|
|
192 |
sub SetExportFile {
|
|
193 |
my $self = shift;
|
|
194 |
my $source = shift;
|
|
195 |
my $destination = shift;
|
|
196 |
my $remove = (shift) ? 1 : 0;
|
|
197 |
my $dependantComponent = shift;
|
|
198 |
|
|
199 |
if (!$source || shift) {
|
|
200 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n";
|
|
201 |
}
|
|
202 |
|
|
203 |
unless ($source and $destination) {
|
|
204 |
croak "Error: Incorrect syntax to 'export_file' keyword in \"$self->{mrpName}\"\n";
|
|
205 |
}
|
|
206 |
|
|
207 |
$source = File::Spec->canonpath($source); # Normalise the path
|
|
208 |
$destination = File::Spec->canonpath($destination);
|
|
209 |
|
|
210 |
if (!$remove) {
|
|
211 |
if (!-e $source) {
|
|
212 |
croak "Error: Export file \"$source\" does not exist\n";
|
|
213 |
}
|
|
214 |
}
|
|
215 |
|
|
216 |
push @{$self->{exportFiles}}, {
|
|
217 |
source => $source,
|
|
218 |
destination => $destination,
|
|
219 |
remove => $remove};
|
|
220 |
|
|
221 |
if ($dependantComponent) {
|
|
222 |
push (@{$self->{exports}->{_dependantComponent}}, $dependantComponent);
|
|
223 |
}
|
|
224 |
}
|
|
225 |
|
|
226 |
sub GetIPRInformation {
|
|
227 |
my $self = shift;
|
|
228 |
|
|
229 |
if (exists $self->{IPR}) {
|
|
230 |
return $self->{IPR};
|
|
231 |
}
|
|
232 |
else {
|
|
233 |
return {};
|
|
234 |
}
|
|
235 |
}
|
|
236 |
|
|
237 |
sub Component {
|
|
238 |
my $self = shift;
|
|
239 |
|
|
240 |
if ($self->{componentName}) {
|
|
241 |
return $self->{componentName};
|
|
242 |
}
|
|
243 |
|
|
244 |
return undef;
|
|
245 |
}
|
|
246 |
|
|
247 |
sub GetExportComponentDependencies {
|
|
248 |
my $self = shift;
|
|
249 |
|
|
250 |
if (exists $self->{exports}->{_dependantComponent}) {
|
|
251 |
return @{$self->{exports}->{_dependantComponent}}
|
|
252 |
}
|
|
253 |
|
|
254 |
return undef;
|
|
255 |
}
|
|
256 |
|
|
257 |
sub GetSource {
|
|
258 |
my $self = shift;
|
|
259 |
|
|
260 |
if (exists $self->{sourceItems}) {
|
|
261 |
return [keys %{$self->{sourceItems}}];
|
|
262 |
}
|
|
263 |
|
|
264 |
return [];
|
|
265 |
}
|
|
266 |
|
|
267 |
sub ValidateParsing {
|
|
268 |
my $self = shift;
|
|
269 |
|
|
270 |
# This flag stops the reader from trying to populate the object more than once
|
|
271 |
$self->{populated} = 1;
|
|
272 |
|
|
273 |
if (exists $self->{sourceItems} && !exists $self->{unresolvedIPR}) {
|
|
274 |
# If no IPR information exists in the MRP file then we set the IPR category
|
|
275 |
# for each source item to undef. This is so that incorrect IPR information is
|
|
276 |
# not returned.
|
|
277 |
|
|
278 |
foreach my $sourceItem (keys %{$self->{sourceItems}}) {
|
|
279 |
$self->{IPR}->{$sourceItem} = {
|
|
280 |
category => undef,
|
|
281 |
exportRestricted => undef,
|
|
282 |
};
|
|
283 |
}
|
|
284 |
}
|
|
285 |
else {
|
|
286 |
# Reconcile the IPR information here so that any warnings are produced sooner...
|
|
287 |
# IPR information can only be included if it matches a source line in the MRP file
|
|
288 |
# All other IPR lines will be ignored. The reconciliation is done here as IPR
|
|
289 |
# lines may appear before source lines in the MRP file.
|
|
290 |
|
|
291 |
if (!defined $self->{sourceItems} && exists $self->{unresolvedIPR}->{default}) {
|
|
292 |
carp "Warning: The default IPR entry does not apply to any source statements in \"$self->{mrpName}\"\n";
|
|
293 |
}
|
|
294 |
|
|
295 |
# Match IPR against source statement by using the length...
|
|
296 |
foreach my $sourceItem (keys %{$self->{sourceItems}}) {
|
|
297 |
# The sort below sorts by longest line first, not shortest line first. Note $b <=> $a, not $a <=> $b...
|
|
298 |
# This allows us to match the most relevant line first, based on longest length/best match
|
|
299 |
foreach my $iprItem (sort {length($b) <=> length($a)} keys %{$self->{unresolvedIPR}}) {
|
|
300 |
next if ($iprItem eq 'default');
|
|
301 |
# If the source item contains the IPR path then it is a match
|
|
302 |
if ($sourceItem =~ m/^\Q$iprItem\E([\\\/]|$)/i) {
|
|
303 |
$self->{IPR}->{$sourceItem} = $self->{unresolvedIPR}->{$iprItem};
|
|
304 |
|
|
305 |
last;
|
|
306 |
}
|
|
307 |
}
|
|
308 |
|
|
309 |
# If it didn't match an IPR then we assign the default
|
|
310 |
if (!exists $self->{IPR}->{$sourceItem}) {
|
|
311 |
$self->{IPR}->{$sourceItem} = $self->{unresolvedIPR}->{default};
|
|
312 |
}
|
|
313 |
}
|
|
314 |
|
|
315 |
delete $self->{unresolvedIPR}->{default};
|
|
316 |
|
|
317 |
# Find IPR entries which do live under a source folder...
|
|
318 |
foreach my $iprItem (keys %{$self->{unresolvedIPR}}) {
|
|
319 |
next if (exists $self->{IPR}->{$iprItem});
|
|
320 |
|
|
321 |
foreach my $sourceItem (keys %{$self->{sourceItems}}) {
|
|
322 |
if ($iprItem =~ /^\Q$sourceItem\E/i) {
|
|
323 |
$self->{IPR}->{$iprItem} = $self->{unresolvedIPR}->{$iprItem};
|
|
324 |
last;
|
|
325 |
}
|
|
326 |
}
|
|
327 |
|
|
328 |
if (!grep /\Q$iprItem\E/i, (keys %{$self->{IPR}})) {
|
|
329 |
# Otherwise this IPR statement does not apply to this MRP file...
|
|
330 |
carp "Warning: The IPR entry for \"$iprItem\" does not apply to any source statements in \"$self->{mrpName}\"\n";
|
|
331 |
}
|
|
332 |
}
|
|
333 |
|
|
334 |
delete $self->{unresolvedIPR};
|
|
335 |
}
|
|
336 |
}
|
|
337 |
|
|
338 |
sub Populated {
|
|
339 |
my $self = shift;
|
|
340 |
|
|
341 |
return $self->{populated};
|
|
342 |
}
|
|
343 |
|
|
344 |
1;
|
|
345 |
|
|
346 |
__END__
|
|
347 |
|
|
348 |
=pod
|
|
349 |
|
|
350 |
=head1 NAME
|
|
351 |
|
|
352 |
Symbian::CBR::MRP - An object representation of an MRP file
|
|
353 |
|
|
354 |
=head1 SYNOPSIS
|
|
355 |
|
|
356 |
use Symbian::CBR::MRP;
|
|
357 |
|
|
358 |
# Construct a Symbian::CBR::MRP object
|
|
359 |
my $mrpObject = Symbian::CBR::MRP->new(mrpName);
|
|
360 |
|
|
361 |
# Use the setters to populate the object
|
|
362 |
|
|
363 |
$mrpObject->SetComponent('componentName');
|
|
364 |
|
|
365 |
$mrpObject->SetSource('\src\aSrcFolder');
|
|
366 |
|
|
367 |
$mrpObject->SetNotesSource('\componentDefs\notes.src');
|
|
368 |
|
|
369 |
# Validate the parsing\perform any post parsing operations
|
|
370 |
$mrpObject->ValidateParsing();
|
|
371 |
|
|
372 |
...
|
|
373 |
|
|
374 |
# Getting information from the Symbian::CBR::MRP object
|
|
375 |
my $iprInformation = $mrpObject->GetIPRInformation();
|
|
376 |
|
|
377 |
# Get the component name
|
|
378 |
my $componentName = $mrpObject->GetComponent();
|
|
379 |
|
|
380 |
=head1 DESCRIPTION
|
|
381 |
|
|
382 |
This object represents an MRP file. It is intended to be created and populated
|
|
383 |
by an MRP file parser, for example Symbian::CBR::MRP::Reader. No parsing
|
|
384 |
functionality is included with this object.
|
|
385 |
|
|
386 |
Once the object has been populated the parser should call the ValidateParsing()
|
|
387 |
method, which will perform any post-population actions, such as resolving IPR
|
|
388 |
information etc.
|
|
389 |
|
|
390 |
=head1 METHODS
|
|
391 |
|
|
392 |
=head2 new(mrpName, verbose)
|
|
393 |
|
|
394 |
Instantiates a Symbian::CBR::MRP object. The mrpName argument is only used for
|
|
395 |
printing error and warning messages.
|
|
396 |
|
|
397 |
=head2 GetIPRInformation()
|
|
398 |
|
|
399 |
Returns a hash containing the IPR information for the component.
|
|
400 |
|
|
401 |
The format is the returned data is a hash:
|
|
402 |
|
|
403 |
Path = (
|
|
404 |
category = char,
|
|
405 |
exportRestricted = boolean
|
|
406 |
)
|
|
407 |
|
|
408 |
=head2 SetBinary(@arguments, test, remove)
|
|
409 |
|
|
410 |
Sets the binary information. @arguments is an array containing the arguments
|
|
411 |
from the MRP line, in the order in which they appeared.
|
|
412 |
|
|
413 |
=head2 SetComponent(componentName)
|
|
414 |
|
|
415 |
Sets the name of the component to componentName.
|
|
416 |
|
|
417 |
=head2 SetExportFile(source, destination, remove, dependantComponent)
|
|
418 |
|
|
419 |
Sets the export file information. The source and destination arguments are both
|
|
420 |
required, if they are not specified a fatal error will be produced. The source
|
|
421 |
file will also be checked to see if it exists and that it has not already been
|
|
422 |
specified as an export file.
|
|
423 |
|
|
424 |
If the export file is not included as source for the current MRP component then
|
|
425 |
the dependant component will also need to be specified.
|
|
426 |
|
|
427 |
=head2 SetExports(path, test, dependantComponent)
|
|
428 |
|
|
429 |
Sets the location of the bld.inf from where the export information can be derived.
|
|
430 |
The location will be checked to see if it exists and that it has not already been
|
|
431 |
specified.
|
|
432 |
|
|
433 |
If the exports are not included as source for the current MRP component then
|
|
434 |
the dependant component will also need to be specified.
|
|
435 |
|
|
436 |
=head2 SetIPR(category, path, exportRestricted)
|
|
437 |
|
|
438 |
Sets the IPR information for the component. If no path is specified then the
|
|
439 |
IPR category is set to be the default category for the component. The
|
|
440 |
exportRestricted argument is boolean.
|
|
441 |
|
|
442 |
If the same path is specified more than once a fatal error will be produced.
|
|
443 |
|
|
444 |
=head2 SetNotesSource(noteSourcePath)
|
|
445 |
|
|
446 |
Sets the notes source to the notesSourcePath specified. If the notes source has
|
|
447 |
already been set, or the path does not exist, a fatal error will be produced.
|
|
448 |
|
|
449 |
=head2 SetSource(sourcePath)
|
|
450 |
|
|
451 |
Adds the sourcePath to the list of included source entries for the component.
|
|
452 |
If the source path does not exist or the path has already been added then a
|
|
453 |
fatal error will be produced.
|
|
454 |
|
|
455 |
=head2 ValidateParsing()
|
|
456 |
|
|
457 |
This method needs to be called once the parser has finished setting all the
|
|
458 |
information. Currently this method reconciles IPR statements against the
|
|
459 |
components source, and also checks that required dependant components have
|
|
460 |
been set.
|
|
461 |
|
|
462 |
If this method is not run then IPR information will be unavailable.
|
|
463 |
|
|
464 |
=head2 GetExportComponentDependencies()
|
|
465 |
|
|
466 |
Returns an array containing the any components which the current component has
|
|
467 |
dependencies on.
|
|
468 |
|
|
469 |
=head2 Component()
|
|
470 |
|
|
471 |
Returns the component name.
|
|
472 |
|
|
473 |
=head2 Populated()
|
|
474 |
|
|
475 |
The MRP file is parsed by a reader, which then populates this MRP object. The
|
|
476 |
Populated method returns a boolean value indicating if the object has been
|
|
477 |
populated.
|
|
478 |
|
|
479 |
=head1 COPYRIGHT
|
|
480 |
|
|
481 |
Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
482 |
All rights reserved.
|
|
483 |
This component and the accompanying materials are made available
|
|
484 |
under the terms of the License "Eclipse Public License v1.0"
|
|
485 |
which accompanies this distribution, and is available
|
|
486 |
at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
487 |
|
|
488 |
Initial Contributors:
|
|
489 |
Nokia Corporation - initial contribution.
|
|
490 |
|
|
491 |
Contributors:
|
|
492 |
|
|
493 |
Description:
|
|
494 |
|
|
495 |
|
|
496 |
=cut
|