ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildFile.pm
Revision: 1.32.2.1
Committed: Fri Feb 15 14:58:01 2008 UTC (17 years, 2 months ago) by muzaffar
Content type: text/plain
Branch: forBinLess_SCRAM
CVS Tags: V2_2_2, V2_2_2_pre4, V2_2_2_pre3, V2_2_2_pre2, V2_2_2_pre1, V2_2_2-pre1, V2_2_1, forV2_2_1, V2_2_0, sm100112, V2_1_4, V2_1_3, V2_1_2, V2_1_1, V2_1_0, V2_0_6, V2_0_5, V2_0_4, V2_0_4_relcand2, V2_0_4_relcand1, V2_0_3, V2_0_3_relcand3, V2_0_3_relcand2, V2_0_3_relcand1, V2_0_2, V2_0_2_relcand1, V2_0_1, V1_2_1b, V1_2_1a, V2_0_1_relcand4, V2_0_1_relcand3, V2_0_1_relcand2, V2_0_1_relcand1, V2_0_0_relcand4, V1_2_3, V2_0_0, V1_2_2, V1_2_2_relcand2, V1_2_2_relcand1, V2_0_0_relcand3, V2_0_0_relcand2, V2_0_0_relcand1, V1_2_1, V1_2_0, V1_2_0-cand11, V1_2_0-cand10, V1_2_0-cand9, V1_2_0-cand8, V1_2_0-cand7, V1_2_0-cand6, V1_2_0-cand5, V1_2_0-cand4, V1_2_0-cand3, V1_2_0-cand2, V1_2_0-cand1
Branch point for: SCRAM_V2_0
Changes since 1.32: +7 -176 lines
Log Message:
binary independent scram in forBinLess_SCRAM branch

File Contents

