ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/Tool.pm
Revision: 1.1.2.9
Committed: Wed Jun 21 13:37:14 2000 UTC (24 years, 10 months ago) by williamc
Content type: text/plain
Branch: V0_9branch
Changes since 1.1.2.8: +58 -0 lines
Log Message:
Add runtime mechanism inside tool object itself

File Contents

# User Rev Content
1 williamc 1.1.2.1 #
2     # Tool.pm - Store basic tool properties
3     #
4     # Originally Written by Christopher Williams
5     #
6     # Description
7     # -----------
8     # Stores basic tool features
9     #
10     # Interface
11     # ---------
12     # new() : A new FeatureTool object
13     # name() : get/set the tools name
14     # version() : get set the tool version
15     # url() : get set the tool url
16     # features() : return a list of features defined (ordered in relation to
17     # their first definition)
18 williamc 1.1.2.3 # listtype(type) : return a list of all features of the specified type
19 williamc 1.1.2.1 # addfeature(name,@value) : add value(s) to the named feature
20     # setfeature(name,@value) : set value(s) for the named feature
21     # getfeature(name) : return a list of elements belonging to the named feature
22 williamc 1.1.2.2 # (with embedded dependencies)
23     # type(name[,type]) : get/set the type associated with a feature
24 williamc 1.1.2.1 # addrequirement() : add a requirement at the current parse position
25     # dependencies() : return a list of dependency objects
26 williamc 1.1.2.3 # store(location) : Save object to given file
27 williamc 1.1.2.2 # restore(location) : Restore object from specified file
28 williamc 1.1.2.5 # reset() : Clean out all the features
29 williamc 1.1.2.7 # equals(toolobj) : return 1 if the tools correspond in url version etc.
30 williamc 1.1.2.9 # runtime(hashref) : set the runtime environment into the specified hash
31 williamc 1.1.2.1
32     package BuildSystem::Tool;
33 williamc 1.1.2.6 use Utilities::Verbose;
34 williamc 1.1.2.1 require 5.004;
35 williamc 1.1.2.6 @ISA=qw(Utilities::Verbose);
36 williamc 1.1.2.1
37     sub new {
38     my $class=shift;
39     my $self={};
40     bless $self, $class;
41     return $self;
42     }
43    
44     sub name {
45     my $self=shift;
46    
47     @_?$self->{name}=shift
48     :$self->{name};
49     }
50    
51     sub version {
52     my $self=shift;
53    
54     @_?$self->{version}=shift
55     :$self->{version};
56     }
57    
58     sub url {
59     my $self=shift;
60    
61     @_?$self->{url}=shift
62     :$self->{url};
63 williamc 1.1.2.7 }
64    
65     sub equals {
66     my $self=shift;
67     my $tool=shift;
68    
69     my $rv=0;
70     if ( ($tool->url() eq $self->url() ) &&
71     ($tool->name() eq $self->name() ) &&
72     ($tool->version() eq $self->version()) ) {
73     $rv=1;
74     }
75     return $rv;
76 williamc 1.1.2.1 }
77    
78 williamc 1.1.2.3 sub listtype {
79     my $self=shift;
80     my $type=shift;
81    
82     my @list=();
83     foreach $v ( $self->features() ) {
84     if ( $self->type($v) eq $type ) {
85     push @list, $v;
86     }
87     }
88     return @list;
89     }
90    
91 williamc 1.1.2.2 sub type {
92     my $self=shift;
93     my $name=shift;
94    
95     if ( @_ ) {
96     $self->{featuretypes}{$name}=shift;
97     }
98     return ((defined $self->{featuretypes}{$name})?
99     $self->{featuretypes}{$name}:"");
100     }
101 williamc 1.1.2.1
102     sub addfeature {
103     my $self=shift;
104     my $name=shift;
105     my @value=@_;
106    
107     $self->_newfeature($name,@value);
108     push @{$self->{features}{$name}}, @value;
109     }
110    
111     sub setfeature {
112     my $self=shift;
113     my $name=shift;
114     my @value=@_;
115    
116     $self->_newfeature($name,@value);
117     @{$self->{features}{$name}}=@value;
118     }
119 williamc 1.1.2.9
120     # ---- runtime routines -----------
121     sub runtime {
122     my $self=shift;
123     my $hashref=shift;
124    
125     my ($val,$f);
126     # -- deal with path types
127     foreach $f ( $self->listtype("runtime_path")) {
128     foreach $val ( $self->getfeature($f) ) {
129     $self->_addpath($f,$val,$hashref);
130     }
131     }
132    
133     # -- regular vars
134     foreach $f ( $self->listtype("runtime")) {
135     foreach $val ( $self->getfeature($f) ) {
136     $self->_addvar($f,$val," ",$hashref);
137     }
138     }
139    
140     }
141    
142     sub _addpath {
143     my $self=shift;
144     my $name=shift;
145     my $val=shift;
146     my $hashref=shift;
147    
148     my $n;
149     my @env;
150     @env=split /:/, $$hashref{$name};
151     foreach $n ( (split /:/, $val ) ){
152     if ( ! grep /^\Q$n\E$/, @env ) { # dont add duplicates
153     $self->_addvar($name,$n,":",$hashref);
154     }
155     }
156     }
157    
158     sub _addvar {
159     my $self=shift;
160     my $name=shift;
161     my $val=shift;
162     my $sep=shift;
163     my $hashref=shift;
164    
165     if ( $val ne "" ) {
166     if ( defined $$hashref{$name} ) {
167     $$hashref{$name}=$$hashref{$name}.$sep.$val;
168     }
169     else {
170     $$hashref{$name}=$val;
171     }
172     }
173     }
174    
175     # --- end runtime routines
176 williamc 1.1.2.1
177 williamc 1.1.2.5 sub reset {
178     my $self=shift;
179     undef $self->{features};
180     undef $self->{'features_ordered'};
181     undef $self->{reqobjs};
182     undef $self->{requireposition};
183     }
184 williamc 1.1.2.1
185     sub _newfeature {
186     my $self=shift;
187     my $name=shift;
188     my @value=@_;
189    
190     # if it dosnt exist , make sure we first mark all the current reqs
191     # get inserted beforehand
192     if ( ! exists $self->{features}{$name} ) {
193     # add feature name to our ordered list
194     push @{$self->{'features_ordered'}},$name;
195     for ( $i=0; $i<=$#{$self->{reqobjs}}; $i++ ) {
196     $self->_recordpos( $name, $i);
197     }
198     }
199     }
200    
201     sub features {
202     my $self=shift;
203    
204     # return (keys %{$self->{features}});
205     return @{$self->{'features_ordered'}};
206     }
207    
208     sub getfeature {
209     my $self=shift;
210     my $name=shift;
211    
212     my @rv=();
213     my @rep;
214     # make sure we insert requirements at the right place
215     for ( my $i=-1; $i<=$#{$self->{features}{$name}}; $i++ ) {
216     if ( $i>=0 ) {
217     push @rv, $self->{features}{$name}[$i];
218     }
219     my @rep=$self->_testpos($name, $i);
220     my $repobj;
221     foreach $repobj ( @rep ) {
222     push @rv, $repobj->getfeature($name);
223     }
224     }
225     return @rv;
226     }
227    
228     sub clearfeature {
229     my $self=shift;
230     my $name=shift;
231    
232     undef @{$self->{features}{$name}};
233     }
234    
235     sub addrequirement {
236     my $self=shift;
237     my $reqobj=shift;
238    
239     push @{$self->{reqobjs}}, $reqobj;
240     foreach $key ( keys %{$self->{features}} ) {
241     $self->_recordpos($key,$#{$self->{reqobjs}});
242     }
243     }
244    
245     sub dependencies {
246     my $self=shift;
247     return @{$self->{recobjs}}
248     }
249    
250 williamc 1.1.2.3 sub store {
251 williamc 1.1.2.2 my $self=shift;
252     my $location=shift;
253    
254     my $fh=FileHandle->new();
255 williamc 1.1.2.6 $self->verbose("opening $location for output");
256 williamc 1.1.2.2 $fh->open(">".$location) or die "Unable to open $location for output".
257     $!."\n";
258 williamc 1.1.2.3 print $fh "name:".$self->name().":_sys\n";
259     print $fh "version:".$self->version().":_sys\n";
260 williamc 1.1.2.4 print $fh "url:".$self->url().":_sys\n";
261 williamc 1.1.2.2 foreach $f ( $self->features()) {
262     foreach $val ( $self->getfeature($f) ) {
263 williamc 1.1.2.3 print $fh $f.":".$val.":".$self->type($f)."\n";
264 williamc 1.1.2.2 }
265     }
266     undef $fh;
267     }
268    
269     sub restore {
270     my $self=shift;
271     my $location=shift;
272    
273     my $fh=FileHandle->new();
274     $fh->open("<".$location) or die "Unable to open $location for output".
275     $!."\n";
276     my ($tool,$type,$variable,$value);
277     while ( <$fh> ) {
278     chomp;
279     next if /^#/;
280     next if /^\s*$/;
281 williamc 1.1.2.3 ($variable, $value, $type)=split /:/;
282 williamc 1.1.2.2 next if ( $variable=~/\&/ );
283     $product=~tr[A-Z][a-z];
284     if ( $type eq "_sys" ) {
285 williamc 1.1.2.3 if ( $self->can($variable)) {
286 williamc 1.1.2.2 $self->$variable($value);
287     }
288     }
289     else {
290     $self->addfeature($variable,$value);
291 williamc 1.1.2.8 if ( $type ne "" ) {
292     $self->type($variable,$type);
293     }
294 williamc 1.1.2.2 }
295     }
296     undef $fh;
297     }
298    
299 williamc 1.1.2.1 sub _recordpos {
300     my $self=shift;
301     my $name=shift;
302     my $recref=shift;
303    
304     push @{$self->{requireposition}{$name}{$#{$self->{features}{$name}}}}
305     ,$recref;
306     }
307    
308     # return array of objects that correspond to the required position
309     sub _testpos {
310     my $self=shift;
311     my $name=shift;
312     my $ref=shift;
313    
314     my @rv=();
315     if ( exists $self->{requireposition}{$name}{$ref} ) {
316     foreach $recref ( @{$self->{requireposition}{$name}{$ref}} ) {
317     push @rv, $self->{reqobjs}[$recref];
318     }
319     }
320     return @rv;
321     }
322 williamc 1.1.2.2
323