ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/TreeItem.pm
Revision: 1.6
Committed: Fri Dec 14 09:03:48 2007 UTC (17 years, 4 months ago) by muzaffar
Content type: text/plain
Branch: MAIN
CVS Tags: V1_1_7, V1_1_6, V1_1_5, V1_1_4, V1_1_3, V1_1_2, V1_1_0_reltag8, V1_1_0_reltag7, V1_1_0_reltag6, V1_1_1, V1_1_0_reltag5, V1_1_0_reltag4, V1_1_0_reltag3, V1_1_0_reltag2, V1_1_0_reltag1, V1_1_0_reltag, V1_1_0_cand3, V1_1_0_cand2, V1_1_0_cand1
Branch point for: forBinLess_SCRAM
Changes since 1.5: +1 -1 lines
Log Message:
replace head with xml branch

File Contents

# User Rev Content
1 sashby 1.2 #____________________________________________________________________
2     # File: TreeItem.pm
3     #____________________________________________________________________
4     #
5     # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6     # Update: 2004-06-24 12:24:57+0200
7 muzaffar 1.6 # Revision: $Id: TreeItem.pm,v 1.4.4.1 2007/11/08 15:25:27 muzaffar Exp $
8 sashby 1.2 #
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 sashby 1.3 sub skip()
103     {
104     my $self=shift;
105     # Skip/unskip a directory:
106     @_ ? $self->{SKIP} = shift
107     : $self->{SKIP};
108     }
109    
110 muzaffar 1.5 sub productstore()
111     {
112     my $self=shift;
113     @_ ? $self->{PRODUCTSTORES} = shift
114     : $self->{PRODUCTSTORES};
115     }
116    
117 sashby 1.2 sub name()
118     {
119     my $self=shift;
120 muzaffar 1.5 my $n=shift;
121     if(defined $n){$self->{NAME}=$n; return;}
122 sashby 1.2
123     # Don't bother doing any work if the NAME exists already - just return it:
124     if (! exists($self->{NAME}))
125     {
126     my $classdir = $self->{CLASSDIR}; # Make a copy for protection
127     # Here we want to return a name that can be used in the templates.
128     # The name could be the name of the subsystem or the package:
129     if ($self->{CLASS} eq 'PACKAGE')
130     {
131     ($self->{NAME}) = ($classdir =~ m|^.*/(.*)?$|);
132     }
133     elsif ($self->{CLASS} eq 'SUBSYSTEM')
134     {
135     # We want the name of the subsystem:
136     ($self->{NAME}) = ($classdir =~ m|^.*/(.*)?$|);
137     }
138 sashby 1.4 elsif ($self->{CLASS} eq 'DOMAIN')
139     {
140     # We want the name of the domain:
141     ($self->{NAME}) = ($classdir =~ m|^.*/(.*)?$|);
142     }
143 muzaffar 1.5 elsif ($self->{CLASS} eq 'LIBRARY')
144     {
145     #use SCRAM::ProductName;
146     #my $n = &SCRAM::ProductName::get_safename($classdir);
147     my $n="";
148     if ($n ne "")
149     {
150     $self->{NAME} = $n;
151     }
152     }
153     if (! exists($self->{NAME}))
154 sashby 1.2 {
155     # Here we have a path that ends in src/bin/test/doc etc. (for real
156     # build products). We still want to return the package name:
157     ($self->{NAME}) = ($classdir =~ m|^.*/(.*)/.*?$|);
158     }
159     }
160     else
161     {
162     return $self->{NAME};
163     }
164     }
165    
166     sub rawdata()
167     {
168     my $self=shift;
169     my ($rawdata)=@_;
170 sashby 1.3
171 sashby 1.2 if ($rawdata)
172     {
173     $self->{RAWDATA} = $rawdata;
174     return $self;
175     }
176     else
177     {
178     if (exists ($self->{RAWDATA}))
179     {
180     return $self->{RAWDATA};
181     }
182     else
183     {
184     return undef;
185     }
186     }
187     }
188    
189     sub parent()
190     {
191     my $self=shift;
192     my ($datapath)=@_;
193     my $thisloc;
194    
195     if ($datapath)
196     {
197     # We don't want to store the parent of src (it has no parent):
198     if ($datapath eq $ENV{SCRAM_SOURCEDIR})
199     {
200     return;
201     }
202    
203     # Given a path like a/b/c we want to return the parent a/b:
204     ($thisloc) = ($datapath =~ m|^(.*)/.*?$|);
205    
206     if ($thisloc ne '')
207     {
208     $self->{PARENT} = $thisloc;
209     }
210     else
211     {
212     $self->{PARENT} = $ENV{SCRAM_SOURCEDIR};
213     }
214     }
215     else
216     {
217     (exists ($self->{PARENT})) ? return $self->{PARENT} : '' ;
218     }
219     }
220    
221     sub children()
222     {
223     my $self=shift;
224     my ($filecache) = @_;
225     my $safesubs=[];
226    
227     if ($filecache)
228     {
229     if (exists $filecache->{$self->{PATH}})
230     {
231     # Get array ref:
232     my @subdirs=@{$filecache->{$self->{PATH}}};
233     my $children=[];
234    
235     foreach my $SD (@subdirs)
236     {
237     # We don't want timestamps or CVS directories:
238     if ($SD !~ /.*CVS/ && $SD !~ /^[0-9]+$/)
239     {
240     my $datapath;
241     # We want to store the data paths for the children:
242     ($datapath = $SD) =~ s|^\Q$ENV{SCRAM_SOURCEDIR}\L/||;
243     push(@$children,$datapath);
244     push(@$safesubs,$SD);
245     }
246     }
247    
248     # Store the children only if there were some:
249     if ($#$children > -1)
250     {
251     $self->{CHILDREN} = $children;
252     # Make safe versions of each subdir:
253     $self->safesubdirs(@$safesubs);
254     }
255     }
256     }
257     else
258     {
259     (exists ($self->{CHILDREN})) ? return @{$self->{CHILDREN}} : undef ;
260     }
261     }
262    
263     sub metabf()
264     {
265     my $self=shift;
266     my (@metabf) = @_;
267    
268     if (@metabf)
269     {
270     foreach my $mbf (@metabf)
271     {
272     if (! grep($mbf eq $_, @{$self->{METABF}})) # Remove duplicates!!
273     {
274     push(@{$self->{METABF}}, $mbf);
275     }
276     }
277     }
278     else
279     {
280     return $self->{METABF};
281     }
282     }
283    
284     sub branchmetadata()
285     {
286     my $self=shift;
287     my ($meta)=@_;
288    
289     # Method to store/retrieve data for complete branch:
290     if ($meta)
291     {
292     # Delete unneeded entries:
293 muzaffar 1.5 #$meta->clean(qw( EXPORT DEFINED_GROUP CLASSPATH SKIPPEDDIRS ));
294     $self->{RAWDATA} = $meta;
295 sashby 1.2 }
296     else
297     {
298 muzaffar 1.5 return $self->{RAWDATA};
299 sashby 1.2 }
300     }
301    
302     sub branchdata()
303     {
304     my $self=shift;
305 muzaffar 1.5 @_ ? $self->{RAWDATA} = shift
306     : $self->{RAWDATA};
307 sashby 1.2 }
308    
309     sub clearmeta()
310     {
311     my $self=shift;
312 muzaffar 1.5 delete $self->{RAWDATA};
313 sashby 1.2 }
314    
315     sub updatechildlist()
316     {
317     my $self=shift;
318     my ($child)=@_;
319    
320     # Loop over list of children, removing the one specified:
321     my $uchildren = [];
322     my $uchilddirs = [];
323    
324     foreach my $c (@{$self->{CHILDREN}})
325     {
326     if ($c ne $child)
327     {
328     push(@$uchildren, $c);
329     # Convert this datapath into a path to be converted to a safepath:
330     push(@{$uchilddirs}, 'src/'.$c);
331     }
332     else
333     {
334     print "TreeItem: Removing $child from parents child list.","\n",if ($ENV{SCRAM_DEBUG});
335     }
336     }
337    
338     # Now store the new list of children:
339     $self->{CHILDREN} = [ @$uchildren ];
340     # Update the safe subdir names:
341     $self->updatesafesubdirs(@$uchilddirs);
342     }
343    
344     sub updatesafesubdirs()
345     {
346     my $self=shift;
347     my (@subdirs)=@_;
348     # Reset the SAFESUBDIRS to the list of subdirs given:
349     delete $self->{SAFESUBDIRS};
350     $self->safesubdirs(@subdirs);
351     }
352    
353     sub updateparentstatus()
354     {
355     my $self=shift;
356     my ($child) = @_;
357    
358     # Add child to CHILDREN (check to make sure it isn't there already):
359     if (exists($self->{CHILDREN}))
360     {
361     if (! grep($child eq $_, @{$self->{CHILDREN}})) # Remove duplicates!!
362     {
363     push(@{$self->{CHILDREN}},$child);
364     }
365     }
366     else
367     {
368     $self->{CHILDREN} = [ $child ];
369     }
370    
371     # Add the SAFESUBDIRS:
372     my $safedir = [ 'src/'.$child ];
373     $self->safesubdirs(@$safedir);
374     }
375    
376     sub template()
377     {
378     my $self=shift;
379     @_ ? $self->{TEMPLATE} = shift
380     : $self->{TEMPLATE};
381     }
382    
383     sub safesubdirs()
384     {
385     my $self=shift;
386     my (@subdirs)=@_;
387    
388     if (@subdirs)
389     {
390     # If we already have SAFESUBDIRS, add to them, don't overwrite:
391     if (exists($self->{SAFESUBDIRS}))
392     {
393     # Store the safe paths of all the children:
394     foreach my $sd (@subdirs)
395     {
396     $sd =~ s|/|_|g;
397     if (! grep($sd eq $_, @{$self->{SAFESUBDIRS}})) # Remove duplicates!!
398     {
399     push(@{$self->{SAFESUBDIRS}}, $sd);
400     }
401     }
402     }
403     else
404     {
405     my $safesubs=[];
406     map {$_ =~ s|/|_|g; push(@$safesubs, $_)} @subdirs;
407     $self->{SAFESUBDIRS} = $safesubs;
408     }
409     }
410     else
411     {
412     # Return formatted as a string:
413     return join(" ",@{$self->{SAFESUBDIRS}});
414     }
415     }
416    
417     sub scramprojectbases()
418     {
419     my $self=shift;
420     # This is needed at project level only:
421     @_ ? $self->{SCRAM_PROJECT_BASES} = shift
422     : $self->{SCRAM_PROJECT_BASES};
423     }
424    
425 muzaffar 1.5 sub publictype()
426     {
427     my $self=shift;
428     my $type=shift;
429     if (defined $type) {$self->{PUBLIC} = $type; return;}
430     if(exists $self->{PUBLIC}){return $self->{PUBLIC};}
431     return 0;
432     }
433    
434 sashby 1.2 sub clean()
435     {
436     my $self=shift;
437 muzaffar 1.5 delete $self->{RAWDATA};
438 sashby 1.2 }
439    
440     1;