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.14 by sashby, Wed May 17 12:21:57 2006 UTC vs.
Revision 1.23 by muzaffar, Tue Feb 7 13:31:35 2012 UTC

# Line 3 | Line 3
3   #____________________________________________________________________
4   #  
5   # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6 # Update: 2003-11-12 15:04:16+0100
7 # Revision: $Id$
8 #
6   # Copyright: 2003 (C) Shaun Ashby
7   #
8   #--------------------------------------------------------------------
# Line 16 | Line 13 | use Exporter;
13   use BuildSystem::ToolCache;
14   use BuildSystem::ToolParser;
15   use Utilities::AddDir;
19 use URL::URLhandler;
16   use Utilities::Verbose;
17 + use SCRAM::MsgLog;
18  
19   @ISA=qw(BuildSystem::ToolCache Utilities::Verbose);
20   @EXPORT_OK=qw( );
21   #
22  
23   sub new
27   ###############################################################
28   # new                                                         #
29   ###############################################################
30   # modified : Wed Nov 12 10:34:10 2003 / SFA                   #
31   # params   :                                                  #
32   #          :                                                  #
33   # function :                                                  #
34   #          :                                                  #
35   ###############################################################
24     {
25     my $proto=shift;
26     my $class=ref($proto) || $proto;
27     my $self=$class->SUPER::new();    # Inherit from ToolCache
40   my $projectarea=shift;
41
28     bless $self,$class;
29 <  
44 <   $self->{arch}=shift;
45 <   $self->{topdir}=$projectarea->location();
46 <   $self->{configdir}=$self->{topdir}."/".$projectarea->configurationdir();
47 <   $self->{cache}=$projectarea->cache();    # Download tool cache
48 <   $self->{toolfiledir}=$self->{topdir}."/.SCRAM/InstalledTools";
49 <   $self->{datastore}=$self->{topdir}."/.SCRAM";
50 <   $self->{archstore}=$self->{topdir}."/.SCRAM/".$ENV{SCRAM_ARCH};
51 <  
52 <   # Make sure our tool download dir exists:
53 <   AddDir::adddir($self->{toolfiledir});
54 <   AddDir::adddir($self->{archstore});
55 <  
56 <   # Set the tool cache file to read/write:
57 <   $self->name($projectarea->toolcachename());
58 <
59 <   # Check for the downloaded tools cache:
60 <   if (exists($self->{cache}))
61 <      {
62 <      $self->{urlhandler}=URL::URLhandler->new($self->{cache});
63 <      }
64 <  
29 >   $self->init (shift);
30     return $self;
31     }
32  
33 < sub clone()
33 > sub init ()
34     {
35     my $self=shift;
36     my $projectarea=shift;
72
73   # Change cache settings to reflect the new location:
37     $self->{topdir}=$projectarea->location();
75
38     $self->{configdir}=$self->{topdir}."/".$projectarea->configurationdir();
39 <   $self->{toolfiledir}=$self->{topdir}."/.SCRAM/InstalledTools";
40 <   $self->{datastore}=$self->{topdir}."/.SCRAM";
79 <   $self->{archstore}=$self->{topdir}."/.SCRAM/".$ENV{SCRAM_ARCH};
80 <
81 <   # Change the cache name:
39 >   $self->{archstore}=$projectarea->archdir();
40 >   $self->{toolcache}=$self->{configdir}."/toolbox/$ENV{SCRAM_ARCH}/tools";
41     $self->name($projectarea->toolcachename());
42 <   $self->cloned_tm(1);
84 <  
85 <   return $self;
42 >   $self->dirty();
43     }
44 <
88 < sub arch_change_after_copy()
89 <   {
90 <   my $self=shift;
91 <   my ($newarch, $cachename)=@_;
92 <   # Make changes to arch-specific settings when copying tool manager
93 <   # object to another arch during setup:
94 <   $self->{arch} = $newarch;
95 <   $self->{archstore} = $self->{topdir}."/.SCRAM/".$newarch;
96 <   # Change the name of the cache to reflect new (arch-specific) location:
97 <   $self->name($cachename);
98 <   }
99 <
100 < sub interactive()
101 <   {
102 <   my $self=shift;
103 <   # Interactive mode on/off:
104 <   @_ ? $self->{interactive} = shift
105 <      : ((defined $self->{interactive}) ? $self->{interactive} : 0);
106 <   }
107 <
44 >  
45   sub setupalltools()
46     {
47     my $self = shift;
48 <   my ($arealocation,$setupopt) = @_;
49 <   my (@localtools);
50 <   my $selected;
114 <  
115 <   # Get the selected tool list. Handle the case where there might not be
116 <   # any selected tools: //FIXME: need to handle case where there are no
117 <   # selected tools (not very often but a possibility):
118 <   my $sel = $self->selected();
119 <  
120 <   if (defined ($sel))
48 >   my @selected=();
49 >   my $tooldir=$self->{toolcache}."/selected";
50 >   foreach my $tool (@{&getfileslist($tooldir)})
51        {
52 <      $selected = [ keys %{$sel} ];
52 >      if ($tool=~/^(.+)\.xml$/) {push @selected,$1;}
53        }
54 <  
55 <   # Setup option "setupopt" directs the setup: 1 is for booting from
126 <   # scratch, 0 is when just doing "scram setup" (in this case we don't
127 <   # want to pick up everything from any scram-managed projects):
128 <   if ($setupopt == 1) # We're booting from scratch
129 <      {
130 <      # Check to see if there are any SCRAM-managed projects in our local requirements:
131 <      my $scramprojects = $::scram->_loadscramdb();
132 <      
133 <      # Look for a match in the scram db:
134 <      foreach my $S (@$selected)
135 <         {
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 only
154 <                     # if the projects have compatible configurations (compare first set of
155 <                     # digits):
156 <                     if ($self->check_compatibility($satoolmanager))
157 <                        {
158 <                        print "DEBUG: $pname and current project have compatible configurations.\n";
159 <                        $self->inheritcontent($satoolmanager);
160 <                        }
161 <                     else
162 <                        {                      
163 <                        print "DEBUG: $pname and current project do NOT have compatible configurations. Skipping...\n";
164 <                        }
165 <                     }
166 <                  }
167 <               }
168 <            # Also add this scram-managed project to list of tools to set up:
169 <            push(@localtools,$S);
170 <            }
171 <         else
172 <            {
173 <            # Store other tools in ReqDoc in separate array. We will set up these tools later:
174 <            push(@localtools,$S);
175 <            }
176 <         }
177 <      
178 <      # Set up extra tools required in this project, in addition to
179 <      # any scram-managed projects
180 <      foreach my $localtool (@localtools)
181 <         {
182 <         # First check to see if it's already set up (i.e., was contained
183 <         # in list of requirements for scram project):
184 <         if (! $self->definedtool($localtool))
185 <            {
186 <            $self->toolsetup($arealocation,$localtool,$self->defaultversion($localtool));
187 <            $self->addtoselected($localtool);
188 <            }
189 <         else
190 <            {
191 <            print $localtool," already set up.","\n",if ($ENV{SCRAM_DEBUG});
192 <            }
193 <         }
194 <      }
195 <   else
196 <      {
197 <      # Just loop over all tools and setup again:
198 <      foreach my $localtool (@{$selected})
199 <         {
200 <         $self->toolsetup($arealocation,$localtool,$self->defaultversion($localtool));  
201 <         }
202 <      }
203 <  
204 <   print "\n";
54 >   foreach my $tool (@selected){$self->coresetup("${tooldir}/${tool}.xml");}
55 >   scramlogmsg("\n");
56     }
57  
58   sub coresetup()
59     {
60     my $self=shift;
61 <   my ($toolname, $toolversion, $toolfile, $force) = @_;
211 <   my ($toolcheck, $toolparser);
212 <  
213 <   print "\n";
214 <   print $::bold."Setting up ",$toolname," version ",$toolversion,":  ".$::normal,"\n";
215 <  
216 <   # New ToolParser object for this tool if there isn't one already.
217 <   # Look in array of raw tools to see if this tool has a ToolParser object:
218 <   $toolcheck=0;
219 <  
220 <   map
221 <      {
222 <      if ($_->toolname() eq $toolname) {$toolcheck = 1; $toolparser = $_;}
223 <      } $self->rawtools();
61 >   my ($toolfile) = @_;
62    
63 <   # Tool not known so we create a new ToolParser object and parse it:
64 <   if ($toolcheck != 1 || $force == 1)
65 <      {
66 <      $toolparser = BuildSystem::ToolParser->new();
67 <      # We only want to store the stuff relevant for one particular version:
68 <      $toolparser->parse($toolname, $toolversion, $toolfile);
69 <      # Store the ToolParser object in the cache:
232 <      $self->store($toolparser);
233 <      print "\nFile $toolfile reparsed (modified)","\n",if ($ENV{SCRAM_DEBUG});
234 <      }
63 >   my $toolparser = BuildSystem::ToolParser->new();
64 >   $toolparser->filehead('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><doc type="BuildSystem::ToolDoc" version="1.0">');
65 >   $toolparser->filetail('</doc>');
66 >   $toolparser->parse($toolfile);
67 >   my $toolname = $toolparser->toolname();
68 >   my $toolversion = $toolparser->toolversion();
69 >   scramlogmsg("\n",$::bold."Setting up ",$toolname," version ",$toolversion,":  ".$::normal,"\n");
70    
71     # Next, set up the tool:
72 <   my $store = $toolparser->processrawtool($self->interactive());
238 <   # Make sure that we have this tool in the list of selected tools (just in case this tool was
239 <   # set up by hand afterwards):
240 <   $self->addtoselected($toolname);
72 >   my $store = $toolparser->processrawtool();
73  
74     # Check to see if this tool is a compiler. If so, store it.
75     # Also store the language that this compiler supprots, and a
# Line 250 | Line 82 | sub coresetup()
82        $self->scram_compiler($supported_language[0],$toolname,$compilername[0]);
83        }
84    
85 <   # Store the ToolData object in the cache:
86 <   $self->storeincache($toolparser->toolname(),$store);
87 <   return $self;
88 <   }
89 <
90 < sub toolsetup()
91 <   {
92 <   my $self=shift;
93 <   my ($arealocation, $toolname, $toolversion, $toolurl) = @_;
94 <   my ($urlcache, $url, $filename, $tfname);
95 <   my $toolfile;
96 <   my $force = 0; # we may have to force a reparse of a tool file
265 <  
266 <   $toolname =~ tr[A-Z][a-z];
267 <   $toolversion ||= $self->defaultversion($toolname);
268 <   $urlcache=URL::URLcache->new($arealocation."/.SCRAM/cache"); # Download tool cache
269 <  
270 <   # Check for the downloaded tools cache:
271 <   if (defined($urlcache))
272 <      {
273 <      $self->{urlhandler}=URL::URLhandler->new($urlcache);
274 <      }
275 <
276 <   $url = $self->toolurls()->{$toolname};
277 <   $filename = $self->{toolfiledir}."/".$toolname;
278 <  
279 <   # If .SCRAM/InstalledTools doesn't exist, create it:
280 <   if (! -d $self->{toolfiledir})
281 <      {
282 <      AddDir::adddir($self->{toolfiledir});
283 <      }
284 <  
285 <   # First, check to see if there was a tool URL given. If so, we might need to read
286 <   # from http or from a file: type URL:
287 <   if (my ($proto, $urlv) = ($toolurl =~ /(.*):(.*)/))
288 <      {      
289 <      # See what kind of URL (file:, http:, cvs:, svn:, .. ):
290 <      if ($proto eq 'file')
291 <         {
292 <         # Check to see if there is a ~ and substitute the user
293 <         # home directory if there is (file:~/xyz):      
294 <         if (my ($urlpath) = ($urlv =~ m|^\~/(.*)$|))
295 <            {
296 <            $urlv = $ENV{HOME}."/".$urlpath;
297 <            }
298 <         elsif (my ($urlpath) = ($urlv =~ m|^\./(.*)$|))
299 <            {
300 <            # Relative to current directory (file:./xyz):
301 <            use Cwd qw(&cwd);
302 <            $urlv = cwd()."/".$urlpath;
303 <            }
304 <        
305 <         # If the tool url is a file and the file exists,
306 <         # copy it to .SCRAM/InstalledTools and set the
307 <         # filename accordingly:
308 <         if ( -f $urlv)
309 <            {
310 <            use File::Copy;
311 <            copy($urlv, $filename);
312 <            my $mode = 0644; chmod $mode, $filename;
313 <            $toolfile=$filename;
314 <            # Here we must account for the fact that the file tool doc may be
315 <            # a modified version of an existing tool in the current config. we
316 <            # make sure that this file is reparsed, even if there is already a
317 <            # ToolParser object for the tool:
318 <            $force = 1;
319 <            }
320 <         else
321 <            {
322 <            $::scram->scramerror("Unable to set up $toolname from URL \"$toolurl\" - $urlv does not exist!");              
323 <            }
324 <         }
325 <      elsif ($proto eq 'http')
326 <         {
327 <         print "SCRAM: downloading $toolname from $toolurl","\n";
328 <         # Download from WWW first:
329 <         use LWP::Simple qw(&getstore);
330 <         my $http_response_val = &getstore($toolurl, $filename);
331 <        
332 <         # Check the HTTP status. If doc not found, exit:
333 <         if ($http_response_val != 200)
334 <            {
335 <            my ($server,$doc) = ($urlv =~ m|//(.*?)/(.*)|);        
336 <            $::scram->scramerror("Unable to set up $toolname: $doc not found on $server!");
337 <            }
338 <         else
339 <            {
340 <            $toolfile=$filename;
341 <            }
342 <         }
343 <      elsif ($proto eq 'cvs')
344 <         {
345 <         print "SCRAM: downloading $toolname from $urlv using protocol $proto.","\n";
346 <         print "[ not yet supported ]","\n";
347 <         exit(0);
348 <         }
349 <      elsif ($proto eq 'svn')
350 <         {
351 <         print "SCRAM: downloading $toolname from $urlv using protocol $proto.","\n";
352 <         print "[ not yet supported ]","\n";
353 <         exit(0);
354 <         }
355 <      else
356 <         {
357 <         $::scram->scramerror("Unable to download $urlv! Unknown protocol \"$proto\". Bye.");
85 >   # Store the ToolData object in the cache:  
86 >   $self->storeincache($toolname,$store);
87 >   my $srcfile=Utilities::AddDir::fixpath($toolfile);
88 >   my $desfile=Utilities::AddDir::fixpath($self->{toolcache}."/selected/${toolname}.xml");
89 >   use File::Copy;
90 >   if ($srcfile ne $desfile)
91 >      {
92 >      use File::Copy;
93 >      my $desfile1=Utilities::AddDir::fixpath($self->{toolcache}."/available/${toolname}.xml");
94 >      if ($srcfile ne $desfile1)
95 >         {
96 >         copy($srcfile,$desfile1);
97           }
98 +      if (-e $desfile) { unlink($desfile);}
99 +      symlink("../available/${toolname}.xml",$desfile);
100        }
101 <   else
361 <      {
362 <      # Copy the downloaded tool file to InstalledTools directory:
363 <      if ( ! -f $filename )
364 <         {
365 <         # If the URL is empty, the chances are that this tool was not downloaded to .SCRAM/InstalledTools.
366 <         # We signal an error and exit:
367 <         if ($url eq '')
368 <            {
369 <            $::scram->scramerror("$toolname was selected in project requirements but is not in the configuration!");
370 <            }
371 <         else
372 <            {
373 <            # Otherwise, we try to download it:
374 <            $self->verbose("Attempting Download of $url");
375 <            # Get file from download cache:
376 <            ($url,$filename)=$self->{urlhandler}->get($url);                
377 <            use File::Copy;
378 <            $tfname=$self->{toolfiledir}."/".$toolname;  
379 <            copy($filename, $tfname);
380 <            my $mode = 0644; chmod $mode, $tfname;
381 <            $toolfile=$tfname;
382 <            }
383 <         }
384 <      else
385 <         {
386 <         # File already exists in the .SCRAM/InstallTools directory:
387 <         $toolfile=$filename;
388 <         }
389 <      }
390 <  
391 <   # Run the core setup routine:
392 <   $self->coresetup($toolname, $toolversion, $toolfile,$force);
101 >   scramlogclean();
102     return $self;
103     }
104  
105   sub setupself()
106     {
107     my $self=shift;
399   my ($location)=@_;
108     # Process the file "Self" in local config directory. This is used to
109     # set all the paths/runtime settings for this project:
110 <   my $filename=$location."/config/Self";
110 >   my $filename=$self->{configdir}."/Self.xml";
111  
112     if ( -f $filename )
113        {
114 <      print "\n";
407 <      print $::bold."Setting up SELF:".$::normal,"\n";
114 >      scramlogmsg("\n",$::bold."Setting up SELF:".$::normal,"\n");
115        # Self file exists so process it:
116        $selfparser = BuildSystem::ToolParser->new();
117 <      $selfparser->parse('self','SELF',$filename);
117 >      $selfparser->filehead ('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><doc type="BuildSystem::ToolDoc" version="1.0">');
118 >      $selfparser->filehead ('</doc>');
119 >      $selfparser->parse($filename);
120  
121        # Next, set up the tool:
122 <      $store = $selfparser->processrawtool($self->interactive());
123 <      
122 >      $store = $selfparser->processrawtool();
123 >
124        # If we are in a developer area, also add RELEASETOP paths:
125        if (exists($ENV{RELEASETOP}))
126           {
# Line 421 | Line 130 | sub setupself()
130        
131        # Store the ToolData object in the cache:
132        $self->storeincache($selfparser->toolname(),$store);
133 <      print "\n";
133 >      scramlogmsg("\n");
134        }
135     else
136        {
137 <      print "\n";
138 <      print "SCRAM: No file config/Self...nothing to do.";
139 <      print "\n";
137 >      scramlogdump();
138 >      print STDERR "\n";
139 >      print STDERR "SCRAM: No file config/Self.xml...nothing to do.";
140 >      print STDERR "\n";
141        return;
142        }
143     }
144  
145 < sub defaultversion()
145 > sub update()
146     {
147 <   my $self = shift;
148 <   my ($tool) = @_;
149 <   # Return default versions as taken from configuration:
150 <   return (%{$self->defaultversions()}->{$tool});
147 >   my $self=shift;
148 >   my $area=shift;
149 >   $self->init($area);
150 >   $self->setupself();
151 >   $self->dirty ()
152     }
153 <
153 >  
154   sub storeincache()
155     {
156     my $self=shift;
# Line 448 | Line 159 | sub storeincache()
159     # Store ToolData object (for a set-up tool) in cache:
160     if (ref($dataobject) eq 'BuildSystem::ToolData')
161        {
162 +      $self->updatetooltimestamp($dataobject, $toolname);
163 +      delete $self->{SETUP}->{$toolname};
164        $self->{SETUP}->{$toolname} = $dataobject;
165        }
166     else
# Line 477 | Line 190 | sub toolsdata()
190     {
191     my $self = shift;
192     my $tooldata = [];
193 <   my $rawsel = $self->selected();
194 <  
195 <   foreach my $tool ( sort { %{$rawsel}->{$a}
483 <                             <=> %{$rawsel}->{$b}}
484 <                      keys %{$rawsel} )
193 >   $self->{internal}{donetools}={};
194 >   $self->{internal}{scram_tools}={};
195 >   foreach my $tool (sort keys %{$self->{SETUP}})
196        {
197 <      # Return tool data objects of all set-up tools, skipping the tool "self":
198 <      if ($_ ne "self")
197 >      if ($self->{SETUP}{$tool}->scram_project()) {$self->{internal}{scram_tools}{$tool}=1;}
198 >      elsif ($tool ne "self")
199           {
200 <         # Keep only tools that have really been set up:
201 <         if (exists $self->{SETUP}->{$tool})
200 >         $self->_toolsdata($tool,$tooldata);
201 >         }
202 >      }
203 >   foreach my $tool (keys %{$self->{internal}{scram_tools}})
204 >      {
205 >      $self->_toolsdata_scram($tool,$tooldata);
206 >      }
207 >   delete $self->{internal}{donetools};
208 >   delete $self->{internal}{scram_tools};
209 >   my $data=[];
210 >   foreach my $d (@$tooldata)
211 >      {
212 >      if (ref($d) eq "ARRAY")
213 >         {
214 >         foreach my $t (@$d) {push @$data,$t;}
215 >         }
216 >      }
217 >   return $data;
218 >   }
219 >
220 > sub _toolsdata()
221 >   {
222 >   my $self = shift;
223 >   my $tool=shift;
224 >   my $data=shift || [];
225 >   my $order=-1;
226 >   if(exists $self->{internal}{donetools}{$tool}){return $self->{internal}{donetools}{$tool};}
227 >   $self->{internal}{donetools}{$tool}=$order;
228 >   if (exists $self->{SETUP}{$tool})
229 >      {
230 >      if (exists $self->{SETUP}{$tool}{USE})
231 >         {
232 >         foreach my $use (@{$self->{SETUP}{$tool}{USE}})
233              {
234 <            push(@tooldata,$self->{SETUP}->{$tool});
234 >            my $o=$self->_toolsdata(lc($use),$data);
235 >            if ($o>$order){$order=$o;}
236              }
237           }
238 +      $order++;
239 +      if(!defined $data->[$order]){$data->[$order]=[];}
240 +      push @{$data->[$order]},$self->{SETUP}{$tool};
241 +      $self->{internal}{donetools}{$tool}=$order;
242        }
243 <  
497 <   # Return the array of tools, in order that they appear in RequirementsDoc:
498 <   return @tooldata;
243 >   return $order;
244     }
245  
246 < sub definedtool()
246 > sub _toolsdata_scram()
247     {
248 <   my $self=shift;
249 <   my ($tool)=@_;
250 <  
251 <   # Check to see if tool X is an external tool:
252 <   grep ($_ eq $tool, keys %{$self->{SETUP}}) ? return 1
253 <      : return 0;
248 >   my $self = shift;
249 >   my $tool=shift;
250 >   my $data=shift || [];
251 >   my $order=-1;
252 >   if(exists $self->{internal}{donetools}{$tool}){return $self->{internal}{donetools}{$tool};}
253 >   $self->{internal}{donetools}{$tool}=$order;
254 >   if(!exists $self->{internal}{scram_tools}{$tool}){return $order;}
255 >   use Configuration::ConfigArea;
256 >   use Cache::CacheUtilities;
257 >   my $cache=uc($tool)."_BASE";
258 >   $cache=$self->{SETUP}{$tool}{$cache};
259 >   if (!-d $cache)
260 >      {
261 >      print STDERR "ERROR: Release area \"$cache\" for \"$tool\" is not available.\n";
262 >      return $order;
263 >      }
264 >   my $area=Configuration::ConfigArea->new();
265 >   $area->location($cache);
266 >   my $cachefile=$area->toolcachename();
267 >   if (!-f $cachefile)
268 >      {
269 >      print STDERR "ERROR: Tools cache file for release area \"$cache\" is not available.\n";
270 >      return $order;
271 >      }
272 >   $cache=&Cache::CacheUtilities::read($cachefile);
273 >   my $tools=$cache->setup();
274 >   $order=scalar(@$data)-1;
275 >   foreach my $use (keys %$tools)
276 >      {
277 >      if ($tools->{$use}->scram_project() == 1)
278 >         {
279 >         my $o=$self->_toolsdata_scram($use,$data);
280 >         if ($o>$order){$order=$o;}
281 >         }
282 >      }
283 >   $order++;
284 >   if(!defined $data->[$order]){$data->[$order]=[];}
285 >   push @{$data->[$order]},$self->{SETUP}{$tool};
286 >   $self->{internal}{donetools}{$tool}=$order;
287 >   return $order;
288     }
289 <
289 >  
290   sub checkifsetup()
291     {
292     my $self=shift;
# Line 517 | Line 296 | sub checkifsetup()
296        : return undef;
297     }
298  
520 sub cloned_tm()
521   {
522   my $self=shift;
523   # Has this area already been cloned and brought in-line with current location:
524   @_ ? $self->{CLONED} = $_[0]
525      : $self->{CLONED};
526   }
527
299   sub remove_tool()
300     {
301     my $self=shift;
302     my ($toolname)=@_;
303 <   my $tools = $self->{SETUP};
304 <   my $newtlist = {};
534 <  
535 <   while (my ($tool, $tooldata) = each %$tools)
303 >   my $tool = $self->{SETUP}{$toolname};
304 >   if ($tool->scram_compiler() == 1)
305        {
306 <      if ($tool ne $toolname)
307 <         {
308 <         $newtlist->{$tool} = $tooldata;
540 <         }
541 <      else
542 <         {
543 <         # Is this tool a compiler?
544 <         if ($tooldata->scram_compiler() == 1)
545 <            {
546 <            # Also remove this from the compiler info if there happens to be an entry:
547 <            while (my ($langtype, $ctool) = each %{$self->{SCRAM_COMPILER}})
548 <               {
549 <               if ($toolname eq $ctool->[0])
550 <                  {
551 <                  delete $self->{SCRAM_COMPILER}->{$langtype};
552 <                  print "Deleting compiler $toolname from cache.","\n";
553 <                  }
554 <               }
555 <            }
556 <         else
557 <            {
558 <            print "Deleting $toolname from cache.","\n";
559 <            }
306 >      while (my ($langtype, $ctool) = each %{$self->{SCRAM_COMPILER}})
307 >         {
308 >         if ($toolname eq $ctool->[0]){delete $self->{SCRAM_COMPILER}->{$langtype};}
309           }
310        }
311 <  
312 <   $self->{SETUP} = $newtlist;
313 <  
565 <   # Now remove from the RAW tool list:
566 <   $self->cleanup_raw($toolname);
567 <   print "ToolManager: Updating tool cache.","\n";
311 >   delete $self->{SETUP}{$toolname};
312 >   print "Deleting $toolname from cache.","\n";
313 >   $self->updatetooltimestamp (undef, $toolname);
314     $self->writecache();
315 +   my $file1=$self->{toolcache}."/selected/${toolname}.xml";
316 +   my $file2=$self->{toolcache}."/available/${toolname}.xml";
317 +   if ((!-f $file2) && (-f $file1))
318 +      {
319 +      use File::Copy;
320 +      copy ($file1,$file2);
321 +      }
322 +   unlink ($file1);
323     }
324  
325   sub scram_projects()
# Line 602 | Line 356 | sub scram_compiler()
356        }
357     }
358  
359 < sub updatetool()
359 > sub updatetooltimestamp ()
360     {
361     my $self=shift;
362 <   my ($name, $obj) = @_;
363 <
364 <   # Replace the existing copy of the tool with the new one:
365 <   if (exists $self->{SETUP}->{$name})
362 >   my $obj=shift;
363 >   my $toolname=shift;
364 >   my $samevalues=0;
365 >   my $stampdir = $self->{archstore}."/timestamps";
366 >   my $stampfile="${stampdir}/${toolname}";
367 >   if (exists $self->{SETUP}->{$toolname})
368        {
369 <      # Check to make sure that we were really passed a compiler with
370 <      # the desired name:
371 <      if ($obj->toolname() eq $name)
372 <         {
373 <         print "ToolManager: Updating the cached copy of ".$name."\n";
374 <         delete $self->{SETUP}->{$name};
375 <         $self->{SETUP}->{$name} = $obj;
376 <         $self->writecache();
377 <         }
378 <      else
379 <         {
380 <         print "WARNING: Tool name (".$name.") and tool obj name (".$obj->toolname().") don't match!","\n";
381 <         print "         Not making any changes.","\n";
369 >      $samevalues=$self->comparetoolsdata($self->{SETUP}->{$toolname},$obj);
370 >      }
371 >   if ($toolname ne "self")
372 >      {
373 >      my $instdir = $self->{archstore}."/InstalledTools";
374 >      my $tfile = "${instdir}/${toolname}";
375 >      if ((!defined $obj) && (-f $tfile)) {unlink $tfile;}
376 >      elsif ((defined $obj) && (!-f $tfile))
377 >         {
378 >         Utilities::AddDir::adddir($instdir);
379 >         my $ref;
380 >         open($ref,">$tfile");
381 >         close($ref);
382           }
383        }
384 <   else
384 >   if ((!$samevalues) || (!-f $stampfile))
385        {
386 <      print "WARNING: No entry in cache for ".$name.". Not making any updates.\n";
386 >      if (!-d $stampdir)
387 >         {
388 >         Utilities::AddDir::adddir($stampdir);
389 >         }
390 >      my $ref;
391 >      open($ref,">$stampfile");
392 >      close($ref);
393 >      if (!$samevalues){$self->dirty();}
394        }
395     }
396  
397 < sub check_compatibility()
397 > sub comparetoolsdata ()
398     {
399     my $self=shift;
400 <   my ($itoolmgr)=@_;
401 <   # Get the version of the toolmanager. If the project fails to return a version
402 <   # string we return 0 for no compatibility (in which case, all tools will be set
403 <   # up in the traditional way):
404 <   my $itm_configversion = $itoolmgr->configversion();
405 <   if ($itm_configversion)
400 >   my $data1=shift || ();
401 >   my $data2=shift || ();
402 >  
403 >   my $ref1=ref($data1);
404 >   my $ref2=ref($data2);
405 >  
406 >   if ($ref1 ne $ref2)
407        {
408 <      # The configurations won't be identical. We must compare the digits:
409 <      my ($numeric_version) = ($itm_configversion =~ /[a-zA-Z]*\_([0-9a-z]*).*?/);
410 <      my $current_configversion = $self->configversion();
411 <      my ($current_numeric_version) = ($current_configversion =~ /[a-zA-Z]*\_([0-9a-z]*).*?/);
412 <      ($current_numeric_version == $numeric_version) && return 1; # OK, compatible;
408 >      return 0;
409 >      }
410 >   elsif ($ref1 eq "CODE")
411 >      {
412 >      return 1;
413 >      }
414 >   elsif(($ref1 eq "SCALAR") || ($ref1 eq ""))
415 >      {
416 >      if ($data1 eq $data2)
417 >         {
418 >         return 1;
419 >         }
420 >      return 0;
421 >      }
422 >   elsif ($ref1 eq "ARRAY")
423 >      {
424 >      my $count = scalar(@$data1);
425 >      if ($count != scalar(@$data2))
426 >         {
427 >         return 0;
428 >         }
429 >      for (my $i=0; $i<$count; $i++)
430 >          {
431 >          if (! $self->comparetoolsdata($data1->[$i],$data2->[$i]))
432 >             {
433 >             return 0;
434 >             }
435 >          }
436 >      return 1;
437 >      }
438 >   else
439 >      {
440 >      foreach my $k (keys %{$data1})
441 >         {
442 >         if (! exists $data2->{$k})
443 >            {
444 >            return 0;
445 >            }
446 >         }
447 >      foreach my $k (keys %{$data2})
448 >         {
449 >         if (! exists $data1->{$k})
450 >            {
451 >            return 0;
452 >            }
453 >         }
454 >      foreach my $k (keys %{$data2})
455 >         {
456 >         if (! $self->comparetoolsdata($data1->{$k},$data2->{$k}))
457 >            {
458 >            return 0;
459 >            }
460 >         }
461 >      return 1;
462        }
650   # Project does not define configuration version so just return:
651   return 0;
652   }
653
654 sub configversion()
655   {
656   my $self=shift;
657   @_ ? $self->{CONFIGVERSION} = shift
658      : $self->{CONFIGVERSION};
463     }
464  
465   1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines