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