1 |
sashby |
1.7 |
=head1 NAME
|
2 |
|
|
|
3 |
|
|
Configuration::BootStrapProject - File parsing utilities for boot files.
|
4 |
|
|
|
5 |
|
|
=head1 SYNOPSIS
|
6 |
|
|
|
7 |
|
|
my $obj = Configuration::BootStrapProject->new([$area]);
|
8 |
|
|
|
9 |
|
|
=head1 DESCRIPTION
|
10 |
|
|
|
11 |
|
|
Package containing functions for parsing bootstrap files (project initialisation documents).
|
12 |
|
|
|
13 |
|
|
=head1 METHODS
|
14 |
|
|
|
15 |
|
|
=over
|
16 |
|
|
|
17 |
|
|
=cut
|
18 |
|
|
|
19 |
|
|
=item C<new($cache,$installbase)>
|
20 |
|
|
|
21 |
|
|
A new bootstrapper.
|
22 |
|
|
|
23 |
|
|
=item C<boot(url[,$devareaname])>
|
24 |
|
|
|
25 |
|
|
Boot up a new project and return the Configuration::ConfigArea.
|
26 |
|
|
|
27 |
|
|
=back
|
28 |
|
|
|
29 |
|
|
=head1 AUTHOR
|
30 |
|
|
|
31 |
|
|
Originally written by Christopher Williams.
|
32 |
|
|
|
33 |
|
|
=head1 MAINTAINER
|
34 |
|
|
|
35 |
|
|
Shaun ASHBY
|
36 |
|
|
|
37 |
|
|
=cut
|
38 |
williamc |
1.2 |
|
39 |
|
|
package Configuration::BootStrapProject;
|
40 |
|
|
use ActiveDoc::SimpleURLDoc;
|
41 |
|
|
use URL::URLhandler;
|
42 |
|
|
use Utilities::Verbose;
|
43 |
|
|
require 5.004;
|
44 |
|
|
|
45 |
|
|
@ISA=qw(Utilities::Verbose);
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
sub new {
|
49 |
|
|
my $class=shift;
|
50 |
|
|
my $self={};
|
51 |
|
|
bless $self, $class;
|
52 |
sashby |
1.5 |
$self->{havesourcedir}=0;
|
53 |
williamc |
1.2 |
$self->{cache}=shift;
|
54 |
|
|
$self->{baselocation}=shift;
|
55 |
sashby |
1.5 |
if ( @_ )
|
56 |
|
|
{
|
57 |
|
|
$self->{area}=shift;
|
58 |
|
|
}
|
59 |
williamc |
1.2 |
$self->{mydoctype}="Configuration::BootStrapProject";
|
60 |
|
|
$self->{mydocversion}="1.0";
|
61 |
|
|
$self->{Arch}=1;
|
62 |
|
|
push @{$self->{ARCHBLOCK}}, $self->{Arch};
|
63 |
|
|
return $self;
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
sub _initswitcher {
|
67 |
|
|
my $self=shift;
|
68 |
|
|
my $switch=ActiveDoc::SimpleURLDoc->new($self->{cache});
|
69 |
|
|
my $parse="boot";
|
70 |
|
|
$switch->newparse($parse);
|
71 |
|
|
$switch->addbasetags($parse);
|
72 |
|
|
$switch->addtag($parse,"RequirementsDoc", \&ReqDoc_start, $self,
|
73 |
|
|
\&print_text, $self,
|
74 |
|
|
\&ReqDoc_end, $self);
|
75 |
|
|
$switch->addtag($parse,"config", \&Config_start, $self,
|
76 |
|
|
"", $self,
|
77 |
|
|
"", $self);
|
78 |
|
|
$switch->addtag($parse,"project", \&Project_start, $self,
|
79 |
|
|
\&print_text, $self,
|
80 |
|
|
\&Project_end, $self);
|
81 |
|
|
$switch->addtag($parse,"download", \&GetToTop_start, $self,
|
82 |
|
|
\&print_text, $self,
|
83 |
|
|
"", $self);
|
84 |
sashby |
1.5 |
$switch->addtag($parse,"SourceCode",
|
85 |
|
|
\&Srcdir_Start,$self,
|
86 |
|
|
\&Srcdir_text, $self,
|
87 |
|
|
\&Srcdir_end,$self);
|
88 |
williamc |
1.2 |
$self->{switch}=$switch;
|
89 |
|
|
}
|
90 |
|
|
|
91 |
sashby |
1.5 |
sub _initswitcherDL
|
92 |
|
|
{
|
93 |
|
|
my $self=shift;
|
94 |
|
|
my $switch=ActiveDoc::SimpleURLDoc->new($self->{cache});
|
95 |
|
|
my $parse="bootupd";
|
96 |
|
|
$switch->newparse($parse);
|
97 |
|
|
$switch->addbasetags($parse);
|
98 |
|
|
$switch->addtag($parse,"download", \&GetToTop_start, $self,
|
99 |
|
|
\&print_text, $self,
|
100 |
|
|
"", $self);
|
101 |
|
|
$self->{switch}=$switch;
|
102 |
|
|
}
|
103 |
|
|
|
104 |
williamc |
1.2 |
sub boot {
|
105 |
|
|
my $self=shift;
|
106 |
|
|
my $url=shift;
|
107 |
sashby |
1.6 |
my $filemode = 0644;
|
108 |
williamc |
1.2 |
|
109 |
|
|
# -- override directory name
|
110 |
|
|
if ( @_ ) {
|
111 |
|
|
$self->{devareaname}=shift;
|
112 |
|
|
}
|
113 |
|
|
else {
|
114 |
|
|
$self->{devareaname}="";
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
# -- initialise file parser
|
118 |
|
|
$self->_initswitcher();
|
119 |
|
|
my ($fullurl,$filename)=$self->{switch}->urldownload($url);
|
120 |
sashby |
1.6 |
chmod $filemode,$filename;
|
121 |
|
|
|
122 |
williamc |
1.2 |
$self->{switch}->filetoparse($filename);
|
123 |
|
|
|
124 |
|
|
# -- document version check
|
125 |
|
|
my ($doctype,$docversion)=$self->{switch}->doctype();
|
126 |
|
|
if ( ( $doctype ne $self->{mydoctype}) &&
|
127 |
|
|
( $docversion ne $self->{mydocversion}) ) {
|
128 |
|
|
$self->{switch}->parseerror("Can Only process documents of type ".
|
129 |
|
|
$self->{mydoctype}." version ".$self->{mydocversion}.
|
130 |
|
|
"\nAre you sure you are using the correct scram version?");
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
$self->{switch}->parse("boot");
|
134 |
|
|
return $self->{area};
|
135 |
|
|
}
|
136 |
|
|
|
137 |
sashby |
1.5 |
sub bootupdate
|
138 |
|
|
{
|
139 |
|
|
my $self=shift;
|
140 |
|
|
my $url=shift;
|
141 |
sashby |
1.6 |
my $filemode = 0644;
|
142 |
|
|
|
143 |
sashby |
1.5 |
# -- initialise file parser for download only (doesn't care about other tags):
|
144 |
|
|
$self->_initswitcherDL();
|
145 |
|
|
my ($fullurl,$filename)=$self->{switch}->urldownload($url);
|
146 |
sashby |
1.6 |
chmod $filemode,$filename;
|
147 |
|
|
|
148 |
sashby |
1.5 |
$self->{switch}->filetoparse($filename);
|
149 |
|
|
|
150 |
|
|
# -- document version check
|
151 |
|
|
my ($doctype,$docversion)=$self->{switch}->doctype();
|
152 |
|
|
$self->{switch}->parse("bootupd");
|
153 |
|
|
return $self->{area};
|
154 |
|
|
}
|
155 |
|
|
|
156 |
williamc |
1.2 |
# --- Tag Routines
|
157 |
|
|
|
158 |
|
|
sub print_text {
|
159 |
|
|
my $self=shift;
|
160 |
|
|
my $name=shift;
|
161 |
|
|
my @text=shift;
|
162 |
|
|
|
163 |
|
|
print "@text\n";
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
sub Project_start {
|
167 |
|
|
my $self=shift;
|
168 |
|
|
my $name=shift;
|
169 |
|
|
my $hashref=shift;
|
170 |
|
|
|
171 |
|
|
$self->{switch}->checktag($name, $hashref, 'name');
|
172 |
|
|
$self->{switch}->checktag($name, $hashref, 'version');
|
173 |
|
|
print "Installing Project $$hashref{'name'} ".
|
174 |
|
|
"Version $$hashref{'version'}\n";
|
175 |
|
|
$self->{area}=Configuration::ConfigArea->new();
|
176 |
|
|
$self->{area}->name($$hashref{'name'});
|
177 |
|
|
$self->{area}->version($$hashref{'version'});
|
178 |
|
|
$self->{area}->setup($self->{baselocation});
|
179 |
|
|
# new urlhandler based on area cache
|
180 |
|
|
$self->{switch}->cache($self->{area}->cache());
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
sub Project_end {
|
184 |
|
|
my $self=shift;
|
185 |
sashby |
1.5 |
# Check to make sure we have a SourceDir tag. Otherwise,
|
186 |
|
|
# assume that src is source directory:
|
187 |
|
|
if ($self->{havesourcedir} ne 1)
|
188 |
|
|
{
|
189 |
|
|
$self->{area}->sourcedir('src');
|
190 |
|
|
$ENV{SCRAM_SOURCEDIR} = $self->{area}->sourcedir();
|
191 |
|
|
}
|
192 |
williamc |
1.2 |
$self->{area}->save();
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
# Set where the project specific configuration files live for the project
|
196 |
sashby |
1.4 |
sub Config_start
|
197 |
|
|
{
|
198 |
|
|
my $self=shift;
|
199 |
|
|
my $name=shift;
|
200 |
|
|
my $hashref=shift;
|
201 |
|
|
|
202 |
|
|
$self->{switch}->checktag($name, $hashref, "dir");
|
203 |
|
|
$$hashref{'dir'}=~s/`//g;
|
204 |
sashby |
1.5 |
##`
|
205 |
sashby |
1.4 |
# Set the project config dir variable here so that
|
206 |
|
|
# "projconfigdir" value can be used while bootstrapping:
|
207 |
sashby |
1.5 |
$ENV{SCRAM_CONFIGDIR} = $$hashref{'dir'};
|
208 |
sashby |
1.4 |
$self->{area}->configurationdir($$hashref{'dir'});
|
209 |
|
|
}
|
210 |
williamc |
1.2 |
|
211 |
|
|
sub ReqDoc_start {
|
212 |
|
|
my $self=shift;
|
213 |
|
|
my $name=shift;
|
214 |
|
|
my $hashref=shift;
|
215 |
|
|
|
216 |
|
|
my ($filename,$fullurl);
|
217 |
|
|
if ( exists $$hashref{'url'} ) {
|
218 |
|
|
# -- download into our cache
|
219 |
|
|
($fullurl,$filename)=$self->{switch}->urlget($$hashref{'url'});
|
220 |
|
|
}
|
221 |
|
|
else {
|
222 |
|
|
$self->{switch}->checktag($name, $hashref, "name");
|
223 |
|
|
$filename=$$hashref{'name'};
|
224 |
|
|
}
|
225 |
|
|
$self->{area}->requirementsdoc($filename);
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
sub GetToTop_start {
|
229 |
|
|
my $self=shift;
|
230 |
|
|
my $name=shift;
|
231 |
|
|
my $hashref=shift;
|
232 |
|
|
|
233 |
|
|
$self->{switch}->checktag($name, $hashref, "url");
|
234 |
|
|
$self->{switch}->checktag($name, $hashref, "name");
|
235 |
|
|
|
236 |
|
|
# -- download into top directory
|
237 |
|
|
my ($fullurl,$filename)=$self->{switch}->urlget($$hashref{'url'},
|
238 |
|
|
$self->{area}->location()."/".$$hashref{'name'});
|
239 |
|
|
}
|
240 |
sashby |
1.5 |
|
241 |
|
|
|
242 |
|
|
# Moved from BuildFile.pm:
|
243 |
|
|
sub Srcdir_Start
|
244 |
|
|
{
|
245 |
|
|
###############################################################
|
246 |
|
|
# Srcdir_Start #
|
247 |
|
|
###############################################################
|
248 |
|
|
# modified : Wed Apr 2 15:47:04 2003 / SFA #
|
249 |
|
|
# params : #
|
250 |
|
|
# : #
|
251 |
|
|
# function : Set INTsrc usig a build file tag. #
|
252 |
|
|
# : #
|
253 |
|
|
###############################################################
|
254 |
|
|
my $self=shift;
|
255 |
|
|
my $name=shift;
|
256 |
|
|
my $hashref=shift;
|
257 |
|
|
|
258 |
|
|
$self->verbose(">> Srcdir_Start: NM ".$name." <<");
|
259 |
|
|
|
260 |
|
|
$self->{switch}->checktag( $name, $hashref, 'dir' );
|
261 |
|
|
my $dir=$$hashref{'dir'};
|
262 |
|
|
$self->{area}->sourcedir($$hashref{'dir'});
|
263 |
|
|
# If this environment var is set here, the dir
|
264 |
|
|
# will be created in the project subroutine:
|
265 |
|
|
$ENV{SCRAM_SOURCEDIR} = $self->{area}->sourcedir();
|
266 |
|
|
}
|
267 |
|
|
|
268 |
|
|
sub Srcdir_text
|
269 |
|
|
{
|
270 |
|
|
###############################################################
|
271 |
|
|
# Srcdir_text #
|
272 |
|
|
###############################################################
|
273 |
|
|
# modified : Wed Apr 2 15:47:04 2003 / SFA #
|
274 |
|
|
# params : #
|
275 |
|
|
# : #
|
276 |
|
|
# function : #
|
277 |
|
|
# : #
|
278 |
|
|
###############################################################
|
279 |
|
|
my $self=shift;
|
280 |
|
|
my $name=shift;
|
281 |
|
|
my @text=shift;
|
282 |
|
|
|
283 |
|
|
print "@text\n";
|
284 |
|
|
|
285 |
|
|
}
|
286 |
|
|
|
287 |
|
|
sub Srcdir_end
|
288 |
|
|
{
|
289 |
|
|
###############################################################
|
290 |
|
|
# Srcdir_end #
|
291 |
|
|
###############################################################
|
292 |
|
|
# modified : Wed Apr 2 15:47:04 2003 / SFA #
|
293 |
|
|
# params : #
|
294 |
|
|
# : #
|
295 |
|
|
# function : #
|
296 |
|
|
# : #
|
297 |
|
|
###############################################################
|
298 |
|
|
my $self=shift;
|
299 |
|
|
my $name=shift;
|
300 |
|
|
my $hashref=shift;
|
301 |
|
|
$self->{havesourcedir} = 1; # To signal that we have a dir
|
302 |
|
|
}
|
303 |
sashby |
1.7 |
|