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

Comparing COMP/SCRAM/src/BuildSystem/ToolDoc.pm (file contents):
Revision 1.3 by williamc, Mon Oct 23 12:56:03 2000 UTC vs.
Revision 1.5 by williamc, Wed Nov 15 10:50:57 2000 UTC

# Line 28 | Line 28 | sub new {
28          bless $self, $class;
29          $self->{cache}=shift;
30          $self->{mydoctype}="BuildSystem::ToolDoc";
31 <        $self->{mydocversion}="1.0";
31 >        $self->{mydocversion}="1.1";
32          $self->init();
33          return $self;
34   }
# Line 36 | Line 36 | sub new {
36   sub init {
37          my $self=shift;
38          $self->{switch}=ActiveDoc::SimpleDoc->new();
39 +        $self->{switch}->newparse("setupinit");
40 +        $self->{switch}->addtag("setupinit","Tool",\&Tool_Start, $self,
41 +                                                "", $self,
42 +                                                \&Tool_End, $self);
43 +        $self->{switch}->addtag("setupinit", "Architecture",
44 +                                        \&Arch_Start,$self,
45 +                                        "", $self,
46 +                                        \&Arch_End,$self);
47 +        $self->{switch}->addtag("setupinit","Environment",
48 +                                        \&Environment_init, $self,
49 +                                        "", $self,
50 +                                        "", $self);
51 +        $self->{switch}->grouptag("Tool","setupinit");
52 +
53          $self->{switch}->newparse("setup");
54          $self->{switch}->addtag("setup","Tool",\&Tool_Start, $self,    
55                                                  "", $self,
# Line 53 | Line 67 | sub init {
67                                                  \&Environment_Start, $self,    
68                                                  \&Env_text, $self,
69                                                  \&Environment_End, $self);
70 +        $self->{switch}->addtag("setup","Makefile",
71 +                                                \&Makefile_Start, $self,        
72 +                                                \&Makefile_text, $self,
73 +                                                \&Makefile_end, $self);
74          $self->{switch}->grouptag("Tool","setup");
75          $self->{switch}->addtag("setup","Architecture",
76                                          \&Arch_Start,$self,
# Line 93 | Line 111 | sub setup {
111          my $file=shift;
112          my $name=shift;
113          my $version=shift;
114 +        my $toolbox=shift;
115  
116          $self->{ToolEnv}{'SCRAMtoolname'}=$name;
117          $self->{ToolEnv}{'SCRAMtoolversion'}=$version;
# Line 105 | Line 124 | sub setup {
124          $self->{toolfound}=1;
125          # -- check the type of document - can we parse it?
126          my($doctype,$docversion)=$self->{switch}->doctype();
127 <        if ( ($doctype ne $self->{mydoctype}) ||
128 <                ($self->{mydocversion} ne $docversion) ) {
127 >        if (($doctype ne $self->{mydoctype}) ||
128 >          (($self->{mydocversion} ne $docversion) && ($docversion ne "1.0")) ) {
129            $self->error("Unable to Parse Document of type $doctype $docversion".
130                  "\n(Only ".$self->{mydoctype}." ". $self->{mydocversion}.")");
131          }
132 +        delete $self->{envcount};
133 +        $self->verbose("Pre-Parse");
134 +        $self->{switch}->parse("setupinit");
135 +        $self->{toolmakefile}=$toolbox->toolmakefile($name,$version);
136 +        $self->verbose("Setup Parse");
137          $self->{switch}->parse("setup");
138 +        undef $self->{toolmakefilefh};
139          return $self->{toolfound};
140   }
141  
# Line 145 | Line 170 | sub _testlocation {
170          my $self=shift;
171          my $default=shift;
172          my $testfiles=shift;
173 +
174          my $OK='false';
175          my $file;
176  
177          chomp $default;
178          $default=$self->_expandvars($default);
179 +        $self->verbose("Testing location");
180          print "Trying $default .... ";
181          if ( -f $default ) {
182                  $OK="true";
183 +                $self->verbose("File OK");
184          }
185          else {
186 <          my $fh=FileHandle->new();
187 <          opendir $fh,  $default or do { print "No \n"; return 0; };
186 >          my $dh=DirHandle->new();
187 >          opendir $dh, $default or do { print "No $!\n"; return 0; };
188           ($#{$testfiles}==-1) ? $OK='false' : $OK='true';
189            print "\n";
190 <          my @files=readdir $fh;
191 <          undef $fh;
190 >          my @files=readdir $dh;
191 >          undef $dh;
192            foreach $file ( @$testfiles ) {
193                  print "   Checking for $file .... ";
194                  # now check that the required files are actually there
# Line 173 | Line 201 | sub _testlocation {
201            }
202          }
203          if ( $OK eq 'true' ) {
204 <                print "Directory Check Complete\n";
204 >                print "Existence Check Complete\n";
205                  return 1
206          }
207          return 0
# Line 211 | Line 239 | sub _askusermenu {
239          my @items=@_;
240  
241          my $path=-1;
242 <        while ( ($path!~/^\d+$/) || ($path > $#items) || ($path < 0) ) {
242 >        my $n;
243 >        while ( ($path!~/^\d+$/) || ($path > ($#items+1)) || ($path < 1) ) {
244           for (my $i=0; $i<=$#items; $i++ ) {
245 <          print $i.") ".$items[$i]."\n";
245 >          $n=$i+1;
246 >          print $n.") ".$items[$i]."\n";
247           }
248           print "\n".$querystring;
249           $path=<STDIN>;
250           chomp $path;
251          }
252 +        $path--;
253          return $path;
254   }
255  
# Line 227 | Line 258 | sub _askuser {
258          my $querystring=shift;
259          my $varname=shift;
260  
261 +        my $type=$self->{tool}->type($varname);
262 +        my $path;
263 +        my $oldpath;
264          print $self->featuretext($self->{EnvContext});
265          for  ( ;; ) {
266           print "\n".$querystring." (RETURN to log as missing)\nset $varname = ";
267           $path=<STDIN>;
268           chomp $path;
269 +         $oldpath=$path;
270           if ( $path ne "" ) {
271 <          if ( defined $self->{'client'}) { # must be a location
272 <           if ( $self->_testlocation($path , "H", $Envtype{$type} )) {
273 <             return $path;
274 <           }
275 <           print "Error : ".$path." does not exist.\n";
241 <           next;
242 <          }
243 <         }
244 <         else {
245 <           return $path;
271 >          ($path)=$self->_validateparam($type,$path);
272 >           if ( ! defined $path ) {
273 >            print "Error : ".$oldpath." is not valid.\n";
274 >            next;
275 >           }
276           }
277 +         return $path;
278          } #end for
279  
280   }
281  
282 + sub _validateparam {
283 +        my $self=shift;
284 +        my $type=shift;
285 +        my @params=@_;
286 +
287 +        my @newparams=();
288 +        foreach $param ( @params ) {
289 +         if ( defined $self->{'client'}) { # must be a location
290 +          if ( $self->_testlocation($param ,
291 +               [ $self->{tool}->getfeature($type)] )) {
292 +            $self->verbose("$param passed validation");
293 +            push @newparams,$param;
294 +          }
295 +          else {
296 +            $self->verbose("$param failed validation");
297 +          }
298 +         }
299 +         else {
300 +           # --- no other tests to pass so it must be OK
301 +           push @newparams,$param;
302 +         }
303 +        }
304 +        return @newparams;
305 + }
306 +
307   #
308   # Propgate through the searcher collecting matching tools
309   #
310   sub _searchtools {
311          my $self=shift;
312          my $tool=shift;
313 +        my $searcher=shift;
314  
315          my @tools=();
316          my $area;
317          my $rtool;
318 <        if ( defined $self->{toolboxsearcher} ) {
319 <           my $it=$self->{toolboxsearcher}->newiterator();
320 <           while ( ! $it->last()  ) {
318 >        my $it=$searcher->newiterator();
319 >
320 >        while ( ! $it->last()  ) {
321               $area=$it->next();
322               if ( defined $area ) {
323                $self->verbose("Searching for ".$tool->name()." ".
# Line 276 | Line 333 | sub _searchtools {
333                                                          .$rtool->version());
334                 }
335                }
336 +              else {
337 +                $self->verbose("Tool Passed as Undefined");
338 +              }
339               }
340               else {
341                  $self->verbose("Area passed is not defined");
342               }
283           }
343          }
344          return @tools;
345   }
# Line 295 | Line 354 | sub _toolparamcopy {
354          my $rv=0;
355          my @params=();
356          $self->verbose("Check Other Projects for tool");
357 <        my @validtools=$self->_searchtools($tool);
358 <        if ( ! $self->interactive() ) {
359 <          if ( $#validtools >=0 ) {
357 >        my @validtools=();
358 >        if ( defined $self->{toolboxsearcher} ) {
359 >          @validtools=$self->_searchtools($tool,$self->{toolboxsearcher});
360 >        }
361 >        if ( $#validtools >=0 ) {
362 >          if ( ! $self->interactive() ) {
363             @params=$validtools[0]->getfeature($param);
364             if ( $#params >=0 ) {
365                  $self->verbose("Extracting Feature $param from tool".
366                          " (= @params )\n");
305                #$tool->setfeature($param,@params);
367                  $rv=1;
368             }
369            }
# Line 310 | Line 371 | sub _toolparamcopy {
371          return ($rv,@params);
372   }
373  
374 + sub _getparamsets {
375 +        my $self=shift;
376 +        my $tool=shift;
377 +        my $param=shift;
378 +
379 +        my @paramlist=();
380 +        my @params=();
381 +        $self->verbose("Searching for parameter settings in other tools");
382 +        my @validtools=();
383 +        if ( defined $self->{toolboxsearcher} ) {
384 +          @validtools=$self->_searchtools($tool,$self->{toolboxsearcher});
385 +        }
386 +        else {
387 +          $self->verbose("No tool searcher available");
388 +        }
389 +        if ( $#validtools >=0 ) {
390 +          foreach $t ( @validtools ) {
391 +            @params=$t->getfeature($param);
392 +            if ( $#params >=0 ) {
393 +              push @paramlist, [ @params ];
394 +              $self->verbose("Found @params");
395 +            }
396 +          }
397 +        }
398 +        return @paramlist;
399 + }
400 +
401   # -- Tag Routines
402  
403   sub Client_start {
# Line 363 | Line 451 | sub Tool_End {
451          $self->{switch}->closegroup("Toolactive");
452   }
453  
454 + sub Makefile_Start {
455 +        my $self=shift;
456 +        my $name=shift;
457 +        my $hashref=shift;
458 +
459 +        if ( $self->{Arch} ) {
460 +         if ( ! defined $self->{toolmakefilefh} ) {
461 +           $self->{toolmakefilefh}=FileHandle->new();
462 +           $self->{toolmakefilefh}->open(">".$self->{toolmakefile});
463 +         }
464 +        }
465 + }
466 +
467 + sub Makefile_text {
468 +        my $self=shift;
469 +        my $name=shift;
470 +        my $string=shift;
471 +
472 +        if ( $self->{Arch} ) {
473 +          print {$self->{toolmakefilefh}} $string;
474 +        }
475 + }
476 +
477 + sub Makefile_end {
478 +        my $self=shift;
479 +        my $name=shift;
480 +        my $hashref=shift;
481 +
482 +        if ( $self->{Arch} ) {
483 +          print {$self->{toolmakefilefh}} "\n";
484 +        }
485 + }
486 +
487 + # -- collect number of variables of the same name - need to know how many
488 + #    before main setup processing
489 + sub Environment_init {
490 +        my $self=shift;
491 +        my $name=shift;
492 +        my $hashref=shift;
493 +
494 +        $self->{switch}->checktag($name, $hashref, 'name');
495 +        if ( $self->{Arch} ) {
496 +        if ( exists $self->{envcount}{$$hashref{'name'}} ) {
497 +          $self->{envcount}{$$hashref{'name'}}++;
498 +        }
499 +        else {
500 +          $self->{envcount}{$$hashref{'name'}}=0;
501 +        }
502 +        }
503 + }
504 +
505   sub Environment_Start {
506          my $self=shift;
507          my $name=shift;
# Line 370 | Line 509 | sub Environment_Start {
509  
510          $self->{switch}->checktag($name, $hashref, 'name');
511          if ( $self->{Arch} ) {
512 +          my $val=undef;
513            if ( defined $self->{EnvContext} ) {
514              $self->parserror(" Attempted to open new <$name> context".
515                          " without closing the previous one");
516            }
517 +          # -- keep a counter of the number of times we see this variable
518 +          if ( exists $self->{EnvironmentCount}{$$hashref{'name'}} ) {
519 +             $self->{EnvironmentCount}{$$hashref{'name'}}++;
520 +          }
521 +          else {
522 +             $self->{EnvironmentCount}{$$hashref{'name'}}=0;
523 +          }
524 +
525            $self->{currentenvtext}="";
526            $self->{EnvContext}=$$hashref{'name'};
527            undef $self->{Envvalue};
# Line 381 | Line 529 | sub Environment_Start {
529              $$hashref{'type'}=~tr[A-Z][a-z];
530              $self->{tool}->type($$hashref{'name'},$$hashref{'type'});
531            }
532 +          # check other installed copies of the tool
533 +          # -- construct a menu of options
534 +          my @menulist=();
535 +          # -- a value is fixed - unless interactive switch is on
536            if ( exists $$hashref{'value'}) {
537 <            $self->{Envvalue}=$$hashref{'value'};
537 >            $val=$$hashref{'value'};
538 >            if ( $self->interactive() ) {
539 >              unshift @menulist,$$hashref{'value'};
540 >            }
541            }
542 <          elsif ( ! $self->interactive() ) {
543 <           # check other installed copies of the tool
544 <           my ($rv,@params)=
545 <                $self->_toolparamcopy($self->{tool},$$hashref{'name'});
546 <           if ( $rv && ($#params == 0)) { #dont use multivalued params!
547 <              # -- if default is OK as well ask user which one to choose
548 <              my $val=$params[0];
394 <              if ( $self->_checkdefault($hashref) ) {
395 <                # -- many options - just ask the user
396 <                my $expdef=$self->_expandvars($$hashref{'default'});
397 <                if ( $expdef ne $val ) {
398 <                 my $in=$self->_askusermenu(
399 <                        "Multiple possibilities found. Please Choose:",
400 <                        ($params[0],$expdef,"Other"));
401 <                 if ( $in == 1 ) {
402 <                  $val=$expdef;
403 <                 }
404 <                 elsif ( $in == 2 ) {
405 <                  $val=$self->_askuser("Please Enter Value:",$$hashref{'name'});
406 <                 }
407 <                }
408 <              }
409 <              $self->{Envvalue}=$val; # single val parameter
542 >          # -- add any default values to the selection
543 >          if ( ! defined $val ) {
544 >           if ( $self->_checkdefault($hashref) ) {
545 >             my $var=$self->_expandvars($$hashref{'default'});
546 >             if ( !grep { $_ eq $var }  @menulist ) {
547 >               unshift @menulist, $var;
548 >             }
549             }
550 <           elsif ( defined $ENV{$$hashref{'name'}} ) {
551 <              # check the environment
552 <              $self->{Envvalue}=$ENV{$$hashref{'name'}};
550 >           # -- check the environment
551 >           if ( defined $ENV{$$hashref{'name'}} ) {
552 >              if ( !grep { $_ eq $ENV{$$hashref{'name'}}} @menulist ) {
553 >                unshift @menulist, $ENV{$$hashref{'name'}};
554 >              }
555             }
556 <           elsif ( $self->_checkdefault($hashref) ) {
557 <              $self->{Envvalue}=$$hashref{'default'};
556 >           my @paramlist=$self->_getparamsets($self->{tool},
557 >                                                        $$hashref{'name'});
558 >           foreach $p ( @paramlist ) {
559 >             # -- only add them if there are the same number of variables
560 >             if ( $#{$p} == $self->{envcount}{$$hashref{'name'}} ) {
561 >              if ( !grep {$_ eq $$p[$self->{EnvironmentCount}
562 >                                {$$hashref{'name'}}] } @menulist) {
563 >                push @menulist,$$p[$self->{EnvironmentCount}
564 >                                                        {$$hashref{'name'}}];
565 >              }
566 >             }
567 >             else {
568 >                $self->verbose("Ignoring tool params - not the same number".
569 >                 " defined (".$#{$p}." != ".
570 >                         $self->{envcount}{$$hashref{'name'}}.")");
571 >             }
572 >           }
573 >           if ( $#menulist >=0 ) {
574 >            print "Validating Values for Variable : ".$$hashref{'name'}."\n";
575 >            @menulist=$self->_validateparam($$hashref{'type'},@menulist);
576             }
577 +           # -- If theres only one option take it without asking
578 +           if ( $#menulist == 0 && ( ! $self->interactive() )) {
579 +                $val=$menulist[0];
580 +           }
581 +           elsif ( $#menulist > 0 ) {
582 +              my $in=$self->_askusermenu(
583 +                "Multiple possibilities found for ".
584 +                $$hashref{'name'}." ( occurance ".
585 +                ($self->{EnvironmentCount}{$$hashref{'name'}}+1)." ) ".
586 +                "\nPlease Choose: ",
587 +                (@menulist,"Other"));
588 +              if ( $in <=$#menulist ) {
589 +                  $val=$menulist[$in];
590 +              }
591 +              else {
592 +                  undef $val;
593 +              }
594 +           }    
595            }
596 +          $self->{Envvalue}=$val; # single val parameter
597          }
598   }
599  
# Line 491 | Line 669 | sub Arch_End {
669          pop @{$self->{ARCHBLOCK}};
670          $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
671   }
494
495

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines