ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildFile.pm
Revision: 1.36
Committed: Mon Apr 23 11:55:08 2012 UTC (13 years ago) by muzaffar
Content type: text/plain
Branch: MAIN
Changes since 1.35: +1 -18 lines
Log Message:
removed unused code:library position attribute not used any more

File Contents

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