# Content
1 #____________________________________________________________________
2 # File: BuildFile.pm
3 #____________________________________________________________________
4 #
5 # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6 # Update: 2003-12-03 19:03:15+0100
7 # Revision: $Id: BuildFile.pm,v 1.32 2007/12/14 09:03:46 muzaffar Exp $
8 #
9 # Copyright: 2003 (C) Shaun Ashby
10 #
11 #--------------------------------------------------------------------
12 package BuildSystem::BuildFile;
13 require 5.004;
14 use Exporter;
15 use ActiveDoc::SimpleDoc;
16
17 @ISA=qw(Exporter);
18 @EXPORT_OK=qw( );
19 #
20 sub new()
21 ###############################################################
22 # new #
23 ###############################################################
24 # modified : Wed Dec 3 19:03:22 2003 / SFA #
25 # params : #
26 # : #
27 # function : #
28 # : #
29 ###############################################################
30 {
31 my $proto=shift;
32 my $class=ref($proto) || $proto;
33 $self={};
34 bless $self,$class;
35 $self->{DEPENDENCIES} = {};
36 $self->{content} = {};
37 $self->{scramdoc}=ActiveDoc::SimpleDoc->new();
38 $self->{scramdoc}->newparse("builder",__PACKAGE__,'Subs',shift);
39 return $self;
40 }
41
42 sub parse()
43 {
44 my $self=shift;
45 my ($filename)=@_;
46 my $fhead='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><doc type="BuildSystem::BuildFile" version="1.0">';
47 my $ftail='</doc>';
48 $self->{scramdoc}->filetoparse($filename);
49 $self->{scramdoc}->parse("builder",$fhead,$ftail);
50 # We're done with the SimpleDoc object so delete it:
51 delete $self->{scramdoc};
52 }
53
54 sub classpath()
55 {
56 my ($object,$name,%attributes)=@_;
57 # The getter part:
58 if (ref($object) eq __PACKAGE__)
59 {
60 return $self->{content}->{CLASSPATH};
61 }
62
63 $self->{nested} == 1 ? push(@{$self->{tagcontent}->{CLASSPATH}}, $attributes{'path'})
64 : push(@{$self->{content}->{CLASSPATH}}, $attributes{'path'});
65 }
66
67 sub productstore()
68 {
69 my ($object,$name,%attributes)=@_;
70 # The getter part:
71 if (ref($object) eq __PACKAGE__)
72 {
73 # Return an array of ProductStore hashes:
74 return $self->{content}->{PRODUCTSTORE};
75 }
76
77 $self->{nested} == 1 ? push(@{$self->{tagcontent}->{PRODUCTSTORE}}, \%attributes)
78 : push(@{$self->{content}->{PRODUCTSTORE}}, \%attributes) ;
79 }
80
81 sub include()
82 {
83 my $self=shift;
84 # Return an array of required includes:
85 return $self->{content}->{INCLUDE};
86 }
87
88 sub include_path()
89 {
90 my ($object,$name,%attributes)=@_;
91 $self->{nested} == 1 ? push(@{$self->{tagcontent}->{INCLUDE}}, $attributes{'path'})
92 : push(@{$self->{content}->{INCLUDE}}, $attributes{'path'});
93 }
94
95 sub use()
96 {
97 my $object=shift;
98 # The getter part:
99 if (ref($object) eq __PACKAGE__)
100 {
101 # Add or return uses (package deps):
102 @_ ? push(@{$self->{content}->{USE}},@_)
103 : @{$self->{content}->{USE}};
104 }
105 else
106 {
107 my ($name,%attributes)=@_;
108 $self->{DEPENDENCIES}->{$attributes{'name'}} = 1;
109 $self->{nested} == 1 ? push(@{$self->{tagcontent}->{USE}}, $attributes{'name'})
110 : push(@{$self->{content}->{USE}}, $attributes{'name'});
111 }
112 }
113
114 sub architecture()
115 {
116 my ($object,$name,%attributes)=@_;
117 $self->pushlevel(\%attributes); # Set nested to 1;
118 }
119
120 sub architecture_()
121 {
122 $self->{content}->{ARCH}->{$self->{id}->{'name'}}=$self->{tagcontent};
123 $self->poplevel();
124 }
125
126 sub export()
127 {
128 $self->pushlevel(); # Set nested to 1;
129 }
130
131 sub export_()
132 {
133 $self->{content}->{EXPORT} = $self->{tagcontent};
134 $self->poplevel();
135 }
136
137 sub lib()
138 {
139 my ($object,$name,%attributes)=@_;
140 # The getter part:
141 if (ref($object) eq __PACKAGE__)
142 {
143 # Return an array of required libs:
144 return $self->{content}->{LIB};
145 }
146
147 my $libname;
148
149 if (exists($attributes{'position'}))
150 {
151 if ($attributes{'position'} eq 'first')
152 {
153 $libname = "F:".$attributes{'name'};
154 }
155 else
156 {
157 # There was a position entry but it didn't make sense:
158 $libname = $attributes{'name'};
159 }
160 }
161 else
162 {
163 $libname = $attributes{'name'};
164 }
165 # We have a libname, add it to the list:
166 $self->{nested} == 1 ? push(@{$self->{tagcontent}->{LIB}}, $libname)
167 : push(@{$self->{content}->{LIB}}, $libname);
168 }
169
170 sub libtype()
171 {
172 my ($object,$name,%attributes)=@_;
173 # The getter part:
174 if (ref($object) eq __PACKAGE__)
175 {
176 # Return an array of required libs:
177 return $self->{content}->{LIBTYPE};
178 }
179
180 $self->{nested} == 1 ? push(@{$self->{tagcontent}->{LIBTYPE}}, $attributes{'type'})
181 : push(@{$self->{content}->{LIBTYPE}}, $attributes{'type'});
182 }
183
184 sub skip()
185 {
186 my ($object,$name,%attributes)=@_;
187 $self->{nested} == 1 ? $self->{tagcontent}->{SKIPPEDDIRS} = [ 1 ]
188 : $self->{content}->{SKIPPEDDIRS} = [ 1 ];
189 }
190
191 sub skip_message()
192 {
193 my ($object,$name,@message) = @_;
194 # Save any message text between <skip> tags:
195 if ($#message > -1)
196 {
197 $self->{nested} == 1 ? push(@{$self->{tagcontent}->{SKIPPEDDIRS}}, [ @message ])
198 : push(@{$self->{content}->{SKIPPEDDIRS}}, [ @message ]);
199 }
200 }
201
202 sub skip_()
203 {
204 my ($object,$name)=@_;
205 }
206
207 sub makefile()
208 {
209 my ($object,$name,%attributes)=@_;
210 # The getter part:
211 if (ref($object) eq __PACKAGE__)
212 {
213 return $self->{content}->{MAKEFILE};
214 }
215 }
216
217 sub makefile_()
218 {
219 my ($object,$name,$cdata)=@_;
220 $self->{nested} == 1 ? push(@{$self->{tagcontent}->{MAKEFILE}}, join("\n",@$cdata))
221 : push(@{$self->{content}->{MAKEFILE}}, join("\n",@$cdata));
222 }
223
224 sub flags()
225 {
226 my ($object,$name,%attributes)=@_;
227 # The getter part:
228 if (ref($object) eq __PACKAGE__)
229 {
230 # Return an array of ProductStore hashes:
231 return $self->{content}->{FLAGS};
232 }
233
234 # Extract the flag name and its value:
235 my ($flagname,$flagvaluestring) = each %attributes;
236 $flagname =~ tr/[a-z]/[A-Z]/; # Keep flag name uppercase
237 chomp($flagvaluestring);
238 my @flagvalues = ( $flagvaluestring );
239 # Is current tag within another tag block?
240 if ($self->{nested} == 1)
241 {
242 # Check to see if the current flag name is already stored in the hash. If so,
243 # just add the new values to the array of flag values:
244 if (exists ($self->{tagcontent}->{FLAGS}->{$flagname}))
245 {
246 push(@{$self->{tagcontent}->{FLAGS}->{$flagname}},@flagvalues);
247 }
248 else
249 {
250 $self->{tagcontent}->{FLAGS}->{$flagname} = [ @flagvalues ];
251 }
252 }
253 else
254 {
255 if (exists ($self->{content}->{FLAGS}->{$flagname}))
256 {
257 push(@{$self->{content}->{FLAGS}->{$flagname}},@flagvalues);
258 }
259 else
260 {
261 $self->{content}->{FLAGS}->{$flagname} = [ @flagvalues ];
262 }
263 }
264 }
265
266 sub allflags()
267 {
268 my $self=shift;
269 # Return hash data for flags:
270 return $self->{content}->{FLAGS};
271 }
272
273 sub archspecific()
274 {
275 my $self=shift;
276
277 # Check to see if there is arch-dependent data. If so, return it:
278 if ((my $nkeys=keys %{$self->{content}->{ARCH}}) > 0)
279 {
280 while (my ($k,$v) = each %{$self->{content}->{ARCH}})
281 {
282 if ( $ENV{SCRAM_ARCH} =~ /$k.*/ )
283 {
284 return $self->{content}->{ARCH}->{$k};
285 }
286 }
287 }
288 return "";
289 }
290
291 sub bin()
292 {
293 my ($object,$name,%attributes) = @_;
294 $self->pushlevel(\%attributes);# Set nested to 1;
295 }
296
297 sub bin_()
298 {
299 # Need unique name for the binary (always use name of product). Either use "name"
300 # given, or use "file" value minus the ending:
301 if (exists ($self->{id}->{'name'}))
302 {
303 $name = $self->{id}->{'name'};
304 }
305 else
306 {
307 ($name) = ($self->{id}->{'file'} =~ /(.*)?\..*$/);
308 }
309
310 # Store the data:
311 $self->productcollector($name,'bin','BIN');
312 $self->poplevel();
313 }
314
315 sub library()
316 {
317 my ($object,$name,%attributes) = @_;
318 $self->pushlevel(\%attributes);# Set nested to 1;
319 }
320
321 sub library_()
322 {
323 # Need unique name for the library (always use name of product). Either use "name"
324 # given, or use "file" value minus the ending:
325 if (exists ($self->{id}->{'name'}))
326 {
327 $name = $self->{id}->{'name'};
328 }
329 else
330 {
331 ($name) = ($self->{id}->{'file'} =~ /(.*)?\..*$/);
332 }
333
334 # Store the data:
335 $self->productcollector($name,'lib','LIBRARY');
336 $self->poplevel();
337 }
338
339 sub productcollector()
340 {
341 my $self=shift;
342 my ($name,$typeshort,$typefull)=@_;
343 # Create a new Product object for storage of data:
344 use BuildSystem::Product;
345 my $product = BuildSystem::Product->new();
346 # Store the name:
347 $product->name($name);
348 $product->type($typeshort);
349 # Store the files. Take the BuildFile path as the initial path for
350 # expanding source file globs:
351 $product->_files($self->{id}->{'file'},[ $self->{scramdoc}->filetoparse() ]);
352 # Store the data content:
353 $product->_data($self->{tagcontent});
354 # And store in a hash (all build products in same place):
355 $self->{content}->{BUILDPRODUCTS}->{$typefull}->{$name} = $product;
356 }
357
358 sub pushlevel
359 {
360 my $self = shift;
361 my ($info)=@_;
362
363 $self->{id} = $info if (defined $info);
364 $self->{nested} = 1;
365 $self->{tagcontent}={};
366 }
367
368 sub poplevel
369 {
370 my $self = shift;
371 delete $self->{id};
372 delete $self->{nested};
373 delete $self->{tagcontent};
374 }
375
376 sub dependencies()
377 {
378 my $self=shift;
379 # Make a copy of the variable so that
380 # we don't have a DEPENDENCIES entry in RAWDATA:
381 my %DEPS=%{$self->{DEPENDENCIES}};
382 delete $self->{DEPENDENCIES};
383 return \%DEPS;
384 }
385
386 sub skippeddirs()
387 {
388 my $self=shift;
389 my ($here)=@_;
390 my $skipped;
391
392 if ($self->{content}->{SKIPPEDDIRS}->[0] == 1)
393 {
394 $skipped = [ @{$self->{content}->{SKIPPEDDIRS}} ];
395 delete $self->{content}->{SKIPPEDDIRS};
396 }
397
398 delete $self->{content}->{SKIPPEDDIRS};
399 return $skipped;
400 }
401
402 sub hasexport()
403 {
404 my $self=shift;
405 # Check to see if there is a valid export block:
406 my $nkeys = $self->exporteddatatypes();
407 $nkeys > 0 ? return 1 : return 0;
408 }
409
410 sub has()
411 {
412 my $self=shift;
413 my ($datatype)=@_;
414 (exists ($self->{content}->{$datatype})) ? return 1 : return 0;
415 }
416
417 sub exported()
418 {
419 my $self=shift;
420 # Return a hash. Keys are type of data provided:
421 return ($self->{content}->{EXPORT});
422 }
423
424 sub exporteddatatypes()
425 {
426 my $self=shift;
427 # Return exported data types:
428 return keys %{$self->{content}->{EXPORT}};
429 }
430
431 sub buildproducts()
432 {
433 my $self=shift;
434 # Returns hash of build products and their data:
435 return $self->{content}->{BUILDPRODUCTS};
436 }
437
438 sub values()
439 {
440 my $self=shift;
441 my ($type)=@_;
442 # Get a list of values from known types
443 return $self->{content}->{BUILDPRODUCTS}->{$type};
444 }
445
446 sub basic_tags()
447 {
448 my $self=shift;
449 my $datatags=[];
450 my $buildtags=[ qw(BIN LIBRARY BUILDPRODUCTS) ];
451 my $skiptags=[ qw(ARCH EXPORT USE CLASSPATH) ];
452 my $otherskiptags=[ qw( SKIPPEDDIRS ) ];
453 my @all_skip_tags;
454
455 push(@all_skip_tags,@$skiptags,@$buildtags,@$otherskiptags);
456
457 foreach my $t (keys %{$self->{content}})
458 {
459 push(@$datatags,$t),if (! grep($t eq $_, @all_skip_tags));
460 }
461 return @{$datatags};
462 }
463
464 sub clean()
465 {
466 my $self=shift;
467 my (@tags) = @_;
468
469 # Delete some useless entries:
470 delete $self->{simpledoc};
471 delete $self->{id};
472 delete $self->{tagcontent};
473 delete $self->{nested};
474
475 delete $self->{DEPENDENCIES};
476
477 map
478 {
479 delete $self->{content}->{$_} if (exists($self->{content}->{$_}));
480 } @tags;
481
482 return $self;
483 }
484
485 sub AUTOLOAD()
486 {
487 my ($xmlparser,$name,%attributes)=@_;
488 return if $AUTOLOAD =~ /::DESTROY$/;
489 my $name=$AUTOLOAD;
490 $name =~ s/.*://;
491 }
492
493 1;