ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildFile.pm
Revision: 1.37
Committed: Thu Apr 26 07:55:35 2012 UTC (13 years ago) by muzaffar
Content type: text/plain
Branch: MAIN
CVS Tags: V2_2_5_pre2, V2_2_5_pre1, V2_2_4, V2_2_4_pre9, V2_2_4_pre8, V2_2_4_pre7, V2_2_4_pre6, V2_2_4_pre5, V2_2_4_pre4, HEAD
Changes since 1.36: +4 -2 lines
Log Message:
do not save un necessary items in ProjectCache.db

File Contents

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