ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/ToolDoc.pm
Revision: 1.1.2.14.2.1.2.1
Committed: Mon Oct 9 17:36:27 2000 UTC (24 years, 7 months ago) by williamc
Content type: text/plain
Branch: V0_15branch
CVS Tags: V0_15_1
Changes since 1.1.2.14.2.1: +11 -1 lines
Log Message:
Extra verbosity added

File Contents

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