ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/ToolParser.pm
Revision: 1.8.2.3.2.3
Committed: Thu Sep 23 10:46:22 2010 UTC (14 years, 7 months ago) by muzaffar
Content type: text/plain
Branch: SCRAM_V2_0
CVS Tags: V2_2_2, V2_2_2_pre4, V2_2_2_pre3, V2_2_2_pre2, V2_2_2_pre1, V2_2_2-pre1
Changes since 1.8.2.3.2.2: +13 -241 lines
Log Message:
cleanup for tool setup. A tool file should always provide all its paths. No more usage of stite/tools.conf file.

File Contents

# User Rev Content
1 sashby 1.2 #____________________________________________________________________
2     # File: ToolParser.pm
3     #____________________________________________________________________
4     #
5     # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6     # Update: 2004-02-09 20:14:55+0100
7 muzaffar 1.8.2.3.2.3 # Revision: $Id: ToolParser.pm,v 1.8.2.3.2.2 2009/03/18 16:58:42 muzaffar Exp $
8 sashby 1.2 #
9     # Copyright: 2004 (C) Shaun Ashby
10     #
11     #--------------------------------------------------------------------
12     package BuildSystem::ToolParser;
13     require 5.004;
14    
15     use Exporter;
16 muzaffar 1.8 use SCRAM::MsgLog;
17 sashby 1.2 use ActiveDoc::SimpleDoc;
18     use Utilities::Verbose;
19    
20     @ISA=qw(Exporter Utilities::Verbose);
21     @EXPORT=qw();
22    
23     #
24     sub new
25     {
26     my $proto=shift;
27     my $class=ref($proto) || $proto;
28 sashby 1.6 $self={};
29 sashby 1.2
30     bless $self,$class;
31    
32     $self->{content} = {};
33     $self->{nested} = 0;
34 sashby 1.6 $self->{scramdoc}=ActiveDoc::SimpleDoc->new();
35 muzaffar 1.8.2.3.2.1 $self->{scramdoc}->newparse("setup","BuildSystem::ToolParser",'Subs',undef,1);
36 muzaffar 1.8.2.2 $self->{envorder}=[];
37 sashby 1.6
38     return $self;
39     }
40    
41     ### Tag handler methods ###
42     sub tool()
43     {
44     my ($object,$name,%attributes)=@_;
45     my $hashref = \%attributes;
46     # A way to distinguish the naming of different nested levels:
47     $self->{levels}=['','tag','nexttag'];
48     $$hashref{'name'} =~ tr[A-Z][a-z];
49    
50 muzaffar 1.8.2.3.2.1 $self->{content}->{TOOLNAME}=$$hashref{'name'};
51     $self->{content}->{TOOLVERSION}=$$hashref{'version'};
52    
53 sashby 1.6 if (exists ($$hashref{'type'}))
54     {
55     $$hashref{'type'} =~ tr[A-Z][a-z];
56     $self->{content}->{SCRAM_PROJECT} = 0;
57    
58     if ($$hashref{'type'} eq 'scram')
59     {
60     $self->{content}->{SCRAM_PROJECT} = 1;
61     }
62     elsif ($$hashref{'type'} eq 'compiler')
63     {
64     $self->{content}->{SCRAM_COMPILER} = 1;
65     }
66     else
67     {
68     $::scram->scramwarn("Unknown type \"".$$hashref{'type'}."\" in tool ".$$hashref{'name'}."\n");
69     }
70     }
71     }
72    
73     sub tool_()
74     {
75     delete $self->{levels};
76     delete $self->{id};
77     delete $self->{nested};
78     }
79    
80     sub lib()
81     {
82     my ($object,$name,%attributes)=@_;
83     push(@{$self->{"$self->{levels}->[$self->{nested}]".content}->{LIB}},$attributes{'name'});
84     }
85    
86     sub info()
87     {
88     my ($object,$name,%attributes)=@_;
89     $self->{"$self->{levels}->[$self->{nested}]".content}->{INFO} = \%attributes;
90     }
91    
92     sub use()
93     {
94     my ($object,$name,%attributes)=@_;
95     push(@{$self->{"$self->{levels}->[$self->{nested}]".content}->{USE}},$attributes{'name'});
96     }
97    
98     sub runtime()
99     {
100     my ($object,$name,%attributes)=@_;
101     my $hashref = \%attributes;
102     my $envname;
103     # Check to see if we have a "type" arg. If so, we use this to create the key:
104     if (exists ($hashref->{'type'}))
105     {
106     my $type=$hashref->{'type'};
107     # Make the type uppercase:
108     $type =~ tr/[a-z]/[A-Z]/;
109     # Rename the environment as "<type>:<env name>":
110     $envname = $type.":".$$hashref{'name'};
111     }
112     else
113     {
114     $envname = $$hashref{'name'};
115     }
116    
117     # Delete name entry so hash is more tidy
118     delete $$hashref{'name'};
119    
120     # Before we save $hashref we need to know if there are already
121     # any runtime tags with the same name. If there are, we must save all
122     # data to an aray of hashes:
123     if (exists ($self->{"$self->{levels}->[$self->{nested}]".content}->{RUNTIME}->{$envname}))
124     {
125     push(@{$self->{"$self->{levels}->[$self->{nested}]".content}->{RUNTIME}->{$envname}},$hashref);
126     }
127     else
128     {
129     # No entry yet so just store the hashref:
130     $self->{"$self->{levels}->[$self->{nested}]".content}->{RUNTIME}->{$envname} = [ $hashref ];
131     }
132     }
133    
134     sub flags()
135     {
136     my ($object,$name,%attributes)=@_;
137     # Extract the flag name and its value:
138     my ($flagname,$flagvaluestring) = each %attributes;
139     $flagname =~ tr/[a-z]/[A-Z]/; # Keep flag name uppercase
140     chomp($flagvaluestring);
141     # Split the value on whitespace so we can push all
142     # individual flags into an array:
143     my @flagvalues = split(' ',$flagvaluestring);
144    
145     # Is current tag within another tag block?
146     if ($self->{nested} > 0)
147     {
148     # Check to see if the current flag name is already stored in the hash. If so,
149     # just add the new values to the array of flag values:
150     if (exists ($self->{"$self->{levels}->[$self->{nested}]".content}->{FLAGS}->{$flagname}))
151     {
152     push(@{$self->{"$self->{levels}->[$self->{nested}]".content}->{FLAGS}->{$flagname}},@flagvalues);
153     }
154     else
155     {
156     $self->{"$self->{levels}->[$self->{nested}]".content}->{FLAGS}->{$flagname} = [ @flagvalues ];
157     }
158     }
159     else
160     {
161     if (exists ($self->{content}->{FLAGS}->{$flagname}))
162     {
163     push(@{$self->{content}->{FLAGS}->{$flagname}},@flagvalues);
164     }
165     else
166     {
167     $self->{content}->{FLAGS}->{$flagname} = [ @flagvalues ];
168     }
169     }
170     }
171    
172     sub client()
173     {
174     $self->pushlevel();
175 sashby 1.2 }
176    
177 sashby 1.6 sub client_()
178 sashby 1.2 {
179 sashby 1.6 if ($self->{isarch} == 1)
180     {
181     # If we already have an architecture tag, we must write to tagcontent hash:
182     $self->{tagcontent}->{CLIENT}=$self->{nexttagcontent};
183     delete $self->{nexttagcontent};
184     }
185     else
186     {
187     $self->{content}->{CLIENT}=$self->{tagcontent};
188     }
189 sashby 1.2
190 sashby 1.6 $self->poplevel();
191     }
192    
193     sub environment()
194     {
195     my ($object,$name,%attributes)=@_;
196     my $hashref = \%attributes;
197     # Save a copy of the name of this environment:
198     my $envname=$$hashref{'name'};
199     delete $$hashref{'name'}; # Delete name entry so hash is more tidy
200     # Before we save $hashref we need to know if there are already
201     # any env tags with the same name. If there are, we must save all
202     # data to an aray of hashes:
203     if (exists ($self->{"$self->{levels}->[$self->{nested}]".content}->{ENVIRONMENT}->{$envname}))
204     {
205     push(@{$self->{"$self->{levels}->[$self->{nested}]".content}->{ENVIRONMENT}->{$envname}},$hashref);
206 muzaffar 1.8.2.3 my @norder=();
207     foreach my $env (@{$self->{envorder}})
208     {
209     if($env ne $envname) {push @norder,$env;}
210     }
211     $self->{envorder}=[];
212     push @{$self->{envorder}},@norder;
213     push @{$self->{envorder}},$envname;
214 sashby 1.6 }
215     else
216     {
217     # No entry yet so just store the hashref:
218     $self->{"$self->{levels}->[$self->{nested}]".content}->{ENVIRONMENT}->{$envname} = [ $hashref ];
219 muzaffar 1.8.2.2 push @{$self->{envorder}},$envname;
220 sashby 1.6 }
221 sashby 1.2 }
222    
223 sashby 1.6 sub makefile()
224     {
225     my ($object,$name,%attributes)=@_;
226     }
227    
228     sub makefile_()
229     {
230 muzaffar 1.8.2.1 my ($object,$name,$cdata)=@_;
231 sashby 1.6 push(@{$self->{"$self->{levels}->[$self->{nested}]".content}->{MAKEFILE}},
232 muzaffar 1.8.2.1 join("\n",@$cdata));
233 sashby 1.6 }
234    
235     sub architecture()
236     {
237     my ($object,$name,%attributes)=@_;
238     $self->pushlevel(\%attributes,1); # Set nested to 1;
239     }
240    
241     sub architecture_()
242     {
243     # Need to be able to cope with multiple arch blocks with same arch string:
244     if (exists ($self->{content}->{ARCH}->{$self->{id}->{'name'}}))
245     {
246     # Already have an architecture tag for this arch:
247     while (my ($k,$v) = each %{$self->{tagcontent}})
248     {
249     # If this tag (e.g. LIB, USE, MAKEFILE) already exists and (as we know
250     # it should be) its data is an ARRAY, push it to the store:
251     if (exists ($self->{content}->{ARCH}->{$self->{id}->{'name'}}->{$k}) &&
252     ref($v) eq 'ARRAY')
253     {
254     push(@{$self->{content}->{ARCH}->{$self->{id}->{'name'}}->{$k}},@$v);
255     }
256     else
257     {
258     # Otherwise (for HASH data) we just store it. Note that, because we do
259     # not loop over the HASH content and check for already existsing keys,
260     # if two arch blocks with same arch name define the same tag (e.g, ENV),
261     # the last occurrence will be kept (i.e. the two values won't be added
262     # to one ENV hash: //FIXME for later....)
263     $self->{content}->{ARCH}->{$self->{id}->{'name'}}->{$k} = $v;
264     }
265     }
266     }
267     else
268     {
269     $self->{content}->{ARCH}->{$self->{id}->{'name'}}=$self->{tagcontent};
270     }
271    
272     delete $self->{isarch};
273     $self->poplevel();
274     }
275    
276 sashby 1.2 sub parse
277     {
278     my $self=shift;
279 muzaffar 1.8.2.3.2.1 my ($file)=@_;
280 sashby 1.6 $self->{scramdoc}->filetoparse($file);
281 sashby 1.2 $self->verbose("Setup Parse");
282 muzaffar 1.8.2.3.2.1 my $fhead='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><doc type="BuildSystem::ToolParser" version="1.0">';
283 muzaffar 1.7 my $ftail='</doc>';
284     $self->{scramdoc}->parse("setup",$fhead,$ftail);
285 sashby 1.6 delete $self->{scramdoc};
286 sashby 1.2 return $self;
287     }
288    
289     sub pushlevel
290     {
291     my $self = shift;
292     my ($info, $nextlevel)=@_;
293    
294     $self->{id} = $info if (defined $info);
295    
296     # Check to see if last tag was arch: if so, ceate new level:
297     if ($self->{isarch} == 1)
298     {
299     $self->{nested} = 2;
300     $self->{nexttagcontent}={};
301     }
302     else
303     {
304     $self->{nested} = 1;
305     $self->{tagcontent}={};
306     }
307    
308     # Set something which says "last starter tag was ARCH":
309     if ($nextlevel)
310     {
311     $self->{isarch} = 1;
312     }
313     }
314    
315     sub poplevel
316     {
317     my $self = shift;
318    
319     # Drop level of nesting by one:
320     $self->{nested}--;
321    
322     if ($self->{isarch} != 1)
323     {
324     delete $self->{tagcontent};
325     }
326     }
327    
328     sub rmenvdata
329     {
330     my $self=shift;
331     delete $self->{ENVDATA};
332     }
333    
334     ###################################
335     ## Data Access Methods ##
336     ###################################
337     sub toolname
338     {
339     my $self=shift;
340     # Return tool name:
341     return ($self->{content}->{TOOLNAME});
342     }
343    
344     sub toolversion
345     {
346     my $self=shift;
347     # Return tool version:
348     return ($self->{content}->{TOOLVERSION});
349     }
350    
351     sub toolcontent
352     {
353     my $self=shift;
354     # Return whole of content hash:
355     return $self->{content};
356     }
357    
358     sub getrawdata()
359     {
360     my $self=shift;
361     my ($tagtype)=@_;
362    
363     # Check to see if we have data for this tag:
364     if (! exists ($self->{content}->{$tagtype}))
365     {
366     # If not, return:
367     return 0;
368     }
369    
370     # Check the number of keys for hash referred to by this object.
371     # If 0, return:
372     if (ref($self->{content}->{$tagtype}) eq 'HASH') #
373     {
374     if ((my $nkeys=keys %{$self->{content}->{$tagtype}}) > 0)
375     {
376     # Return the data for the tag $tagtype. ARCH is a bit special because
377     # we want the data for the actual arch (thus, data is on a different level):
378     if ($tagtype eq 'ARCH')
379     {
380     my $archmatch = {};
381     # Check for matching arch key and return hash of relevant data.
382     # Also must take into account the fact that several arch names may match, e.g. Linux, Linux__2 and
383     # Linux__2.4 all match. If we find more than one match, collect ALL matching data and return it:
384     while (my ($k,$v) = each %{$self->{content}->{ARCH}})
385     {
386     # For every matching architecture we snatch the data and squirrel it away:
387     if ( $ENV{SCRAM_ARCH} =~ /$k.*/ )
388     {
389     # Now we check the tags inside the arch block. Note that we do not want to descend
390     # into CLIENT tags, if these exist. We just want to return all data in the ARCH
391     # block while making sure that multiple matches are handled correctly. We assume that
392     # you will only find one CLIENT block inside and ARCH:
393     while (my ($matchtag, $matchval) = each %{$v})
394     {
395     if ($matchtag =~ /CLIENT|FLAGS|RUNTIME/)
396     {
397     $archmatch->{$matchtag} = $matchval;
398     }
399     else
400     {
401     # Treat tags differently according to whether they are HASHes or ARRAYs:
402     if (ref($matchval) =~ /HASH/)
403     {
404     while (my ($t, $val) = each %{$matchval})
405     {
406     if (exists ($archmatch->{$matchtag}->{$t}))
407     {
408     push(@{$archmatch->{$matchtag}->{$t}},@$val);
409     }
410     else
411     {
412     $archmatch->{$matchtag}->{$t} = $val;
413     }
414     }
415     }
416     else # Here we deal with arrays:
417     {
418     if (exists ($archmatch->{$matchtag}))
419     {
420     push(@{$archmatch->{$matchtag}},@$matchval);
421     }
422     else
423     {
424     $archmatch->{$matchtag} = $matchval;
425     }
426     }
427     }
428     }
429     }
430     }
431     # Return the squirrel:
432     return $archmatch;
433    
434     } # End of ARCH tag treatment
435     else
436     {
437     # Return other tag data:
438     return $self->{content}->{$tagtype};
439     }
440     }
441     else
442     {
443     print "Warning: $tagtype tags contain no other tag data!","\n";
444     return undef;
445     }
446     }
447     else
448     {
449     # We have an array of data or a scalar:
450     return $self->{content}->{$tagtype};
451     }
452     }
453    
454     sub processrawtool()
455     {
456     my $self=shift;
457     my $data = [];
458     my $environments = {}; # Somewhere to collect our environments
459    
460     # Somewhere to store the data:
461     use BuildSystem::ToolData;
462     my $tooldataobj = BuildSystem::ToolData->new();
463    
464     # Set the name and version:
465     $tooldataobj->toolname($self->toolname());
466     $tooldataobj->toolversion($self->toolversion());
467    
468     # First, collect all tag data so that we only have non-nested tags.
469     # Check for architecture-dependent data first, followed by client tags:
470     foreach $nested_tag (qw( ARCH CLIENT ))
471     {
472     if (my $thisdata=$self->getrawdata($nested_tag))
473     {
474     foreach my $item (keys %{ $thisdata })
475     {
476     if ($item eq 'CLIENT')
477     {
478     my $clientdata = $thisdata->{$item};
479     foreach my $ckey (keys %{$clientdata})
480     {
481     $environments->{$ckey} = $clientdata->{$ckey};
482     }
483     }
484     elsif ($item eq 'ENVIRONMENT' || $item eq 'RUNTIME')
485     {
486     # Check to see if tag already exists before saving:
487     if (exists($environments->{$item}))
488     {
489     foreach my $ek (keys %{$thisdata})
490     {
491     if (exists($environments->{$item}->{$ek}))
492     {
493     push(@{$environments->{$item}->{$ek}}, @{$thisdata->{$item}->{$ek}});
494     }
495     else
496     {
497     $environments->{$item}->{$ek} = $thisdata->{$item}->{$ek};
498     }
499     }
500     }
501     else
502     {
503     # There isn't an entry yet:
504     $environments->{$item} = $thisdata->{$item};
505     }
506     }
507     else
508     {
509     my $data = $thisdata->{$item};
510    
511     if (ref($data) eq 'HASH')
512     {
513     while (my ($f,$v) = each %$data)
514     {
515     $tooldataobj->flags($f,$v);
516     }
517     }
518     else
519     {
520     my $subname = lc($item);
521     $tooldataobj->$subname($data), if ($#$data != -1);
522     }
523     }
524     }
525     }
526     else
527     {
528     # No entry for this nested tag. Proceed.
529     next;
530     }
531     }
532     # Now handle all other normal tags:
533     foreach my $normal_tag (qw( ENVIRONMENT RUNTIME ))
534     {
535     # Do we have some data for this tag?
536     if (my $thisdata=$self->getrawdata($normal_tag))
537     {
538     # Add the data to our environments hash. We must check to see if
539     # there is an entry already:
540     if (exists($environments->{$normal_tag}))
541     {
542     foreach my $ek (keys %{$thisdata})
543     {
544     if (exists($environments->{$normal_tag}->{$ek}))
545     {
546     push(@{$environments->{$normal_tag}->{$ek}}, @{$thisdata->{$normal_tag}->{$ek}});
547     }
548     else
549     {
550     $environments->{$normal_tag}->{$ek} = $thisdata->{$normal_tag}->{$ek};
551     }
552     }
553     }
554     else
555     {
556     # There isn't an entry yet:
557     $environments->{$normal_tag} = $thisdata;
558     }
559     }
560     else
561     {
562     # No data so proceed:
563     next;
564     }
565     }
566    
567     # Finally, tags that can be stored straight away:
568     foreach my $tag (qw( FLAGS MAKEFILE ))
569     {
570     my $bdata = $self->getrawdata($tag);
571     if (ref($bdata) eq 'HASH')
572     {
573     while (my ($f,$v) = each %$bdata)
574     {
575     $tooldataobj->flags($f,$v);
576     }
577     }
578     else
579     {
580     $tooldataobj->makefile($bdata), if ($#$bdata != -1);
581     }
582     }
583    
584     # Libs and tool dependencise:
585     foreach my $tag (qw( LIB USE ))
586     {
587     my $bdata = $self->getrawdata($tag);
588     my $subname = lc($tag);
589     $tooldataobj->$subname($bdata), if ($#$bdata != -1);
590     }
591    
592     # Also check to see if this tool is a scram-managed project. If
593     # so, set the SCRAM_PROJECT variable in the ToolData object:
594     if (exists ($self->{content}->{SCRAM_PROJECT}))
595     {
596     $tooldataobj->scram_project($self->{content}->{SCRAM_PROJECT});
597     }
598 sashby 1.4
599     # And check to see if this tool is a compiler. If so, set
600     # the SCRAM_COMPILER variable in the ToolData object:
601     if (exists ($self->{content}->{SCRAM_COMPILER}))
602     {
603     $tooldataobj->scram_compiler($self->{content}->{SCRAM_COMPILER});
604     }
605 muzaffar 1.8.2.3
606     my @order=(); push @order,@{$self->{envorder}};
607     my %uorder=(); map {$uorder{$_}=1} @order;
608     foreach my $type (qw (ENVIRONMENT RUNTIME))
609     {
610     if (exists $environments->{$type})
611     {
612     foreach my $env (keys %{$environments->{$type}})
613     {
614     if (!exists $uorder{$env}){$uorder{$env}=1; push @order,$env;}
615     }
616     }
617     }
618 muzaffar 1.8.2.3.2.3 $self->find_settings($tooldataobj, $environments, \@order);
619 sashby 1.2 return $tooldataobj;
620     }
621    
622     sub find_settings()
623     {
624     my $self=shift;
625     my ($tooldataobj, $environments, $ordering)=@_;
626     my $stringtoeval;
627     my $runtime=[];
628     my $path;
629    
630     use BuildSystem::ToolSettingValidator;
631    
632     my $tsv = BuildSystem::ToolSettingValidator->new($environments, $self->toolname());
633    
634     foreach my $envname (@$ordering)
635     {
636     my $type = 'ENVIRONMENT';
637     my $envdata = $tsv->environment($type, $envname);
638    
639     # Handle single-occurrence variables first (i.e. VAR appears once
640     # in array of hashes):
641     if ($envdata != 0 && $#$envdata == 0) # One element only!
642     {
643 muzaffar 1.8 scramlogmsg("\nFinding a value for $envname:","\n\n");
644 muzaffar 1.8.2.3.2.3 $path = $tsv->findvalue($envname, $envdata);
645     $self->store($tooldataobj, $envname, $path);
646 sashby 1.2 }
647     elsif ($envdata != 0 && $#$envdata > 0)
648     {
649 muzaffar 1.8 scramlogmsg("\nFinding a value for $envname:","\n\n");
650 sashby 1.2 foreach my $elementdata (@$envdata)
651     {
652 muzaffar 1.8.2.3.2.3 $path = $tsv->findvalue($envname, $elementdata);
653     $self->store($tooldataobj, $envname, $path);
654 sashby 1.2 }
655     }
656     else
657     {
658     push(@$runtime, $envname);
659     }
660     }
661     $self->_lib_validate($tooldataobj);
662 muzaffar 1.8 scramlogmsg("\n-------------------------------\n");
663 sashby 1.2 foreach my $rtname (@$runtime)
664     {
665     my $type = 'RUNTIME';
666     my $envdata = $tsv->environment($type, $rtname);
667     my ($rttype,$realrtname) = split(':',$rtname);
668 muzaffar 1.8.2.3.2.3
669 sashby 1.2 # Only validate paths:
670     if ($rtname =~ /:/)
671     {
672     if ($envdata != 0 && $#$envdata == 0) # One element only!
673     {
674 muzaffar 1.8 scramlogmsg("\nRuntime path settings for $realrtname:","\n\n");
675 muzaffar 1.8.2.3.2.3 $path = $tsv->findvalue($rtname, $envdata);
676     $tooldataobj->runtime($rtname, [ $path ]);
677 sashby 1.2 }
678     elsif ($envdata != 0 && $#$envdata > 0)
679     {
680 muzaffar 1.8 scramlogmsg("\nRuntime path settings for $realrtname:","\n\n");
681 sashby 1.2 foreach my $elementdata (@$envdata)
682     {
683     $path = $tsv->findvalue($rtname, $elementdata);
684     $tooldataobj->runtime($rtname, [ $path ]);
685     }
686     }
687     else
688     {
689     next;
690     }
691     }
692     else
693     {
694     if ($envdata != 0 && $#$envdata == 0) # One element only!
695     {
696     my $value='';
697 muzaffar 1.8.2.3.2.3 if ($tsv->checkdefaults($envdata, \$value)==0)
698     {
699     $tsv->promptuser($rtname,$value);
700     }
701 muzaffar 1.8 scramlogmsg("\n");
702 sashby 1.2
703     if ($value =~ /$/)
704     {
705     my $dvalue = $tsv->_expandvars($value);
706     $value = $dvalue;
707     }
708    
709 muzaffar 1.8 scramlogmsg("Runtime variable ",$rtname," set to \"",$value,"\"\n");
710 sashby 1.2 $tooldataobj->runtime($rtname, [ $value ]);
711     }
712     else
713     {
714     next;
715     }
716     }
717     }
718    
719 muzaffar 1.8 scramlogmsg("\n");
720 sashby 1.2 }
721    
722     sub store()
723     {
724     my $self=shift;
725     my ($tooldataobj, $envname, $path) = @_;
726     my $subrtn = lc($envname);
727    
728     if ($tooldataobj->can($subrtn))
729     {
730     $tooldataobj->$subrtn([ $path ]);
731     }
732     else
733     {
734     $tooldataobj->variable_data($envname, $path);
735     }
736     }
737    
738     sub _lib_validate()
739     {
740     my $self=shift;
741     my ($toolobj)=@_;
742     my $errorstatus = { 0 => $main::good."[OK]".$main::normal, 1 => $main::error."[ERROR]".$main::normal };
743     my $libsfound={};
744    
745     # Firstly, we check to see if there are libraries provided by this tool:
746     my @libraries = $toolobj->lib();
747     my @libpaths = $toolobj->libdir();
748    
749     foreach my $ldir (@libpaths)
750     {
751     my $full_libname_glob="lib".$lib."*.*";
752     # Change to lib dir so we avoid the very long paths in our glob:
753     chdir($ldir);
754     # Next we use a glob to get libs matching this string (so we
755     # can see if there's a shared or archive lib):
756     my @possible_libs = glob($full_libname_glob);
757     #
758     map
759     {
760     $_ =~ s/\.so*|\.a*//g; # Remove all endings
761     # Store in our hash of found libs:
762     $libsfound->{$_} = 1;
763     } @possible_libs;
764     }
765    
766     # Next we iterate over the list of libraries in our tool and
767     # see if it was found in one of the libdirs:
768 muzaffar 1.8 scramlogmsg("\n\n"), if ($#libraries != -1);
769 sashby 1.2 foreach my $library (@libraries)
770     {
771     # Good status:
772     my $errorid = 0;
773     if (! exists ($libsfound->{'lib'.$library}))
774     {
775     # Check in system library dirs:
776     if ($self->_check_system_libs($library))
777     {
778     $errorid = 0;
779     }
780     else
781     {
782     $errorid = 1;
783     }
784     }
785 muzaffar 1.8 scramlogmsg(sprintf("* Library check %-10s for lib%-12s\n",$errorstatus->{$errorid}, $library));
786 sashby 1.2 }
787    
788 muzaffar 1.8 scramlogmsg("\n");
789 sashby 1.2 }
790    
791     sub _check_system_libs()
792     {
793     my $self=shift;
794     my ($lib)=@_;
795     my $libsfound = {};
796     my $systemdirs = [ qw( /lib /usr/lib /usr/local/lib /usr/X11R6/lib ) ];
797     my $full_libname_glob="lib".$lib."*.*";
798     my $found = 0;
799    
800     foreach my $dir (@$systemdirs)
801     {
802     # Change to lib dir so we avoid the very long paths in our glob:
803     chdir($dir);
804     # Next we use a glob to get libs matching this string (so we
805     # can see if there's a shared or archive lib):
806     my @possible_libs = glob($full_libname_glob);
807     #
808     map
809     {
810     $_ =~ s/\.so*|\.a*//g; # Remove all endings
811     # Store in our hash of found libs:
812     $libsfound->{$_} = 1;
813     } @possible_libs;
814     }
815    
816     # See if we find the library in the system lib directories:
817     if (! exists ($libsfound->{'lib'.$library}))
818     {
819     $found = 1;
820     }
821    
822     return $found;
823     }
824    
825 sashby 1.6 sub AUTOLOAD()
826     {
827     my ($xmlparser,$name,%attributes)=@_;
828     return if $AUTOLOAD =~ /::DESTROY$/;
829     my $name=$AUTOLOAD;
830     $name =~ s/.*://;
831     }
832    
833 sashby 1.2 1;