ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildDataStorage.pm
Revision: 1.13
Committed: Fri Jul 29 15:48:35 2005 UTC (19 years, 9 months ago) by sashby
Content type: text/plain
Branch: MAIN
CVS Tags: V1_0_2, V1_0_2_p1
Branch point for: v103_branch
Changes since 1.12: +27 -1 lines
Log Message:
try to get skip functionality working

File Contents

# User Rev Content
1 sashby 1.2 #____________________________________________________________________
2     # File: BuildDataStorage.pm
3     #____________________________________________________________________
4     #
5     # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6     # Update: 2004-06-22 15:16:01+0200
7 sashby 1.13 # Revision: $Id: BuildDataStorage.pm,v 1.12 2005/07/26 15:14:00 sashby Exp $
8 sashby 1.2 #
9     # Copyright: 2004 (C) Shaun Ashby
10     #
11     #--------------------------------------------------------------------
12     package BuildSystem::BuildDataStorage;
13     require 5.004;
14     use Exporter;
15     @ISA=qw(Exporter);
16     @EXPORT_OK=qw( );
17    
18     sub new()
19     ###############################################################
20     # new #
21     ###############################################################
22     # modified : Tue Jun 22 15:16:08 2004 / SFA #
23     # params : #
24     # : #
25     # function : #
26     # : #
27     ###############################################################
28     {
29     my $proto=shift;
30     my $class=ref($proto) || $proto;
31     my ($configdir) = @_;
32     my $self=
33     {
34     BUILDTREE => {}, # Path/data pairs;
35     STATUS => 0, # Status of cache
36     VERBOSE => 0 # Verbose mode (0/1);
37     };
38    
39     bless $self,$class;
40    
41     # The location of the top-level BuildFile:
42     $self->{CONFIGDIR} = $configdir;
43    
44     # Somewhere to store the dependencies:
45     $self->{DEPENDENCIES} = {}; # GLOBAL dependencies
46 sashby 1.3 $self->{SKIPPEDDIRS} = {}; # Global skipped dirs
47 sashby 1.2
48     # Initialize the Template Engine:
49     $self->init_engine();
50    
51     return $self;
52     }
53    
54     sub grapher()
55     {
56     my $self=shift;
57     my ($mode,$writeopt)=@_;
58    
59     if ($mode)
60     {
61     $mode =~ tr[A-Z][a-z];
62     # Check to see what the mode is:
63     if ($mode =~ /^g.*?/)
64     {
65     $self->{GRAPH_MODE} = 'GLOBAL';
66     # GLOBAL package graphing:
67     use BuildSystem::SCRAMGrapher;
68     $self->{SCRAMGRAPHER} = BuildSystem::SCRAMGrapher->new();
69     }
70     elsif ($mode =~ /^p.*?/)
71     {
72     # All other cases assume per package. This means that each package
73     # is responsible for creating/destroying grapher objects and writing
74     # out graphs, if required:
75     $self->{GRAPH_MODE} = 'PACKAGE';
76     }
77     else
78     {
79     print "SCRAM error: no mode (w=p,w=g) given for graphing utility!","\n";
80     exit(1);
81     }
82    
83     # Set write option:
84     $self->{GRAPH_WRITE} = $writeopt;
85     }
86     else
87     {
88     print "SCRAM error: no mode (w=p,w=g) given for graphing utility!","\n";
89     exit(1);
90     }
91     }
92    
93     sub global_graph_writer()
94     {
95     my $self=shift;
96     my $name='Project';
97     # Only produce graphs with DOT if enabled. This routine is
98     # only used at Project level:
99     if (defined($self->{SCRAMGRAPHER}) && $self->{GRAPH_WRITE})
100     {
101     my $data; # Fake data - there isn't a DataCollector object
102     $self->{SCRAMGRAPHER}->graph_write($data, $name);
103     delete $self->{SCRAMGRAPHER};
104     }
105     else
106     {
107     print "SCRAM error: can't write graph!","\n";
108     exit(1);
109     }
110    
111     return;
112     }
113    
114     #### The methods ####
115     sub datapath()
116     {
117     my $self=shift;
118     my ($path)=@_;
119     my $datapath;
120     # At project-level, the path is src so just return src. Also,
121     # if we received a BuildFile path that we need to determine the data path for,
122     # check first to see if the path matches config/BuildFile. If it does, we have the top-level
123     # datapath which should be src:
124     if ($path eq "$ENV{LOCALTOP}/$ENV{SCRAM_CONFIGDIR}/BuildFile" || $path eq $ENV{SCRAM_SOURCEDIR})
125     {
126     return $ENV{SCRAM_SOURCEDIR};
127     }
128    
129     # For other paths, strip off the src dir (part of LOCALTOP) and the final BuildFile to
130     # get a data position to be used as a key:
131     ($datapath = $path) =~ s|^\Q$ENV{SCRAM_SOURCEDIR}\L/||;
132    
133     if ($datapath =~ m|(.*)/BuildFile$|)
134     {
135     return $1;
136     }
137    
138     return $datapath;
139     }
140    
141     sub check_global_config()
142     {
143     my $self=shift;
144     my $topbuildfile = $self->{CONFIGDIR}."/BuildFile";
145    
146     if ( ! -f $topbuildfile )
147     {
148     print "SCRAM error: no BuildFile at top-level (config)! Invalid area!","\n";
149     exit(1);
150     }
151    
152     return $self;
153     }
154    
155     sub processtree()
156     {
157     my $self=shift;
158     my $parent = $ENV{SCRAM_SOURCEDIR};
159     $self->procrecursive($parent);
160     return $self;
161     }
162    
163     sub updatetree()
164     {
165     my $self=shift;
166     my ($startdir) = @_;
167     print "Updating metadata from $startdir","\n",if ($ENV{SCRAM_DEBUG});
168     $self->updaterecursive($startdir);
169     return $self;
170     }
171    
172     sub updatemkfrommeta()
173     {
174     my $self=shift;
175     my ($startdir)=$ENV{SCRAM_SOURCEDIR};
176     print "Updating Makefile from $startdir","\n",if ($ENV{SCRAM_DEBUG});
177     $self->updatefrommeta($startdir);
178     return $self;
179     }
180    
181     sub scanbranch()
182     {
183     my $self=shift;
184 sashby 1.7 my ($files, $datapath)=@_;
185     my $bfbranch;
186     my $buildfiles;
187 sashby 1.4 # Fix (or rather hack) so that only the current buildfile is parsed, not the parent.
188     # This is required becuase it's not desired to pick up dependencies from the level lower:
189     # one should always do it via a <use name=x> to get the package deps. We don't care about
190     # deps in subsystems (they're only used to define groups) and project-wide deps are added at
191     # template level:
192 sashby 1.7 if (exists($ENV{SCRAM_XMLBUILDFILES}) && ($ENV{SCRAM_XMLBUILDFILES}))
193     {
194 sashby 1.10 print "Reading ".$files->[0].".xml","\n";
195 sashby 1.7 use BuildSystem::XMLBuildFile;
196     $bfbranch=BuildSystem::XMLBuildFile->new();
197     $buildfiles = [ $files->[0].".xml" ];
198     }
199     else
200     {
201     use BuildSystem::BuildFile;
202     $bfbranch=BuildSystem::BuildFile->new();
203     $buildfiles=[ $files->[0] ];
204     }
205 sashby 1.4
206 sashby 1.2 # Scan all buildfiles in a branch:
207 sashby 1.7 $bfbranch->parsebranchfiles($buildfiles);
208    
209 sashby 1.2 # Store:
210     $self->storebranchmetadata($datapath,$bfbranch);
211 sashby 1.7
212 sashby 1.2 return $self;
213     }
214    
215     sub procrecursive()
216     {
217     my $self=shift;
218     my ($dir)=@_;
219     my $datacollector;
220 sashby 1.11
221 sashby 1.13 # Check to see if the dir was skipped. If so, don't push anything to
222     # the Makefile:
223     if ($self->skipdir($dir))
224     {
225     print "procrecursive -> $dir skipped.","\n",if ($ENV{SCRAM_DEBUG});
226     return $self;
227     }
228    
229 sashby 1.2 # Data for current dir:
230     my $treedata = $self->buildtreeitem($dir);
231     # Data for the parent:
232     my $parent = $treedata->parent();
233     my $parenttree = $self->buildtreeitem($parent);
234     # Base classes. These are structural template classes which are fixed in SCRAM:
235 sashby 1.8 my $baseclasses = [ qw( DOMAIN SUBSYSTEM PACKAGE ) ];
236 sashby 1.2
237     # If we have a parent dir, collect METABF. Skip inheriting from config/BuildFile:
238     if (defined ($parenttree) && $parenttree->metabf() && $parent ne 'src')
239     {
240     # Add the meta (BuildFile) location to the current locations meta:
241     $treedata->metabf(@{$parenttree->metabf()});
242     }
243    
244     # Perfect match to class:
245     if ($treedata->suffix() eq '')
246     {
247     # For directories where there's a full match to the classpath, check the class.
248     # Only process Buildfiles if the match occurs for a build product class. In either case,
249     # run the template engine.
250     # Don't process BuildFiles unless we happen to be in a product branch (i.e.,
251     # not a baseclass as defined above) except for Project which we do want:
252     if (! grep($treedata->class() eq $_, @$baseclasses))
253     {
254     # Scan all BuildFiles in this branch:
255     $self->scanbranch($treedata->metabf(),$self->datapath($dir));
256     # Process the build data:
257     $datacollector = $self->processbuildfile($dir, $treedata->path());
258     $treedata->clean(); # Get rid of BRANCHMETA
259     $treedata->branchdata($datacollector);
260     }
261    
262     # And run the engine:
263     $self->run_engine($treedata);
264    
265     foreach my $c ($treedata->children())
266     {
267     if ($c ne '')
268     {
269     $self->procrecursive($c);
270     }
271     }
272     }
273     else
274     {
275     # For directories where there isn't a full match, just run the template engine:
276     $self->run_engine($treedata);
277    
278     foreach my $c ($treedata->children())
279     {
280     if ($c ne '')
281     {
282     $self->procrecursive($c);
283     }
284     }
285     }
286    
287     return $self;
288     }
289    
290     sub updaterecursive()
291     {
292     my $self=shift;
293     my ($dir)=@_;
294     my $datacollector;
295 sashby 1.13
296     # Check to see if the dir was skipped. If so, don't push anything to
297     # the Makefile:
298     if ($self->skipdir($dir))
299     {
300     print "updaterecursive -> $dir: skipped.","\n",if ($ENV{SCRAM_DEBUG});
301     return;
302     }
303    
304 sashby 1.2 # updaterecursive() only SCANS and UPDATES METADATA. The Makefile is rebuilt in
305     # its entirety using updatefrommeta(), called after metadata is updated and stored:
306     # Data for current dir:
307     my $treedata = $self->buildtreeitem($dir);
308     # Data for the parent:
309     my $parent = $treedata->parent();
310     my $parenttree = $self->buildtreeitem($parent);
311     # Base classes. These are structural template classes which are fixed in SCRAM:
312 sashby 1.8 my $baseclasses = [ qw( DOMAIN SUBSYSTEM PACKAGE ) ];
313 sashby 1.2
314     # If we have a parent dir, collect METABF. Skip inheriting from config/BuildFile:
315     if (defined ($parenttree) && $parenttree->metabf() && $parent ne 'src')
316     {
317     # Add the meta (BuildFile) location to the current locations meta:
318     $treedata->metabf(@{$parenttree->metabf()});
319     }
320    
321     # Perfect match to class:
322     if ($treedata->suffix() eq '')
323     {
324     # For directories where there's a full match to the classpath, check the class.
325     # Only process Buildfiles if the match occurs for a build product class. In either case,
326     # run the template engine.
327     # Don't process BuildFiles unless we happen to be in a product branch (i.e.,
328     # not a baseclass as defined above):
329     if (! grep($treedata->class() eq $_, @$baseclasses))
330     {
331     # Scan all BuildFiles in this branch:
332     $self->scanbranch($treedata->metabf(),$self->datapath($dir));
333     # Process the build data:
334     $datacollector = $self->processbuildfile($dir, $treedata->path());
335     $treedata->clean();
336     $treedata->branchdata($datacollector);
337     }
338    
339     foreach my $c ($treedata->children())
340     {
341     if ($c ne '')
342     {
343     $self->updaterecursive($c);
344     }
345     }
346     }
347     else
348     {
349     foreach my $c ($treedata->children())
350     {
351     if ($c ne '')
352     {
353     $self->updaterecursive($c);
354     }
355     }
356     }
357    
358     return $self;
359     }
360    
361     sub updatefrommeta()
362     {
363     my $self=shift;
364     my $datacollector;
365     my ($startdir)=@_;
366 sashby 1.13
367     # Check to see if the dir was skipped. If so, don't push anything to
368     # the Makefile:
369     if ($self->skipdir($startdir))
370     {
371     print "updatefrommeta -> $startdir: skipped.","\n",if ($ENV{SCRAM_DEBUG});
372     return;
373     }
374    
375 sashby 1.2 # Data for current dir:
376     my $treedata = $self->buildtreeitem($startdir);
377     # Run the engine:
378 sashby 1.3 $self->run_engine($treedata);
379 sashby 1.2
380     foreach my $c ($treedata->children())
381     {
382     if ($c ne '')
383     {
384     $self->updatefrommeta($c);
385     }
386     }
387    
388     return $self;
389     }
390    
391     sub buildtreeitem()
392     {
393     my $self=shift;
394     my ($datapath)=@_;
395     # This will return the TreeItem object for
396     # the corresponding data path:
397     return $self->{BUILDTREE}->{$datapath};
398     }
399    
400     sub bproductparse()
401     {
402     my $self=shift;
403     my ($dataposition, $path, $bcollector, $product, $localg)=@_;
404     my $packdir;
405    
406     if ($dataposition =~ m|(.*)/src|)
407     {
408     $packdir=$1;
409     }
410     elsif ($dataposition =~ m|(.*)/|)
411     {
412     $packdir=$dataposition;
413     }
414    
415     # Probably better to use the bin name/safename:
416     $packdir = $product->safename();
417     my $label = $product->name();
418    
419     # Look for architecture-specific tags:
420     if (my $archdata=$product->archspecific())
421     {
422     $bcollector->resolve_arch($archdata,$packdir);
423     }
424    
425     # Groups:
426     if (my @groups=$product->group())
427     {
428     $bcollector->resolve_groups(\@groups,$packdir);
429     }
430    
431     # Check for packages and external tools:
432     if (my @otheruses=$product->use())
433     {
434     $bcollector->localgraph()->vertex($packdir);
435    
436     # Add vertex and edges for current package and its dependencies:
437     foreach my $OU (@otheruses)
438     {
439     $bcollector->localgraph()->edge($packdir, $OU);
440     }
441    
442     $bcollector->resolve_use(\@otheruses);
443     }
444    
445     # For each tag type that has associated data in this buildfile
446     # data object, get the data and store it:
447     map { my $subname = lc($_); $bcollector->storedata($_, $product->$subname(),$packdir); }
448     $product->basic_tags();
449    
450     # Prepare the metadata for this location:
451     my $graphexists = $bcollector->prepare_meta($packdir);
452    
453     # Write out the graph if required:
454     if ($localg && $self->{GRAPH_WRITE} && $graphexists)
455     {
456     $bcollector->localgraph()->graph_write($bcollector->attribute_data(), $packdir);
457     }
458    
459     # Clean up:
460     $bcollector->clean4storage();
461     return $bcollector;
462     }
463    
464     sub processbuildfile()
465     {
466     my $self=shift;
467     my ($dataposition, $path)=@_;
468     my $collector;
469     my $packdir;
470     my $CURRENTBF = $self->metaobject($dataposition);
471     my $localgrapher=0;
472     my $scramgrapher;
473 sashby 1.4
474 sashby 1.2 if (defined($CURRENTBF))
475     {
476     use BuildSystem::DataCollector;
477    
478     # Graphing:
479     if (! defined($self->{SCRAMGRAPHER}))
480     {
481     # We don't have a grapher object so we must we working at package level.
482     $localgrapher=1;
483     # Create the object here:
484     use BuildSystem::SCRAMGrapher;
485     $scramgrapher = BuildSystem::SCRAMGrapher->new();
486     }
487     else
488     {
489     $scramgrapher = $self->{SCRAMGRAPHER};
490     }
491    
492     my %projects = %{$self->{SCRAM_PROJECTS}};
493     my %projectbases = %{$self->{SCRAM_PROJECT_BASES}};
494    
495     # Set up the collector object:
496     $collector = BuildSystem::DataCollector->new($self, $self->{TOOLMANAGER},
497     $path, \%projects, \%projectbases,
498     $scramgrapher);
499    
500     # Need the package name for our dep tracking:
501     if ($dataposition =~ m|(.*)/src|)
502     {
503     $packdir=$1;
504     }
505     elsif ($dataposition =~ m|(.*)/|)
506     {
507     $packdir=$dataposition;
508     }
509     elsif ($dataposition eq $ENV{SCRAM_SOURCEDIR})
510     {
511     $packdir = $ENV{SCRAM_SOURCEDIR};
512     }
513    
514     # Look for architecture-specific tags:
515     if (my $archdata=$CURRENTBF->archspecific())
516     {
517     $collector->resolve_arch($archdata,$packdir);
518     }
519    
520     # Groups:
521     if (my @groups=$CURRENTBF->group())
522     {
523     $collector->resolve_groups(\@groups,$packdir);
524     }
525    
526     # Check for packages and external tools:
527     if (my @otheruses=$CURRENTBF->use())
528     {
529     $scramgrapher->vertex($packdir);
530    
531     # Add vertex and edges for current package and its dependencies:
532     foreach my $OU (@otheruses)
533     {
534     $scramgrapher->edge($packdir, $OU);
535     }
536    
537     $collector->resolve_use(\@otheruses);
538     }
539    
540     # If we are at project-level, also resolve the 'self' tool. We ONLY do this
541     # at project-level:
542     if ($dataposition eq $ENV{SCRAM_SOURCEDIR})
543     {
544     $collector->resolve_use(['self']);
545     }
546    
547     # For each tag type that has associated data in this buildfile
548     # data object, get the data and store it:
549     map { my $subname = lc($_); $collector->storedata($_, $CURRENTBF->$subname(),$packdir); }
550     $CURRENTBF->basic_tags();
551    
552     # Check for build products and process them here:
553     my $buildproducts=$CURRENTBF->buildproducts();
554    
555     my $BUILDP = {};
556    
557     # If we have build products:
558     if ($buildproducts)
559     {
560     # Build a list of target types that should built at this location in
561     # addition to normal libraries:
562     foreach my $type (keys %$buildproducts)
563     {
564     my $typedata=$CURRENTBF->values($type);
565     while (my ($name,$product) = each %$typedata)
566     {
567     # We make a copy from existing collector object. This is basically a "new()"
568     # followed by some copying of relevant data elements:
569     $bcollector = $collector->copy($localgrapher);
570     # The Product object inherits from same core utility packages
571 sashby 1.4 # as BuildFile so all BuildFile methods can be used on the Product object:
572 sashby 1.2 $self->bproductparse($dataposition,$path,$bcollector,$product,$localgrapher);
573     $product->data($bcollector);
574     $BUILDP->{$product->safename()} = $product;
575     }
576     }
577    
578     # Return the hash of products (safe_name/Product object pairs):
579     return $BUILDP;
580     }
581     else
582     {
583     # Prepare the metadata for this location. Also needed for each build product:
584     my $graphexists = $collector->prepare_meta($packdir);
585    
586     # Write out the graph if required (also to be done for each product):
587     if ($localgrapher && $self->{GRAPH_WRITE} && $graphexists)
588     {
589     $scramgrapher->graph_write($collector->attribute_data(), $packdir);
590     }
591    
592     # At this point I think we can clean away the graph object:
593     $collector->clean4storage();
594    
595     # No products: return main collector:
596     return $collector;
597     }
598     }
599     else
600     {
601     # No build data, just return:
602     return $collector;
603     }
604     }
605    
606     sub create_productstores()
607     {
608     my $self=shift;
609     # This routine will only ever be run for top-level so
610     # datapath can be coded here:
611     my $datapath='src';
612     my $tldata=$self->buildtreeitem($datapath);
613     my $stores=$tldata->rawdata()->productstore();
614    
615     # Iterate over the stores:
616     foreach my $H (@$stores)
617     {
618     my $storename="";
619     # Probably want the store value to be set to <name/<arch> or <arch>/<name> with
620     # <path> only prepending to this value rather than replacing <name>: FIXME...
621     if ($$H{'type'} eq 'arch')
622     {
623     if ($$H{'swap'} eq 'true')
624     {
625     (exists $$H{'path'}) ? ($storename .= $$H{'path'}."/".$ENV{SCRAM_ARCH})
626     : ($storename .= $$H{'name'}."/".$ENV{SCRAM_ARCH});
627     }
628     else
629     {
630     (exists $$H{'path'}) ? ($storename .= $ENV{SCRAM_ARCH}."/".$$H{'path'})
631     : ($storename .= $ENV{SCRAM_ARCH}."/".$$H{'name'});
632     }
633     }
634     else
635     {
636     (exists $$H{'path'}) ? ($storename .= $$H{'path'})
637     : ($storename .= $$H{'name'});
638     }
639    
640     # Create the dir: FIXME: may need a more portable mkdir?
641     system("mkdir","-p",$ENV{LOCALTOP}."/".$storename);
642     }
643     }
644    
645     sub populate()
646     {
647     my $self=shift;
648     my ($paths,$filecache,$toolmanager)=@_;
649     my $datapath;
650     my $buildfile;
651     $|=1; # Flush
652    
653     # The tool manager:
654     $self->{TOOLMANAGER} = $toolmanager;
655    
656 sashby 1.5 # If there are some paths to iterate over, get scram projects from
657     # toolbox. Each project cache is loaded at this point too.
658     # Note that this could be done later, when running processtree() which
659     # is when access to the project caches is really needed (actually when
660     # running datacollector::processbuildfile):
661 sashby 1.2 $self->scramprojects();
662    
663     # Check that there's a global config. Exit if not:
664     $self->check_global_config();
665    
666     # Loop over all paths. Apply a sort so that src (shortest path) is first (FIXME!):
667     foreach my $path (sort(@$paths))
668     {
669     # Ignore config content here:
670     next if ($path !~ m|^\Q$ENV{SCRAM_SOURCEDIR}\L|);
671 sashby 1.3
672 sashby 1.2 # Set the data path:
673 sashby 1.3 $datapath = $self->datapath($path);
674    
675 sashby 1.2 # Create a TreeItem object:
676     use BuildSystem::TreeItem;
677     my $treeitem = BuildSystem::TreeItem->new();
678     $self->{BUILDTREE}->{$datapath} = $treeitem;
679    
680     # If we have the project root (i.e. src), we want to process the
681     # top-level (project config) BuildFile:
682     if ($path eq $ENV{SCRAM_SOURCEDIR})
683     {
684     $buildfile = $ENV{SCRAM_CONFIGDIR}."/BuildFile";
685     # Parse the top-level BuildFile. We must do this here
686     # because we need the ClassPaths. Store as RAWDATA:
687     $self->scan($buildfile, $datapath);
688     # At this point, we've scanned the top-level BuildFile so we can
689     # create the store dirs and setup "self":
690     $self->create_productstores();
691     # We need scram project base vars at project-level:
692     $treeitem->scramprojectbases($self->{SCRAM_PROJECT_BASES});
693     }
694     else
695     {
696     $buildfile = $path."/BuildFile";
697     }
698    
699     # If this BuildFile exists, store in METABF:
700     if ( -f $buildfile )
701     {
702     # This level has a buildfile so store this path:
703     $treeitem->metabf($buildfile);
704     # Scan to resolve groups. Store as RAWDATA:
705     $self->scan($buildfile, $datapath);
706     ($ENV{SCRAM_DEBUG}) ? print "Scanning ",$buildfile,"\n" : print "." ;
707     }
708    
709 sashby 1.3 if ($self->skipdir($datapath))
710     {
711     $treeitem->skip(1);
712     print $datapath," building skipped.\n", if ($ENV{SCRAM_DEBUG});
713     }
714    
715 sashby 1.2 # Now add the class and path info to the TreeItem:
716     my ($class, $classdir, $suffix) = @{$self->buildclass($path)};
717    
718     $treeitem->class($class);
719     $treeitem->classdir($classdir);
720     $treeitem->suffix($suffix);
721     $treeitem->path($path);
722     $treeitem->safepath($path);
723     $treeitem->parent($datapath);
724     $treeitem->children($filecache);
725     $treeitem->name();
726     }
727    
728     print "\n";
729    
730     # Check dependencies- look for cycles in the global dependency data:
731     $self->check_dependencies();
732 sashby 1.3 $self->skipdir() if ($ENV{SCRAM_DEBUG});
733 sashby 1.2 }
734    
735     sub check_dependencies()
736     {
737     my $self=shift;
738     # Use the SCRAMGrapher to process the deps and return a
739     # Graph object:
740     use BuildSystem::SCRAMGrapher;
741    
742     my $SG = BuildSystem::SCRAMGrapher->new($self->{DEPENDENCIES}); # GLOBAL dependencies
743     my $G = $SG->_graph_init();
744     my @classification = $G->edge_classify();
745     my @cycles;
746     my $status=0;
747    
748     # Dump the vertex classification if required:
749     if ($ENV{SCRAM_DEBUG})
750     {
751     print "\n";
752     print "Dumping vertex/path classifications:","\n";
753     print "\n";
754     printf("%-40s %-40s %-15s\n",'Vertex_i','Vertex_j','CLASS');
755     printf("%-95s\n",'-'x95);
756     }
757    
758     foreach my $element (@classification)
759     {
760     printf("%-40s %-40s %-15s\n",$element->[0],$element->[1],$element->[2]), if ($ENV{SCRAM_DEBUG});
761     # Save our cycles to list separately:
762     if ($element->[2] eq 'back')
763     {
764     push(@cycles,$element);
765     $status++;
766     }
767     }
768    
769     print "\n";
770     if ($status)
771     {
772     map
773     {
774     print $::fail."SCRAM buildsystem ERROR: Cyclic dependency ",$_->[0]," <--------> ",$_->[1].$::normal."\n";
775     } @cycles;
776     print "\n";
777    
778     # Exit:
779     exit(1);
780     }
781    
782     # Otherwise return:
783     return;
784     }
785    
786     sub update_toplevel()
787     {
788     my $self=shift;
789     my (@buildfiles) = @_;
790     my $treeitem;
791    
792     print "Re-scanning at top-level..\n";
793    
794     my $datapath = $self->datapath($ENV{LOCALTOP}."/".$ENV{SCRAM_CONFIGDIR}."/BuildFile");
795    
796     # This updates the raw data:
797     $self->scan($ENV{LOCALTOP}."/".$ENV{SCRAM_CONFIGDIR}."/BuildFile", $datapath);
798    
799     # Update everything else:
800     foreach my $B (@buildfiles)
801     {
802     next if ($B eq $ENV{LOCALTOP}."/config/BuildFile");
803     $datapath = $self->datapath($B);
804     # Check to see if we already have the raw data for this buildfile.
805     # Note that we won't if this scan was run from update mode. In this
806     # case, we set up the TreeItem object:
807     if (! exists($self->{BUILDTREE}->{$datapath}))
808     {
809     use BuildSystem::TreeItem;
810     $treeitem = BuildSystem::TreeItem->new();
811     my $path=$ENV{SCRAM_SOURCEDIR}."/".$datapath;
812     my ($class, $classdir, $suffix) = @{$self->buildclass($path)};
813    
814     $treeitem->class($class);
815     $treeitem->classdir($classdir);
816     $treeitem->suffix($suffix);
817     $treeitem->path($path);
818     $treeitem->safepath($path);
819     $treeitem->parent($datapath);
820     $treeitem->children($filecache);
821     $treeitem->name();
822    
823     $self->{BUILDTREE}->{$datapath} = $treeitem;
824    
825     print "Scanning ",$B,"\n";
826     $self->scan($B,$datapath); # This updates the raw data
827     }
828     else
829     {
830     print "Scanning ",$B,"\n";
831     $self->scan($B,$datapath); # This updates the raw data
832     }
833    
834     # Recursively update the tree from this data path:
835     $self->updatetree($datapath);
836     }
837     }
838    
839     sub update()
840     {
841     my $self=shift;
842     my ($changeddirs, $addeddirs, $bf, $removedpaths, $toolmanager, $filecache) = @_;
843     my $buildfiles = {};
844     # Copy the contents of the array of BuildFiles to a hash so that
845     # we can track which ones have been parsed:
846     map
847     {
848     $buildfiles->{$_} = 0;
849     } @$bf;
850    
851     # Tool manager:
852     $self->{TOOLMANAGER} = $toolmanager;
853     # Get scram projects from toolbox. Each project cache is
854     # loaded at this point too:
855     $self->scramprojects();
856    
857     # Remove build data for removed directories:
858     $self->removedata($removedpaths);
859    
860     # Now check to see if something changed at the top-level. If so we reparse everything:
861     my $toplevel = $ENV{LOCALTOP}."/".$ENV{SCRAM_CONFIGDIR}."/BuildFile";
862    
863     if (exists($buildfiles->{$toplevel}))
864     {
865     $buildfiles->{$toplevel} = 1; # Parsed
866     $self->update_toplevel(@$bf);
867     }
868     else
869     {
870     # Process all new directories first then changed ones. This means that everything will be in
871     # place once we start parsing any modified BuildFiles and once we run updatetree():
872    
873     $self->update_newdirs($addeddirs);
874    
875     $self->update_existingdirs($changeddirs);
876    
877     # Now check for any modified BuildFiles that have not yet been rescanned:
878     foreach my $bftoscan (keys %$buildfiles)
879     {
880     if ($buildfiles->{$bftoscan} == 0)
881     {
882     my $datapath = $self->datapath($bftoscan);
883     $self->scan($bftoscan,$datapath); # This updates the raw data
884     }
885     }
886     }
887    
888     # Also rebuild the project Makefile from scratch:
889     $self->updatemkfrommeta();
890     print "\n";
891     }
892    
893     sub update_newdirs()
894     {
895     my $self=shift;
896     my ($newdirs) = @_;
897     foreach my $path (@$newdirs)
898     {
899     print "Processing new directory \"",$path,"\"\n",if ($ENV{SCRAM_DEBUG});
900     $self->updateadir($path);
901 sashby 1.11 # Now check to see if the current (newly-added) package is needed by some
902     # packages that have already built their metadata. If so, force an update
903     # of those packages:
904     my $locations = $self->unresolved_locations($self->datapath($path));
905     if ($#$locations >= 0)
906     {
907     # Also need to check to see if a location is updated more than once.
908     foreach my $notified_dir (@$locations)
909     {
910 sashby 1.12 print "Going to notify $notified_dir of update","\n", if ($ENV{SCRAM_DEBUG});
911 sashby 1.11 $self->updateadir($notified_dir);
912     $self->remove_unresolved($self->datapath($path),$notified_dir);
913     }
914     }
915 sashby 1.2 }
916     }
917    
918     sub update_existingdirs()
919     {
920     my $self=shift;
921     my ($changeddirs) = @_;
922     foreach my $path (@$changeddirs)
923     {
924     print "Processing modified directory \"",$path,"\"\n",if ($ENV{SCRAM_DEBUG});
925     $self->updateadir($path);
926     }
927     }
928    
929     sub updateadir()
930     {
931     my $self=shift;
932     my ($path) = @_;
933     my $datapath = $self->datapath($path);
934     my $possiblebf = $path."/BuildFile";
935     my $treeitem;
936    
937     if (! exists($self->{BUILDTREE}->{$datapath}))
938     {
939     use BuildSystem::TreeItem;
940     $treeitem = BuildSystem::TreeItem->new();
941    
942     # Get the class info:
943     my ($class, $classdir, $suffix) = @{$self->buildclass($path)};
944    
945     $treeitem->class($class);
946     $treeitem->classdir($classdir);
947     $treeitem->suffix($suffix);
948     $treeitem->path($path);
949     $treeitem->safepath($path);
950     $treeitem->parent($datapath);
951     $treeitem->children($filecache);
952     $treeitem->name();
953     # Store the TreeItem object:
954     $self->{BUILDTREE}->{$datapath} = $treeitem;
955     }
956    
957     # Update the status of the parent. Add the child and update
958     # the safe subdirs:
959     my $parent = $self->{BUILDTREE}->{$datapath}->parent();
960 sashby 1.9
961     if (defined($self->{BUILDTREE}->{$parent}))
962     {
963     $self->{BUILDTREE}->{$parent}->updateparentstatus($datapath);
964     }
965 sashby 1.2
966     # Now check to see if there is a BuildFile here. If there is, parse it:
967     if ( -f $possiblebf)
968     {
969     # This level has a buildfile so store this path:
970     $self->{BUILDTREE}->{$datapath}->metabf($possiblebf);
971     # Scan to resolve groups. Store as RAWDATA:
972     print "Scanning ",$possiblebf,"\n";
973     $self->scan($possiblebf, $datapath);
974     # Check to see if this BuildFile is known to have needed scanning. If so,
975     # mark it as read:
976     if (exists($buildfiles->{$possiblebf}))
977     {
978     $buildfiles->{$possiblebf} = 1;
979     }
980     }
981    
982     # Recursively update the tree from this data path:
983     $self->updatetree($datapath);
984     }
985    
986     sub scan()
987     {
988     my $self=shift;
989 sashby 1.7 my ($inputbuildfile, $datapath) = @_;
990     my $bfparse;
991     my $buildfile;
992 sashby 1.2
993 sashby 1.7 if (exists($ENV{SCRAM_XMLBUILDFILES}) && ($ENV{SCRAM_XMLBUILDFILES}))
994     {
995     use BuildSystem::XMLBuildFile;
996     $bfparse=BuildSystem::XMLBuildFile->new();
997     $buildfile=$inputbuildfile.".xml";
998 sashby 1.10 print "Reading ",$buildfile,"\n";
999 sashby 1.7 }
1000     else
1001     {
1002     use BuildSystem::BuildFile;
1003     $bfparse=BuildSystem::BuildFile->new();
1004     $buildfile=$inputbuildfile;
1005     }
1006    
1007     # Execute the parse:
1008 sashby 1.2 $bfparse->parse($buildfile);
1009 sashby 1.7
1010 sashby 1.2 # Store group data:
1011 sashby 1.3 $self->addgroup($bfparse->defined_group(), $datapath)
1012     if ($bfparse->defined_group());
1013    
1014     # See if there were skipped dirs:
1015     my $skipped = $bfparse->skippeddirs($datapath);
1016     # Check to see if there was an info array for this location.
1017     # If so, we extract the first element of the array (i.e. ->[1])
1018     # and store it under the datapath entry. This is just so that useful
1019     # messages explaining why the dir was skipped can be preserved.
1020     if (ref($skipped) eq 'ARRAY')
1021     {
1022     $self->skipdir($datapath,$skipped->[1]);
1023     }
1024 sashby 1.2
1025     $self->storedata($datapath, $bfparse);
1026    
1027 sashby 1.3 # Add the dependency list to our store:
1028     $self->{DEPENDENCIES}->{$datapath} = $bfparse->dependencies();
1029 sashby 1.2 return $self;
1030     }
1031    
1032     sub init_engine()
1033     {
1034     my $self=shift;
1035    
1036     # Create the interface to the template engine:
1037     use BuildSystem::TemplateInterface;
1038     # Pass in the config dir as the location where templates live:
1039     $self->{TEMPLATE_ENGINE} = BuildSystem::TemplateInterface->new();
1040     }
1041    
1042     sub run_engine()
1043     {
1044     my $self=shift;
1045     my ($templatedata)=@_;
1046    
1047     $self->{TEMPLATE_ENGINE}->template_data($templatedata);
1048     $self->{TEMPLATE_ENGINE}->run();
1049     return $self;
1050     }
1051    
1052     sub buildclass
1053     {
1054     my $self=shift;
1055     my ($path)=@_;
1056     my $cache=[];
1057 sashby 1.11 # From Lassi TUURA (with mods by me):
1058     #
1059 sashby 1.2 # Associate a path with ClassPath setting.
1060     # For now, just assumes global data has been scanned and class settings
1061     # are already known (in $self->{CONFIGDATA}->classpath()).
1062     # Generate more optimal classpath data structure, only once.
1063     # Split every cache definition into an array of pairs, directory
1064     # name and class. So ClassPath of type "+foo/+bar/src+library"
1065     # becomes [ [ "" "foo" ] [ "" "bar" ] [ "src" "library" ] ]
1066     my @CLASSPATHS=@{$self->{BUILDTREE}->{$ENV{SCRAM_SOURCEDIR}}->rawdata()->classpath()};
1067    
1068     if (! scalar @$cache)
1069     {
1070     foreach my $classpath (@CLASSPATHS)
1071     {
1072     push (@$cache, [map { [ split(/\+/, $_) ] } split(/\//, $classpath)]);
1073     }
1074     }
1075    
1076     print "WARNING: No ClassPath definitions, nothing will be done!","\n",
1077     if (! scalar @$cache);
1078     # Now scan the class paths. All the classpaths are given a rank
1079     # to mark how relevant they are, and then the best match is chosen.
1080     #
1081     # The ranking logic is as follows. We scan each class path and
1082     # drop if it doesn't match at all. For paths that match, we
1083     # record how many components of the class was *not* used to match
1084     # on the class: for a short $path, many classes will match.
1085     # For each path component we record whether the match was exact
1086     # (if the class part is empty, i.e. "", it's a wildcard that
1087     # matches everything). Given these rankings, we pick
1088     # - the *first* class that
1089     # - has least *unmatched* components
1090     # - with *first* or *longest* exact match sequence in
1091     # left-to-right order.
1092     my @ranks = ();
1093     my @dirs = split(/\/+/, $path);
1094     CLASS: foreach my $class (@$cache)
1095     {
1096     # The first two members of $rank are fixed: how much of path
1097     # was and was not used in the match.
1098     my $rank = [[], [@dirs]];
1099     foreach my $component (@$class)
1100     {
1101     my $dir = $rank->[1][0];
1102     if (! defined $dir)
1103     {
1104     # Path exhausted. Leave used/unused as is.
1105     last;
1106     }
1107     elsif ($component->[0] eq "")
1108     {
1109     # Wildcard match, push class and use up path
1110     push(@$rank, [1, $component->[1]]);
1111     push(@{$rank->[0]}, shift(@{$rank->[1]}));
1112     }
1113     elsif ($component->[0] eq $dir)
1114     {
1115     # Exact match, push class and use up path
1116     push(@$rank, [0, $component->[1]]);
1117     push(@{$rank->[0]}, shift(@{$rank->[1]}));
1118     }
1119     else
1120     {
1121     # Unmatched, leave used/unused as is.
1122     last;
1123     }
1124     }
1125    
1126     push(@ranks, $rank);
1127     }
1128    
1129     # If no classes match, bail out:
1130     if (! scalar @ranks)
1131     {
1132     return "";
1133     }
1134    
1135     # Sort in ascending order by how much was of class was not used;
1136     # the first entry has least "extra" trailing match data. Then
1137     # truncate to only those equal to the best rank.
1138     my @sorted = sort { scalar(@{$a->[1]}) <=> scalar(@{$b->[1]}) } @ranks;
1139     my @best = grep(scalar(@{$_->[1]}) == scalar(@{$sorted[0][1]}), @sorted);
1140    
1141     # Now figure which of the best-ranking classes have the longest
1142     # exact match in left-to-right order (= which one is first, and
1143     # those with equal first exact match, longest exact match).
1144     my $n = 0;
1145     my $class = $best[$n][scalar @{$best[$n]}-1];
1146    
1147     # Return the class data:
1148     return [ $class->[1], join('/', @{$best[$n][0]}), join('/', @{$best[$n][1]}) ];
1149     }
1150    
1151     sub storedata
1152     {
1153     my $self=shift;
1154     my ($datapath, $data)=@_;
1155 sashby 1.3
1156 sashby 1.2 # Store the content of this BuildFile in cache:
1157     $self->{BUILDTREE}->{$datapath}->rawdata($data);
1158     return $self;
1159     }
1160    
1161     sub removedata
1162     {
1163     my $self=shift;
1164     my ($removedpaths) = @_;
1165    
1166     foreach my $rd (@$removedpaths)
1167     {
1168     my $datapath = $self->datapath($rd);
1169     # Remove all data, recursively, from $datapath:
1170     $self->recursive_remove_data($datapath);
1171     }
1172    
1173     return $self;
1174     }
1175    
1176     sub recursive_remove_data()
1177     {
1178     my $self=shift;
1179     my ($datapath)=@_;
1180    
1181     # Delete main entry in build data via TreeItem:
1182     if (exists($self->{BUILDTREE}->{$datapath}))
1183     {
1184     # We also must modify the parent TreeItem to remove the child
1185     # from SAFE_SUBDIRS as well as from CHILDREN array:
1186     my $parent = $self->{BUILDTREE}->{$datapath}->parent();
1187     $self->{BUILDTREE}->{$parent}->updatechildlist($datapath);
1188    
1189     # Get the children:
1190     my @children = $self->{BUILDTREE}->{$datapath}->children();
1191    
1192     foreach my $childpath (@children)
1193     {
1194     # The child path value is the datapath so can be used
1195     # directly when deleting data entries
1196     $self->recursive_remove_data($childpath);
1197     }
1198    
1199     # Finally, delete the parent data (a TreeItem):
1200     delete $self->{BUILDTREE}->{$datapath};
1201     }
1202    
1203     # return:
1204     return $self;
1205     }
1206    
1207     sub storebranchmetadata()
1208     {
1209     my $self=shift;
1210     my ($datapath,$data)=@_;
1211    
1212     # Store the content of this BuildFile in cache:
1213     $self->{BUILDTREE}->{$datapath}->branchmetadata($data);
1214     return $self;
1215     }
1216    
1217     sub buildobject
1218     {
1219     my $self=shift;
1220     my ($datapath)=@_;
1221    
1222     if (exists($self->{BUILDTREE}->{$datapath}) && defined($self->{BUILDTREE}->{$datapath}->rawdata()))
1223     {
1224     return $self->{BUILDTREE}->{$datapath}->rawdata();
1225     }
1226     else
1227     {
1228     return undef;
1229     }
1230     }
1231    
1232     sub metaobject
1233     {
1234     my $self=shift;
1235     my ($datapath)=@_;
1236    
1237     if (exists($self->{BUILDTREE}->{$datapath}) && defined($self->{BUILDTREE}->{$datapath}->branchmetadata()))
1238     {
1239     return $self->{BUILDTREE}->{$datapath}->branchmetadata();
1240     }
1241     else
1242     {
1243     return undef;
1244     }
1245     }
1246    
1247     sub addgroup
1248     {
1249     my $self=shift;
1250     my ($grouparray,$datapath)=@_;
1251 sashby 1.6 my $project;
1252 sashby 1.2
1253     foreach my $group (@{$grouparray})
1254     {
1255 sashby 1.6 # Report an error if the group is defined already in a BuildFile
1256     # other than the one at $path (avoids errors because KNOWNGROUPS
1257     # is not reset before re-parsing a BuildFile in which a group is defined):
1258 sashby 1.2 if (exists $self->{KNOWNGROUPS}->{$group}
1259     && $self->{KNOWNGROUPS}->{$group} ne $datapath)
1260     {
1261 sashby 1.6 # Group already exists locally so exit:
1262     print "\n\n";
1263     $::scram->scramerror("Group \"".$group."\", defined in ".$datapath."/BuildFile, is already defined in ".
1264     $self->{KNOWNGROUPS}->{$group}."/BuildFile.\n");
1265     print "\n";
1266     }
1267     elsif ($self->searchprojects($group,\$project))
1268     {
1269     # Group already exists in a scram project so exit:
1270     print "\n\n";
1271     $::scram->scramerror("Group \"".$group."\", defined locally in ".$datapath."/BuildFile, is already defined in ".
1272     $project."\n");
1273     print "\n";
1274 sashby 1.2 }
1275     else
1276     {
1277     $self->{KNOWNGROUPS}->{$group} = $datapath;
1278     }
1279     }
1280     }
1281    
1282 sashby 1.6 sub searchprojects()
1283     {
1284     my $self=shift;
1285     my ($group,$projectref)=@_;
1286    
1287     foreach my $pjt (keys %{$self->{SCRAM_PROJECTS}})
1288     {
1289     print "Checking for group $group in SCRAM project $pjt","\n", if ($ENV{SCRAM_DEBUG});
1290     # As soon as a project is found to have defined $group, we return
1291     # the project name:
1292     if (exists $self->{SCRAM_PROJECTS}->{$pjt}->{KNOWNGROUPS}->{$group})
1293     {
1294     # Store the project name and data path:
1295     $$projectref="project ".uc($pjt)." (".$self->{SCRAM_PROJECTS}->{$pjt}->{KNOWNGROUPS}->{$group}."/BuildFile)";
1296     return(1);
1297     }
1298     }
1299    
1300     # No group found to have been defined already so return false:
1301     return (0);
1302     }
1303    
1304 sashby 1.2 sub findgroup
1305     {
1306     my $self=shift;
1307     my ($groupname) = @_;
1308    
1309     if (exists $self->{KNOWNGROUPS}->{$groupname})
1310     {
1311     # If group exists, return data:
1312     return $self->{KNOWNGROUPS}->{$groupname};
1313     }
1314     else
1315     {
1316     # Not found so return:
1317     return(0);
1318     }
1319     }
1320    
1321     sub knowngroups
1322     {
1323     my $self=shift;
1324     @_ ? $self->{KNOWNGROUPS}=shift
1325     : $self->{KNOWNGROUPS}
1326     }
1327    
1328     sub scramprojects()
1329     {
1330     my $self=shift;
1331     # Need this to be able to read our project cache:
1332     use Cache::CacheUtilities;
1333    
1334     $self->{SCRAM_PROJECTS} = $self->{TOOLMANAGER}->scram_projects();
1335    
1336     # Also store the BASE of each project:
1337     $self->{SCRAM_PROJECT_BASES}={};
1338    
1339     # Load the project cache for every scram-managed project in our toolbox:
1340     while (my ($project, $info) = each %{$self->{SCRAM_PROJECTS}})
1341     {
1342     if ( -f $info."/.SCRAM/".$ENV{SCRAM_ARCH}."/ProjectCache.db")
1343     {
1344     print "Reading cache for ",uc($project),"\n", if ($ENV{SCRAM_DEBUG});
1345     $self->{SCRAM_PROJECTS}->{$project} =
1346     &Cache::CacheUtilities::read($info."/.SCRAM/".$ENV{SCRAM_ARCH}."/ProjectCache.db");
1347     $self->{SCRAM_PROJECT_BASES}->{uc($project)."_BASE"} = $info;
1348     }
1349     else
1350     {
1351     print "WARNING: Unable to read project cache for ",uc($project)," tool.\n", if ($ENV{SCRAM_DEBUG});
1352     print " It could be that the project has not been built for your current architecture.","\n",
1353     if ($ENV{SCRAM_DEBUG});
1354     delete $self->{SCRAM_PROJECTS}->{$project};
1355     }
1356     }
1357    
1358     # Also check to see if we're based on a release area. If so, store the cache as above. Don't store
1359     # the project name but instead just use 'RELEASE':
1360     if (my $releasearea=$::scram->releasearea() && exists $ENV{RELEASETOP})
1361     {
1362     if ( -f $ENV{RELEASETOP}."/.SCRAM/".$ENV{SCRAM_ARCH}."/ProjectCache.db")
1363     {
1364     # OK, so we found the cache. Now read it and store in the projects list:
1365     $self->{SCRAM_PROJECTS}->{RELEASE} =
1366     &Cache::CacheUtilities::read($ENV{RELEASETOP}."/.SCRAM/".$ENV{SCRAM_ARCH}."/ProjectCache.db");
1367     print "OK found release cache ",$self->{SCRAM_PROJECTS}->{RELEASE},"\n", if ($ENV{SCRAM_DEBUG});
1368     }
1369     else
1370     {
1371     print "WARNING: Current area is based on a release area but the project cache does not exist!","\n";
1372     }
1373     }
1374     }
1375    
1376     sub scramprojectbases()
1377     {
1378     my $self=shift;
1379     return $self->{SCRAM_PROJECT_BASES};
1380     }
1381    
1382     sub alldirs
1383     {
1384     my $self=shift;
1385     return @{$self->{ALLDIRS}};
1386     }
1387    
1388 sashby 1.3 sub skipdir
1389     {
1390     my $self=shift;
1391     my ($dir, $message) = @_;
1392    
1393     # Set the info if we have both args:
1394     if ($dir && $message)
1395     {
1396     $self->{SKIPPEDDIRS}->{$dir} = $message;
1397     }
1398     # If we have the dir name only, return true if
1399     # this dir is to be skipped:
1400     elsif ($dir)
1401     {
1402     (exists($self->{SKIPPEDDIRS}->{$dir})) ? return 1 : return 0;
1403     }
1404     else
1405     {
1406     # Dump the list of directories and the message for each:
1407     foreach my $directory (keys %{$self->{SKIPPEDDIRS}})
1408     {
1409     print "Directory \"",$directory,"\" skipped by the build system";
1410     if (length($self->{SKIPPEDDIRS}->{$directory}->[0]) > 10)
1411     {
1412     chomp($self->{SKIPPEDDIRS}->{$directory}->[0]);
1413     my @lines = split("\n",$self->{SKIPPEDDIRS}->{$directory}->[0]); print ":\n";
1414     foreach my $line (@lines)
1415     {
1416     next if ($line =~ /^\s*$/);
1417     print "\t-- ",$line,"\n";
1418     }
1419     print "\n";
1420     }
1421     else
1422     {
1423     print ".","\n";
1424     }
1425     }
1426     }
1427     }
1428    
1429 sashby 1.11 # Keep a record of which packages are missed by each location
1430     # so that, on subsequent updates, these can be inserted auto-
1431     # matically in the metadata for the location:
1432     sub unresolved()
1433     {
1434     my $self=shift;
1435     my ($location, $pneeded) = @_;
1436     # Need to record a mapping "LOCATION -> [ missing packages ]" and a
1437     # reverse-lookup "<missing package> -> [ LOCATIONS (where update required) ]"
1438     $self->{UNRESOLVED_DEPS_BY_LOC}->{$location}->{$pneeded} = 1;
1439     $self->{UNRESOLVED_DEPS_BY_PKG}->{$pneeded}->{$location} = 1;
1440     }
1441    
1442     sub remove_unresolved()
1443     {
1444     my $self=shift;
1445     my ($package, $dir) = @_;
1446     if (exists($self->{UNRESOLVED_DEPS_BY_PKG}->{$package}->{$dir}))
1447     {
1448     delete $self->{UNRESOLVED_DEPS_BY_PKG}->{$package}->{$dir};
1449     # Check to see if there are any keys left. If not, remove the
1450     # package entry:
1451     my $nkeys = scalar(keys %{$self->{UNRESOLVED_DEPS_BY_PKG}->{$package}});
1452     if ($nkeys == 0)
1453     {
1454     delete $self->{UNRESOLVED_DEPS_BY_PKG}->{$package};
1455     }
1456     }
1457     }
1458    
1459     sub unresolved_locations()
1460     {
1461     my $self=shift;
1462     my ($package)=@_;
1463    
1464     if (exists ($self->{UNRESOLVED_DEPS_BY_PKG}->{$package}))
1465     {
1466     # Return locations which miss the metadata of $package:
1467     return [ keys %{$self->{UNRESOLVED_DEPS_BY_PKG}->{$package}} ];
1468     }
1469     }
1470    
1471     sub unresolved_packages()
1472     {
1473     my $self=shift;
1474     my ($location)=@_;
1475    
1476     if (exists ($self->{UNRESOLVED_DEPS_BY_LOC}->{$location}))
1477     {
1478     # Return packages which are needed by $location:
1479     return [ keys %{$self->{UNRESOLVED_DEPS_BY_LOC}->{$location}} ];
1480     }
1481     }
1482    
1483 sashby 1.2 sub verbose
1484     {
1485     my $self=shift;
1486     # Turn on verbose mode:
1487     @_ ? $self->{VERBOSE} = shift
1488     : $self->{VERBOSE}
1489     }
1490    
1491     sub cachestatus()
1492     {
1493     my $self=shift;
1494     # Set/return the status of the cache:
1495     @_ ? $self->{STATUS} = shift
1496     : $self->{STATUS}
1497     }
1498    
1499     sub logmsg
1500     {
1501     my $self=shift;
1502     # Print a message to STDOUT if VERBOSE is true:
1503     print STDERR @_ if $self->verbose();
1504     }
1505    
1506     sub name()
1507     {
1508     my $self=shift;
1509     # Set/return the name of the cache to use:
1510     @_ ? $self->{CACHENAME} = shift
1511     : $self->{CACHENAME}
1512     }
1513    
1514     sub save()
1515     {
1516     my $self=shift;
1517     # Delete unwanted stuff:
1518     delete $self->{DEPENDENCIES};
1519     delete $self->{TOOLMANAGER};
1520     delete $self->{TEMPLATE_ENGINE};
1521     delete $self->{SCRAM_PROJECTS};
1522     delete $self->{SCRAM_PROJECT_BASES};
1523     return $self;
1524     }
1525    
1526 sashby 1.7
1527    
1528    
1529    
1530    
1531    
1532     #### Routines for migrating BuildFile syntax to XML ####
1533     sub scan2xml()
1534     {
1535     my $self=shift;
1536     my ($buildfile) = @_;
1537     print "Migrating $buildfile to XML","\n";
1538     use BuildSystem::BuildFileXMLWriter;
1539     my $bfparse=BuildSystem::BuildFileXMLWriter->new();
1540     $bfparse->parse($buildfile);
1541     return $self;
1542     }
1543    
1544     sub migrate2XML()
1545     {
1546     my $self=shift;
1547     my ($paths)=@_;
1548     my $datapath;
1549     my $buildfile;
1550     $|=1; # Flush
1551    
1552     # Loop over all paths. Apply a sort so that src (shortest path) is first (FIXME!):
1553     foreach my $path (sort(@$paths))
1554     {
1555     # Ignore config content here:
1556     next if ($path !~ m|^\Q$ENV{SCRAM_SOURCEDIR}\L|);
1557    
1558     # If we have the project root (i.e. src), we want to process the
1559     # top-level (project config) BuildFile:
1560     if ($path eq $ENV{SCRAM_SOURCEDIR})
1561     {
1562     $buildfile = $ENV{SCRAM_CONFIGDIR}."/BuildFile";
1563     # Parse the top-level BuildFile. We must do this here
1564     # because we need the ClassPaths. Store as RAWDATA:
1565     $self->scan2xml($buildfile);
1566     next;
1567     }
1568     else
1569     {
1570     $buildfile = $path."/BuildFile";
1571     }
1572    
1573     # If this BuildFile exists, store in METABF:
1574     if ( -f $buildfile )
1575     {
1576     # Scan to resolve groups. Store as RAWDATA:
1577     $self->scan2xml($buildfile);
1578     }
1579     }
1580    
1581     print "\n";
1582     }
1583    
1584 sashby 1.2 1;