ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/ToolManager.pm
Revision: 1.19.2.2.2.1
Committed: Thu Mar 13 12:54:50 2008 UTC (17 years, 1 month ago) by muzaffar
Content type: text/plain
Branch: SCRAM_V2_0
CVS Tags: V2_0_4_relcand1, V2_0_3, V2_0_3_relcand3, V2_0_3_relcand2, V2_0_3_relcand1, V2_0_2, V2_0_2_relcand1, V2_0_1, V2_0_1_relcand4, V2_0_1_relcand3, V2_0_1_relcand2, V2_0_1_relcand1, V2_0_0_relcand4, V2_0_0, V2_0_0_relcand3, V2_0_0_relcand2, V2_0_0_relcand1
Changes since 1.19.2.2: +139 -388 lines
Log Message:
scram v2.0 for multiple arch support and big lib stuff

File Contents

# Content
1 #____________________________________________________________________
2 # File: ToolManager.pm
3 #____________________________________________________________________
4 #
5 # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6 # Update: 2003-11-12 15:04:16+0100
7 # Revision: $Id: ToolManager.pm,v 1.19.2.2 2008/02/19 15:06:03 muzaffar Exp $
8 #
9 # Copyright: 2003 (C) Shaun Ashby
10 #
11 #--------------------------------------------------------------------
12 package BuildSystem::ToolManager;
13 require 5.004;
14
15 use Exporter;
16 use BuildSystem::ToolCache;
17 use BuildSystem::ToolParser;
18 use Utilities::AddDir;
19 use Utilities::Verbose;
20 use SCRAM::MsgLog;
21
22 @ISA=qw(BuildSystem::ToolCache Utilities::Verbose);
23 @EXPORT_OK=qw( );
24 #
25
26 sub new
27 {
28 my $proto=shift;
29 my $class=ref($proto) || $proto;
30 my $self=$class->SUPER::new(); # Inherit from ToolCache
31 bless $self,$class;
32 $self->init (shift);
33 return $self;
34 }
35
36 sub init ()
37 {
38 my $self=shift;
39 my $projectarea=shift;
40 $self->{topdir}=$projectarea->location();
41 $self->{configdir}=$self->{topdir}."/".$projectarea->configurationdir();
42 $self->{archstore}=$projectarea->archdir();
43 $self->{toolcache}=$self->{configdir}."/toolbox/".$projectarea->arch()."/tools";
44 $self->name($projectarea->toolcachename());
45 $self->dirty();
46 }
47
48 sub interactive()
49 {
50 my $self=shift;
51 # Interactive mode on/off:
52 @_ ? $self->{interactive} = shift
53 : ((defined $self->{interactive}) ? $self->{interactive} : 0);
54 }
55
56 sub setupalltools()
57 {
58 my $self = shift;
59 my @selected=();
60 my $tooldir=$self->{toolcache}."/selected";
61 foreach my $tool (@{&getfileslist($tooldir)})
62 {
63 if ($tool=~/^(.+)\.xml$/) {push @selected,$1;}
64 }
65 foreach my $tool (@selected){$self->coresetup("${tooldir}/${tool}.xml");}
66 scramlogmsg("\n");
67 }
68
69 sub coresetup()
70 {
71 my $self=shift;
72 my ($toolfile) = @_;
73
74 my $toolparser = BuildSystem::ToolParser->new();
75 $toolparser->filehead('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><doc type="BuildSystem::ToolDoc" version="1.0">');
76 $toolparser->filetail('</doc>');
77 $toolparser->parse($toolfile);
78 my $toolname = $toolparser->toolname();
79 my $toolversion = $toolparser->toolversion();
80 scramlogmsg("\n",$::bold."Setting up ",$toolname," version ",$toolversion,": ".$::normal,"\n");
81
82 # Next, set up the tool:
83 my $store = $toolparser->processrawtool($self->interactive());
84
85 # Check to see if this tool is a compiler. If so, store it.
86 # Also store the language that this compiler supprots, and a
87 # compiler name (e.g. gcc323) which, in conjunction with a stem
88 # architecture name like slc3_ia32_, can be used to build a complete arch string:
89 if ($store->scram_compiler() == 1)
90 {
91 my @supported_language = $store->flags("SCRAM_LANGUAGE_TYPE");
92 my @compilername = $store->flags("SCRAM_COMPILER_NAME");
93 $self->scram_compiler($supported_language[0],$toolname,$compilername[0]);
94 }
95
96 # Store the ToolData object in the cache:
97 $self->storeincache($toolname,$store);
98 my $srcfile=Utilities::AddDir::fixpath($toolfile);
99 my $desfile=Utilities::AddDir::fixpath($self->{toolcache}."/selected/${toolname}.xml");
100 use File::Copy;
101 if ($srcfile ne $desfile)
102 {
103 use File::Copy;
104 my $desfile1=Utilities::AddDir::fixpath($self->{toolcache}."/available/${toolname}.xml");
105 if ($srcfile ne $desfile1)
106 {
107 copy($srcfile,$desfile1);
108 }
109 symlink("../available/${toolname}.xml",$desfile);
110 }
111 return $self;
112 }
113
114 sub setupself()
115 {
116 my $self=shift;
117 # Process the file "Self" in local config directory. This is used to
118 # set all the paths/runtime settings for this project:
119 my $filename=$self->{configdir}."/Self.xml";
120
121 if ( -f $filename )
122 {
123 scramlogmsg("\n",$::bold."Setting up SELF:".$::normal,"\n");
124 # Self file exists so process it:
125 $selfparser = BuildSystem::ToolParser->new();
126 $selfparser->filehead ('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><doc type="BuildSystem::ToolDoc" version="1.0">');
127 $selfparser->filehead ('</doc>');
128 $selfparser->parse($filename);
129
130 # Next, set up the tool:
131 $store = $selfparser->processrawtool($self->interactive());
132
133 # If we are in a developer area, also add RELEASETOP paths:
134 if (exists($ENV{RELEASETOP}))
135 {
136 print "\nAdding RELEASE area settings to self....OK","\n", if ($ENV{SCRAM_DEBUG});
137 $store->addreleasetoself();
138 }
139
140 # Store the ToolData object in the cache:
141 $self->storeincache($selfparser->toolname(),$store);
142 scramlogmsg("\n");
143 }
144 else
145 {
146 scramlogdump();
147 print "\n";
148 print "SCRAM: No file config/Self.xml...nothing to do.";
149 print "\n";
150 return;
151 }
152 }
153
154 sub update()
155 {
156 my $self=shift;
157 my $area=shift;
158 $self->init($area);
159 $self->setupself();
160 $self->dirty ()
161 }
162
163 sub storeincache()
164 {
165 my $self=shift;
166 my ($toolname,$dataobject)=@_;
167
168 # Store ToolData object (for a set-up tool) in cache:
169 if (ref($dataobject) eq 'BuildSystem::ToolData')
170 {
171 $self->updatetooltimestamp($dataobject, $toolname);
172 delete $self->{SETUP}->{$toolname};
173 $self->{SETUP}->{$toolname} = $dataobject;
174 }
175 else
176 {
177 $::scram->scramerror("ToolManager: BuildSystem::ToolData object reference expected.")
178 }
179 }
180
181 sub tools()
182 {
183 my $self = shift;
184 my @tools;
185
186 map
187 {
188 if ($_ ne "self")
189 {
190 push(@tools, $_);
191 }
192 } keys %{$self->{SETUP}};
193
194 # Return list of set-up tools:
195 return @tools;
196 }
197
198 sub toolsdata()
199 {
200 my $self = shift;
201 my $tooldata = [];
202 $self->{internal}{donetools}={};
203 $self->{internal}{scram_tools}={};
204 foreach my $tool (sort keys %{$self->{SETUP}})
205 {
206 if ($self->{SETUP}{$tool}->scram_project()) {$self->{internal}{scram_tools}{$tool}=1;}
207 elsif ($tool ne "self")
208 {
209 $self->_toolsdata($tool,$tooldata);
210 }
211 }
212 foreach my $tool (keys %{$self->{internal}{scram_tools}})
213 {
214 $self->_toolsdata_scram($tool,$tooldata);
215 }
216 delete $self->{internal}{donetools};
217 delete $self->{internal}{scram_tools};
218 return $tooldata;
219 }
220
221 sub _toolsdata()
222 {
223 my $self = shift;
224 my $tool=shift;
225 my $data=shift || [];
226 if(exists $self->{internal}{donetools}{$tool}){return;}
227 $self->{internal}{donetools}{$tool}=1;
228 if (exists $self->{SETUP}{$tool})
229 {
230 if (exists $self->{SETUP}{$tool}{USE})
231 {
232 foreach my $use (@{$self->{SETUP}{$tool}{USE}}){$self->_toolsdata(lc($use),$data);}
233 }
234 push @$data,$self->{SETUP}{$tool};
235 }
236 }
237
238 sub _toolsdata_scram()
239 {
240 my $self = shift;
241 my $tool=shift;
242 my $data=shift || [];
243 if(exists $self->{internal}{donetools}{$tool}){return;}
244 if(!exists $self->{internal}{scram_tools}{$tool}){return;}
245 $self->{internal}{donetools}{$tool}=1;
246 use Configuration::ConfigArea;
247 use Cache::CacheUtilities;
248 my $cache=uc($tool)."_BASE";
249 $cache=$self->{SETUP}{$tool}{$cache};
250 if (!-d $cache)
251 {
252 print "ERROR: Release area \"$cache\" for \"$tool\" is not available.\n";
253 return;
254 }
255 my $area=Configuration::ConfigArea->new();
256 $area->location($cache);
257 my $cachefile=$area->toolcachename();
258 if (!-f $cachefile)
259 {
260 print "ERROR: Tools cache file for release area \"$cache\" is not available.\n";
261 $self->{internal}{donetools}{$tool}=1;
262 return;
263 }
264 $cache=&Cache::CacheUtilities::read($cachefile);
265 my $tools=$cache->setup();
266 foreach my $use (keys %$tools)
267 {
268 if ($tools->{$use}->scram_project() == 1)
269 {
270 $self->_toolsdata_scram($use,$data);
271 }
272 }
273 push @$data,$self->{SETUP}{$tool};
274 }
275
276 sub checkifsetup()
277 {
278 my $self=shift;
279 my ($tool)=@_;
280 # Return the ToolData object if the tool has been set up:
281 (exists $self->{SETUP}->{$tool}) ? return ($self->{SETUP}->{$tool})
282 : return undef;
283 }
284
285 sub remove_tool()
286 {
287 my $self=shift;
288 my ($toolname)=@_;
289 my $tool = $self->{SETUP}{$toolname};
290 if ($tool->scram_compiler() == 1)
291 {
292 while (my ($langtype, $ctool) = each %{$self->{SCRAM_COMPILER}})
293 {
294 if ($toolname eq $ctool->[0]){delete $self->{SCRAM_COMPILER}->{$langtype};}
295 }
296 }
297 delete $self->{SETUP}{$toolname};
298 print "Deleting $toolname from cache.","\n";
299 $self->updatetooltimestamp (undef, $toolname);
300 $self->writecache();
301 my $file1=$self->{toolcache}."/selected/${toolname}.xml";
302 my $file2=$self->{toolcache}."/available/${toolname}.xml";
303 if ((!-f $file2) && (-f $file1))
304 {
305 use File::Copy;
306 copy ($file1,$file2);
307 }
308 unlink ($file1);
309 }
310
311 sub scram_projects()
312 {
313 my $self=shift;
314 my $scram_projects={};
315
316 foreach my $t ($self->tools())
317 {
318 # Get the ToolData object:
319 my $td=$self->{SETUP}->{$t};
320 $scram_projects->{$t}=$td->variable_data(uc($t)."_BASE"), if ($td->scram_project());
321 }
322
323 return $scram_projects;
324 }
325
326 sub scram_compiler()
327 {
328 my $self=shift;
329 my ($langtype, $toolname, $compilername)=@_;
330
331 if ($langtype)
332 {
333 # Store the compiler info according to supported
334 # language types.
335 #
336 # ---------------------- e.g C++ cxxcompiler gcc323
337 $self->{SCRAM_COMPILER}->{$langtype}=[ $toolname, $compilername ];
338 }
339 else
340 {
341 return $self->{SCRAM_COMPILER};
342 }
343 }
344
345 sub updatetooltimestamp ()
346 {
347 my $self=shift;
348 my $obj=shift;
349 my $toolname=shift;
350 my $samevalues=0;
351 my $stampdir = $self->{archstore}."/timestamps";
352 my $stampfile="${stampdir}/${toolname}";
353 if (exists $self->{SETUP}->{$toolname})
354 {
355 $samevalues=$self->comparetoolsdata($self->{SETUP}->{$toolname},$obj);
356 }
357 if ($toolname ne "self")
358 {
359 my $instdir = $self->{archstore}."/InstalledTools";
360 my $tfile = "${instdir}/${toolname}";
361 if ((!defined $obj) && (-f $tfile)) {unlink $tfile;}
362 elsif ((defined $obj) && (!-f $tfile))
363 {
364 Utilities::AddDir::adddir($instdir);
365 my $ref;
366 open($ref,">$tfile");
367 close($ref);
368 }
369 }
370 if ((!$samevalues) || (!-f $stampfile))
371 {
372 if (!-d $stampdir)
373 {
374 Utilities::AddDir::adddir($stampdir);
375 }
376 my $ref;
377 open($ref,">$stampfile");
378 close($ref);
379 if (!$samevalues){$self->dirty();}
380 }
381 }
382
383 sub comparetoolsdata ()
384 {
385 my $self=shift;
386 my $data1=shift || ();
387 my $data2=shift || ();
388
389 my $ref1=ref($data1);
390 my $ref2=ref($data2);
391
392 if ($ref1 ne $ref2)
393 {
394 return 0;
395 }
396 elsif ($ref1 eq "CODE")
397 {
398 return 1;
399 }
400 elsif(($ref1 eq "SCALAR") || ($ref1 eq ""))
401 {
402 if ($data1 eq $data2)
403 {
404 return 1;
405 }
406 return 0;
407 }
408 elsif ($ref1 eq "ARRAY")
409 {
410 my $count = scalar(@$data1);
411 if ($count != scalar(@$data2))
412 {
413 return 0;
414 }
415 for (my $i=0; $i<$count; $i++)
416 {
417 if (! $self->comparetoolsdata($data1->[$i],$data2->[$i]))
418 {
419 return 0;
420 }
421 }
422 return 1;
423 }
424 else
425 {
426 foreach my $k (keys %{$data1})
427 {
428 if (! exists $data2->{$k})
429 {
430 return 0;
431 }
432 }
433 foreach my $k (keys %{$data2})
434 {
435 if (! exists $data1->{$k})
436 {
437 return 0;
438 }
439 }
440 foreach my $k (keys %{$data2})
441 {
442 if (! $self->comparetoolsdata($data1->{$k},$data2->{$k}))
443 {
444 return 0;
445 }
446 }
447 return 1;
448 }
449 }
450
451 1;