ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildFile.pm
(Generate patch)

Comparing COMP/SCRAM/src/BuildSystem/BuildFile.pm (file contents):
Revision 1.26 by sashby, Fri Dec 10 13:41:37 2004 UTC vs.
Revision 1.36 by muzaffar, Mon Apr 23 11:55:08 2012 UTC

# Line 3 | Line 3
3   #____________________________________________________________________
4   #  
5   # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6 # Update: 2003-12-03 19:03:15+0100
7 # Revision: $Id$
8 #
6   # Copyright: 2003 (C) Shaun Ashby
7   #
8   #--------------------------------------------------------------------
9   package BuildSystem::BuildFile;
10   require 5.004;
11   use Exporter;
15 use BuildSystem::TagUtils;
16 use BuildSystem::BuildDataUtils;
12   use ActiveDoc::SimpleDoc;
13  
14 < @ISA=qw(Exporter BuildSystem::BuildDataUtils);
14 > @ISA=qw(Exporter);
15   @EXPORT_OK=qw( );
21
16   #
17   sub new()
18     ###############################################################
# Line 33 | Line 27 | sub new()
27     {
28     my $proto=shift;
29     my $class=ref($proto) || $proto;
30 <   my $self={};
37 <  
30 >   $self={};
31     bless $self,$class;
39
32     $self->{DEPENDENCIES} = {};
33     $self->{content} = {};
34 +   $self->{scramdoc}=ActiveDoc::SimpleDoc->new();
35 +   $self->{scramdoc}->newparse("builder",__PACKAGE__,'Subs',shift);
36 +   $self->{archs}=[];
37 +   $self->{archflag}=1;
38     return $self;
39     }
40  
41 < sub _initparser()
41 > sub parse()
42     {
43     my $self=shift;
44 +   my ($filename)=@_;
45 +   my $fhead='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><doc type="BuildSystem::BuildFile" version="1.0">';
46 +   my $ftail='</doc>';
47 +   $self->{scramdoc}->filetoparse($filename);
48 +   $self->{scramdoc}->parse("builder",$fhead,$ftail);
49 +   # We're done with the SimpleDoc object so delete it:
50 +   delete $self->{scramdoc};
51 +   }
52  
53 <   $self->{simpledoc}=ActiveDoc::SimpleDoc->new();
54 <   $self->{simpledoc}->newparse("builder");
55 <   $self->{simpledoc}->addignoretags("builder");
53 > 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 >   if (!$self->{archflag}){return;}
62 >   $self->{nested} == 1 ? push(@{$self->{tagcontent}->{CLASSPATH}}, $attributes{'path'})
63 >      : push(@{$self->{content}->{CLASSPATH}}, $attributes{'path'});
64 >   }
65  
66 <   # For blank lines do nothing:
67 <   $self->{simpledoc}->addtag("builder","none",
68 <                              "", $self,
69 <                              "", $self,
70 <                              "", $self);
71 <  
72 <   # Define the tags to be used in this class:
73 <   $self->{simpledoc}->addtag("builder","classpath",
74 <                              \&BuildSystem::TagUtils::classpathtagOpen, $self,
75 <                              "", $self,
76 <                              "", $self);
77 <
65 <   $self->{simpledoc}->addtag("builder","productstore",
66 <                              \&BuildSystem::TagUtils::productstoretagOpen, $self,
67 <                              "", $self,
68 <                              "", $self);
69 <
70 <   $self->{simpledoc}->addtag("builder","architecture",
71 <                              \&BuildSystem::TagUtils::archtagOpen, $self,
72 <                              "", $self,
73 <                              \&BuildSystem::TagUtils::archtagClose, $self);
74 <
75 <   $self->{simpledoc}->addtag("builder","include_path",
76 <                              \&BuildSystem::TagUtils::includetagOpen, $self,
77 <                              "", $self,
78 <                              "", $self);
79 <  
80 <   $self->{simpledoc}->addtag("builder","define_group",
81 <                              \&BuildSystem::TagUtils::groupdeftagOpen, $self,
82 <                              "", $self,
83 <                              \&BuildSystem::TagUtils::groupdeftagClose, $self);
84 <  
85 <   $self->{simpledoc}->addtag("builder","group",
86 <                              \&BuildSystem::TagUtils::grouptagOpen, $self,
87 <                              "", $self,
88 <                              "", $self);
89 <  
90 <   $self->{simpledoc}->addtag("builder","lib",
91 <                              \&BuildSystem::TagUtils::libtagOpen, $self,
92 <                              "", $self,
93 <                              "", $self);
94 <
95 <   $self->{simpledoc}->addtag("builder","export",
96 <                              \&BuildSystem::TagUtils::exporttagOpen, $self,
97 <                              "", $self,
98 <                              \&BuildSystem::TagUtils::exporttagClose, $self);
99 <
100 <   $self->{simpledoc}->addtag("builder","use",
101 <                              \&BuildSystem::TagUtils::usetagOpen, $self,
102 <                              "", $self,
103 <                              "", $self);
104 <  
105 <   $self->{simpledoc}->addtag("builder","libtype",
106 <                              \&BuildSystem::TagUtils::libtypetagOpen, $self,
107 <                              "", $self,
108 <                              "", $self);
109 <  
110 <   $self->{simpledoc}->addtag("builder","makefile",
111 <                              \&BuildSystem::TagUtils::makefiletagOpen, $self,
112 <                              \&BuildSystem::TagUtils::makefiletagContent, $self,
113 <                              \&BuildSystem::TagUtils::makefiletagClose, $self);
114 <
115 <   $self->{simpledoc}->addtag("builder","flags",
116 <                              \&BuildSystem::TagUtils::flagstagOpen, $self,
117 <                              "", $self,
118 <                              "", $self);
119 <  
120 <   $self->{simpledoc}->addtag("builder","bin",
121 <                              \&BuildSystem::TagUtils::binarytagOpen, $self,
122 <                              "", $self,
123 <                              \&BuildSystem::TagUtils::binarytagClose, $self);
124 <  
125 <   $self->{simpledoc}->addtag("builder","module",
126 <                              \&BuildSystem::TagUtils::moduletagOpen, $self,
127 <                              "", $self,
128 <                              \&BuildSystem::TagUtils::moduletagClose, $self);
129 <  
130 <   $self->{simpledoc}->addtag("builder","application",
131 <                              \&BuildSystem::TagUtils::applicationtagOpen, $self,
132 <                              "", $self,
133 <                              \&BuildSystem::TagUtils::applicationtagClose, $self);
134 <
135 <   $self->{simpledoc}->addtag("builder","library",
136 <                              \&BuildSystem::TagUtils::librarytagOpen, $self,
137 <                              "", $self,
138 <                              \&BuildSystem::TagUtils::librarytagClose, $self);
139 <
140 < #    $self->{simpledoc}->addtag("builder"," ",
141 < #                             \&BuildSystem::TagUtils::  ,$self,
142 < #                             \&BuildSystem::TagUtils::  ,$self,
143 < #                             \&BuildSystem::TagUtils::  ,$self);
144 <
145 <   return $self->{simpledoc};
66 > 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 >   if (!$self->{archflag}){return;}
76 >   $self->{nested} == 1 ? push(@{$self->{tagcontent}->{PRODUCTSTORE}}, \%attributes)
77 >      : push(@{$self->{content}->{PRODUCTSTORE}}, \%attributes) ;
78     }
79  
80 < sub parse()
80 > sub include()
81     {
82     my $self=shift;
83 <   my ($filename)=@_;
83 >   # Return an array of required includes:
84 >   return $self->{content}->{INCLUDE};
85 >   }
86  
87 <   $self->{simpledoc}=$self->_initparser();
88 <   $self->{simpledoc}->filetoparse($filename);
89 <   $self->{simpledoc}->parse("builder");
90 <  
91 <   # We're done with the SimpleDoc object so delete it:
92 <   delete $self->{simpledoc};
87 > sub include_path()
88 >   {
89 >   my ($object,$name,%attributes)=@_;
90 >   if (!$self->{archflag}){return;}
91 >   $self->{nested} == 1 ? push(@{$self->{tagcontent}->{INCLUDE}}, $attributes{'path'})
92 >      : push(@{$self->{content}->{INCLUDE}}, $attributes{'path'});
93     }
94  
95 < sub _initbranchparser()
95 > sub use()
96     {
97 <   my $self=shift;
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 >      if (!$self->{archflag}){return;}
108 >      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 <   $self->{simpledoc}=ActiveDoc::SimpleDoc->new();
116 <   $self->{simpledoc}->newparse("branchbuilder");
117 <   $self->{simpledoc}->addignoretags("branchbuilder");
115 > sub architecture()
116 >   {
117 >   my ($object,$name,%attributes)=@_;
118 >   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 >   }
123  
124 <   # For blank lines do nothing:
125 <   $self->{simpledoc}->addtag("branchbuilder","none",
126 <                              "", $self,
127 <                              "", $self,
128 <                              "", $self);
129 <  
130 <   # Define the tags to be used in this class:
131 <   $self->{simpledoc}->addtag("branchbuilder","productstore",
132 <                              \&BuildSystem::TagUtils::productstoretagOpen, $self,
133 <                              "", $self,
134 <                              "", $self);
135 <  
136 <   $self->{simpledoc}->addtag("branchbuilder","architecture",
137 <                              \&BuildSystem::TagUtils::archtagOpen, $self,
138 <                              "", $self,
139 <                              \&BuildSystem::TagUtils::archtagClose, $self);
140 <
141 <   $self->{simpledoc}->addtag("branchbuilder","include_path",
142 <                              \&BuildSystem::TagUtils::includetagOpen, $self,
143 <                              "", $self,
144 <                              "", $self);
145 <  
146 <   $self->{simpledoc}->addtag("branchbuilder","export",
147 <                              \&BuildSystem::TagUtils::exporttagOpen, $self,
148 <                              "", $self,
149 <                              \&BuildSystem::TagUtils::exporttagClose, $self);
150 <
151 <   $self->{simpledoc}->addtag("branchbuilder","define_group",
152 <                              \&BuildSystem::TagUtils::groupdeftagOpen, $self,
153 <                              "", $self,
154 <                              \&BuildSystem::TagUtils::groupdeftagClose, $self);
155 <  
156 <   $self->{simpledoc}->addtag("branchbuilder","group",
157 <                              \&BuildSystem::TagUtils::grouptagOpen, $self,
158 <                              "", $self,
159 <                              "", $self);
160 <  
161 <   $self->{simpledoc}->addtag("branchbuilder","lib",
162 <                              \&BuildSystem::TagUtils::libtagOpen, $self,
163 <                              "", $self,
164 <                              "", $self);
165 <
166 <   $self->{simpledoc}->addtag("branchbuilder","use",
167 <                              \&BuildSystem::TagUtils::usetagOpen, $self,
168 <                              "", $self,
169 <                              "", $self);
170 <  
171 <   $self->{simpledoc}->addtag("branchbuilder","libtype",
172 <                              \&BuildSystem::TagUtils::libtypetagOpen, $self,
173 <                              "", $self,
174 <                              "", $self);
175 <  
176 <   $self->{simpledoc}->addtag("branchbuilder","makefile",
177 <                              \&BuildSystem::TagUtils::makefiletagOpen, $self,
178 <                              \&BuildSystem::TagUtils::makefiletagContent, $self,
179 <                              \&BuildSystem::TagUtils::makefiletagClose, $self);
180 <
181 <   $self->{simpledoc}->addtag("branchbuilder","flags",
182 <                              \&BuildSystem::TagUtils::flagstagOpen, $self,
183 <                              "", $self,
184 <                              "", $self);
185 <  
186 <   $self->{simpledoc}->addtag("branchbuilder","bin",
187 <                              \&BuildSystem::TagUtils::binarytagOpen, $self,
188 <                              "", $self,
189 <                              \&BuildSystem::TagUtils::binarytagClose, $self);
190 <  
191 <   $self->{simpledoc}->addtag("branchbuilder","module",
192 <                              \&BuildSystem::TagUtils::moduletagOpen, $self,
193 <                              "", $self,
194 <                              \&BuildSystem::TagUtils::moduletagClose, $self);
195 <  
196 <   $self->{simpledoc}->addtag("branchbuilder","application",
197 <                              \&BuildSystem::TagUtils::applicationtagOpen, $self,
198 <                              "", $self,
199 <                              \&BuildSystem::TagUtils::applicationtagClose, $self);
200 <
201 <   $self->{simpledoc}->addtag("branchbuilder","library",
202 <                              \&BuildSystem::TagUtils::librarytagOpen, $self,
203 <                              "", $self,
204 <                              \&BuildSystem::TagUtils::librarytagClose, $self);
205 <  
206 <   return $self->{simpledoc};
124 > sub architecture_()
125 >   {
126 >   my ($object,$name,%attributes)=@_;
127 >   $self->{archflag}=pop @{$self->{archs}};
128 >   }
129 >
130 > sub export()
131 >   {
132 >   my ($object,$name,%attributes)=@_;
133 >   if (!$self->{archflag}){return;}
134 >   $self->pushlevel(); # Set nested to 1;
135 >   }
136 >
137 > sub export_()
138 >   {
139 >   my ($object,$name,%attributes)=@_;
140 >   if (!$self->{archflag}){return;}
141 >   $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 >   if (!$self->{archflag}){return;}
155 >   my $libname = $attributes{'name'};
156 >   # 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 >   my ($object,$name,$cdata)=@_;
174 >   if (!$self->{archflag}){return;}
175 >   $self->{nested} == 1 ? push(@{$self->{tagcontent}->{MAKEFILE}}, join("\n",@$cdata))
176 >      : push(@{$self->{content}->{MAKEFILE}}, join("\n",@$cdata));
177 >   }
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 >   if (!$self->{archflag}){return;}
189 >   # 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 >   my @flagvalues = ( $flagvaluestring );
194 >   # 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  
221 < sub parsebranchfiles()
221 > sub allflags()
222     {
223     my $self=shift;
224 <   my ($filenames)=@_; # array ref
225 <   # List of buildfiles:
226 <   $self->{localpaths}=$filenames;
227 <   $self->{simpledoc}=$self->_initbranchparser();
228 <   # We iterate over an array of files to be read in turn: all
229 <   # build data will be stored in the same BuildFile object:
230 <   $self->{simpledoc}->parsefilelist("branchbuilder",$filenames);
231 <   # We're done with the SimpleDoc object so delete it:
232 <   delete $self->{simpledoc};
224 >   # Return hash data for flags:
225 >   return $self->{content}->{FLAGS};
226 >   }
227 >
228 > sub bin()
229 >   {
230 >   my ($object,$name,%attributes) = @_;
231 >   if (!$self->{archflag}){return;}
232 >   $self->pushlevel(\%attributes);# Set nested to 1;
233 >   }
234 >
235 > sub bin_()
236 >   {
237 >   my ($object,$name,%attributes) = @_;
238 >   if (!$self->{archflag}){return;}
239 >   # 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 >
250 >   # Store the data:
251 >   $self->productcollector($name,'bin','BIN');
252 >   $self->poplevel();
253 >   }
254 >
255 > sub library()
256 >   {
257 >   my ($object,$name,%attributes) = @_;
258 >   if (!$self->{archflag}){return;}
259 >   $self->pushlevel(\%attributes);# Set nested to 1;
260 >   }
261 >
262 > sub library_()
263 >   {
264 >   my ($object,$name,%attributes) = @_;
265 >   if (!$self->{archflag}){return;}
266 >   # 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   sub productcollector()
# Line 275 | Line 289 | sub productcollector()
289     # Store the name:
290     $product->name($name);
291     $product->type($typeshort);
292 <   # Store the files:
293 <   $product->_files($self->{id}->{'file'},$self->{localpaths});
292 >   # 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     # Store the data content:
296     $product->_data($self->{tagcontent});
297     # And store in a hash (all build products in same place):
# Line 311 | Line 326 | sub dependencies()
326     return \%DEPS;
327     }
328  
329 < #
330 < # All data access methods are inherited from BuildDataUtils.
331 < #
329 > 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 > 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 >   my $buildtags=[ qw(BIN LIBRARY BUILDPRODUCTS) ];
394 >   my $skiptags=[ qw(ARCH EXPORT USE CLASSPATH) ];
395 >   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   1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines