ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Scram/ScramFunctions.pm
Revision: 1.1.2.5
Committed: Mon Aug 14 15:36:07 2000 UTC (24 years, 9 months ago) by williamc
Content type: text/plain
Branch: HPWbranch
CVS Tags: V0_14_0
Changes since 1.1.2.4: +1 -0 lines
Log Message:
Add verbose comments

File Contents

# Content
1 #
2 # ScramFunctions.pm
3 #
4 # Written by Christopher Williams
5 #
6 # Description
7 #
8 # Interface
9 # ---------
10 # new() : A new ScramCommands object
11 # project(urlstring,dir[,areaname]): Create a project from the given url file
12 # return the area
13 # satellite(name,version,installdirectory[,areaname]): create a satellite
14 # project from the specified name version
15 # addareatoDB(ConfigArea[,name[,version]]) : add area to the db
16 # globalcache([cachedirectory])) : return the global cache object/set at dir.
17 # scramprojectdb() : return the scram project DB object
18 # areatoolbox(ConfigArea) : return the toolbox of the specified area
19 # setuptoolsinarea($area[,$toolname[,$toolversion[,toolfile]) : setup
20 # arch() : get/set the architecture string
21
22 package Scram::ScramFunctions;
23 use URL::URLcache;
24 use Utilities::Verbose;
25 require 5.004;
26
27 @ISA=qw(Utilities::Verbose);
28
29 sub new {
30 my $class=shift;
31 $self={};
32 bless $self, $class;
33 # -- default settings
34 $self->{cachedir}=$ENV{HOME}."/.SCRAM/globalcache";
35 $self->{scramprojectsdbdir}=$ENV{SCRAM_LOOKUPDB};
36 return $self;
37 }
38
39 sub project {
40 my $self=shift;
41 my $url=shift;
42 my $installarea=shift;
43
44 my $areaname="";
45 if ( @_ ) {
46 $areaname=shift;
47 }
48 require Configuration::BootStrapProject;
49 my $bs=Configuration::BootStrapProject->
50 new($self->globalcache(),$installarea);
51 $self->verbose("BootStrapping $url");
52 my $area=$bs->boot($url,$areaname);
53 $area->archname($self->arch());
54
55 # -- download all tool description files
56 my $req=$self->arearequirements($area);
57 if ( defined $req ) {
58 $req->download($self->areatoolbox($area));
59 }
60
61 return $area;
62 }
63
64 sub setuptoolsinarea {
65 my $self=shift;
66 my $area=shift;
67
68 # -- initialise
69 $self->_allprojectinitsearcher();
70
71 # -- create a new toolbox object
72 my $toolbox=$self->areatoolbox($area);
73 $toolbox->searcher($self->_projsearcher());
74
75 if ( @_ ) {
76 # -- specific tool specified
77 if ( my $rv=$toolbox->toolsetup(@_) ) {
78 if ( $rv eq 1 ) {
79 print "Unknown tool $toolname @ARGV\n";
80 exit 1;
81 }
82 }
83 }
84 else {
85 # -- setup all tools specified in the requirements doc
86 my $reqs=$self->arearequirements($area);
87 $self->verbose("Setup ToolBox from Requirements doc ($reqs)");
88 $reqs->setup($toolbox);
89 }
90 }
91
92 sub satellite {
93 my $self=shift;
94 my $name=shift;
95 my $version=shift;
96 my $installarea=shift;
97
98 my $areaname="";
99 if ( @_ ) {
100 $areaname=shift;
101 }
102
103 # -- look up scram database for location
104 my $relarea=$self->_lookupareaindb($name,$version);
105 if ( ! defined $relarea ) {
106 $self->error("Unable to Find Project $name $version");
107 }
108
109 # -- create satellite
110 my $area=$relarea->satellite($installarea,$areaname);
111 $area->archname($self->arch());
112
113 # -- copy setup info - deprecated by toolbox copy method
114 #$relarea->copysetup($area->location());
115
116 # -- copy toolbox
117 my $rtb=$self->areatoolbox($relarea);
118 my $tb=$self->areatoolbox($area);
119 $rtb->copytools($tb);
120
121 # -- copy configuration directory
122 if ( ! -d $area->location()."/".$area->configurationdir() ) {
123 use Utilities::AddDir;
124 AddDir::copydir($relarea->location()."/".$relarea->configurationdir(),
125 $area->location()."/".$area->configurationdir() );
126 }
127
128 # -- copy RequirementsDoc
129 if ( ! -f $area->requirementsdoc() ) {
130 copy( $relarea->requirementsdoc() , $area->requirementsdoc());
131 }
132
133 return $area;
134 }
135
136 sub addareatoDB {
137 my $self=shift;
138 my $area=shift;
139 my $tagname=shift;
140 my $version=shift;
141
142 # -- create defaults if necessary
143 if ( (! defined $version) || ( $version eq "") ) {
144 $version=$area->version();
145 }
146 if ( (! defined $tagname) || ( $tagname eq "") ) {
147 $tagname=$area->name();
148 }
149
150 # -- Add to the DB
151 $self->scramprojectdb()->addarea($tagname,$version,$area);
152 }
153
154 sub globalcache {
155 my $self=shift;
156 if ( @_ ) {
157 $self->{cachedir}=shift;
158 }
159 if ( ! defined $self->{globalcache} ) {
160 $self->{globalcache}=URL::URLcache->new($self->{cachedir});
161 }
162 return $self->{globalcache};
163 }
164
165
166 sub scramprojectdb {
167 my $self=shift;
168 if ( @_ ) {
169 $self->{scramprojectsdbdir}=shift;
170 }
171 if ( ! defined $self->{scramprojectsdb} ) {
172 require Scram::ScramProjectDB;
173 $self->{scramprojectsdb}=Scram::ScramProjectDB->new(
174 $self->{scramprojectsdbdir} );
175 $self->{scramprojectsdb}->verbosity($self->verbosity());
176 }
177 return $self->{scramprojectsdb};
178 }
179
180 sub areatoolbox {
181 my $self=shift;
182 my $area=shift;
183
184 my $name=$area->location();
185 if ( ! defined $self->{toolboxes}{$name} ) {
186 # -- create a new toolbox object
187 require BuildSystem::ToolBox;
188 $self->{toolboxes}{$name}=BuildSystem::ToolBox->new($area);
189 $self->{toolboxes}{$name}->verbosity($self->verbosity());
190 }
191 return $self->{toolboxes}{$name};
192 }
193
194 sub arearequirements {
195 my $self=shift;
196 my $area=shift;
197
198 my $name=$area->location();
199 if ( ! defined $self->{requirements}{$name} ) {
200 # -- create a new toolbox object
201 require BuildSystem::Requirements;
202 my $doc=$area->requirementsdoc();
203 my $cache=$area->cache();
204 $self->{requirements}{$name}=
205 BuildSystem::Requirements->new($doc,$cache);
206 $self->{requirements}{$name}->verbosity($self->verbosity());
207 $self->verbose("Requirements Doc (".$self->{requirements}{$name}.
208 ") for area :\n $name\n initiated from $doc");
209 }
210 else {
211 $self->verbose("Requirements Doc (".$self->{requirements}{$name}.")");
212 }
213 return $self->{requirements}{$name};
214 }
215
216 sub arch {
217 my $self=shift;
218
219 @_?$self->{arch}=shift
220 :$self->{arch};
221 }
222
223 # -------------- Support Routines ------------------------------
224
225
226 sub _allprojectinitsearcher {
227 if ( ! defined $self->{projsearcher} ) {
228 my $search=_projsearcher();
229 foreach $proj ( $self->scramprojectdb()->list() ) {
230 $search->addproject($$proj[0],$$proj[1]);
231 }
232 }
233 }
234
235 sub _projsearcher {
236 if ( ! defined $self->{projsearcher} ) {
237 require Scram::ProjectSearcher;
238 $self->{projsearcher}=Scram::ProjectSearcher->new(
239 $self->scramprojectdb());
240 }
241 return $self->{projsearcher};
242 }
243
244
245 sub _lookupareaindb {
246 my $self=shift;
247
248 my $area=undef;
249 # -- Look up the area in the databse
250 my @areas=$self->scramprojectdb()->getarea(@_);
251 if ( $#areas > 0 ) { #ambigous
252 # could ask user - for now just error
253 $self->error("Ambigous request - please be more specific");
254 }
255 elsif ( $#areas != 0 ) { #not found
256 $self->error("The project requested has not been found");
257 }
258 else {
259 $area=$areas[0];
260 }
261 return $area;
262 }