ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/Requirements.pm
Revision: 1.26
Committed: Fri Jan 14 17:36:42 2011 UTC (14 years, 3 months ago) by muzaffar
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.25: +0 -0 lines
State: FILE REMOVED
Log Message:
merged SCRAM_V2 branch in to head

File Contents

# User Rev Content
1 williamc 1.2 # Requirements Doc - just to get ordering info
2     #
3     # Interface
4     # ---------
5     # new(ActiveStore,url[,arch]) : new requirements doc
6     # setup(toolbox): set up the requirements into the specified toolbox object
7     # download(toolbox) : download description files (into toolbox cache)
8     # tools() : Return list of ALL requirements (ordered)
9     # selectedtools() : Return list of only those tools selected
10     # version(tool) : return the version of a given tool
11     # toolurl(tool) : return the url of a given tool
12     # getreqforarch(arch) : Return a RequirementsObject corresponding to the
13     # specified architecture
14     # toolcomment(tool,version) : return the comment string for the specified tool
15     # distributionurl(tool,version) : return the dist info url for the tool
16    
17     package BuildSystem::Requirements;
18 sashby 1.23
19     BEGIN
20     {
21     die "\n\n".__PACKAGE__.": this package has been moved to Configuration::Requirements. This one is obsolete and can be removed.\n\n";
22     }
23    
24 williamc 1.2 use ActiveDoc::ActiveDoc;
25     use Utilities::Verbose;
26    
27     require 5.004;
28     @ISA=qw(Utilities::Verbose);
29 sashby 1.23 $BuildSystem::Requirements::self;
30 williamc 1.2
31 sashby 1.20 sub new
32     {
33     my $class=shift;
34 sashby 1.23 # Initialise the global package variable:
35     no strict 'refs';
36     $self = defined $self ? $self
37     : (bless {}, $class );
38 sashby 1.20 $self->{dbstore}=shift;
39     $self->{file}=shift;
40     $self->{cache}=$self->{dbstore}->cache();
41    
42     if ( @_ )
43     {
44     $self->arch(shift);
45     }
46     $self->verbose("Initialising a new Requirements Doc");
47 sashby 1.23 $self->{mydoctype} = "BuildSystem::Requirements";
48 sashby 1.20 $self->{mydocversion}="2.0";
49     # Counter for downloaded tools: zero it here. It will
50     # be auto-incremented as each tool is selected:
51     $self->{selectcounter}=0;
52    
53     $self->{Arch}=1;
54     push @{$self->{ARCHBLOCK}}, $self->{Arch};
55     $self->init($self->{file});
56     return $self;
57     }
58    
59     sub toolmanager
60     {
61     my $self=shift;
62    
63     @_ ? $self->{toolmanagerobject} = shift
64     : $self->{toolmanagerobject};
65    
66     }
67 williamc 1.2
68 sashby 1.20 sub configversion
69 sashby 1.7 {
70     my $self=shift;
71 sashby 1.20 @_ ? $self->{configversion} = shift
72     : $self->{configversion};
73     }
74 sashby 1.7
75 sashby 1.20 sub url
76     {
77     my $self=shift;
78    
79     if ( @_ )
80 sashby 1.7 {
81 sashby 1.20 $self->{file}=shift;
82 sashby 1.7 }
83 sashby 1.20 return $self->{file};
84     }
85    
86     sub tools
87     {
88     my $self=shift;
89     return @{$self->{tools}};
90     }
91    
92     sub toolcomment
93     {
94     my $self=shift;
95     my $tool=shift;
96     my $version=shift;
97    
98     return $self->{reqtext}{$tool}{$version};
99     }
100    
101     sub distributionurl
102     {
103     my $self=shift;
104     my $tool=shift;
105     my $version=shift;
106    
107     return ( defined $self->{dist}{$tool}{$version})?
108     $self->{dist}{$tool}{$version}:undef;
109 sashby 1.7 }
110 williamc 1.2
111 sashby 1.20 sub version
112     {
113     my $self=shift;
114     my $tool=shift;
115     return $self->{'version'}{$tool};
116     }
117 williamc 1.2
118 sashby 1.20 sub toolurl
119     {
120     my $self=shift;
121     my $tool=shift;
122     return $self->{'url'}{$tool};
123     }
124 sashby 1.11
125 sashby 1.20 sub init
126 sashby 1.8 {
127 sashby 1.11 my $self=shift;
128 sashby 1.20 my $url=shift;
129 sashby 1.23 my $scramdoc=ActiveDoc::ActiveDoc->new($self->{dbstore});
130     $scramdoc->verbosity($self->verbosity());
131     $scramdoc->url($url);
132     $scramdoc->newparse("ordering",$self->{mydoctype},'Subs');
133 sashby 1.20 $self->{reqcontext}=0;
134 sashby 1.23 $self->{scramdoc}=$scramdoc;
135 sashby 1.20 undef $self->{restrictstack};
136     @{$self->{tools}}=();
137 sashby 1.23 @{$self->{ArchStack}}=();
138     $self->verbose("Initial Document Parse");
139 muzaffar 1.25 my $fhead='<?xml version="1.0" encoding="UTF-8" standalone="yes"?<doc type="BuildSystem::Requirements" version="2.0">';
140     my $ftail='</doc>';
141     $self->{scramdoc}->parse("ordering",$fhead,$ftail);
142 sashby 1.23 # Set the config version. If there isn't a version, it means that we
143     # have a stand-alone repository for the toolbox, rather than a CVS
144     # one. Hence, no CVS tag (== version):
145     ($scramdoc->{configurl}->param('version') eq '') ?
146     $self->configversion("STANDALONE") :
147     $self->configversion($scramdoc->{configurl}->param('version'));
148 sashby 1.20 }
149    
150     sub arch
151     {
152     my $self=shift;
153     # $self->arch is the SCRAM_ARCH value:
154     if ( @_ )
155     {
156     $self->{arch}=shift;
157     }
158     else
159     {
160     if ( ! defined $self->{arch} )
161 sashby 1.11 {
162 sashby 1.20 $self->{arch}="";
163 sashby 1.11 }
164     }
165 sashby 1.20 return $self->{arch};
166 sashby 1.11 }
167    
168 sashby 1.20 sub archlist
169     {
170     my $self=shift;
171     return @{$self->{ArchStack}};
172     }
173 sashby 1.11
174 sashby 1.20 sub getreqforarch
175 sashby 1.11 {
176 sashby 1.8 my $self=shift;
177 sashby 1.20 my $arch=shift;
178 sashby 1.11
179 sashby 1.20 if ( ! defined $self->{reqsforarch}{$arch} )
180 sashby 1.8 {
181 sashby 1.20 $self->{reqsforarch}{$arch}=
182     BuildSystem::Requirements->new($self->{dbstore},$self->{file},
183     $arch);
184 sashby 1.8 }
185 sashby 1.20 return $self->{reqsforarch}{$arch};
186 sashby 1.8 }
187 sashby 1.11
188 sashby 1.13 sub download
189     {
190     my $self=shift;
191     my $tool;
192     $| = 1; # Unbuffer the output
193    
194     print "Downloading tool descriptions....","\n";
195     print " ";
196     foreach $tool ( $self->tools() )
197     {
198     print "#";
199     $self->verbose("Downloading ".$self->toolurl($tool));
200 sashby 1.20 # get into the cache:
201 sashby 1.23 $self->{scramdoc}->urlget($self->toolurl($tool));
202 sashby 1.13 }
203 sashby 1.20 print "\nDone.","\n";
204     # So now add the list of downloaded tools, and which were
205     # selected, to tool cache:
206     print "Tool info cached locally.","\n","\n";
207    
208     # Now copy required info from this object to ToolManager (ToolCache):
209     $self->toolmanager()->downloadedtools($self->{tools});
210     $self->toolmanager()->defaultversions($self->{version});
211     $self->toolmanager()->toolurls($self->{url});
212     $self->toolmanager()->selected($self->{selected});
213 sashby 1.13 }
214 williamc 1.2
215 sashby 1.23 #sub _autoselect
216     # {
217     # my $self=shift;
218     # if ( @_ )
219     # {
220     # $self->{autoselect}=shift;
221     # }
222     # # -- default is true
223     # return ((defined $self->{autoselect})?$self->{autoselect}:1);
224     # }
225 williamc 1.2
226 sashby 1.23 sub require()
227 sashby 1.8 {
228     my $self=shift;
229     my $name=shift;
230     my $hashref=shift;
231 sashby 1.20
232 sashby 1.23 $self->{scramdoc}->checktag( $name, $hashref, 'version');
233     $self->{scramdoc}->checktag( $name, $hashref, 'name');
234     $self->{scramdoc}->checktag( $name, $hashref, 'url');
235 sashby 1.20
236     if ( $self->{reqcontext} == 1 )
237     {
238 sashby 1.23 $self->{scramdoc}->parseerror(
239 sashby 1.20 "Open new $name context without previous </$name>");
240     }
241     $self->{reqcontext}=1;
242 sashby 1.8 $$hashref{'name'}=~tr[A-Z][a-z];
243 sashby 1.20
244     # Add protection so that architecture tags are obeyed during download:
245 sashby 1.8 if ( $self->{Arch} )
246     {
247 sashby 1.20 # Add tool to the tool array:
248     push @{$self->{tools}}, $$hashref{'name'};
249    
250     # If the tool already has an entry, modify the version string to
251     # include both versions. The versions can later be separated and
252     # parsed as normal:
253     if (defined $self->{version}{$$hashref{'name'}})
254     {
255     # Don't need an extra entry for this tool onto tool array:
256     pop @{$self->{tools}}, $$hashref{'name'};
257     # Modify the version string to append the other tool version.
258     # Separate using a colon:
259     my $newversion=$self->{version}{$$hashref{'name'}}.":".$$hashref{'version'};
260     $self->{version}{$$hashref{'name'}}=$newversion;
261     }
262     else
263     {
264     $self->{version}{$$hashref{'name'}}=$$hashref{'version'};
265     }
266     # -- make sure the full url is taken
267 sashby 1.23 my $urlobj=$self->{scramdoc}->expandurl($$hashref{'url'});
268 sashby 1.20 $self->{url}{$$hashref{'name'}}=$urlobj->url();
269    
270     $self->{creqtool}=$$hashref{'name'};
271     $self->{creqversion}=$$hashref{'version'};
272     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}="";
273     }
274     }
275    
276     sub require_text
277     {
278     my $self=shift;
279     my $name=shift;
280     my $string=shift;
281    
282     chomp $string;
283     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}=
284     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}.
285     $string;
286     }
287    
288     sub require_end
289     {
290     my $self=shift;
291     my $name=shift;
292    
293     if ( $self->{reqcontext} != 1 )
294     {
295 sashby 1.23 $self->{scramdoc}->parseerror("No matching tag for </$name>");
296 sashby 1.20 }
297     else
298     {
299     $self->{reqcontext}=0;
300 sashby 1.8 }
301     }
302    
303 sashby 1.20 sub select_start
304 sashby 1.8 {
305     my $self=shift;
306     my $name=shift;
307     my $hashref=shift;
308 sashby 1.20
309 sashby 1.23 $self->{scramdoc}->checktag( $name, $hashref, 'name');
310 sashby 1.8 $$hashref{'name'}=~tr[A-Z][a-z];
311     if ( $self->{Arch} )
312     {
313 sashby 1.20 $self->verbose("Selecting ".$$hashref{'name'});
314     # Increment counter:
315     $self->{selectcounter}++;
316     $self->{selected}{$$hashref{'name'}}=$self->{selectcounter};
317 sashby 1.8 }
318     }
319 williamc 1.2
320 sashby 1.14 sub Arch_Start
321     {
322     my $self=shift;
323     my $name=shift;
324     my $hashref=shift;
325 sashby 1.20
326 sashby 1.14 # Check the architecture tag:
327 sashby 1.23 $self->{scramdoc}->checktag($name, $hashref,'name');
328 sashby 1.20 ( ($self->arch()=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
329     : ($self->{Arch}=0);
330 sashby 1.19
331 sashby 1.14 $self->verbose(($self->{Arch}?"OK":"skipping")." ".$$hashref{name});
332     push @{$self->{ARCHBLOCK}}, $self->{Arch};
333     push @{$self->{ArchStack}}, $$hashref{'name'};
334     }
335 williamc 1.2
336 sashby 1.20 sub Arch_End
337     {
338     my $self=shift;
339     my $name=shift;
340     pop @{$self->{ARCHBLOCK}};
341     $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
342     }
343    
344     sub disttag
345     {
346     my $self=shift;
347     my $name=shift;
348     my $hashref=shift;
349    
350     if ( exists $$hashref{'url'} )
351     {
352     $self->{dist}{$self->{creqtool}}{$self->{creqversion}}=
353     $$hashref{'url'};
354     }
355     }
356 sashby 1.23
357     sub select()
358     {
359     my ($xmlparser,$name,%attributes)=@_;
360     # print "Selecting ".$attributes{'name'},"\n";
361     }
362    
363     sub select_()
364     {}
365    
366     sub AUTOLOAD()
367     {
368     my ($xmlparser,$name,%attributes)=@_;
369     return if $AUTOLOAD =~ /::DESTROY$/;
370     my $name=$AUTOLOAD;
371     $name =~ s/.*://;
372     # Delegate missing function calls to the doc parser class:
373     $self->{scramdoc}->$name(%attributes);
374     }
375    
376     1;