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 |
|
} |
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, |
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, |
95 |
|
|
96 |
|
sub toolsearcher { |
97 |
|
my $self=shift; |
98 |
+ |
|
99 |
|
if ( @_ ) { |
100 |
|
my $searcher=shift; |
101 |
|
if ( ! defined $searcher ) { |
112 |
|
my $file=shift; |
113 |
|
my $name=shift; |
114 |
|
my $version=shift; |
115 |
+ |
my $toolbox=shift; |
116 |
|
|
117 |
|
$self->{ToolEnv}{'SCRAMtoolname'}=$name; |
118 |
|
$self->{ToolEnv}{'SCRAMtoolversion'}=$version; |
125 |
|
$self->{toolfound}=1; |
126 |
|
# -- check the type of document - can we parse it? |
127 |
|
my($doctype,$docversion)=$self->{switch}->doctype(); |
128 |
< |
if ( ($doctype ne $self->{mydoctype}) || |
129 |
< |
($self->{mydocversion} ne $docversion) ) { |
128 |
> |
if (($doctype ne $self->{mydoctype}) || |
129 |
> |
(($self->{mydocversion} ne $docversion) && ($docversion ne "1.0")) ) { |
130 |
|
$self->error("Unable to Parse Document of type $doctype $docversion". |
131 |
|
"\n(Only ".$self->{mydoctype}." ". $self->{mydocversion}.")"); |
132 |
|
} |
133 |
+ |
delete $self->{envcount}; |
134 |
+ |
$self->verbose("Pre-Parse"); |
135 |
+ |
$self->{switch}->parse("setupinit"); |
136 |
+ |
$self->{toolmakefile}=$toolbox->toolmakefile($name,$version); |
137 |
+ |
$self->verbose("Setup Parse"); |
138 |
|
$self->{switch}->parse("setup"); |
139 |
+ |
undef $self->{toolmakefilefh}; |
140 |
+ |
|
141 |
|
return $self->{toolfound}; |
142 |
|
} |
143 |
|
|
168 |
|
return 0; |
169 |
|
} |
170 |
|
|
171 |
< |
sub _testlocation { |
172 |
< |
my $self=shift; |
173 |
< |
my $default=shift; |
174 |
< |
my $testfiles=shift; |
175 |
< |
my $OK='false'; |
176 |
< |
my $file; |
177 |
< |
|
178 |
< |
chomp $default; |
179 |
< |
$default=$self->_expandvars($default); |
180 |
< |
print "Trying $default .... "; |
181 |
< |
if ( -f $default ) { |
182 |
< |
$OK="true"; |
183 |
< |
} |
184 |
< |
else { |
185 |
< |
my $fh=FileHandle->new(); |
186 |
< |
opendir $fh, $default or do { print "No \n"; return 0; }; |
187 |
< |
($#{$testfiles}==-1) ? $OK='false' : $OK='true'; |
188 |
< |
print "\n"; |
189 |
< |
my @files=readdir $fh; |
190 |
< |
undef $fh; |
191 |
< |
foreach $file ( @$testfiles ) { |
192 |
< |
print " Checking for $file .... "; |
193 |
< |
# now check that the required files are actually there |
194 |
< |
if ( ( $number = grep /\Q$file\L/, @files) == 0 ) { |
195 |
< |
$OK='false'; |
196 |
< |
print "not found\n"; |
197 |
< |
last; |
198 |
< |
} |
199 |
< |
print "found\n"; |
200 |
< |
} |
201 |
< |
} |
202 |
< |
if ( $OK eq 'true' ) { |
203 |
< |
print "Directory Check Complete\n"; |
204 |
< |
return 1 |
205 |
< |
} |
206 |
< |
return 0 |
207 |
< |
} |
171 |
> |
sub _testlocation |
172 |
> |
{ |
173 |
> |
my $self=shift; |
174 |
> |
my $default=shift; |
175 |
> |
my $testfiles=shift; |
176 |
> |
my $OK='false'; |
177 |
> |
my $file; |
178 |
> |
|
179 |
> |
chomp $default; |
180 |
> |
$default=$self->_expandvars($default); |
181 |
> |
$self->verbose("Testing location"); |
182 |
> |
|
183 |
> |
if ( -f $default ) |
184 |
> |
{ |
185 |
> |
$OK="true"; |
186 |
> |
$self->verbose("File OK"); |
187 |
> |
} |
188 |
> |
else |
189 |
> |
{ |
190 |
> |
my $dh=DirHandle->new(); |
191 |
> |
|
192 |
> |
opendir $dh, $default or do |
193 |
> |
{ |
194 |
> |
printf ("\nTrying %-s ...... >>%s<<\n",$default,$!,); |
195 |
> |
return 0; |
196 |
> |
}; |
197 |
> |
|
198 |
> |
($#{$testfiles}==-1) ? $OK='false' : $OK='true'; |
199 |
> |
#print "\n"; |
200 |
> |
my @files=readdir $dh; |
201 |
> |
undef $dh; |
202 |
> |
|
203 |
> |
foreach $file ( @$testfiles ) |
204 |
> |
{ |
205 |
> |
# now check that the required files are actually there |
206 |
> |
if ( ( $number = grep /\Q$file\L/, @files) == 0 ) |
207 |
> |
{ |
208 |
> |
$OK='false'; |
209 |
> |
$status = "[not found]"; |
210 |
> |
last; |
211 |
> |
} |
212 |
> |
$status = "[OK]"; |
213 |
> |
printf ("\t\tChecking for %-22s............ %-s\n",$file,$status); |
214 |
> |
} |
215 |
> |
print "\n"; |
216 |
> |
} |
217 |
> |
|
218 |
> |
if ( $OK eq 'true' ) |
219 |
> |
{ |
220 |
> |
printf ("Existence check for %-30s ............ [OK]\n",$default.":"); |
221 |
> |
return 1; |
222 |
> |
} |
223 |
> |
|
224 |
> |
return 0; |
225 |
> |
} |
226 |
|
|
227 |
|
sub _expandvars { |
228 |
|
my $self=shift; |
256 |
|
my @items=@_; |
257 |
|
|
258 |
|
my $path=-1; |
259 |
< |
while ( ($path!~/^\d+$/) || ($path > $#items) || ($path < 0) ) { |
259 |
> |
my $n; |
260 |
> |
while ( ($path!~/^\d+$/) || ($path > ($#items+1)) || ($path < 1) ) { |
261 |
|
for (my $i=0; $i<=$#items; $i++ ) { |
262 |
< |
print $i.") ".$items[$i]."\n"; |
262 |
> |
$n=$i+1; |
263 |
> |
print $n.") ".$items[$i]."\n"; |
264 |
|
} |
265 |
|
print "\n".$querystring; |
266 |
|
$path=<STDIN>; |
267 |
|
chomp $path; |
268 |
|
} |
269 |
+ |
$path--; |
270 |
|
return $path; |
271 |
|
} |
272 |
|
|
275 |
|
my $querystring=shift; |
276 |
|
my $varname=shift; |
277 |
|
|
278 |
+ |
my $type=$self->{tool}->type($varname); |
279 |
+ |
my $path; |
280 |
+ |
my $oldpath; |
281 |
|
print $self->featuretext($self->{EnvContext}); |
282 |
|
for ( ;; ) { |
283 |
|
print "\n".$querystring." (RETURN to log as missing)\nset $varname = "; |
284 |
|
$path=<STDIN>; |
285 |
|
chomp $path; |
286 |
+ |
$oldpath=$path; |
287 |
|
if ( $path ne "" ) { |
288 |
< |
if ( defined $self->{'client'}) { # must be a location |
289 |
< |
if ( $self->_testlocation($path , "H", $Envtype{$type} )) { |
290 |
< |
return $path; |
291 |
< |
} |
292 |
< |
print "Error : ".$path." does not exist.\n"; |
241 |
< |
next; |
242 |
< |
} |
243 |
< |
} |
244 |
< |
else { |
245 |
< |
return $path; |
288 |
> |
($path)=$self->_validateparam($type,$path); |
289 |
> |
if ( ! defined $path ) { |
290 |
> |
print "Error : ".$oldpath." is not valid.\n"; |
291 |
> |
next; |
292 |
> |
} |
293 |
|
} |
294 |
+ |
return $path; |
295 |
|
} #end for |
296 |
|
|
297 |
|
} |
298 |
|
|
299 |
+ |
sub _validateparam { |
300 |
+ |
my $self=shift; |
301 |
+ |
my $type=shift; |
302 |
+ |
my @params=@_; |
303 |
+ |
|
304 |
+ |
my @newparams=(); |
305 |
+ |
foreach $param ( @params ) { |
306 |
+ |
if ( defined $self->{'client'}) { # must be a location |
307 |
+ |
if ( $self->_testlocation($param , |
308 |
+ |
[ $self->{tool}->getfeature($type)] )) { |
309 |
+ |
$self->verbose("$param passed validation"); |
310 |
+ |
push @newparams,$param; |
311 |
+ |
} |
312 |
+ |
else { |
313 |
+ |
$self->verbose("$param failed validation"); |
314 |
+ |
} |
315 |
+ |
} |
316 |
+ |
else { |
317 |
+ |
# --- no other tests to pass so it must be OK |
318 |
+ |
push @newparams,$param; |
319 |
+ |
} |
320 |
+ |
} |
321 |
+ |
return @newparams; |
322 |
+ |
} |
323 |
+ |
|
324 |
|
# |
325 |
|
# Propgate through the searcher collecting matching tools |
326 |
|
# |
327 |
|
sub _searchtools { |
328 |
|
my $self=shift; |
329 |
|
my $tool=shift; |
330 |
+ |
my $searcher=shift; |
331 |
|
|
332 |
|
my @tools=(); |
333 |
|
my $area; |
334 |
|
my $rtool; |
335 |
< |
if ( defined $self->{toolboxsearcher} ) { |
336 |
< |
my $it=$self->{toolboxsearcher}->newiterator(); |
337 |
< |
while ( ! $it->last() ) { |
335 |
> |
my $it=$searcher->newiterator(); |
336 |
> |
|
337 |
> |
while ( ! $it->last() ) { |
338 |
|
$area=$it->next(); |
339 |
|
if ( defined $area ) { |
340 |
|
$self->verbose("Searching for ".$tool->name()." ". |
350 |
|
.$rtool->version()); |
351 |
|
} |
352 |
|
} |
353 |
+ |
else { |
354 |
+ |
$self->verbose("Tool Passed as Undefined"); |
355 |
+ |
} |
356 |
|
} |
357 |
|
else { |
358 |
|
$self->verbose("Area passed is not defined"); |
359 |
|
} |
283 |
– |
} |
360 |
|
} |
361 |
|
return @tools; |
362 |
|
} |
371 |
|
my $rv=0; |
372 |
|
my @params=(); |
373 |
|
$self->verbose("Check Other Projects for tool"); |
374 |
< |
my @validtools=$self->_searchtools($tool); |
375 |
< |
if ( ! $self->interactive() ) { |
376 |
< |
if ( $#validtools >=0 ) { |
374 |
> |
my @validtools=(); |
375 |
> |
if ( defined $self->{toolboxsearcher} ) { |
376 |
> |
@validtools=$self->_searchtools($tool,$self->{toolboxsearcher}); |
377 |
> |
} |
378 |
> |
if ( $#validtools >=0 ) { |
379 |
> |
if ( ! $self->interactive() ) { |
380 |
|
@params=$validtools[0]->getfeature($param); |
381 |
|
if ( $#params >=0 ) { |
382 |
|
$self->verbose("Extracting Feature $param from tool". |
383 |
|
" (= @params )\n"); |
305 |
– |
#$tool->setfeature($param,@params); |
384 |
|
$rv=1; |
385 |
|
} |
386 |
|
} |
388 |
|
return ($rv,@params); |
389 |
|
} |
390 |
|
|
391 |
+ |
sub _getparamsets { |
392 |
+ |
my $self=shift; |
393 |
+ |
my $tool=shift; |
394 |
+ |
my $param=shift; |
395 |
+ |
|
396 |
+ |
my @paramlist=(); |
397 |
+ |
my @params=(); |
398 |
+ |
$self->verbose("Searching for parameter settings in other tools"); |
399 |
+ |
my @validtools=(); |
400 |
+ |
if ( defined $self->{toolboxsearcher} ) { |
401 |
+ |
@validtools=$self->_searchtools($tool,$self->{toolboxsearcher}); |
402 |
+ |
} |
403 |
+ |
else { |
404 |
+ |
$self->verbose("No tool searcher available"); |
405 |
+ |
} |
406 |
+ |
if ( $#validtools >=0 ) { |
407 |
+ |
foreach $t ( @validtools ) { |
408 |
+ |
@params=$t->getfeature($param); |
409 |
+ |
if ( $#params >=0 ) { |
410 |
+ |
push @paramlist, [ @params ]; |
411 |
+ |
$self->verbose("Found @params"); |
412 |
+ |
} |
413 |
+ |
} |
414 |
+ |
} |
415 |
+ |
return @paramlist; |
416 |
+ |
} |
417 |
+ |
|
418 |
|
# -- Tag Routines |
419 |
|
|
420 |
|
sub Client_start { |
468 |
|
$self->{switch}->closegroup("Toolactive"); |
469 |
|
} |
470 |
|
|
471 |
+ |
sub Makefile_Start { |
472 |
+ |
my $self=shift; |
473 |
+ |
my $name=shift; |
474 |
+ |
my $hashref=shift; |
475 |
+ |
|
476 |
+ |
if ( $self->{Arch} ) { |
477 |
+ |
if ( ! defined $self->{toolmakefilefh} ) { |
478 |
+ |
$self->{toolmakefilefh}=FileHandle->new(); |
479 |
+ |
$self->{toolmakefilefh}->open(">".$self->{toolmakefile}); |
480 |
+ |
} |
481 |
+ |
} |
482 |
+ |
} |
483 |
+ |
|
484 |
+ |
sub Makefile_text { |
485 |
+ |
my $self=shift; |
486 |
+ |
my $name=shift; |
487 |
+ |
my $string=shift; |
488 |
+ |
|
489 |
+ |
if ( $self->{Arch} ) { |
490 |
+ |
print {$self->{toolmakefilefh}} $string; |
491 |
+ |
} |
492 |
+ |
} |
493 |
+ |
|
494 |
+ |
sub Makefile_end { |
495 |
+ |
my $self=shift; |
496 |
+ |
my $name=shift; |
497 |
+ |
my $hashref=shift; |
498 |
+ |
|
499 |
+ |
if ( $self->{Arch} ) { |
500 |
+ |
print {$self->{toolmakefilefh}} "\n"; |
501 |
+ |
} |
502 |
+ |
} |
503 |
+ |
|
504 |
+ |
# -- collect number of variables of the same name - need to know how many |
505 |
+ |
# before main setup processing |
506 |
+ |
sub Environment_init { |
507 |
+ |
my $self=shift; |
508 |
+ |
my $name=shift; |
509 |
+ |
my $hashref=shift; |
510 |
+ |
|
511 |
+ |
$self->{switch}->checktag($name, $hashref, 'name'); |
512 |
+ |
if ( $self->{Arch} ) { |
513 |
+ |
if ( exists $self->{envcount}{$$hashref{'name'}} ) { |
514 |
+ |
$self->{envcount}{$$hashref{'name'}}++; |
515 |
+ |
} |
516 |
+ |
else { |
517 |
+ |
$self->{envcount}{$$hashref{'name'}}=0; |
518 |
+ |
} |
519 |
+ |
} |
520 |
+ |
} |
521 |
+ |
|
522 |
|
sub Environment_Start { |
523 |
|
my $self=shift; |
524 |
|
my $name=shift; |
525 |
|
my $hashref=shift; |
526 |
< |
|
526 |
> |
|
527 |
|
$self->{switch}->checktag($name, $hashref, 'name'); |
528 |
|
if ( $self->{Arch} ) { |
529 |
+ |
my $val=undef; |
530 |
|
if ( defined $self->{EnvContext} ) { |
531 |
|
$self->parserror(" Attempted to open new <$name> context". |
532 |
|
" without closing the previous one"); |
533 |
|
} |
534 |
+ |
# -- keep a counter of the number of times we see this variable |
535 |
+ |
if ( exists $self->{EnvironmentCount}{$$hashref{'name'}} ) { |
536 |
+ |
$self->{EnvironmentCount}{$$hashref{'name'}}++; |
537 |
+ |
} |
538 |
+ |
else { |
539 |
+ |
$self->{EnvironmentCount}{$$hashref{'name'}}=0; |
540 |
+ |
} |
541 |
+ |
|
542 |
|
$self->{currentenvtext}=""; |
543 |
|
$self->{EnvContext}=$$hashref{'name'}; |
544 |
|
undef $self->{Envvalue}; |
546 |
|
$$hashref{'type'}=~tr[A-Z][a-z]; |
547 |
|
$self->{tool}->type($$hashref{'name'},$$hashref{'type'}); |
548 |
|
} |
549 |
+ |
# check other installed copies of the tool |
550 |
+ |
# -- construct a menu of options |
551 |
+ |
my @menulist=(); |
552 |
+ |
# -- a value is fixed - unless interactive switch is on |
553 |
|
if ( exists $$hashref{'value'}) { |
554 |
< |
$self->{Envvalue}=$$hashref{'value'}; |
554 |
> |
$val=$$hashref{'value'}; |
555 |
> |
if ( $self->interactive() ) { |
556 |
> |
unshift @menulist,$$hashref{'value'}; |
557 |
> |
} |
558 |
|
} |
559 |
< |
elsif ( ! $self->interactive() ) { |
560 |
< |
# check other installed copies of the tool |
561 |
< |
my ($rv,@params)= |
562 |
< |
$self->_toolparamcopy($self->{tool},$$hashref{'name'}); |
563 |
< |
if ( $rv && ($#params == 0)) { #dont use multivalued params! |
564 |
< |
# -- if default is OK as well ask user which one to choose |
565 |
< |
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 |
559 |
> |
# -- add any default values to the selection |
560 |
> |
if ( ! defined $val ) { |
561 |
> |
if ( $self->_checkdefault($hashref) ) { |
562 |
> |
my $var=$self->_expandvars($$hashref{'default'}); |
563 |
> |
if ( !grep { $_ eq $var } @menulist ) { |
564 |
> |
unshift @menulist, $var; |
565 |
> |
} |
566 |
|
} |
567 |
< |
elsif ( defined $ENV{$$hashref{'name'}} ) { |
568 |
< |
# check the environment |
569 |
< |
$self->{Envvalue}=$ENV{$$hashref{'name'}}; |
567 |
> |
# -- check the environment |
568 |
> |
if ( defined $ENV{$$hashref{'name'}} ) { |
569 |
> |
if ( !grep { $_ eq $ENV{$$hashref{'name'}}} @menulist ) { |
570 |
> |
unshift @menulist, $ENV{$$hashref{'name'}}; |
571 |
> |
} |
572 |
|
} |
573 |
< |
elsif ( $self->_checkdefault($hashref) ) { |
574 |
< |
$self->{Envvalue}=$$hashref{'default'}; |
573 |
> |
my @paramlist=$self->_getparamsets($self->{tool}, |
574 |
> |
$$hashref{'name'}); |
575 |
> |
foreach $p ( @paramlist ) { |
576 |
> |
# -- only add them if there are the same number of variables |
577 |
> |
if ( $#{$p} == $self->{envcount}{$$hashref{'name'}} ) { |
578 |
> |
if ( !grep {$_ eq $$p[$self->{EnvironmentCount} |
579 |
> |
{$$hashref{'name'}}] } @menulist) { |
580 |
> |
push @menulist,$$p[$self->{EnvironmentCount} |
581 |
> |
{$$hashref{'name'}}]; |
582 |
> |
} |
583 |
> |
} |
584 |
> |
else { |
585 |
> |
$self->verbose("Ignoring tool params - not the same number". |
586 |
> |
" defined (".$#{$p}." != ". |
587 |
> |
$self->{envcount}{$$hashref{'name'}}.")"); |
588 |
> |
} |
589 |
> |
} |
590 |
> |
if ( $#menulist >=0 ) { |
591 |
> |
print "Validating Values for Variable: ".$$hashref{'name'}."\n"; |
592 |
> |
@menulist=$self->_validateparam($$hashref{'type'},@menulist); |
593 |
|
} |
594 |
+ |
print "\n"; |
595 |
+ |
# -- If theres only one option take it without asking |
596 |
+ |
if ( $#menulist == 0 && ( ! $self->interactive() )) |
597 |
+ |
{ |
598 |
+ |
print "VALUE: ",$val,"\n"; |
599 |
+ |
$val=$menulist[0]; |
600 |
+ |
} |
601 |
+ |
elsif ( $#menulist > 0 ) { |
602 |
+ |
my $in=$self->_askusermenu( |
603 |
+ |
"Multiple possibilities found for ". |
604 |
+ |
$$hashref{'name'}." ( occurrance ". |
605 |
+ |
($self->{EnvironmentCount}{$$hashref{'name'}}+1)." ) ". |
606 |
+ |
"\nPlease Choose: ", |
607 |
+ |
(@menulist,"Other")); |
608 |
+ |
if ( $in <=$#menulist ) { |
609 |
+ |
$val=$menulist[$in]; |
610 |
+ |
} |
611 |
+ |
else { |
612 |
+ |
undef $val; |
613 |
+ |
} |
614 |
+ |
} |
615 |
|
} |
616 |
+ |
$self->{Envvalue}=$val; # single val parameter |
617 |
|
} |
618 |
|
} |
619 |
|
|
689 |
|
pop @{$self->{ARCHBLOCK}}; |
690 |
|
$self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}]; |
691 |
|
} |
494 |
– |
|
495 |
– |
|