ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Configuration/BootStrapProject.pm
Revision: 1.6
Committed: Fri Feb 4 16:04:55 2005 UTC (20 years, 3 months ago) by sashby
Content type: text/plain
Branch: MAIN
CVS Tags: v102p1, V1_0_1
Changes since 1.5: +7 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 williamc 1.2 # 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 sashby 1.5 $self->{havesourcedir}=0;
22 williamc 1.2 $self->{cache}=shift;
23     $self->{baselocation}=shift;
24 sashby 1.5 if ( @_ )
25     {
26     $self->{area}=shift;
27     }
28 williamc 1.2 $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 sashby 1.5 $switch->addtag($parse,"SourceCode",
54     \&Srcdir_Start,$self,
55     \&Srcdir_text, $self,
56     \&Srcdir_end,$self);
57 williamc 1.2 $self->{switch}=$switch;
58     }
59    
60 sashby 1.5 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 williamc 1.2 sub boot {
74     my $self=shift;
75     my $url=shift;
76 sashby 1.6 my $filemode = 0644;
77 williamc 1.2
78     # -- override directory name
79     if ( @_ ) {
80     $self->{devareaname}=shift;
81     }
82     else {
83     $self->{devareaname}="";
84     }
85    
86     # -- initialise file parser
87     $self->_initswitcher();
88     my ($fullurl,$filename)=$self->{switch}->urldownload($url);
89 sashby 1.6 chmod $filemode,$filename;
90    
91 williamc 1.2 $self->{switch}->filetoparse($filename);
92    
93     # -- document version check
94     my ($doctype,$docversion)=$self->{switch}->doctype();
95     if ( ( $doctype ne $self->{mydoctype}) &&
96     ( $docversion ne $self->{mydocversion}) ) {
97     $self->{switch}->parseerror("Can Only process documents of type ".
98     $self->{mydoctype}." version ".$self->{mydocversion}.
99     "\nAre you sure you are using the correct scram version?");
100     }
101    
102     $self->{switch}->parse("boot");
103     return $self->{area};
104     }
105    
106 sashby 1.5 sub bootupdate
107     {
108     my $self=shift;
109     my $url=shift;
110 sashby 1.6 my $filemode = 0644;
111    
112 sashby 1.5 # -- initialise file parser for download only (doesn't care about other tags):
113     $self->_initswitcherDL();
114     my ($fullurl,$filename)=$self->{switch}->urldownload($url);
115 sashby 1.6 chmod $filemode,$filename;
116    
117 sashby 1.5 $self->{switch}->filetoparse($filename);
118    
119     # -- document version check
120     my ($doctype,$docversion)=$self->{switch}->doctype();
121     $self->{switch}->parse("bootupd");
122     return $self->{area};
123     }
124    
125 williamc 1.2 # --- Tag Routines
126    
127     sub print_text {
128     my $self=shift;
129     my $name=shift;
130     my @text=shift;
131    
132     print "@text\n";
133     }
134    
135     sub Project_start {
136     my $self=shift;
137     my $name=shift;
138     my $hashref=shift;
139    
140     $self->{switch}->checktag($name, $hashref, 'name');
141     $self->{switch}->checktag($name, $hashref, 'version');
142     print "Installing Project $$hashref{'name'} ".
143     "Version $$hashref{'version'}\n";
144     $self->{area}=Configuration::ConfigArea->new();
145     $self->{area}->name($$hashref{'name'});
146     $self->{area}->version($$hashref{'version'});
147     $self->{area}->setup($self->{baselocation});
148     # new urlhandler based on area cache
149     $self->{switch}->cache($self->{area}->cache());
150     }
151    
152     sub Project_end {
153     my $self=shift;
154 sashby 1.5 # Check to make sure we have a SourceDir tag. Otherwise,
155     # assume that src is source directory:
156     if ($self->{havesourcedir} ne 1)
157     {
158     $self->{area}->sourcedir('src');
159     $ENV{SCRAM_SOURCEDIR} = $self->{area}->sourcedir();
160     }
161 williamc 1.2 $self->{area}->save();
162     }
163    
164     # Set where the project specific configuration files live for the project
165 sashby 1.4 sub Config_start
166     {
167     my $self=shift;
168     my $name=shift;
169     my $hashref=shift;
170    
171     $self->{switch}->checktag($name, $hashref, "dir");
172     $$hashref{'dir'}=~s/`//g;
173 sashby 1.5 ##`
174 sashby 1.4 # Set the project config dir variable here so that
175     # "projconfigdir" value can be used while bootstrapping:
176 sashby 1.5 $ENV{SCRAM_CONFIGDIR} = $$hashref{'dir'};
177 sashby 1.4 $self->{area}->configurationdir($$hashref{'dir'});
178     }
179 williamc 1.2
180     sub ReqDoc_start {
181     my $self=shift;
182     my $name=shift;
183     my $hashref=shift;
184    
185     my ($filename,$fullurl);
186     if ( exists $$hashref{'url'} ) {
187     # -- download into our cache
188     ($fullurl,$filename)=$self->{switch}->urlget($$hashref{'url'});
189     }
190     else {
191     $self->{switch}->checktag($name, $hashref, "name");
192     $filename=$$hashref{'name'};
193     }
194     $self->{area}->requirementsdoc($filename);
195     }
196    
197     sub GetToTop_start {
198     my $self=shift;
199     my $name=shift;
200     my $hashref=shift;
201    
202     $self->{switch}->checktag($name, $hashref, "url");
203     $self->{switch}->checktag($name, $hashref, "name");
204    
205     # -- download into top directory
206     my ($fullurl,$filename)=$self->{switch}->urlget($$hashref{'url'},
207     $self->{area}->location()."/".$$hashref{'name'});
208     }
209 sashby 1.5
210    
211     # Moved from BuildFile.pm:
212     sub Srcdir_Start
213     {
214     ###############################################################
215     # Srcdir_Start #
216     ###############################################################
217     # modified : Wed Apr 2 15:47:04 2003 / SFA #
218     # params : #
219     # : #
220     # function : Set INTsrc usig a build file tag. #
221     # : #
222     ###############################################################
223     my $self=shift;
224     my $name=shift;
225     my $hashref=shift;
226    
227     $self->verbose(">> Srcdir_Start: NM ".$name." <<");
228    
229     $self->{switch}->checktag( $name, $hashref, 'dir' );
230     my $dir=$$hashref{'dir'};
231     $self->{area}->sourcedir($$hashref{'dir'});
232     # If this environment var is set here, the dir
233     # will be created in the project subroutine:
234     $ENV{SCRAM_SOURCEDIR} = $self->{area}->sourcedir();
235     }
236    
237     sub Srcdir_text
238     {
239     ###############################################################
240     # Srcdir_text #
241     ###############################################################
242     # modified : Wed Apr 2 15:47:04 2003 / SFA #
243     # params : #
244     # : #
245     # function : #
246     # : #
247     ###############################################################
248     my $self=shift;
249     my $name=shift;
250     my @text=shift;
251    
252     print "@text\n";
253    
254     }
255    
256     sub Srcdir_end
257     {
258     ###############################################################
259     # Srcdir_end #
260     ###############################################################
261     # modified : Wed Apr 2 15:47:04 2003 / SFA #
262     # params : #
263     # : #
264     # function : #
265     # : #
266     ###############################################################
267     my $self=shift;
268     my $name=shift;
269     my $hashref=shift;
270     $self->{havesourcedir} = 1; # To signal that we have a dir
271     }