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

# Content
1 # 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
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 use ActiveDoc::ActiveDoc;
25 use Utilities::Verbose;
26
27 require 5.004;
28 @ISA=qw(Utilities::Verbose);
29 $BuildSystem::Requirements::self;
30
31 sub new
32 {
33 my $class=shift;
34 # Initialise the global package variable:
35 no strict 'refs';
36 $self = defined $self ? $self
37 : (bless {}, $class );
38 $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 $self->{mydoctype} = "BuildSystem::Requirements";
48 $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
68 sub configversion
69 {
70 my $self=shift;
71 @_ ? $self->{configversion} = shift
72 : $self->{configversion};
73 }
74
75 sub url
76 {
77 my $self=shift;
78
79 if ( @_ )
80 {
81 $self->{file}=shift;
82 }
83 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 }
110
111 sub version
112 {
113 my $self=shift;
114 my $tool=shift;
115 return $self->{'version'}{$tool};
116 }
117
118 sub toolurl
119 {
120 my $self=shift;
121 my $tool=shift;
122 return $self->{'url'}{$tool};
123 }
124
125 sub init
126 {
127 my $self=shift;
128 my $url=shift;
129 my $scramdoc=ActiveDoc::ActiveDoc->new($self->{dbstore});
130 $scramdoc->verbosity($self->verbosity());
131 $scramdoc->url($url);
132 $scramdoc->newparse("ordering",$self->{mydoctype},'Subs');
133 $self->{reqcontext}=0;
134 $self->{scramdoc}=$scramdoc;
135 undef $self->{restrictstack};
136 @{$self->{tools}}=();
137 @{$self->{ArchStack}}=();
138 $self->verbose("Initial Document Parse");
139 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 # 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 }
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 {
162 $self->{arch}="";
163 }
164 }
165 return $self->{arch};
166 }
167
168 sub archlist
169 {
170 my $self=shift;
171 return @{$self->{ArchStack}};
172 }
173
174 sub getreqforarch
175 {
176 my $self=shift;
177 my $arch=shift;
178
179 if ( ! defined $self->{reqsforarch}{$arch} )
180 {
181 $self->{reqsforarch}{$arch}=
182 BuildSystem::Requirements->new($self->{dbstore},$self->{file},
183 $arch);
184 }
185 return $self->{reqsforarch}{$arch};
186 }
187
188 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 # get into the cache:
201 $self->{scramdoc}->urlget($self->toolurl($tool));
202 }
203 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 }
214
215 #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
226 sub require()
227 {
228 my $self=shift;
229 my $name=shift;
230 my $hashref=shift;
231
232 $self->{scramdoc}->checktag( $name, $hashref, 'version');
233 $self->{scramdoc}->checktag( $name, $hashref, 'name');
234 $self->{scramdoc}->checktag( $name, $hashref, 'url');
235
236 if ( $self->{reqcontext} == 1 )
237 {
238 $self->{scramdoc}->parseerror(
239 "Open new $name context without previous </$name>");
240 }
241 $self->{reqcontext}=1;
242 $$hashref{'name'}=~tr[A-Z][a-z];
243
244 # Add protection so that architecture tags are obeyed during download:
245 if ( $self->{Arch} )
246 {
247 # 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 my $urlobj=$self->{scramdoc}->expandurl($$hashref{'url'});
268 $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 $self->{scramdoc}->parseerror("No matching tag for </$name>");
296 }
297 else
298 {
299 $self->{reqcontext}=0;
300 }
301 }
302
303 sub select_start
304 {
305 my $self=shift;
306 my $name=shift;
307 my $hashref=shift;
308
309 $self->{scramdoc}->checktag( $name, $hashref, 'name');
310 $$hashref{'name'}=~tr[A-Z][a-z];
311 if ( $self->{Arch} )
312 {
313 $self->verbose("Selecting ".$$hashref{'name'});
314 # Increment counter:
315 $self->{selectcounter}++;
316 $self->{selected}{$$hashref{'name'}}=$self->{selectcounter};
317 }
318 }
319
320 sub Arch_Start
321 {
322 my $self=shift;
323 my $name=shift;
324 my $hashref=shift;
325
326 # Check the architecture tag:
327 $self->{scramdoc}->checktag($name, $hashref,'name');
328 ( ($self->arch()=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
329 : ($self->{Arch}=0);
330
331 $self->verbose(($self->{Arch}?"OK":"skipping")." ".$$hashref{name});
332 push @{$self->{ARCHBLOCK}}, $self->{Arch};
333 push @{$self->{ArchStack}}, $$hashref{'name'};
334 }
335
336 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
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;