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 |
sashby |
1.5 |
# Revision: $Id: ToolParser.pm,v 1.4 2005/04/13 16:45:36 sashby 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 |
|
|
use ActiveDoc::SimpleDoc;
|
17 |
|
|
use Utilities::Verbose;
|
18 |
|
|
use BuildSystem::ToolTagUtils;
|
19 |
|
|
|
20 |
|
|
@ISA=qw(Exporter Utilities::Verbose);
|
21 |
|
|
@EXPORT=qw();
|
22 |
|
|
|
23 |
|
|
#
|
24 |
|
|
sub new
|
25 |
|
|
###############################################################
|
26 |
|
|
# new #
|
27 |
|
|
###############################################################
|
28 |
|
|
# modified : Thu Nov 13 10:42:08 2003 / SFA #
|
29 |
|
|
# params : #
|
30 |
|
|
# : #
|
31 |
|
|
# function : #
|
32 |
|
|
# : #
|
33 |
|
|
###############################################################
|
34 |
|
|
{
|
35 |
|
|
my $proto=shift;
|
36 |
|
|
my $class=ref($proto) || $proto;
|
37 |
|
|
my $self={};
|
38 |
|
|
|
39 |
|
|
bless $self,$class;
|
40 |
|
|
|
41 |
|
|
$self->{cache}=shift;
|
42 |
|
|
$self->{mydoctype}="BuildSystem::ToolParser";
|
43 |
|
|
$self->{mydocversion}="1.1";
|
44 |
|
|
$self->{interactive} = 0;
|
45 |
|
|
$self->{content} = {};
|
46 |
|
|
$self->{nested} = 0;
|
47 |
|
|
|
48 |
|
|
$self->_initparser();
|
49 |
|
|
|
50 |
|
|
return $self;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
sub _initparser
|
54 |
|
|
{
|
55 |
|
|
my $self=shift;
|
56 |
|
|
|
57 |
|
|
$self->{simpledoc}=ActiveDoc::SimpleDoc->new();
|
58 |
|
|
$self->{simpledoc}->newparse("setup");
|
59 |
|
|
$self->{simpledoc}->addtag("setup","Tool",
|
60 |
|
|
\&BuildSystem::ToolTagUtils::tooltagOpen, $self,
|
61 |
|
|
"", $self,
|
62 |
|
|
\&BuildSystem::ToolTagUtils::tooltagClose, $self);
|
63 |
|
|
|
64 |
|
|
$self->{simpledoc}->addtag("setup","Lib",
|
65 |
|
|
\&BuildSystem::ToolTagUtils::libtagOpen, $self,
|
66 |
|
|
"", $self,
|
67 |
|
|
"", $self);
|
68 |
|
|
|
69 |
|
|
$self->{simpledoc}->addtag("setup","info",
|
70 |
|
|
\&BuildSystem::ToolTagUtils::infotagOpen, $self,
|
71 |
|
|
"", $self,
|
72 |
|
|
"", $self);
|
73 |
|
|
|
74 |
|
|
$self->{simpledoc}->addtag("setup","Use",
|
75 |
|
|
\&BuildSystem::ToolTagUtils::usetagOpen, $self,
|
76 |
|
|
"", $self,
|
77 |
|
|
"", $self);
|
78 |
|
|
|
79 |
|
|
$self->{simpledoc}->addtag("setup","Runtime",
|
80 |
|
|
\&BuildSystem::ToolTagUtils::runtimetagOpen, $self,
|
81 |
|
|
"", $self,
|
82 |
|
|
"", $self);
|
83 |
|
|
|
84 |
|
|
$self->{simpledoc}->addtag("setup","Flags",
|
85 |
|
|
\&BuildSystem::ToolTagUtils::flagstagOpen, $self,
|
86 |
|
|
"", $self,
|
87 |
|
|
"", $self);
|
88 |
|
|
|
89 |
|
|
$self->{simpledoc}->addtag("setup","Client",
|
90 |
|
|
\&BuildSystem::ToolTagUtils::clienttagOpen, $self,
|
91 |
|
|
"", $self,
|
92 |
|
|
\&BuildSystem::ToolTagUtils::clienttagClose, $self);
|
93 |
|
|
|
94 |
|
|
$self->{simpledoc}->addtag("setup","Environment",
|
95 |
|
|
\&BuildSystem::ToolTagUtils::environmenttagOpen, $self,
|
96 |
|
|
"", $self,
|
97 |
|
|
"", $self);
|
98 |
|
|
|
99 |
|
|
$self->{simpledoc}->addtag("setup","Makefile",
|
100 |
|
|
\&BuildSystem::ToolTagUtils::makefiletagOpen, $self,
|
101 |
|
|
\&BuildSystem::ToolTagUtils::makefiletagContent, $self,
|
102 |
|
|
\&BuildSystem::ToolTagUtils::makefiletagClose, $self);
|
103 |
|
|
|
104 |
|
|
$self->{simpledoc}->grouptag("Tool","setup");
|
105 |
|
|
$self->{simpledoc}->addtag("setup","Architecture",
|
106 |
|
|
\&BuildSystem::ToolTagUtils::archtagOpen,$self,
|
107 |
|
|
"", $self,
|
108 |
|
|
\&BuildSystem::ToolTagUtils::archtagClose,$self);
|
109 |
|
|
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
sub parse
|
113 |
|
|
{
|
114 |
|
|
my $self=shift;
|
115 |
|
|
my ($tool,$toolver,$file)=@_;
|
116 |
|
|
|
117 |
|
|
$self->{tool}=$tool;
|
118 |
|
|
$self->{version}=$toolver;
|
119 |
|
|
$self->{simpledoc}->filetoparse($file);
|
120 |
|
|
$self->verbose("Setup Parse");
|
121 |
|
|
$self->{simpledoc}->parse("setup");
|
122 |
|
|
|
123 |
|
|
delete $self->{simpledoc};
|
124 |
|
|
return $self;
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
sub pushlevel
|
128 |
|
|
{
|
129 |
|
|
my $self = shift;
|
130 |
|
|
my ($info, $nextlevel)=@_;
|
131 |
|
|
|
132 |
|
|
$self->{id} = $info if (defined $info);
|
133 |
|
|
|
134 |
|
|
# Check to see if last tag was arch: if so, ceate new level:
|
135 |
|
|
if ($self->{isarch} == 1)
|
136 |
|
|
{
|
137 |
|
|
$self->{nested} = 2;
|
138 |
|
|
$self->{nexttagcontent}={};
|
139 |
|
|
}
|
140 |
|
|
else
|
141 |
|
|
{
|
142 |
|
|
$self->{nested} = 1;
|
143 |
|
|
$self->{tagcontent}={};
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
# Set something which says "last starter tag was ARCH":
|
147 |
|
|
if ($nextlevel)
|
148 |
|
|
{
|
149 |
|
|
$self->{isarch} = 1;
|
150 |
|
|
}
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
sub poplevel
|
154 |
|
|
{
|
155 |
|
|
my $self = shift;
|
156 |
|
|
|
157 |
|
|
# Drop level of nesting by one:
|
158 |
|
|
$self->{nested}--;
|
159 |
|
|
|
160 |
|
|
if ($self->{isarch} != 1)
|
161 |
|
|
{
|
162 |
|
|
delete $self->{tagcontent};
|
163 |
|
|
}
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
sub rmenvdata
|
167 |
|
|
{
|
168 |
|
|
my $self=shift;
|
169 |
|
|
delete $self->{ENVDATA};
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
###################################
|
173 |
|
|
## Data Access Methods ##
|
174 |
|
|
###################################
|
175 |
|
|
sub toolname
|
176 |
|
|
{
|
177 |
|
|
my $self=shift;
|
178 |
|
|
# Return tool name:
|
179 |
|
|
return ($self->{content}->{TOOLNAME});
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
sub toolversion
|
183 |
|
|
{
|
184 |
|
|
my $self=shift;
|
185 |
|
|
# Return tool version:
|
186 |
|
|
return ($self->{content}->{TOOLVERSION});
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
sub toolcontent
|
190 |
|
|
{
|
191 |
|
|
my $self=shift;
|
192 |
|
|
# Return whole of content hash:
|
193 |
|
|
return $self->{content};
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
sub getrawdata()
|
197 |
|
|
{
|
198 |
|
|
my $self=shift;
|
199 |
|
|
my ($tagtype)=@_;
|
200 |
|
|
|
201 |
|
|
# Check to see if we have data for this tag:
|
202 |
|
|
if (! exists ($self->{content}->{$tagtype}))
|
203 |
|
|
{
|
204 |
|
|
# If not, return:
|
205 |
|
|
return 0;
|
206 |
|
|
}
|
207 |
|
|
|
208 |
|
|
# Check the number of keys for hash referred to by this object.
|
209 |
|
|
# If 0, return:
|
210 |
|
|
if (ref($self->{content}->{$tagtype}) eq 'HASH') #
|
211 |
|
|
{
|
212 |
|
|
if ((my $nkeys=keys %{$self->{content}->{$tagtype}}) > 0)
|
213 |
|
|
{
|
214 |
|
|
# Return the data for the tag $tagtype. ARCH is a bit special because
|
215 |
|
|
# we want the data for the actual arch (thus, data is on a different level):
|
216 |
|
|
if ($tagtype eq 'ARCH')
|
217 |
|
|
{
|
218 |
|
|
my $archmatch = {};
|
219 |
|
|
# Check for matching arch key and return hash of relevant data.
|
220 |
|
|
# Also must take into account the fact that several arch names may match, e.g. Linux, Linux__2 and
|
221 |
|
|
# Linux__2.4 all match. If we find more than one match, collect ALL matching data and return it:
|
222 |
|
|
while (my ($k,$v) = each %{$self->{content}->{ARCH}})
|
223 |
|
|
{
|
224 |
|
|
# For every matching architecture we snatch the data and squirrel it away:
|
225 |
|
|
if ( $ENV{SCRAM_ARCH} =~ /$k.*/ )
|
226 |
|
|
{
|
227 |
|
|
# Now we check the tags inside the arch block. Note that we do not want to descend
|
228 |
|
|
# into CLIENT tags, if these exist. We just want to return all data in the ARCH
|
229 |
|
|
# block while making sure that multiple matches are handled correctly. We assume that
|
230 |
|
|
# you will only find one CLIENT block inside and ARCH:
|
231 |
|
|
while (my ($matchtag, $matchval) = each %{$v})
|
232 |
|
|
{
|
233 |
|
|
if ($matchtag =~ /CLIENT|FLAGS|RUNTIME/)
|
234 |
|
|
{
|
235 |
|
|
$archmatch->{$matchtag} = $matchval;
|
236 |
|
|
}
|
237 |
|
|
else
|
238 |
|
|
{
|
239 |
|
|
# Treat tags differently according to whether they are HASHes or ARRAYs:
|
240 |
|
|
if (ref($matchval) =~ /HASH/)
|
241 |
|
|
{
|
242 |
|
|
while (my ($t, $val) = each %{$matchval})
|
243 |
|
|
{
|
244 |
|
|
if (exists ($archmatch->{$matchtag}->{$t}))
|
245 |
|
|
{
|
246 |
|
|
push(@{$archmatch->{$matchtag}->{$t}},@$val);
|
247 |
|
|
}
|
248 |
|
|
else
|
249 |
|
|
{
|
250 |
|
|
$archmatch->{$matchtag}->{$t} = $val;
|
251 |
|
|
}
|
252 |
|
|
}
|
253 |
|
|
}
|
254 |
|
|
else # Here we deal with arrays:
|
255 |
|
|
{
|
256 |
|
|
if (exists ($archmatch->{$matchtag}))
|
257 |
|
|
{
|
258 |
|
|
push(@{$archmatch->{$matchtag}},@$matchval);
|
259 |
|
|
}
|
260 |
|
|
else
|
261 |
|
|
{
|
262 |
|
|
$archmatch->{$matchtag} = $matchval;
|
263 |
|
|
}
|
264 |
|
|
}
|
265 |
|
|
}
|
266 |
|
|
}
|
267 |
|
|
}
|
268 |
|
|
}
|
269 |
|
|
# Return the squirrel:
|
270 |
|
|
return $archmatch;
|
271 |
|
|
|
272 |
|
|
} # End of ARCH tag treatment
|
273 |
|
|
else
|
274 |
|
|
{
|
275 |
|
|
# Return other tag data:
|
276 |
|
|
return $self->{content}->{$tagtype};
|
277 |
|
|
}
|
278 |
|
|
}
|
279 |
|
|
else
|
280 |
|
|
{
|
281 |
|
|
print "Warning: $tagtype tags contain no other tag data!","\n";
|
282 |
|
|
return undef;
|
283 |
|
|
}
|
284 |
|
|
}
|
285 |
|
|
else
|
286 |
|
|
{
|
287 |
|
|
# We have an array of data or a scalar:
|
288 |
|
|
return $self->{content}->{$tagtype};
|
289 |
|
|
}
|
290 |
|
|
}
|
291 |
|
|
|
292 |
|
|
sub processrawtool()
|
293 |
|
|
{
|
294 |
|
|
my $self=shift;
|
295 |
|
|
my ($interactive) = @_;
|
296 |
|
|
my $data = [];
|
297 |
|
|
my $environments = {}; # Somewhere to collect our environments
|
298 |
|
|
|
299 |
|
|
# Set interactive mode if required:
|
300 |
|
|
$self->{interactive} = $interactive;
|
301 |
|
|
|
302 |
|
|
# Somewhere to store the data:
|
303 |
|
|
use BuildSystem::ToolData;
|
304 |
|
|
my $tooldataobj = BuildSystem::ToolData->new();
|
305 |
|
|
|
306 |
|
|
# Set the name and version:
|
307 |
|
|
$tooldataobj->toolname($self->toolname());
|
308 |
|
|
$tooldataobj->toolversion($self->toolversion());
|
309 |
|
|
|
310 |
|
|
# First, collect all tag data so that we only have non-nested tags.
|
311 |
|
|
# Check for architecture-dependent data first, followed by client tags:
|
312 |
|
|
foreach $nested_tag (qw( ARCH CLIENT ))
|
313 |
|
|
{
|
314 |
|
|
if (my $thisdata=$self->getrawdata($nested_tag))
|
315 |
|
|
{
|
316 |
|
|
foreach my $item (keys %{ $thisdata })
|
317 |
|
|
{
|
318 |
|
|
if ($item eq 'CLIENT')
|
319 |
|
|
{
|
320 |
|
|
my $clientdata = $thisdata->{$item};
|
321 |
|
|
foreach my $ckey (keys %{$clientdata})
|
322 |
|
|
{
|
323 |
|
|
$environments->{$ckey} = $clientdata->{$ckey};
|
324 |
|
|
}
|
325 |
|
|
}
|
326 |
|
|
elsif ($item eq 'ENVIRONMENT' || $item eq 'RUNTIME')
|
327 |
|
|
{
|
328 |
|
|
# Check to see if tag already exists before saving:
|
329 |
|
|
if (exists($environments->{$item}))
|
330 |
|
|
{
|
331 |
|
|
foreach my $ek (keys %{$thisdata})
|
332 |
|
|
{
|
333 |
|
|
if (exists($environments->{$item}->{$ek}))
|
334 |
|
|
{
|
335 |
|
|
push(@{$environments->{$item}->{$ek}}, @{$thisdata->{$item}->{$ek}});
|
336 |
|
|
}
|
337 |
|
|
else
|
338 |
|
|
{
|
339 |
|
|
$environments->{$item}->{$ek} = $thisdata->{$item}->{$ek};
|
340 |
|
|
}
|
341 |
|
|
}
|
342 |
|
|
}
|
343 |
|
|
else
|
344 |
|
|
{
|
345 |
|
|
# There isn't an entry yet:
|
346 |
|
|
$environments->{$item} = $thisdata->{$item};
|
347 |
|
|
}
|
348 |
|
|
}
|
349 |
|
|
else
|
350 |
|
|
{
|
351 |
|
|
my $data = $thisdata->{$item};
|
352 |
|
|
|
353 |
|
|
if (ref($data) eq 'HASH')
|
354 |
|
|
{
|
355 |
|
|
while (my ($f,$v) = each %$data)
|
356 |
|
|
{
|
357 |
|
|
$tooldataobj->flags($f,$v);
|
358 |
|
|
}
|
359 |
|
|
}
|
360 |
|
|
else
|
361 |
|
|
{
|
362 |
|
|
my $subname = lc($item);
|
363 |
|
|
$tooldataobj->$subname($data), if ($#$data != -1);
|
364 |
|
|
}
|
365 |
|
|
}
|
366 |
|
|
}
|
367 |
|
|
}
|
368 |
|
|
else
|
369 |
|
|
{
|
370 |
|
|
# No entry for this nested tag. Proceed.
|
371 |
|
|
next;
|
372 |
|
|
}
|
373 |
|
|
}
|
374 |
|
|
|
375 |
|
|
# Now handle all other normal tags:
|
376 |
|
|
foreach my $normal_tag (qw( ENVIRONMENT RUNTIME ))
|
377 |
|
|
{
|
378 |
|
|
# Do we have some data for this tag?
|
379 |
|
|
if (my $thisdata=$self->getrawdata($normal_tag))
|
380 |
|
|
{
|
381 |
|
|
# Add the data to our environments hash. We must check to see if
|
382 |
|
|
# there is an entry already:
|
383 |
|
|
if (exists($environments->{$normal_tag}))
|
384 |
|
|
{
|
385 |
|
|
foreach my $ek (keys %{$thisdata})
|
386 |
|
|
{
|
387 |
|
|
if (exists($environments->{$normal_tag}->{$ek}))
|
388 |
|
|
{
|
389 |
|
|
push(@{$environments->{$normal_tag}->{$ek}}, @{$thisdata->{$normal_tag}->{$ek}});
|
390 |
|
|
}
|
391 |
|
|
else
|
392 |
|
|
{
|
393 |
|
|
$environments->{$normal_tag}->{$ek} = $thisdata->{$normal_tag}->{$ek};
|
394 |
|
|
}
|
395 |
|
|
}
|
396 |
|
|
}
|
397 |
|
|
else
|
398 |
|
|
{
|
399 |
|
|
# There isn't an entry yet:
|
400 |
|
|
$environments->{$normal_tag} = $thisdata;
|
401 |
|
|
}
|
402 |
|
|
}
|
403 |
|
|
else
|
404 |
|
|
{
|
405 |
|
|
# No data so proceed:
|
406 |
|
|
next;
|
407 |
|
|
}
|
408 |
|
|
}
|
409 |
|
|
|
410 |
|
|
# Finally, tags that can be stored straight away:
|
411 |
|
|
foreach my $tag (qw( FLAGS MAKEFILE ))
|
412 |
|
|
{
|
413 |
|
|
my $bdata = $self->getrawdata($tag);
|
414 |
|
|
if (ref($bdata) eq 'HASH')
|
415 |
|
|
{
|
416 |
|
|
while (my ($f,$v) = each %$bdata)
|
417 |
|
|
{
|
418 |
|
|
$tooldataobj->flags($f,$v);
|
419 |
|
|
}
|
420 |
|
|
}
|
421 |
|
|
else
|
422 |
|
|
{
|
423 |
|
|
$tooldataobj->makefile($bdata), if ($#$bdata != -1);
|
424 |
|
|
}
|
425 |
|
|
}
|
426 |
|
|
|
427 |
|
|
# Libs and tool dependencise:
|
428 |
|
|
foreach my $tag (qw( LIB USE ))
|
429 |
|
|
{
|
430 |
|
|
my $bdata = $self->getrawdata($tag);
|
431 |
|
|
my $subname = lc($tag);
|
432 |
|
|
$tooldataobj->$subname($bdata), if ($#$bdata != -1);
|
433 |
|
|
}
|
434 |
|
|
|
435 |
|
|
# Also check to see if this tool is a scram-managed project. If
|
436 |
|
|
# so, set the SCRAM_PROJECT variable in the ToolData object:
|
437 |
|
|
if (exists ($self->{content}->{SCRAM_PROJECT}))
|
438 |
|
|
{
|
439 |
|
|
$tooldataobj->scram_project($self->{content}->{SCRAM_PROJECT});
|
440 |
|
|
}
|
441 |
sashby |
1.4 |
|
442 |
|
|
# And check to see if this tool is a compiler. If so, set
|
443 |
|
|
# the SCRAM_COMPILER variable in the ToolData object:
|
444 |
|
|
if (exists ($self->{content}->{SCRAM_COMPILER}))
|
445 |
|
|
{
|
446 |
|
|
$tooldataobj->scram_compiler($self->{content}->{SCRAM_COMPILER});
|
447 |
|
|
}
|
448 |
sashby |
1.2 |
|
449 |
|
|
# Establish the order of parsing the value strings:
|
450 |
|
|
my $order = $self->process_environments($environments);
|
451 |
|
|
|
452 |
|
|
if ($self->{interactive})
|
453 |
|
|
{
|
454 |
|
|
# Set the values interactively:
|
455 |
|
|
$self->interactively_find_settings($tooldataobj, $environments, $order);
|
456 |
|
|
}
|
457 |
|
|
else
|
458 |
|
|
{
|
459 |
|
|
# Set the values:
|
460 |
|
|
$self->find_settings($tooldataobj, $environments, $order);
|
461 |
|
|
}
|
462 |
|
|
|
463 |
|
|
# Return a ToolData object:
|
464 |
|
|
return $tooldataobj;
|
465 |
|
|
}
|
466 |
|
|
|
467 |
|
|
sub process_environments()
|
468 |
|
|
{
|
469 |
|
|
my $self=shift;
|
470 |
|
|
my ($environments)=@_;
|
471 |
|
|
|
472 |
|
|
use BuildSystem::SCRAMGrapher;
|
473 |
|
|
my $G = BuildSystem::SCRAMGrapher->new();
|
474 |
|
|
|
475 |
|
|
foreach $envtype (keys %{$environments})
|
476 |
|
|
{
|
477 |
|
|
while (my ($envcontent,$envdata) = each %{$environments->{$envtype}})
|
478 |
|
|
{
|
479 |
|
|
# Add a vertex for the VARIABLE name:
|
480 |
|
|
$G->vertex($envcontent);
|
481 |
|
|
|
482 |
|
|
foreach my $element (@$envdata)
|
483 |
|
|
{
|
484 |
|
|
if (exists($element->{'ELEMENTS'}))
|
485 |
|
|
{
|
486 |
|
|
map
|
487 |
|
|
{
|
488 |
|
|
# Add a path for each element in ELEMENTS:
|
489 |
|
|
$G->edge($envcontent, $_);
|
490 |
|
|
} @{$element->{'ELEMENTS'}};
|
491 |
|
|
}
|
492 |
|
|
}
|
493 |
|
|
}
|
494 |
|
|
}
|
495 |
|
|
|
496 |
|
|
my $setup_order = $G->sort();
|
497 |
|
|
return $setup_order;
|
498 |
|
|
}
|
499 |
|
|
|
500 |
|
|
sub find_settings()
|
501 |
|
|
{
|
502 |
|
|
my $self=shift;
|
503 |
|
|
my ($tooldataobj, $environments, $ordering)=@_;
|
504 |
|
|
my $stringtoeval;
|
505 |
|
|
my $runtime=[];
|
506 |
|
|
my $path;
|
507 |
|
|
|
508 |
|
|
use BuildSystem::ToolSettingValidator;
|
509 |
|
|
|
510 |
|
|
my $tsv = BuildSystem::ToolSettingValidator->new($environments, $self->toolname());
|
511 |
|
|
|
512 |
|
|
foreach my $envname (@$ordering)
|
513 |
|
|
{
|
514 |
|
|
my $type = 'ENVIRONMENT';
|
515 |
|
|
my $envdata = $tsv->environment($type, $envname);
|
516 |
|
|
|
517 |
|
|
# Handle single-occurrence variables first (i.e. VAR appears once
|
518 |
|
|
# in array of hashes):
|
519 |
|
|
if ($envdata != 0 && $#$envdata == 0) # One element only!
|
520 |
|
|
{
|
521 |
|
|
print "\nFinding a value for $envname:","\n";
|
522 |
|
|
print "\n";
|
523 |
|
|
# We have an environment and only one data element:
|
524 |
|
|
# Check the lookup DB:
|
525 |
|
|
if ($tsv->checkDB($envname))
|
526 |
|
|
{
|
527 |
|
|
print "\tValidating value for $envname (found in tool DB):","\n";
|
528 |
|
|
if ($tsv->validatepath())
|
529 |
|
|
{
|
530 |
|
|
# Save in TSV and store in ToolData object:
|
531 |
|
|
$tsv->savevalue($envname,$tsv->pathfromdb());
|
532 |
|
|
$self->store($tooldataobj, $envname, $tsv->pathfromdb());
|
533 |
|
|
}
|
534 |
|
|
else
|
535 |
|
|
{
|
536 |
|
|
$path = $tsv->findvalue($envname, $envdata);
|
537 |
|
|
# Save the value in ToolData object:
|
538 |
|
|
$self->store($tooldataobj, $envname, $path);
|
539 |
|
|
}
|
540 |
|
|
}
|
541 |
|
|
else
|
542 |
|
|
{
|
543 |
|
|
$path = $tsv->findvalue($envname, $envdata);
|
544 |
|
|
# Save in ToolData object:
|
545 |
|
|
$self->store($tooldataobj, $envname, $path);
|
546 |
|
|
}
|
547 |
|
|
}
|
548 |
|
|
elsif ($envdata != 0 && $#$envdata > 0)
|
549 |
|
|
{
|
550 |
|
|
print "\nFinding a value for $envname:","\n";
|
551 |
|
|
print "\n";
|
552 |
|
|
foreach my $elementdata (@$envdata)
|
553 |
|
|
{
|
554 |
|
|
$path = $tsv->findvalue($envname, $elementdata);
|
555 |
|
|
# Save in ToolData object:
|
556 |
|
|
$self->store($tooldataobj, $envname, $path);
|
557 |
|
|
}
|
558 |
|
|
}
|
559 |
|
|
elsif (exists($ENV{$envname}))
|
560 |
|
|
{
|
561 |
|
|
# Nothing to do here:
|
562 |
sashby |
1.5 |
push(@$runtime, $envname); # FIX From Shahzad.
|
563 |
sashby |
1.2 |
next;
|
564 |
|
|
}
|
565 |
|
|
else
|
566 |
|
|
{
|
567 |
|
|
push(@$runtime, $envname);
|
568 |
|
|
}
|
569 |
|
|
}
|
570 |
|
|
|
571 |
|
|
# Check that the required libraries exist:
|
572 |
|
|
$self->_lib_validate($tooldataobj);
|
573 |
|
|
|
574 |
|
|
# Now process the runtime settings:
|
575 |
|
|
print "\n";
|
576 |
|
|
print "-------------------------------\n";
|
577 |
|
|
|
578 |
|
|
foreach my $rtname (@$runtime)
|
579 |
|
|
{
|
580 |
|
|
my $type = 'RUNTIME';
|
581 |
|
|
my $envdata = $tsv->environment($type, $rtname);
|
582 |
|
|
my ($rttype,$realrtname) = split(':',$rtname);
|
583 |
sashby |
1.3 |
|
584 |
sashby |
1.2 |
# Only validate paths:
|
585 |
|
|
if ($rtname =~ /:/)
|
586 |
|
|
{
|
587 |
|
|
# Handle single-occurrence variables first (i.e. VAR appears once
|
588 |
|
|
# in array of hashes):
|
589 |
|
|
if ($envdata != 0 && $#$envdata == 0) # One element only!
|
590 |
|
|
{
|
591 |
|
|
print "\nRuntime path settings for $realrtname:","\n";
|
592 |
|
|
print "\n";
|
593 |
|
|
# We have an environment and only one data element:
|
594 |
|
|
# Check the lookup DB:
|
595 |
|
|
if ($tsv->checkDB($rtname))
|
596 |
|
|
{
|
597 |
|
|
print "\tValidating value for path $realrtname (found in tool DB):","\n";
|
598 |
|
|
if ($tsv->validatepath())
|
599 |
|
|
{
|
600 |
|
|
# Save in TSV and store in ToolData object:
|
601 |
|
|
$tsv->savevalue($rtname, $tsv->pathfromdb());
|
602 |
|
|
$tooldataobj->runtime($rtname, [ $tsv->pathfromdb() ]);
|
603 |
|
|
}
|
604 |
|
|
else
|
605 |
|
|
{
|
606 |
|
|
$path = $tsv->findvalue($rtname, $envdata);
|
607 |
|
|
# Save the value in ToolData object:
|
608 |
|
|
$tooldataobj->runtime($rtname, [ $path ]);
|
609 |
|
|
}
|
610 |
|
|
}
|
611 |
|
|
else
|
612 |
|
|
{
|
613 |
|
|
$path = $tsv->findvalue($rtname, $envdata);
|
614 |
|
|
# Save in ToolData object:
|
615 |
|
|
$tooldataobj->runtime($rtname, [ $path ]);
|
616 |
|
|
}
|
617 |
|
|
}
|
618 |
|
|
elsif ($envdata != 0 && $#$envdata > 0)
|
619 |
|
|
{
|
620 |
|
|
print "\nRuntime path settings for $realrtname:","\n";
|
621 |
|
|
print "\n";
|
622 |
|
|
foreach my $elementdata (@$envdata)
|
623 |
|
|
{
|
624 |
|
|
$path = $tsv->findvalue($rtname, $elementdata);
|
625 |
|
|
# Save in ToolData object:
|
626 |
|
|
$tooldataobj->runtime($rtname, [ $path ]);
|
627 |
|
|
}
|
628 |
|
|
}
|
629 |
|
|
else
|
630 |
|
|
{
|
631 |
|
|
next;
|
632 |
|
|
}
|
633 |
|
|
}
|
634 |
|
|
else
|
635 |
|
|
{
|
636 |
|
|
# Handle runtime variables:
|
637 |
|
|
if ($envdata != 0 && $#$envdata == 0) # One element only!
|
638 |
|
|
{
|
639 |
|
|
my $value='';
|
640 |
|
|
$tsv->checkdefaults($envdata, \$value);
|
641 |
|
|
print "\n";
|
642 |
|
|
|
643 |
|
|
# Chck to see if the value contains a variable that should be evaluated:
|
644 |
|
|
if ($value =~ /$/)
|
645 |
|
|
{
|
646 |
|
|
# If so, find the value and substitute. This should work for all
|
647 |
|
|
# occurrences of variables because by this point (and because the ordering
|
648 |
|
|
# was established at the start) all other variables will have real values:
|
649 |
|
|
my $dvalue = $tsv->_expandvars($value);
|
650 |
|
|
$value = $dvalue;
|
651 |
|
|
}
|
652 |
|
|
|
653 |
|
|
print "Runtime variable ",$rtname," set to \"",$value,"\"\n";
|
654 |
|
|
|
655 |
|
|
# Store the variable setting:
|
656 |
|
|
$tooldataobj->runtime($rtname, [ $value ]);
|
657 |
|
|
}
|
658 |
|
|
else
|
659 |
|
|
{
|
660 |
|
|
next;
|
661 |
|
|
}
|
662 |
|
|
}
|
663 |
|
|
}
|
664 |
|
|
|
665 |
|
|
print "\n";
|
666 |
|
|
}
|
667 |
|
|
|
668 |
|
|
sub interactively_find_settings()
|
669 |
|
|
{
|
670 |
|
|
my $self=shift;
|
671 |
|
|
my ($tooldataobj, $environments, $ordering)=@_;
|
672 |
|
|
my $stringtoeval;
|
673 |
|
|
my $runtime=[];
|
674 |
|
|
my ($path, $dpath);
|
675 |
|
|
|
676 |
|
|
use BuildSystem::ToolSettingValidator;
|
677 |
|
|
|
678 |
|
|
my $tsv = BuildSystem::ToolSettingValidator->new($environments, $self->toolname(), $self->{interactive});
|
679 |
|
|
|
680 |
|
|
foreach my $envname (@$ordering)
|
681 |
|
|
{
|
682 |
|
|
my $type = 'ENVIRONMENT';
|
683 |
|
|
my $envdata = $tsv->environment($type, $envname);
|
684 |
|
|
|
685 |
|
|
# Handle single-occurrence variables first (i.e. VAR appears once
|
686 |
|
|
# in array of hashes):
|
687 |
|
|
if ($envdata != 0 && $#$envdata == 0) # One element only!
|
688 |
|
|
{
|
689 |
|
|
print "\nFinding a value for $envname:","\n";
|
690 |
|
|
print "\n";
|
691 |
|
|
# We have an environment and only one data element:
|
692 |
|
|
# Check the lookup DB:
|
693 |
|
|
if ($tsv->checkDB($envname))
|
694 |
|
|
{
|
695 |
|
|
print "\tValidating value for $envname (found in tool DB):","\n";
|
696 |
|
|
if ($tsv->validatepath())
|
697 |
|
|
{
|
698 |
|
|
# This is our default:
|
699 |
|
|
$dpath = $tsv->pathfromdb();
|
700 |
|
|
# Run promptuser() to see if this value can be kept
|
701 |
|
|
# or should be changed:
|
702 |
|
|
$path = $tsv->promptuser($envname, $dpath);
|
703 |
|
|
# Save in TSV and store in ToolData object:
|
704 |
|
|
$tsv->savevalue($envname,$path);
|
705 |
|
|
$self->store($tooldataobj, $envname, $path);
|
706 |
|
|
}
|
707 |
|
|
else
|
708 |
|
|
{
|
709 |
|
|
$path = $tsv->ifindvalue($envname, $envdata);
|
710 |
|
|
# Save the value in ToolData object:
|
711 |
|
|
$self->store($tooldataobj, $envname, $path);
|
712 |
|
|
}
|
713 |
|
|
}
|
714 |
|
|
else
|
715 |
|
|
{
|
716 |
|
|
$dpath = $tsv->ifindvalue($envname, $envdata);
|
717 |
|
|
# Save in ToolData object:
|
718 |
|
|
$self->store($tooldataobj, $envname, $dpath);
|
719 |
|
|
}
|
720 |
|
|
}
|
721 |
|
|
elsif ($envdata != 0 && $#$envdata > 0)
|
722 |
|
|
{
|
723 |
|
|
print "\nFinding a value for $envname:","\n";
|
724 |
|
|
print "\n";
|
725 |
|
|
foreach my $elementdata (@$envdata)
|
726 |
|
|
{
|
727 |
|
|
$path = $tsv->ifindvalue($envname, $elementdata);
|
728 |
|
|
# Save in ToolData object:
|
729 |
|
|
$self->store($tooldataobj, $envname, $path);
|
730 |
|
|
}
|
731 |
|
|
}
|
732 |
|
|
elsif (exists($ENV{$envname}))
|
733 |
|
|
{
|
734 |
|
|
# Nothing to do here:
|
735 |
|
|
next;
|
736 |
|
|
}
|
737 |
|
|
else
|
738 |
|
|
{
|
739 |
|
|
push(@$runtime, $envname);
|
740 |
|
|
}
|
741 |
|
|
}
|
742 |
|
|
|
743 |
|
|
# Check that the required libraries exist:
|
744 |
|
|
$self->_lib_validate($tooldataobj);
|
745 |
|
|
|
746 |
|
|
# Now process the runtime settings:
|
747 |
|
|
print "\n";
|
748 |
|
|
print "-------------------------------\n";
|
749 |
|
|
foreach my $rtname (@$runtime)
|
750 |
|
|
{
|
751 |
|
|
my $type = 'RUNTIME';
|
752 |
|
|
my $envdata = $tsv->environment($type, $rtname);
|
753 |
|
|
my ($rttype,$realrtname) = split(':',$rtname);
|
754 |
|
|
|
755 |
|
|
# Only validate paths:
|
756 |
|
|
if ($rtname =~ /:/)
|
757 |
|
|
{
|
758 |
|
|
# Handle single-occurrence variables first (i.e. VAR appears once
|
759 |
|
|
# in array of hashes):
|
760 |
|
|
if ($envdata != 0 && $#$envdata == 0) # One element only!
|
761 |
|
|
{
|
762 |
|
|
print "\nRuntime path settings for $realrtname:","\n";
|
763 |
|
|
print "\n";
|
764 |
|
|
# We have an environment and only one data element:
|
765 |
|
|
# Check the lookup DB:
|
766 |
|
|
if ($tsv->checkDB($rtname))
|
767 |
|
|
{
|
768 |
|
|
print "\tValidating value for path $realrtname (found in tool DB):","\n";
|
769 |
|
|
if ($tsv->validatepath())
|
770 |
|
|
{
|
771 |
|
|
$dpath = $tsv->pathfromdb();
|
772 |
|
|
# Run promptuser() to see if this value can be kept
|
773 |
|
|
# or should be changed:
|
774 |
|
|
$path = $tsv->promptuser($rtname, $dpath);
|
775 |
|
|
# Save in TSV and store in ToolData object:
|
776 |
|
|
$tsv->savevalue($rtname, $path);
|
777 |
|
|
$tooldataobj->runtime($rtname, [ $path ]);
|
778 |
|
|
}
|
779 |
|
|
else
|
780 |
|
|
{
|
781 |
|
|
$dpath = $tsv->ifindvalue($rtname, $envdata);
|
782 |
|
|
# Save the value in ToolData object:
|
783 |
|
|
$tooldataobj->runtime($rtname, [ $path ]);
|
784 |
|
|
}
|
785 |
|
|
}
|
786 |
|
|
else
|
787 |
|
|
{
|
788 |
|
|
$path = $tsv->ifindvalue($rtname, $envdata);
|
789 |
|
|
# Save in ToolData object:
|
790 |
|
|
$tooldataobj->runtime($rtname, [ $path ]);
|
791 |
|
|
}
|
792 |
|
|
}
|
793 |
|
|
elsif ($envdata != 0 && $#$envdata > 0)
|
794 |
|
|
{
|
795 |
|
|
print "\nRuntime path settings for $realrtname:","\n";
|
796 |
|
|
print "\n";
|
797 |
|
|
foreach my $elementdata (@$envdata)
|
798 |
|
|
{
|
799 |
|
|
$path = $tsv->ifindvalue($rtname, $elementdata);
|
800 |
|
|
# Save in ToolData object:
|
801 |
|
|
$tooldataobj->runtime($rtname, [ $path ]);
|
802 |
|
|
}
|
803 |
|
|
}
|
804 |
|
|
else
|
805 |
|
|
{
|
806 |
|
|
next;
|
807 |
|
|
}
|
808 |
|
|
}
|
809 |
|
|
else
|
810 |
|
|
{
|
811 |
|
|
# Handle runtime variables:
|
812 |
|
|
if ($envdata != 0 && $#$envdata == 0) # One element only!
|
813 |
|
|
{
|
814 |
|
|
my $dvalue='';
|
815 |
|
|
$tsv->checkdefaults($envdata, \$dvalue);
|
816 |
|
|
print "\n";
|
817 |
|
|
my $value = $tsv->promptuserforvar($rtname, $dvalue);
|
818 |
|
|
# Store the variable setting:
|
819 |
|
|
$tooldataobj->runtime($rtname, [ $value ]);
|
820 |
|
|
}
|
821 |
|
|
else
|
822 |
|
|
{
|
823 |
|
|
next;
|
824 |
|
|
}
|
825 |
|
|
}
|
826 |
|
|
}
|
827 |
|
|
|
828 |
|
|
print "\n";
|
829 |
|
|
}
|
830 |
|
|
|
831 |
|
|
sub store()
|
832 |
|
|
{
|
833 |
|
|
my $self=shift;
|
834 |
|
|
my ($tooldataobj, $envname, $path) = @_;
|
835 |
|
|
my $subrtn = lc($envname);
|
836 |
|
|
|
837 |
|
|
if ($tooldataobj->can($subrtn))
|
838 |
|
|
{
|
839 |
|
|
$tooldataobj->$subrtn([ $path ]);
|
840 |
|
|
}
|
841 |
|
|
else
|
842 |
|
|
{
|
843 |
|
|
$tooldataobj->variable_data($envname, $path);
|
844 |
|
|
}
|
845 |
|
|
}
|
846 |
|
|
|
847 |
|
|
sub _lib_validate()
|
848 |
|
|
{
|
849 |
|
|
my $self=shift;
|
850 |
|
|
my ($toolobj)=@_;
|
851 |
|
|
my $errorstatus = { 0 => $main::good."[OK]".$main::normal, 1 => $main::error."[ERROR]".$main::normal };
|
852 |
|
|
my $libsfound={};
|
853 |
|
|
|
854 |
|
|
# Firstly, we check to see if there are libraries provided by this tool:
|
855 |
|
|
my @libraries = $toolobj->lib();
|
856 |
|
|
my @libpaths = $toolobj->libdir();
|
857 |
|
|
|
858 |
|
|
foreach my $ldir (@libpaths)
|
859 |
|
|
{
|
860 |
|
|
my $full_libname_glob="lib".$lib."*.*";
|
861 |
|
|
# Change to lib dir so we avoid the very long paths in our glob:
|
862 |
|
|
chdir($ldir);
|
863 |
|
|
# Next we use a glob to get libs matching this string (so we
|
864 |
|
|
# can see if there's a shared or archive lib):
|
865 |
|
|
my @possible_libs = glob($full_libname_glob);
|
866 |
|
|
#
|
867 |
|
|
map
|
868 |
|
|
{
|
869 |
|
|
$_ =~ s/\.so*|\.a*//g; # Remove all endings
|
870 |
|
|
# Store in our hash of found libs:
|
871 |
|
|
$libsfound->{$_} = 1;
|
872 |
|
|
} @possible_libs;
|
873 |
|
|
}
|
874 |
|
|
|
875 |
|
|
# Next we iterate over the list of libraries in our tool and
|
876 |
|
|
# see if it was found in one of the libdirs:
|
877 |
|
|
print "\n\n", if ($#libraries != -1);
|
878 |
|
|
foreach my $library (@libraries)
|
879 |
|
|
{
|
880 |
|
|
# Good status:
|
881 |
|
|
my $errorid = 0;
|
882 |
|
|
if (! exists ($libsfound->{'lib'.$library}))
|
883 |
|
|
{
|
884 |
|
|
# Check in system library dirs:
|
885 |
|
|
if ($self->_check_system_libs($library))
|
886 |
|
|
{
|
887 |
|
|
$errorid = 0;
|
888 |
|
|
}
|
889 |
|
|
else
|
890 |
|
|
{
|
891 |
|
|
$errorid = 1;
|
892 |
|
|
}
|
893 |
|
|
}
|
894 |
|
|
printf("* Library check %-10s for lib%-12s\n",$errorstatus->{$errorid}, $library);
|
895 |
|
|
}
|
896 |
|
|
|
897 |
|
|
print "\n";
|
898 |
|
|
}
|
899 |
|
|
|
900 |
|
|
sub _check_system_libs()
|
901 |
|
|
{
|
902 |
|
|
my $self=shift;
|
903 |
|
|
my ($lib)=@_;
|
904 |
|
|
my $libsfound = {};
|
905 |
|
|
my $systemdirs = [ qw( /lib /usr/lib /usr/local/lib /usr/X11R6/lib ) ];
|
906 |
|
|
my $full_libname_glob="lib".$lib."*.*";
|
907 |
|
|
my $found = 0;
|
908 |
|
|
|
909 |
|
|
foreach my $dir (@$systemdirs)
|
910 |
|
|
{
|
911 |
|
|
# Change to lib dir so we avoid the very long paths in our glob:
|
912 |
|
|
chdir($dir);
|
913 |
|
|
# Next we use a glob to get libs matching this string (so we
|
914 |
|
|
# can see if there's a shared or archive lib):
|
915 |
|
|
my @possible_libs = glob($full_libname_glob);
|
916 |
|
|
#
|
917 |
|
|
map
|
918 |
|
|
{
|
919 |
|
|
$_ =~ s/\.so*|\.a*//g; # Remove all endings
|
920 |
|
|
# Store in our hash of found libs:
|
921 |
|
|
$libsfound->{$_} = 1;
|
922 |
|
|
} @possible_libs;
|
923 |
|
|
}
|
924 |
|
|
|
925 |
|
|
# See if we find the library in the system lib directories:
|
926 |
|
|
if (! exists ($libsfound->{'lib'.$library}))
|
927 |
|
|
{
|
928 |
|
|
$found = 1;
|
929 |
|
|
}
|
930 |
|
|
|
931 |
|
|
return $found;
|
932 |
|
|
}
|
933 |
|
|
|
934 |
|
|
1;
|