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

Comparing COMP/SCRAM/src/BuildSystem/TreeItem.pm (file contents):
Revision 1.1 by sashby, Tue Jul 20 12:01:46 2004 UTC vs.
Revision 1.2 by sashby, Fri Dec 10 13:41:38 2004 UTC

# Line 0 | Line 1
1 + #____________________________________________________________________
2 + # File: TreeItem.pm
3 + #____________________________________________________________________
4 + #  
5 + # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6 + # Update: 2004-06-24 12:24:57+0200
7 + # Revision: $Id$
8 + #
9 + # Copyright: 2004 (C) Shaun Ashby
10 + #
11 + #--------------------------------------------------------------------
12 + package BuildSystem::TreeItem;
13 + require 5.004;
14 + use Exporter;
15 + @ISA=qw(Exporter);
16 + @EXPORT_OK=qw( );
17 +
18 + sub new()
19 +  ###############################################################
20 +  # new                                                         #
21 +  ###############################################################
22 +  # modified : Thu Jun 24 12:25:02 2004 / SFA                   #
23 +  # params   :                                                  #
24 +  #          :                                                  #
25 +  # function :                                                  #
26 +  #          :                                                  #
27 +  ###############################################################
28 +  {
29 +  my $proto=shift;
30 +  my $class=ref($proto) || $proto;
31 +  my $self={};
32 +
33 +  bless $self,$class;
34 +  $self->{METABF} = [];
35 +  return $self;
36 +  }
37 +
38 + sub safepath()
39 +   {
40 +   my $self=shift;
41 +  
42 +   if ($self->{PATH})
43 +      {
44 +      # Make a safe path from our path:
45 +      ($safepath = $self->{PATH}) =~ s|/|_|g;
46 +      $self->{SAFEPATH} = $safepath;
47 +      }
48 +
49 +   # Return the safe version of the current path:
50 +   return $self->{SAFEPATH};
51 +   }
52 +
53 + sub path()
54 +   {
55 +   my $self=shift;
56 +   @_ ? $self->{PATH} = shift
57 +      : $self->{PATH};
58 +   }
59 +
60 + sub class()
61 +   {
62 +   my $self=shift;
63 +   my ($class)=@_;
64 +   # Set/return the part of the ClassPath that matched a template name.
65 +   # Note that we store it as uppercase! The template name is, of course,
66 +   # exactly as it appears in the ClassPath:
67 +   if ($class)
68 +      {
69 +      # Store template name. We add the standard suffix:
70 +      $self->template($class."_template.tmpl");
71 +      $self->{CLASS} = uc($class);
72 +      }
73 +   else
74 +      {
75 +      return $self->{CLASS};
76 +      }
77 +   }
78 +
79 + sub template()
80 +   {
81 +   my $self=shift;
82 +   @_ ? $self->{TEMPLATE} = shift
83 +      : $self->{TEMPLATE};
84 +   }
85 +
86 + sub classdir()
87 +   {
88 +   my $self=shift;
89 +   # Set/return the part of the ClassPath that matched:
90 +   @_ ? $self->{CLASSDIR} = shift
91 +      : $self->{CLASSDIR};
92 +   }
93 +
94 + sub suffix()
95 +   {
96 +   my $self=shift;
97 +   # Set/return the part of the ClassPath that didn't match:
98 +   @_ ? $self->{SUFFIX} = shift
99 +      : $self->{SUFFIX};
100 +   }
101 +
102 + sub name()
103 +   {
104 +   my $self=shift;
105 +
106 +   # Don't bother doing any work if the NAME exists already - just return it:
107 +   if (! exists($self->{NAME}))
108 +      {
109 +      my $classdir = $self->{CLASSDIR}; # Make a copy for protection      
110 +      # Here we want to return a name that can be used in the templates.
111 +      # The name could be the name of the subsystem or the package:
112 +      if ($self->{CLASS} eq 'PACKAGE')
113 +         {
114 +         ($self->{NAME}) = ($classdir =~ m|^.*/(.*)?$|);        
115 +         }
116 +      elsif ($self->{CLASS} eq 'SUBSYSTEM')
117 +         {
118 +         # We want the name of the subsystem:
119 +         ($self->{NAME}) = ($classdir =~ m|^.*/(.*)?$|);
120 +         }
121 +      else
122 +         {
123 +         # Here we have a path that ends in src/bin/test/doc etc. (for real
124 +         # build products). We still want to return the package name:
125 +         ($self->{NAME}) = ($classdir =~ m|^.*/(.*)/.*?$|);
126 +         }
127 +      }
128 +   else  
129 +      {
130 +      return $self->{NAME};
131 +      }
132 +   }
133 +
134 + sub rawdata()
135 +   {
136 +   my $self=shift;
137 +   my ($rawdata)=@_;
138 +  
139 +   if ($rawdata)
140 +      {
141 +      $self->{RAWDATA} = $rawdata;
142 +      return $self;
143 +      }
144 +   else
145 +      {      
146 +      if (exists ($self->{RAWDATA}))
147 +         {
148 +         return $self->{RAWDATA};
149 +         }
150 +      else
151 +         {
152 +         return undef;
153 +         }
154 +      }
155 +   }
156 +
157 + sub parent()
158 +   {
159 +   my $self=shift;
160 +   my ($datapath)=@_;
161 +   my $thisloc;
162 +
163 +   if ($datapath)
164 +      {
165 +      # We don't want to store the parent of src (it has no parent):
166 +      if ($datapath eq $ENV{SCRAM_SOURCEDIR})
167 +         {
168 +         return;
169 +         }
170 +      
171 +      # Given a path like a/b/c we want to return the parent a/b:
172 +      ($thisloc) = ($datapath =~ m|^(.*)/.*?$|);
173 +
174 +      if ($thisloc ne '')
175 +         {
176 +         $self->{PARENT} = $thisloc;
177 +         }
178 +      else
179 +         {
180 +         $self->{PARENT} = $ENV{SCRAM_SOURCEDIR};
181 +         }
182 +      }
183 +   else
184 +      {
185 +      (exists ($self->{PARENT})) ? return $self->{PARENT} : '' ;
186 +      }
187 +   }
188 +
189 + sub children()
190 +   {
191 +   my $self=shift;
192 +   my ($filecache) = @_;
193 +   my $safesubs=[];
194 +  
195 +   if ($filecache)
196 +      {
197 +      if (exists $filecache->{$self->{PATH}})
198 +         {
199 +         # Get array ref:
200 +         my @subdirs=@{$filecache->{$self->{PATH}}};
201 +         my $children=[];
202 +
203 +         foreach my $SD (@subdirs)
204 +            {
205 +            # We don't want timestamps or CVS directories:
206 +            if ($SD !~ /.*CVS/ && $SD !~ /^[0-9]+$/)
207 +               {
208 +               my $datapath;
209 +               # We want to store the data paths for the children:
210 +               ($datapath = $SD) =~ s|^\Q$ENV{SCRAM_SOURCEDIR}\L/||;
211 +               push(@$children,$datapath);
212 +               push(@$safesubs,$SD);
213 +               }
214 +            }
215 +        
216 +         # Store the children only if there were some:
217 +         if ($#$children > -1)
218 +            {
219 +            $self->{CHILDREN} = $children;
220 +            # Make safe versions of each subdir:
221 +            $self->safesubdirs(@$safesubs);
222 +            }
223 +         }
224 +      }
225 +   else
226 +      {
227 +      (exists ($self->{CHILDREN})) ? return @{$self->{CHILDREN}} : undef ;
228 +      }
229 +   }
230 +
231 + sub metabf()
232 +   {
233 +   my $self=shift;
234 +   my (@metabf) = @_;
235 +
236 +   if (@metabf)
237 +      {      
238 +      foreach my $mbf (@metabf)
239 +         {
240 +         if (! grep($mbf eq $_, @{$self->{METABF}})) # Remove duplicates!!
241 +            {
242 +            push(@{$self->{METABF}}, $mbf);
243 +            }
244 +         }
245 +      }
246 +   else
247 +      {
248 +      return $self->{METABF};
249 +      }
250 +   }
251 +
252 + sub branchmetadata()
253 +   {
254 +   my $self=shift;
255 +   my ($meta)=@_;
256 +
257 +   # Method to store/retrieve data for complete branch:
258 +   if ($meta)
259 +      {
260 +      # Delete unneeded entries:
261 +      $meta->clean(qw( EXPORT DEFINED_GROUP CLASSPATH ));
262 +      $self->{BRANCHMETA} = $meta;
263 +      }
264 +   else
265 +      {
266 +      return $self->{BRANCHMETA};
267 +      }
268 +   }
269 +
270 + sub branchdata()
271 +   {
272 +   my $self=shift;
273 +   @_ ? $self->{BRANCHDATA} = shift
274 +      : $self->{BRANCHDATA};
275 +   }
276 +
277 + sub clearmeta()
278 +   {
279 +   my $self=shift;
280 +   delete $self->{BRANCHDATA}, if (exists $self->{BRANCHDATA});
281 +   }
282 +
283 + sub updatechildlist()
284 +   {
285 +   my $self=shift;
286 +   my ($child)=@_;
287 +
288 +   # Loop over list of children, removing the one specified:
289 +   my $uchildren = [];
290 +   my $uchilddirs = [];
291 +  
292 +   foreach my $c (@{$self->{CHILDREN}})
293 +      {
294 +      if ($c ne $child)
295 +         {
296 +         push(@$uchildren, $c);
297 +         # Convert this datapath into a path to be converted to a safepath:
298 +         push(@{$uchilddirs}, 'src/'.$c);
299 +         }
300 +      else
301 +         {
302 +         print "TreeItem: Removing $child from parents child list.","\n",if ($ENV{SCRAM_DEBUG});
303 +         }
304 +      }
305 +  
306 +   # Now store the new list of children:
307 +   $self->{CHILDREN} = [ @$uchildren ];
308 +   # Update the safe subdir names:
309 +   $self->updatesafesubdirs(@$uchilddirs);  
310 +   }
311 +
312 + sub updatesafesubdirs()
313 +   {
314 +   my $self=shift;
315 +   my (@subdirs)=@_;
316 +   # Reset the SAFESUBDIRS to the list of subdirs given:
317 +   delete $self->{SAFESUBDIRS};
318 +   $self->safesubdirs(@subdirs);
319 +   }
320 +
321 + sub updateparentstatus()
322 +   {
323 +   my $self=shift;
324 +   my ($child) = @_;
325 +
326 +   # Add child to CHILDREN (check to make sure it isn't there already):
327 +   if (exists($self->{CHILDREN}))
328 +      {
329 +      if (! grep($child eq $_, @{$self->{CHILDREN}})) # Remove duplicates!!
330 +         {
331 +         push(@{$self->{CHILDREN}},$child);
332 +         }
333 +      }
334 +   else
335 +      {
336 +      $self->{CHILDREN} = [ $child ];
337 +      }
338 +
339 +   # Add the SAFESUBDIRS:
340 +   my $safedir = [ 'src/'.$child ];
341 +   $self->safesubdirs(@$safedir);
342 +   }
343 +
344 + sub template()
345 +   {
346 +   my $self=shift;
347 +   @_ ? $self->{TEMPLATE} = shift
348 +      : $self->{TEMPLATE};
349 +   }
350 +
351 + sub safesubdirs()
352 +   {
353 +   my $self=shift;
354 +   my (@subdirs)=@_;
355 +  
356 +   if (@subdirs)
357 +      {      
358 +      # If we already have SAFESUBDIRS, add to them, don't overwrite:
359 +      if (exists($self->{SAFESUBDIRS}))
360 +         {
361 +         # Store the safe paths of all the children:
362 +         foreach my $sd (@subdirs)
363 +            {
364 +            $sd =~ s|/|_|g;
365 +            if (! grep($sd eq $_, @{$self->{SAFESUBDIRS}})) # Remove duplicates!!
366 +               {
367 +               push(@{$self->{SAFESUBDIRS}}, $sd);
368 +               }
369 +            }
370 +         }
371 +      else
372 +         {
373 +         my $safesubs=[];
374 +         map {$_ =~ s|/|_|g; push(@$safesubs, $_)} @subdirs;
375 +         $self->{SAFESUBDIRS} = $safesubs;
376 +         }
377 +      }
378 +   else
379 +      {
380 +      # Return formatted as a string:
381 +      return join(" ",@{$self->{SAFESUBDIRS}});
382 +      }
383 +   }
384 +
385 + sub scramprojectbases()
386 +   {
387 +   my $self=shift;
388 +   # This is needed at project level only:
389 +   @_ ? $self->{SCRAM_PROJECT_BASES} = shift
390 +      : $self->{SCRAM_PROJECT_BASES};
391 +   }
392 +
393 + sub clean()
394 +   {
395 +   my $self=shift;
396 +   delete $self->{BRANCHMETA};
397 +   }
398 +
399 + 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines