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.1 by williamc, Tue Apr 18 09:09:57 2000 UTC vs.
Revision 1.1.2.14 by williamc, Thu Jun 22 08:41:52 2000 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines