ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/Requirements.pm
(Generate patch)

Comparing COMP/SCRAM/src/BuildSystem/Requirements.pm (file contents):
Revision 1.1.2.4 by williamc, Thu May 4 15:45:07 2000 UTC vs.
Revision 1.26 by muzaffar, Fri Jan 14 17:36:42 2011 UTC

# Line 2 | Line 2
2   #
3   # Interface
4   # ---------
5 < # new(file)     : new requirements doc
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 requirements (ordered)
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 < # url(tool)     : return the url 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 < use ActiveDoc::SimpleDoc;
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 <        my $class=shift;
33 <        my $self={};
34 <        bless $self, $class;
35 <        $self->{file}=shift;
36 <        $self->{Arch}=1;
37 <        push @{$self->{ARCHBLOCK}}, $self->{Arch};
38 <        $self->init($self->{file});
39 <        return $self;
40 < }
41 <
42 < sub setup {
43 <        my $self=shift;
44 <        my $toolbox=shift;
45 <
46 <        my $tool;
47 <        foreach $tool ( $self->tools() ) {
48 <          $toolbox->toolsetup($tool, $self->version($tool), $self->url($tool));
49 <        }
50 < }
51 <
52 < sub tools {
53 <        my $self=shift;
54 <        return @{$self->{tools}};
55 < }
56 <
57 < sub version {
58 <        my $self=shift;
59 <        my $tool=shift;
60 <        return $self->{'version'}{$tool};
61 < }
62 <
63 < sub url {
64 <        my $self=shift;
65 <        my $tool=shift;
66 <        return $self->{'url'}{$tool};
67 < }
68 <
69 < sub init {
70 <        my $self=shift;
71 <        my $file=shift;
72 <
73 <        my $switch=ActiveDoc::SimpleDoc->new();
74 <        $switch->filetoparse($file);
75 <        $switch->newparse("doc");
76 <        $switch->addtag("doc","Doc", \&Doc_start,$self,"",$self,"",$self);
77 <        $switch->newparse("ordering");
78 <        $switch->addtag("ordering","Architecture",
79 <                                        \&Arch_Start,$self,
80 <                                        "", $self,
81 <                                        \&Arch_End, $self);
82 <        $switch->grouptag("Architecture","ordering");
83 <        $switch->addtag("ordering","require",
84 <                                        \&require_start,$self,
85 <                                        "", $self,
86 <                                        "", $self);
87 <        $self->{switch}=$switch;
88 <        @{$self->{tools}}=();
89 <        
90 <        $self->{switch}->parse("doc");
91 <        # -- for backwards compatability only parse if we have a docversion
92 <        #    defined
93 <        if ( defined $self->{docversion} ) {
94 <          $self->{switch}->parse("ordering");
95 <        }
96 < }
97 <
98 < sub download {
99 <        my $self=shift;
100 <        my $toolbox=shift;
101 <
102 <        my $tool;
103 <        foreach $tool ( $self->tools() ) {
104 <          $self->verbose("Downloading ".$self->url($tool));
105 <          $toolbox->_download($self->url($tool));
106 <        }
107 < }
108 <
109 < # ---- Tag routines
110 <
111 < sub Doc_start {
112 <        my $self=shift;
113 <        my $name=shift;
114 <        my $hashref=shift;
115 <
116 <        $self->{switch}->checktag( $name, $hashref, 'type');
117 <        $self->{switch}->checktag( $name, $hashref, 'version');
118 <
119 <        $self->{docversion}=$$hashref{'version'};
120 < }
121 <
122 < sub require_start {
123 <        my $self=shift;
124 <        my $name=shift;
125 <        my $hashref=shift;
126 <        
127 <        $self->{switch}->checktag( $name, $hashref, 'version');
128 <        $self->{switch}->checktag( $name, $hashref, 'name');
129 <        $self->{switch}->checktag( $name, $hashref, 'file');
130 <        if ( $self->{Arch} ) {
131 <          push @{$self->{tools}}, $$hashref{'name'};
132 <          $self->{version}{$$hashref{'name'}}=$$hashref{'version'};
133 <          $self->{url}{$$hashref{'name'}}=$$hashref{'file'};
134 <        }
135 < }
136 <
137 < sub Arch_Start {
138 <        my $self=shift;
139 <        my $name=shift;
140 <        my $hashref=shift;
141 <
142 <        $self->{switch}->checktag($name, $hashref,'name');
143 <        ( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
144 <                                                : ($self->{Arch}=0);
145 <        push @{$self->{ARCHBLOCK}}, $self->{Arch};
146 < }
147 <
148 < sub Arch_End {
149 <        my $self=shift;
150 <        my $name=shift;
151 <
152 <        pop @{$self->{ARCHBLOCK}};
153 <        $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
154 < }
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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines