ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/ToolManager.pm
(Generate patch)

Comparing COMP/SCRAM/src/BuildSystem/ToolManager.pm (file contents):
Revision 1.11 by sashby, Fri Jul 15 15:27:27 2005 UTC vs.
Revision 1.18 by muzaffar, Tue Nov 6 14:13:49 2007 UTC

# Line 48 | Line 48 | sub new
48     $self->{toolfiledir}=$self->{topdir}."/.SCRAM/InstalledTools";
49     $self->{datastore}=$self->{topdir}."/.SCRAM";
50     $self->{archstore}=$self->{topdir}."/.SCRAM/".$ENV{SCRAM_ARCH};
51 +   $self->{tooltimestamp}="timestamps";
52    
53     # Make sure our tool download dir exists:
54     AddDir::adddir($self->{toolfiledir});
# Line 127 | Line 128 | sub setupalltools()
128     # want to pick up everything from any scram-managed projects):
129     if ($setupopt == 1) # We're booting from scratch
130        {
130      # Check to see if there are any SCRAM-managed projects in our local requirements:
131      my $scramprojects = $::scram->_loadscramdb();
132      
131        # Look for a match in the scram db:
132        foreach my $S (@$selected)
133           {
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            {
134              # Store other tools in ReqDoc in separate array. We will set up these tools later:
135              push(@localtools,$S);
165            }
136           }
137        
138        # Set up extra tools required in this project, in addition to
# Line 197 | Line 167 | sub setupalltools()
167   sub coresetup()
168     {
169     my $self=shift;
170 <   my ($toolname, $toolversion, $toolfile) = @_;
170 >   my ($toolname, $toolversion, $toolfile, $force) = @_;
171     my ($toolcheck, $toolparser);
172    
173     print "\n";
# Line 213 | Line 183 | sub coresetup()
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:
# Line 239 | Line 212 | sub coresetup()
212        $self->scram_compiler($supported_language[0],$toolname,$compilername[0]);
213        }
214    
215 <   # Store the ToolData object in the cache:
215 >   # Store the ToolData object in the cache:  
216     $self->storeincache($toolparser->toolname(),$store);
217     return $self;
218     }
# Line 250 | Line 223 | sub toolsetup()
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);
# Line 278 | Line 252 | sub toolsetup()
252        if ($proto eq 'file')
253           {
254           # Check to see if there is a ~ and substitute the user
255 <         # home directory if there is:
256 <         my ($urlpath) = ($urlv =~ m|^\~/(.*)$|);
257 <         $urlv = $ENV{HOME}."/".$urlpath;
258 <
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:
# Line 291 | Line 273 | sub toolsetup()
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')
# Line 303 | Line 290 | sub toolsetup()
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              {
# Line 364 | Line 351 | sub toolsetup()
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  
# Line 374 | Line 361 | sub setupself()
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        {
# Line 382 | Line 369 | sub setupself()
369        print $::bold."Setting up SELF:".$::normal,"\n";
370        # Self file exists so process it:
371        $selfparser = BuildSystem::ToolParser->new();
372 +      $selfparser->filehead ('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><doc type="BuildSystem::ToolDoc" version="1.0">');
373 +      $selfparser->filehead ('</doc>');
374        $selfparser->parse('self','SELF',$filename);
375  
376        # Next, set up the tool:
# Line 401 | Line 390 | sub setupself()
390     else
391        {
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        }
# Line 423 | Line 412 | sub storeincache()
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
# Line 536 | Line 526 | sub remove_tool()
526        }
527    
528     $self->{SETUP} = $newtlist;
529 <  
529 >   $self->updatetooltimestamp ("", $toolname);
530     # Now remove from the RAW tool list:
531     $self->cleanup_raw($toolname);
532     print "ToolManager: Updating tool cache.","\n";
# Line 577 | Line 567 | sub scram_compiler()
567        }
568     }
569  
570 < sub updatecompiler()
570 > sub updatetool()
571     {
572     my $self=shift;
573 <   my ($compilername, $compilerobj) = @_;
573 >   my ($name, $obj) = @_;
574  
575     # Replace the existing copy of the tool with the new one:
576 <   if (exists $self->{SETUP}->{$compilername})
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 ($compilerobj->toolname() eq $compilername)
580 >      if ($obj->toolname() eq $name)
581           {
582 <         print "ToolManager: Updating the cached copy of ".$compilername."\n";
583 <         delete $self->{SETUP}->{$compilername};
584 <         $self->{SETUP}->{$compilername} = $compilerobj;
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: compiler name (".$compilername.") and tool obj name (".$compilerobj->toolname().") don't match!","\n";
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 ".$compilername.". Not making any updates.\n";
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines