ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Scram/ScramFunctions.pm
Revision: 1.6
Committed: Wed Sep 6 08:14:46 2000 UTC (24 years, 8 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.5: +40 -0 lines
Log Message:
Add scramobjectinterface method

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 # scramobjectinterface(Class) : print out the interface of a scram class
22
23 package Scram::ScramFunctions;
24 use URL::URLcache;
25 use Utilities::Verbose;
26 require 5.004;
27
28 @ISA=qw(Utilities::Verbose);
29
30 sub new {
31 my $class=shift;
32 $self={};
33 bless $self, $class;
34 # -- default settings
35 $self->{cachedir}=$ENV{HOME}."/.scramrc/globalcache";
36 $self->{scramprojectsdbdir}=$ENV{SCRAM_LOOKUPDB};
37 return $self;
38 }
39
40 sub project {
41 my $self=shift;
42 my $url=shift;
43 my $installarea=shift;
44
45 my $areaname="";
46 if ( @_ ) {
47 $areaname=shift;
48 }
49 require Configuration::BootStrapProject;
50 my $bs=Configuration::BootStrapProject->
51 new($self->globalcache(),$installarea);
52 $self->verbose("BootStrapping $url");
53 my $area=$bs->boot($url,$areaname);
54 if ( ! defined $area ) {
55 $self->error("Unable to create project area");
56 }
57 $area->archname($self->arch());
58
59 # -- download all tool description files
60 my $req=$self->arearequirements($area);
61 if ( defined $req ) {
62 $req->download($self->areatoolbox($area));
63 }
64
65 return $area;
66 }
67
68 sub setuptoolsinarea {
69 my $self=shift;
70 my $area=shift;
71
72 # -- initialise
73 $self->_allprojectinitsearcher();
74
75 # -- create a new toolbox object
76 my $toolbox=$self->areatoolbox($area);
77 $toolbox->searcher($self->_projsearcher());
78
79 if ( @_ ) {
80 # -- specific tool specified
81 if ( my $rv=$toolbox->toolsetup(@_) ) {
82 if ( $rv eq 1 ) {
83 print "Unknown tool $toolname @ARGV\n";
84 exit 1;
85 }
86 }
87 }
88 else {
89 # -- setup all tools specified in the requirements doc
90 my $reqs=$self->arearequirements($area);
91 $self->verbose("Setup ToolBox from Requirements doc ($reqs)");
92 $reqs->setup($toolbox);
93 }
94 }
95
96 sub satellite {
97 my $self=shift;
98 my $name=shift;
99 my $version=shift;
100 my $installarea=shift;
101
102 my $areaname=undef;
103 if ( @_ ) {
104 $areaname=shift;
105 }
106
107 # -- look up scram database for location
108 my $relarea=$self->_lookupareaindb($name,$version);
109 if ( ! defined $relarea ) {
110 $self->error("Unable to Find Project $name $version");
111 }
112
113 # -- fix for old broken areas
114 if ( (! defined $relarea->version()) || ($relarea->version() eq "") ) {
115 $relarea->version($version);
116 }
117
118 # -- create satellite
119 my $area=$relarea->satellite($installarea,$areaname);
120 $area->archname($self->arch());
121
122 # -- copy setup info - deprecated by toolbox copy method
123 #$relarea->copysetup($area->location());
124
125 # -- copy toolbox
126 my $rtb=$self->areatoolbox($relarea);
127 my $tb=$self->areatoolbox($area);
128 $rtb->copytools($tb);
129
130 # -- copy configuration directory
131 if ( ! -d $area->location()."/".$area->configurationdir() ) {
132 use Utilities::AddDir;
133 AddDir::copydir($relarea->location()."/".$relarea->configurationdir(),
134 $area->location()."/".$area->configurationdir() );
135 }
136
137 # -- copy RequirementsDoc
138 if ( ! -f $area->requirementsdoc() ) {
139 use File::Copy;
140 copy( $relarea->requirementsdoc() , $area->requirementsdoc());
141 }
142
143 return $area;
144 }
145
146 sub addareatoDB {
147 my $self=shift;
148 my $area=shift;
149 my $tagname=shift;
150 my $version=shift;
151
152 # -- create defaults if necessary
153 if ( (! defined $version) || ( $version eq "") ) {
154 $version=$area->version();
155 }
156 if ( (! defined $tagname) || ( $tagname eq "") ) {
157 $tagname=$area->name();
158 }
159
160 # -- Add to the DB
161 $self->scramprojectdb()->addarea($tagname,$version,$area);
162 }
163
164 sub globalcache {
165 my $self=shift;
166 if ( @_ ) {
167 $self->{cachedir}=shift;
168 }
169 if ( ! defined $self->{globalcache} ) {
170 $self->{globalcache}=URL::URLcache->new($self->{cachedir});
171 }
172 return $self->{globalcache};
173 }
174
175
176 sub scramprojectdb {
177 my $self=shift;
178 if ( @_ ) {
179 $self->{scramprojectsdbdir}=shift;
180 }
181 if ( ! defined $self->{scramprojectsdb} ) {
182 require Scram::ScramProjectDB;
183 $self->{scramprojectsdb}=Scram::ScramProjectDB->new(
184 $self->{scramprojectsdbdir} );
185 $self->{scramprojectsdb}->verbosity($self->verbosity());
186 }
187 return $self->{scramprojectsdb};
188 }
189
190 sub areatoolbox {
191 my $self=shift;
192 my $area=shift;
193
194 my $name=$area->location();
195 if ( ! defined $self->{toolboxes}{$name} ) {
196 # -- create a new toolbox object
197 require BuildSystem::ToolBox;
198 $self->{toolboxes}{$name}=BuildSystem::ToolBox->new($area);
199 $self->{toolboxes}{$name}->verbosity($self->verbosity());
200 }
201 return $self->{toolboxes}{$name};
202 }
203
204 sub arearequirements {
205 my $self=shift;
206 my $area=shift;
207
208 my $name=$area->location();
209 if ( ! defined $self->{requirements}{$name} ) {
210 # -- create a new toolbox object
211 require BuildSystem::Requirements;
212 my $doc=$area->requirementsdoc();
213 my $cache=$area->cache();
214 my $db=$area->objectstore();
215 require ActiveDoc::ActiveStore;
216 my $astore=ActiveDoc::ActiveStore->new($db,$cache);
217 $self->{requirements}{$name}=
218 BuildSystem::Requirements->new($astore,"file:".$doc,
219 $ENV{SCRAM_ARCH});
220 $self->{requirements}{$name}->verbosity($self->verbosity());
221 $self->verbose("Requirements Doc (".$self->{requirements}{$name}.
222 ") for area :\n $name\n initiated from $doc");
223 }
224 else {
225 $self->verbose("Requirements Doc (".$self->{requirements}{$name}.")");
226 }
227 return $self->{requirements}{$name};
228 }
229
230 sub arch {
231 my $self=shift;
232
233 @_?$self->{arch}=shift
234 :$self->{arch};
235 }
236
237 sub scramobjectinterface {
238 my $self=shift;
239 my $class=shift;
240
241 my $file;
242 ($file=$class."\.pm")=~s/::/\//g;
243 $file=$ENV{TOOL_HOME}."/".$file;
244
245 if ( ! -f $file ) {
246 $self->error("Unable to find $class in ".$ENV{TOOL_HOME});
247 }
248 print "--------------------- $class ------------------\n";
249 my $fh=FileHandle->new();
250 $fh->open("<$file");
251 while ( <$fh> ) {
252 if ( $_=~/#\s*Interface/g ) {
253 $intregion=1;
254 next;
255 }
256 if ( $intregion ) { # if we are in the interface documentation
257 if ( ( $_!~/^#/ ) || ( $_=~/^#\s?-{40}/ ) ) { #moving out of Int doc
258 $intregion=0;
259 next;
260 }
261 print $_;
262 if ( $_=~/^#\s*(.*)\((.*)\)?:(.*)/ ) {
263 $interface=$1;
264 $args=$2;
265 $rest=$3;
266 next if ($interface eq "");
267 push @interfaces,$interface;
268 $interfaceargs{$interface}=$args;
269 }
270 }
271 }
272 print "\n";
273 undef $fh;
274 }
275
276 # -------------- Support Routines ------------------------------
277
278
279 sub _allprojectinitsearcher {
280 if ( ! defined $self->{projsearcher} ) {
281 my $search=_projsearcher();
282 foreach $proj ( $self->scramprojectdb()->list() ) {
283 $search->addproject($$proj[0],$$proj[1]);
284 }
285 }
286 }
287
288 sub _projsearcher {
289 if ( ! defined $self->{projsearcher} ) {
290 require Scram::ProjectSearcher;
291 $self->{projsearcher}=Scram::ProjectSearcher->new(
292 $self->scramprojectdb());
293 }
294 return $self->{projsearcher};
295 }
296
297
298 sub _lookupareaindb {
299 my $self=shift;
300
301 my $area=undef;
302 # -- Look up the area in the databse
303 my @areas=$self->scramprojectdb()->getarea(@_);
304 if ( $#areas > 0 ) { #ambigous
305 # could ask user - for now just error
306 $self->error("Ambigous request - please be more specific");
307 }
308 elsif ( $#areas != 0 ) { #not found
309 $self->error("The project requested has not been found");
310 }
311 else {
312 $area=$areas[0];
313 }
314 return $area;
315 }