18 |
|
use Utilities::AddDir; |
19 |
|
use URL::URLhandler; |
20 |
|
use Utilities::Verbose; |
21 |
+ |
use SCRAM::MsgLog; |
22 |
|
|
23 |
|
@ISA=qw(BuildSystem::ToolCache Utilities::Verbose); |
24 |
|
@EXPORT_OK=qw( ); |
25 |
|
# |
26 |
< |
# |
26 |
> |
|
27 |
|
sub new |
28 |
|
############################################################### |
29 |
|
# new # |
49 |
|
$self->{toolfiledir}=$self->{topdir}."/.SCRAM/InstalledTools"; |
50 |
|
$self->{datastore}=$self->{topdir}."/.SCRAM"; |
51 |
|
$self->{archstore}=$self->{topdir}."/.SCRAM/".$ENV{SCRAM_ARCH}; |
52 |
+ |
$self->{tooltimestamp}="timestamps"; |
53 |
|
|
54 |
|
# Make sure our tool download dir exists: |
55 |
|
AddDir::adddir($self->{toolfiledir}); |
129 |
|
# want to pick up everything from any scram-managed projects): |
130 |
|
if ($setupopt == 1) # We're booting from scratch |
131 |
|
{ |
130 |
– |
# Check to see if there are any SCRAM-managed projects in our local requirements: |
131 |
– |
my $scramprojects = $::scram->_loadscramdb(); |
132 |
– |
|
132 |
|
# Look for a match in the scram db: |
133 |
|
foreach my $S (@$selected) |
134 |
|
{ |
136 |
– |
if (exists ($scramprojects->{$S})) |
137 |
– |
{ |
138 |
– |
# Now check the version required exists in |
139 |
– |
# list of scram projects with this name: |
140 |
– |
while (my ($pdata,$plocation) = each %{$scramprojects->{$S}}) |
141 |
– |
{ |
142 |
– |
# Split the $pdata string to get the real name and the version: |
143 |
– |
my ($pname,$pversion) = split(":",$pdata); |
144 |
– |
if ($pversion eq $self->defaultversion($S)) |
145 |
– |
{ |
146 |
– |
# Get the tool manager for the scram project: |
147 |
– |
my $sa=$::scram->scramfunctions()->scramprojectdb()->getarea($pname,$pversion); |
148 |
– |
# Load the tool cache: |
149 |
– |
if ( -r $sa->toolcachename()) |
150 |
– |
{ |
151 |
– |
use Cache::CacheUtilities; |
152 |
– |
my $satoolmanager=&Cache::CacheUtilities::read($sa->toolcachename()); |
153 |
– |
# Copy needed content from toolmanager for scram-managed project: |
154 |
– |
$self->inheritcontent($satoolmanager); |
155 |
– |
} |
156 |
– |
} |
157 |
– |
} |
158 |
– |
# Also add this scram-managed project to list of tools to set up: |
159 |
– |
push(@localtools,$S); |
160 |
– |
} |
161 |
– |
else |
162 |
– |
{ |
135 |
|
# Store other tools in ReqDoc in separate array. We will set up these tools later: |
136 |
|
push(@localtools,$S); |
165 |
– |
} |
137 |
|
} |
138 |
|
|
139 |
|
# Set up extra tools required in this project, in addition to |
149 |
|
} |
150 |
|
else |
151 |
|
{ |
152 |
< |
print $localtool," already set up.","\n",if ($ENV{SCRAM_DEBUG}); |
152 |
> |
scramlogmsg($localtool," already set up.","\n"),if ($ENV{SCRAM_DEBUG}); |
153 |
|
} |
154 |
|
} |
155 |
|
} |
162 |
|
} |
163 |
|
} |
164 |
|
|
165 |
< |
print "\n"; |
165 |
> |
scramlogmsg("\n"); |
166 |
|
} |
167 |
|
|
168 |
|
sub coresetup() |
169 |
|
{ |
170 |
|
my $self=shift; |
171 |
< |
my ($toolname, $toolversion, $toolfile) = @_; |
171 |
> |
my ($toolname, $toolversion, $toolfile, $force) = @_; |
172 |
|
my ($toolcheck, $toolparser); |
173 |
|
|
174 |
< |
print "\n"; |
204 |
< |
print $::bold."Setting up ",$toolname," version ",$toolversion,": ".$::normal,"\n"; |
174 |
> |
scramlogmsg("\n",$::bold."Setting up ",$toolname," version ",$toolversion,": ".$::normal,"\n"); |
175 |
|
|
176 |
|
# New ToolParser object for this tool if there isn't one already. |
177 |
|
# Look in array of raw tools to see if this tool has a ToolParser object: |
183 |
|
} $self->rawtools(); |
184 |
|
|
185 |
|
# Tool not known so we create a new ToolParser object and parse it: |
186 |
< |
if ($toolcheck != 1) |
186 |
> |
if ($toolcheck != 1 || $force == 1) |
187 |
|
{ |
188 |
|
$toolparser = BuildSystem::ToolParser->new(); |
189 |
+ |
$toolparser->filehead('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><doc type="BuildSystem::ToolDoc" version="1.0">'); |
190 |
+ |
$toolparser->filetail('</doc>'); |
191 |
|
# We only want to store the stuff relevant for one particular version: |
192 |
|
$toolparser->parse($toolname, $toolversion, $toolfile); |
193 |
|
# Store the ToolParser object in the cache: |
194 |
|
$self->store($toolparser); |
195 |
+ |
print "\nFile $toolfile reparsed (modified)","\n",if ($ENV{SCRAM_DEBUG}); |
196 |
|
} |
197 |
|
|
198 |
|
# Next, set up the tool: |
200 |
|
# Make sure that we have this tool in the list of selected tools (just in case this tool was |
201 |
|
# set up by hand afterwards): |
202 |
|
$self->addtoselected($toolname); |
203 |
< |
# Store the ToolData object in the cache: |
203 |
> |
|
204 |
> |
# Check to see if this tool is a compiler. If so, store it. |
205 |
> |
# Also store the language that this compiler supprots, and a |
206 |
> |
# compiler name (e.g. gcc323) which, in conjunction with a stem |
207 |
> |
# architecture name like slc3_ia32_, can be used to build a complete arch string: |
208 |
> |
if ($store->scram_compiler() == 1) |
209 |
> |
{ |
210 |
> |
my @supported_language = $store->flags("SCRAM_LANGUAGE_TYPE"); |
211 |
> |
my @compilername = $store->flags("SCRAM_COMPILER_NAME"); |
212 |
> |
$self->scram_compiler($supported_language[0],$toolname,$compilername[0]); |
213 |
> |
} |
214 |
> |
|
215 |
> |
# Store the ToolData object in the cache: |
216 |
|
$self->storeincache($toolparser->toolname(),$store); |
217 |
|
return $self; |
218 |
|
} |
223 |
|
my ($arealocation, $toolname, $toolversion, $toolurl) = @_; |
224 |
|
my ($urlcache, $url, $filename, $tfname); |
225 |
|
my $toolfile; |
226 |
+ |
my $force = 0; # we may have to force a reparse of a tool file |
227 |
|
|
228 |
|
$toolname =~ tr[A-Z][a-z]; |
229 |
|
$toolversion ||= $self->defaultversion($toolname); |
251 |
|
# See what kind of URL (file:, http:, cvs:, svn:, .. ): |
252 |
|
if ($proto eq 'file') |
253 |
|
{ |
254 |
+ |
# Check to see if there is a ~ and substitute the user |
255 |
+ |
# home directory if there is (file:~/xyz): |
256 |
+ |
if (my ($urlpath) = ($urlv =~ m|^\~/(.*)$|)) |
257 |
+ |
{ |
258 |
+ |
$urlv = $ENV{HOME}."/".$urlpath; |
259 |
+ |
} |
260 |
+ |
elsif (my ($urlpath) = ($urlv =~ m|^\./(.*)$|)) |
261 |
+ |
{ |
262 |
+ |
# Relative to current directory (file:./xyz): |
263 |
+ |
use Cwd qw(&cwd); |
264 |
+ |
$urlv = cwd()."/".$urlpath; |
265 |
+ |
} |
266 |
+ |
|
267 |
|
# If the tool url is a file and the file exists, |
268 |
|
# copy it to .SCRAM/InstalledTools and set the |
269 |
|
# filename accordingly: |
273 |
|
copy($urlv, $filename); |
274 |
|
my $mode = 0644; chmod $mode, $filename; |
275 |
|
$toolfile=$filename; |
276 |
+ |
# Here we must account for the fact that the file tool doc may be |
277 |
+ |
# a modified version of an existing tool in the current config. we |
278 |
+ |
# make sure that this file is reparsed, even if there is already a |
279 |
+ |
# ToolParser object for the tool: |
280 |
+ |
$force = 1; |
281 |
|
} |
282 |
|
else |
283 |
|
{ |
284 |
< |
$::scram->scramerror("Unable to set up $toolname from URL $toolurl-- $urlv does not exist!"); |
284 |
> |
$::scram->scramerror("Unable to set up $toolname from URL \"$toolurl\" - $urlv does not exist!"); |
285 |
|
} |
286 |
|
} |
287 |
|
elsif ($proto eq 'http') |
290 |
|
# Download from WWW first: |
291 |
|
use LWP::Simple qw(&getstore); |
292 |
|
my $http_response_val = &getstore($toolurl, $filename); |
293 |
< |
|
293 |
> |
|
294 |
|
# Check the HTTP status. If doc not found, exit: |
295 |
|
if ($http_response_val != 200) |
296 |
|
{ |
351 |
|
} |
352 |
|
|
353 |
|
# Run the core setup routine: |
354 |
< |
$self->coresetup($toolname, $toolversion, $toolfile); |
354 |
> |
$self->coresetup($toolname, $toolversion, $toolfile,$force); |
355 |
|
return $self; |
356 |
|
} |
357 |
|
|
361 |
|
my ($location)=@_; |
362 |
|
# Process the file "Self" in local config directory. This is used to |
363 |
|
# set all the paths/runtime settings for this project: |
364 |
< |
my $filename=$location."/config/Self"; |
364 |
> |
my $filename=$location."/config/Self.xml"; |
365 |
|
|
366 |
|
if ( -f $filename ) |
367 |
|
{ |
368 |
< |
print "\n"; |
365 |
< |
print $::bold."Setting up SELF:".$::normal,"\n"; |
368 |
> |
scramlogmsg("\n",$::bold."Setting up SELF:".$::normal,"\n"); |
369 |
|
# Self file exists so process it: |
370 |
|
$selfparser = BuildSystem::ToolParser->new(); |
371 |
+ |
$selfparser->filehead ('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><doc type="BuildSystem::ToolDoc" version="1.0">'); |
372 |
+ |
$selfparser->filehead ('</doc>'); |
373 |
|
$selfparser->parse('self','SELF',$filename); |
374 |
|
|
375 |
|
# Next, set up the tool: |
376 |
|
$store = $selfparser->processrawtool($self->interactive()); |
377 |
< |
|
377 |
> |
|
378 |
|
# If we are in a developer area, also add RELEASETOP paths: |
379 |
|
if (exists($ENV{RELEASETOP})) |
380 |
|
{ |
384 |
|
|
385 |
|
# Store the ToolData object in the cache: |
386 |
|
$self->storeincache($selfparser->toolname(),$store); |
387 |
< |
print "\n"; |
387 |
> |
scramlogmsg("\n"); |
388 |
|
} |
389 |
|
else |
390 |
|
{ |
391 |
+ |
scramlogdump(); |
392 |
|
print "\n"; |
393 |
< |
print "SCRAM: No file config/Self...nothing to do."; |
393 |
> |
print "SCRAM: No file config/Self.xml...nothing to do."; |
394 |
|
print "\n"; |
395 |
|
return; |
396 |
|
} |
412 |
|
# Store ToolData object (for a set-up tool) in cache: |
413 |
|
if (ref($dataobject) eq 'BuildSystem::ToolData') |
414 |
|
{ |
415 |
+ |
$self->updatetooltimestamp($dataobject, $toolname); |
416 |
|
$self->{SETUP}->{$toolname} = $dataobject; |
417 |
|
} |
418 |
|
else |
505 |
|
} |
506 |
|
else |
507 |
|
{ |
508 |
< |
print "Deleting $toolname from cache.","\n"; |
508 |
> |
# Is this tool a compiler? |
509 |
> |
if ($tooldata->scram_compiler() == 1) |
510 |
> |
{ |
511 |
> |
# Also remove this from the compiler info if there happens to be an entry: |
512 |
> |
while (my ($langtype, $ctool) = each %{$self->{SCRAM_COMPILER}}) |
513 |
> |
{ |
514 |
> |
if ($toolname eq $ctool->[0]) |
515 |
> |
{ |
516 |
> |
delete $self->{SCRAM_COMPILER}->{$langtype}; |
517 |
> |
print "Deleting compiler $toolname from cache.","\n"; |
518 |
> |
} |
519 |
> |
} |
520 |
> |
} |
521 |
> |
else |
522 |
> |
{ |
523 |
> |
print "Deleting $toolname from cache.","\n"; |
524 |
> |
} |
525 |
|
} |
526 |
|
} |
527 |
|
|
528 |
|
$self->{SETUP} = $newtlist; |
529 |
< |
|
529 |
> |
$self->updatetooltimestamp ("", $toolname); |
530 |
|
# Now remove from the RAW tool list: |
531 |
|
$self->cleanup_raw($toolname); |
509 |
– |
|
532 |
|
print "ToolManager: Updating tool cache.","\n"; |
533 |
|
$self->writecache(); |
534 |
|
} |
548 |
|
return $scram_projects; |
549 |
|
} |
550 |
|
|
551 |
+ |
sub scram_compiler() |
552 |
+ |
{ |
553 |
+ |
my $self=shift; |
554 |
+ |
my ($langtype, $toolname, $compilername)=@_; |
555 |
+ |
|
556 |
+ |
if ($langtype) |
557 |
+ |
{ |
558 |
+ |
# Store the compiler info according to supported |
559 |
+ |
# language types. |
560 |
+ |
# |
561 |
+ |
# ---------------------- e.g C++ cxxcompiler gcc323 |
562 |
+ |
$self->{SCRAM_COMPILER}->{$langtype}=[ $toolname, $compilername ]; |
563 |
+ |
} |
564 |
+ |
else |
565 |
+ |
{ |
566 |
+ |
return $self->{SCRAM_COMPILER}; |
567 |
+ |
} |
568 |
+ |
} |
569 |
+ |
|
570 |
+ |
sub updatetool() |
571 |
+ |
{ |
572 |
+ |
my $self=shift; |
573 |
+ |
my ($name, $obj) = @_; |
574 |
+ |
|
575 |
+ |
# Replace the existing copy of the tool with the new one: |
576 |
+ |
if (exists $self->{SETUP}->{$name}) |
577 |
+ |
{ |
578 |
+ |
# Check to make sure that we were really passed a compiler with |
579 |
+ |
# the desired name: |
580 |
+ |
if ($obj->toolname() eq $name) |
581 |
+ |
{ |
582 |
+ |
$self->updatetooltimestamp ($obj, $name); |
583 |
+ |
print "ToolManager: Updating the cached copy of ".$name."\n"; |
584 |
+ |
delete $self->{SETUP}->{$name}; |
585 |
+ |
$self->{SETUP}->{$name} = $obj; |
586 |
+ |
$self->writecache(); |
587 |
+ |
} |
588 |
+ |
else |
589 |
+ |
{ |
590 |
+ |
print "WARNING: Tool name (".$name.") and tool obj name (".$obj->toolname().") don't match!","\n"; |
591 |
+ |
print " Not making any changes.","\n"; |
592 |
+ |
} |
593 |
+ |
} |
594 |
+ |
else |
595 |
+ |
{ |
596 |
+ |
print "WARNING: No entry in cache for ".$name.". Not making any updates.\n"; |
597 |
+ |
} |
598 |
+ |
} |
599 |
+ |
|
600 |
+ |
sub check_compatibility() |
601 |
+ |
{ |
602 |
+ |
my $self=shift; |
603 |
+ |
my ($itoolmgr)=@_; |
604 |
+ |
# Get the version of the toolmanager. If the project fails to return a version |
605 |
+ |
# string we return 0 for no compatibility (in which case, all tools will be set |
606 |
+ |
# up in the traditional way): |
607 |
+ |
my $itm_configversion = $itoolmgr->configversion(); |
608 |
+ |
if ($itm_configversion) |
609 |
+ |
{ |
610 |
+ |
# The configurations won't be identical. We must compare the digits: |
611 |
+ |
my ($numeric_version) = ($itm_configversion =~ /[a-zA-Z]*\_([0-9a-z]*).*?/); |
612 |
+ |
my $current_configversion = $self->configversion(); |
613 |
+ |
my ($current_numeric_version) = ($current_configversion =~ /[a-zA-Z]*\_([0-9a-z]*).*?/); |
614 |
+ |
($current_numeric_version == $numeric_version) && return 1; # OK, compatible; |
615 |
+ |
} |
616 |
+ |
# Project does not define configuration version so just return: |
617 |
+ |
return 0; |
618 |
+ |
} |
619 |
+ |
|
620 |
+ |
sub configversion() |
621 |
+ |
{ |
622 |
+ |
my $self=shift; |
623 |
+ |
@_ ? $self->{CONFIGVERSION} = shift |
624 |
+ |
: $self->{CONFIGVERSION}; |
625 |
+ |
} |
626 |
+ |
|
627 |
+ |
sub updatetooltimestamp () |
628 |
+ |
{ |
629 |
+ |
my $self=shift; |
630 |
+ |
my $obj=shift; |
631 |
+ |
my $toolname=shift; |
632 |
+ |
my $samevalues=0; |
633 |
+ |
my $stampdir = $self->{archstore}."/timestamps"; |
634 |
+ |
my $stampfile="${stampdir}/${toolname}"; |
635 |
+ |
if (exists $self->{SETUP}->{$toolname}) |
636 |
+ |
{ |
637 |
+ |
$samevalues=$self->comparetoolsdata($self->{SETUP}->{$toolname},$obj); |
638 |
+ |
} |
639 |
+ |
if ((!$samevalues) || (!-f $stampfile)) |
640 |
+ |
{ |
641 |
+ |
if (!-d $stampdir) |
642 |
+ |
{ |
643 |
+ |
AddDir::adddir($stampdir); |
644 |
+ |
} |
645 |
+ |
open(TIMESTAMPFILE,">$stampfile"); |
646 |
+ |
close(TIMESTAMPFILE); |
647 |
+ |
} |
648 |
+ |
} |
649 |
+ |
|
650 |
+ |
sub comparetoolsdata () |
651 |
+ |
{ |
652 |
+ |
my $self=shift; |
653 |
+ |
my $data1=shift || (); |
654 |
+ |
my $data2=shift || (); |
655 |
+ |
|
656 |
+ |
my $ref1=ref($data1); |
657 |
+ |
my $ref2=ref($data2); |
658 |
+ |
|
659 |
+ |
if ($ref1 ne $ref2) |
660 |
+ |
{ |
661 |
+ |
return 0; |
662 |
+ |
} |
663 |
+ |
elsif ($ref1 eq "CODE") |
664 |
+ |
{ |
665 |
+ |
return 1; |
666 |
+ |
} |
667 |
+ |
elsif(($ref1 eq "SCALAR") || ($ref1 eq "")) |
668 |
+ |
{ |
669 |
+ |
if ($data1 eq $data2) |
670 |
+ |
{ |
671 |
+ |
return 1; |
672 |
+ |
} |
673 |
+ |
return 0; |
674 |
+ |
} |
675 |
+ |
elsif ($ref1 eq "ARRAY") |
676 |
+ |
{ |
677 |
+ |
my $count = scalar(@$data1); |
678 |
+ |
if ($count != scalar(@$data2)) |
679 |
+ |
{ |
680 |
+ |
return 0; |
681 |
+ |
} |
682 |
+ |
for (my $i=0; $i<$count; $i++) |
683 |
+ |
{ |
684 |
+ |
if (! $self->comparetoolsdata($data1->[$i],$data2->[$i])) |
685 |
+ |
{ |
686 |
+ |
return 0; |
687 |
+ |
} |
688 |
+ |
} |
689 |
+ |
return 1; |
690 |
+ |
} |
691 |
+ |
else |
692 |
+ |
{ |
693 |
+ |
foreach my $k (keys %{$data1}) |
694 |
+ |
{ |
695 |
+ |
if (! exists $data2->{$k}) |
696 |
+ |
{ |
697 |
+ |
return 0; |
698 |
+ |
} |
699 |
+ |
} |
700 |
+ |
foreach my $k (keys %{$data2}) |
701 |
+ |
{ |
702 |
+ |
if (! exists $data1->{$k}) |
703 |
+ |
{ |
704 |
+ |
return 0; |
705 |
+ |
} |
706 |
+ |
} |
707 |
+ |
foreach my $k (keys %{$data2}) |
708 |
+ |
{ |
709 |
+ |
if (! $self->comparetoolsdata($data1->{$k},$data2->{$k})) |
710 |
+ |
{ |
711 |
+ |
return 0; |
712 |
+ |
} |
713 |
+ |
} |
714 |
+ |
return 1; |
715 |
+ |
} |
716 |
+ |
} |
717 |
+ |
|
718 |
|
1; |