ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/ToolDoc.pm
Revision: 1.1.2.11
Committed: Tue Jun 20 12:52:18 2000 UTC (24 years, 10 months ago) by williamc
Content type: text/plain
Branch: V0_9branch
Changes since 1.1.2.10: +71 -4 lines
Log Message:
updates to tool searching mechanism - now only take parameters requested rather than copying the whole tool

File Contents

# Content
1 #
2 # ToolDoc.pm
3 #
4 # Originally Written by Christopher Williams
5 #
6 # Description
7 # -----------
8 # SimpleDoc interface to initialise Tool objects
9 #
10 # Interface
11 # ---------
12 # new() : A new ToolDoc object
13 # tool(toolobj) : set the tool object for the class
14 # toolsearcher(searcher) : set the searcher for finding reference tools
15 # setup(file,$name,$version) : setup a tool object from the specified file
16 # return 0 for OK 1 for cancel
17 # interactive([0|1]) : set the interactive node 0=off 1=on
18
19 package BuildSystem::ToolDoc;
20 require 5.004;
21 use ActiveDoc::SimpleDoc;
22 use Utilities::Verbose;
23 @ISA=qw(Utilities::Verbose);
24
25 sub new {
26 my $class=shift;
27 $self={};
28 bless $self, $class;
29 $self->init();
30 return $self;
31 }
32
33 sub init {
34 my $self=shift;
35 $self->{switch}=ActiveDoc::SimpleDoc->new();
36 $self->{switch}->newparse("setup");
37 $self->{switch}->addtag("setup","Tool",\&Tool_Start, $self,
38 "", $self,
39 \&Tool_End, $self);
40 $self->{switch}->addtag("setup","Lib",\&Lib, $self,
41 "", $self,
42 "", $self);
43 $self->{switch}->addtag("setup","External",\&External_Start, $self,
44 "", $self,
45 "", $self);
46 $self->{switch}->addtag("setup","Client",\&Client_start, $self,
47 "", $self,
48 \&Client_end, $self);
49 $self->{switch}->addtag("setup","Environment",
50 \&Environment_Start, $self,
51 \&Env_text, $self,
52 \&Environment_End, $self);
53 $self->{switch}->grouptag("Tool","setup");
54 $self->{switch}->addtag("setup","Architecture",
55 \&Arch_Start,$self,
56 "", $self,
57 \&Arch_End,$self);
58 $self->{Arch}=1;
59 push @{$self->{ARCHBLOCK}}, $self->{Arch};
60
61 }
62
63 sub interactive {
64 my $self=shift;
65
66 @_?$self->{interactive}=shift
67 :((defined $self->{interactive})?$self->{interactive}:0);
68 }
69
70 sub tool {
71 my $self=shift;
72 $self->{tool}=shift;
73 }
74
75 sub toolsearcher {
76 my $self=shift;
77 if ( @_ ) {
78 $self->{toolboxsearcher}=shift;
79 }
80 return $self->{toolboxsearcher};
81 }
82
83 sub setup {
84 my $self=shift;
85 my $file=shift;
86 my $name=shift;
87 my $version=shift;
88
89 $self->{ToolEnv}{'SCRAMtoolname'}=$name;
90 $self->{ToolEnv}{'SCRAMtoolversion'}=$version;
91 $self->{ToolEnv}{'SCRAM_ARCH'}=$ENV{'SCRAM_ARCH'};
92
93 $name=~tr[A-Z][a-z];
94 $self->{tool}->name($name);
95 $self->{tool}->version($version);
96 $self->{switch}->filetoparse($file);
97 $self->{toolfound}=1;
98 $self->{switch}->parse("setup");
99 return $self->{toolfound};
100 }
101
102 sub featuretext {
103 my $self=shift;
104 my $feature=shift;
105
106 if ( @_ ) {
107 $self->{featuretext}{$feature}=shift;
108 }
109 else {
110 return ($self->{featuretext}{$feature});
111 }
112 }
113
114 sub _checkdefault {
115 my $self=shift;
116 my $hashref=shift;
117
118 if ( defined $$hashref{'default'} ) { #check default
119 my $default;
120 foreach $default ( split /:/, $$hashref{'default'} ) {
121 $default=~s/\"//;
122 if ($self->_testlocation($default,
123 [ $self->{tool}->getfeature($$hashref{'type'})] )) { return 1; }
124 }
125 }
126 return 0;
127 }
128
129 sub _testlocation {
130 my $self=shift;
131 my $default=shift;
132 my $testfiles=shift;
133 my $OK='false';
134 my $file;
135
136 chomp $default;
137 $default=$self->_expandvars($default);
138 print "Trying $default .... ";
139 if ( -f $default ) {
140 $OK="true";
141 }
142 else {
143 my $fh=FileHandle->new();
144 opendir $fh, $default or do { print "No \n"; return 0; };
145 ($#{$testfiles}==-1) ? $OK='false' : $OK='true';
146 print "\n";
147 my @files=readdir $fh;
148 undef $fh;
149 foreach $file ( @$testfiles ) {
150 print " Checking for $file .... ";
151 # now check that the required files are actually there
152 if ( ( $number = grep /\Q$file\L/, @files) == 0 ) {
153 $OK='false';
154 print "not found\n";
155 last;
156 }
157 print "found\n";
158 }
159 }
160 if ( $OK eq 'true' ) {
161 print "Directory Check Complete\n";
162 return 1
163 }
164 return 0
165 }
166
167 sub _expandvars {
168 my $self=shift;
169 my $string=shift;
170
171 return "" , if ( ! defined $string );
172 $string=~s{
173 \$\((\w+)\)
174 }{
175 if (defined $self->{ToolEnv}{$1}) {
176 $self->_expandvars($self->{ToolEnv}{$1});
177 } else {
178 "\$$1";
179 }
180 }egx;
181 $string=~s{
182 \$(\w+)
183 }{
184 if (defined $self->{ToolEnv}{$1}) {
185 $self->_expandvars($self->{ToolEnv}{$1});
186 } else {
187 "\$$1";
188 }
189 }egx;
190 return $string;
191 }
192
193
194 sub _askuser {
195 my $self=shift;
196 my $querystring=shift;
197 my $varname=shift;
198
199 print $self->featuretext($self->{EnvContext});
200 for ( ;; ) {
201 print "\n".$querystring." (RETURN to log as missing)\nset $varname = ";
202 $path=<STDIN>;
203 chomp $path;
204 if ( $path ne "" ) {
205 if ( defined $self->{'client'}) { # must be a location
206 if ( $self->_testlocation($path , "H", $Envtype{$type} )) {
207 return $path;
208 }
209 print "Error : ".$path." does not exist.\n";
210 next;
211 }
212 }
213 else {
214 return $path;
215 }
216 } #end for
217
218 }
219
220 #
221 # Propgate through the searcher collecting matching tools
222 #
223 sub _searchtools {
224 my $self=shift;
225 my $tool=shift;
226
227 my @tools=();
228 my $area;
229 my $rtool;
230 if ( defined $self->{toolboxsearcher} ) {
231 my $it=$self->{toolboxsearcher}->newiterator();
232 while ( ! $it->last() ) {
233 $area=$it->next();
234 if ( defined $area ) {
235 $self->verbose("Searching for ".$tool->name()." ".
236 $tool->version()." in ".$area->location());
237 $rtool=$area->toolbox()->gettool($tool->name(),$tool->version());
238 if ( (defined $rtool) && $rtool->equals($tool) ) {
239 push @tools,$rtool;
240 }
241 }
242 }
243 }
244 return @tools;
245 }
246
247 # search toolboxes for a nice list
248 #
249 sub _toolparamcopy {
250 my $self=shift;
251 my $tool=shift;
252 my $param=shift;
253
254 my $rv=0;
255 $self->verbose("Check Other Projects for tool");
256 my @validtools=$self->_searchtools($tool);
257 if ( ! $self->interactive() ) {
258 if ( $#validtools >=0 ) {
259 my @params=$validtools[0]->getfeature($param);
260 if ( $#params >=0 ) {
261 $self->verbose("Extracting Feature $param from tool".
262 " (= @params )\n");
263 $tool->setfeature($param,@params);
264 $rv=1;
265 }
266 }
267 }
268 return $rv;
269 }
270
271 # -- Tag Routines
272
273 sub Client_start {
274 my $self=shift;
275 my $name=shift;
276 my $hashref=shift;
277
278 if ( $self->{Arch} ) {
279 $self->{'client'}=1;
280 }
281 }
282
283 sub Client_end {
284 my $self=shift;
285 if ( $self->{Arch} ) {
286 undef $self->{'client'};
287 }
288 }
289
290 sub Tool_Start {
291 my $self=shift;
292 my $name=shift;
293 my $hashref=shift;
294
295 $self->{switch}->checktag($name, $hashref, 'name');
296 $self->{switch}->checktag($name, $hashref, 'version');
297 $self->{switch}->opengroup("Toolactive");
298
299 # lower case the name
300 $$hashref{'name'}=~tr[A-Z][a-z];
301 # make sure we only pick up the tool requested
302 if ( ( $self->{tool}->name() eq $$hashref{'name'} ) &&
303 ($self->{tool}->version() eq $$hashref{'version'})) {
304 $self->{switch}->
305 allowgroup("Toolactive",$self->{switch}->currentparsename());
306 $self->{ToolEnv}{'SCRAMtoolname'}=$$hashref{'name'};
307 $self->{ToolEnv}{'SCRAMtoolversion'}=$$hashref{'version'};
308 $self->{toolfound}=0;
309 }
310 else {
311 $self->{switch}->disallowgroup("Toolactive",
312 $self->{switch}->currentparsename());
313 }
314 }
315
316 sub Tool_End {
317 my $self=shift;
318 my $name=shift;
319 my $hashref=shift;
320
321 $self->{switch}->closegroup("Toolactive");
322 }
323
324 sub Environment_Start {
325 my $self=shift;
326 my $name=shift;
327 my $hashref=shift;
328
329 $self->{switch}->checktag($name, $hashref, 'name');
330 if ( $self->{Arch} ) {
331 if ( defined $self->{EnvContext} ) {
332 $self->parserror(" Attempted to open new <$name> context".
333 " without closing the previous one");
334 }
335 $self->{currentenvtext}="";
336 $self->{EnvContext}=$$hashref{'name'};
337 undef $self->{Envvalue};
338 if ( exists $$hashref{'type'} ) {
339 $$hashref{'type'}=~tr[A-Z][a-z];
340 $self->{tool}->type($$hashref{'name'},$$hashref{'type'});
341 }
342 if ( exists $$hashref{'value'}) {
343 $self->{Envvalue}=$$hashref{'value'};
344 }
345 elsif ( ! $self->interactive() ) {
346 # check other installed copies of the tool
347 if ( $self->_toolparamcopy($self->{tool},$$hashref{'name'}) ) {
348 my @tmp=$self->{tool}->getfeature($$hashref{'name'});
349 $self->{Envvalue}=$tmp[0]; # assume single val parameter!
350 }
351 elsif ( defined $ENV{$$hashref{'name'}} ) {
352 # check the environment
353 $self->{Envvalue}=$ENV{$$hashref{'name'}};
354 }
355 elsif ( $self->_checkdefault($hashref) ) {
356 $self->{Envvalue}=$$hashref{'default'};
357 }
358 }
359 }
360 }
361
362 sub Env_text {
363 my $self=shift;
364 my $name=shift;
365 my $string=shift;
366
367 if ( $self->{Arch} ) {
368 $self->{currentenvtext}=$self->{currentenvtext}.$string;
369 }
370 }
371
372 sub Environment_End {
373 my $self=shift;
374 my $name=shift;
375
376 if ( $self->{Arch} ) {
377 if ( ! defined $self->{EnvContext} ) {
378 $self->{switch}->parseerror("</$name> without an opening context");
379 }
380 # - set the help text
381 $self->featuretext($self->{EnvContext},$self->{currentenvtext});
382 if ( ! defined $self->{Envvalue} ) {
383 $self->{Envvalue}=$self->_askuser("Please Enter the Value Below:",
384 $self->{EnvContext});
385 }
386 $self->{Envvalue}=$self->_expandvars($self->{Envvalue});
387 $self->{tool}->addfeature($self->{EnvContext}, $self->{Envvalue});
388 $self->{ToolEnv}{$self->{EnvContext}}=$self->{Envvalue};
389 undef $self->{EnvContext};
390 undef $self->{Envvalue};
391 }
392 }
393
394 sub Lib {
395 my $self=shift;
396 my $name=shift;
397 my $hashref=shift;
398
399 $self->{switch}->checktag($name, $hashref, 'name');
400 if ( $self->{Arch} ) {
401 $self->{tool}->addfeature("lib",$$hashref{'name'});
402 }
403 }
404
405 sub External_Start {
406 my $self=shift;
407 my $name=shift;
408 my $hashref=shift;
409
410 $self->{switch}->checktag($name, $hashref,'ref');
411 if ( $self->{Arch} ) {
412 $self->{tool}->addfeature("_externals",$$hashref{'ref'});
413 }
414 }
415
416 sub Arch_Start {
417 my $self=shift;
418 my $name=shift;
419 my $hashref=shift;
420
421 $self->{switch}->checktag($name, $hashref,'name');
422 ( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
423 : ($self->{Arch}=0);
424 push @{$self->{ARCHBLOCK}}, $self->{Arch};
425 }
426
427 sub Arch_End {
428 my $self=shift;
429 my $name=shift;
430
431 pop @{$self->{ARCHBLOCK}};
432 $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
433 }
434
435