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