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 |
# webget(area,url) : get the url into the cache of the specified area
|
23 |
# getversion() : return the current scram version
|
24 |
# spawnversion(version,@args) : spawn the scram version with the given args
|
25 |
# classverbose(classstring,setting) : Set the class verbosity level
|
26 |
# toolruntime(ConfigArea): Get a runtime object withthe settings from
|
27 |
# the specified toolbox
|
28 |
|
29 |
package Scram::ScramFunctions;
|
30 |
use URL::URLcache;
|
31 |
use Utilities::Verbose;
|
32 |
require 5.004;
|
33 |
|
34 |
@ISA=qw(Utilities::Verbose);
|
35 |
|
36 |
sub new {
|
37 |
my $class=shift;
|
38 |
$self={};
|
39 |
bless $self, $class;
|
40 |
# -- default settings
|
41 |
$self->{cachedir}=$ENV{HOME}."/.scramrc/globalcache";
|
42 |
$self->{scramprojectsdbdir}=$ENV{SCRAM_LOOKUPDB};
|
43 |
($self->{scram_top})=( $ENV{SCRAM_HOME}=~/(.*)\//) ;
|
44 |
|
45 |
return $self;
|
46 |
}
|
47 |
|
48 |
sub classverbose {
|
49 |
my $self=shift;
|
50 |
my $class=shift;
|
51 |
my $val=shift;
|
52 |
|
53 |
$ENV{"VERBOSE_".$class}=$val;
|
54 |
}
|
55 |
|
56 |
sub project {
|
57 |
my $self=shift;
|
58 |
my $url=shift;
|
59 |
my $installarea=shift;
|
60 |
|
61 |
my $areaname="";
|
62 |
if ( @_ ) {
|
63 |
$areaname=shift;
|
64 |
}
|
65 |
require Configuration::BootStrapProject;
|
66 |
my $bs=Configuration::BootStrapProject->
|
67 |
new($self->globalcache(),$installarea);
|
68 |
$self->verbose("BootStrapping $url");
|
69 |
my $area=$bs->boot($url,$areaname);
|
70 |
if ( ! defined $area ) {
|
71 |
$self->error("Unable to create project area");
|
72 |
}
|
73 |
$area->archname($self->arch());
|
74 |
|
75 |
# -- download all tool description files
|
76 |
my $req=$self->arearequirements($area);
|
77 |
if ( defined $req ) {
|
78 |
$req->download($self->areatoolbox($area));
|
79 |
}
|
80 |
|
81 |
return $area;
|
82 |
}
|
83 |
|
84 |
sub setuptoolsinarea {
|
85 |
my $self=shift;
|
86 |
my $area=shift;
|
87 |
|
88 |
# -- initialise
|
89 |
$self->_allprojectinitsearcher();
|
90 |
|
91 |
# -- create a new toolbox object
|
92 |
my $toolbox=$self->areatoolbox($area);
|
93 |
$toolbox->searcher($self->_allprojectinitsearcher());
|
94 |
|
95 |
if ( @_ ) {
|
96 |
# -- specific tool specified
|
97 |
if ( my $rv=$toolbox->toolsetup(@_) ) {
|
98 |
if ( $rv eq 1 ) {
|
99 |
print "Unknown tool $toolname @ARGV\n";
|
100 |
exit 1;
|
101 |
}
|
102 |
}
|
103 |
}
|
104 |
else {
|
105 |
# -- setup all tools specified in the requirements doc
|
106 |
my $reqs=$self->arearequirements($area);
|
107 |
$self->verbose("Setup ToolBox from Requirements doc ($reqs)");
|
108 |
$reqs->setup($toolbox);
|
109 |
}
|
110 |
}
|
111 |
|
112 |
sub satellite {
|
113 |
my $self=shift;
|
114 |
my $name=shift;
|
115 |
my $version=shift;
|
116 |
my $installarea=shift;
|
117 |
|
118 |
my $areaname=undef;
|
119 |
if ( @_ ) {
|
120 |
$areaname=shift;
|
121 |
}
|
122 |
|
123 |
# -- look up scram database for location
|
124 |
my $relarea=$self->_lookupareaindb($name,$version);
|
125 |
if ( ! defined $relarea ) {
|
126 |
$self->error("Unable to Find Project $name $version");
|
127 |
}
|
128 |
|
129 |
# -- fix for old broken areas
|
130 |
if ( (! defined $relarea->version()) || ($relarea->version() eq "") ) {
|
131 |
$relarea->version($version);
|
132 |
}
|
133 |
|
134 |
# -- create satellite
|
135 |
my $area=$relarea->satellite($installarea,$areaname);
|
136 |
$area->archname($self->arch());
|
137 |
|
138 |
# -- copy setup info - deprecated by toolbox copy method
|
139 |
#$relarea->copysetup($area->location());
|
140 |
|
141 |
# -- copy toolbox
|
142 |
my $rtb=$self->areatoolbox($relarea);
|
143 |
my $tb=$self->areatoolbox($area);
|
144 |
$rtb->copytools($tb);
|
145 |
|
146 |
# -- copy configuration directory
|
147 |
if ( ! -d $area->location()."/".$area->configurationdir() ) {
|
148 |
use Utilities::AddDir;
|
149 |
AddDir::copydir($relarea->location()."/".$relarea->configurationdir(),
|
150 |
$area->location()."/".$area->configurationdir() );
|
151 |
}
|
152 |
|
153 |
# -- copy RequirementsDoc
|
154 |
if ( ! -f $area->requirementsdoc() ) {
|
155 |
use File::Copy;
|
156 |
copy( $relarea->requirementsdoc() , $area->requirementsdoc());
|
157 |
}
|
158 |
|
159 |
return $area;
|
160 |
}
|
161 |
|
162 |
sub toolruntime {
|
163 |
my $self=shift;
|
164 |
my $area=shift;
|
165 |
|
166 |
my $name=$area->location();
|
167 |
if ( ! defined $self->{toolruntime}{$name} ) {
|
168 |
require Runtime;
|
169 |
my $toolbox=$self->areatoolbox($area);
|
170 |
$self->{toolruntime}{$name}=Runtime->new();
|
171 |
|
172 |
# -- add scram area specific runtimes
|
173 |
$self->{toolruntime}{$name}->addvar("LD_LIBRARY_PATH",
|
174 |
$area->location()."/lib/".$self->arch(),"path");
|
175 |
$self->{toolruntime}{$name}->addvar("PATH",
|
176 |
$area->location()."/bin/".$self->arch(),"path");
|
177 |
if ( defined $area->linkarea() ) {
|
178 |
my $reltop=$area->linkarea()->location();
|
179 |
$self->{toolruntime}{$name}->addvar("LD_LIBRARY_PATH",
|
180 |
$reltop."/lib/".$self->arch(),"path");
|
181 |
$self->{toolruntime}{$name}->addvar("PATH",
|
182 |
$reltop."/bin/".$self->arch(),"path");
|
183 |
}
|
184 |
|
185 |
# -- get the runtime environment from all the tools
|
186 |
my $tool;
|
187 |
foreach $toolname ( $toolbox->tools() ) {
|
188 |
$tool=$toolbox->gettool($toolname);
|
189 |
if ( defined $tool ) {
|
190 |
# -- get runtime paths
|
191 |
foreach $f ( $tool->listtype("runtime_path")) {
|
192 |
foreach $val ( $tool->getfeature($f) ) {
|
193 |
$self->{toolruntime}{$name}->addvar($f,$val,"path");
|
194 |
}
|
195 |
}
|
196 |
# -- get runtime vars
|
197 |
foreach $f ( $tool->listtype("runtime")) {
|
198 |
foreach $val ( $tool->getfeature($f) ) {
|
199 |
$self->{toolruntime}{$name}->addvar($f,$val);
|
200 |
}
|
201 |
}
|
202 |
}
|
203 |
}
|
204 |
|
205 |
# -- Get the project level environment
|
206 |
my $runtimefile=$area->location()."/".$area->configurationdir()
|
207 |
."/Runtime";
|
208 |
if ( -f $runtimefile ) {
|
209 |
$self->{toolruntime}{$name}->file($runtimefile);
|
210 |
}
|
211 |
}
|
212 |
return $self->{toolruntime}{$name};
|
213 |
}
|
214 |
|
215 |
sub webget {
|
216 |
my $self=shift;
|
217 |
my $area=shift;
|
218 |
my $url=shift;
|
219 |
|
220 |
require URL::URLhandler;
|
221 |
my $handler=URL::URLhandler->new($area->cache());
|
222 |
return ($handler->download($url));
|
223 |
}
|
224 |
|
225 |
sub addareatoDB {
|
226 |
my $self=shift;
|
227 |
my $area=shift;
|
228 |
my $tagname=shift;
|
229 |
my $version=shift;
|
230 |
|
231 |
# -- create defaults if necessary
|
232 |
if ( (! defined $version) || ( $version eq "") ) {
|
233 |
$version=$area->version();
|
234 |
}
|
235 |
if ( (! defined $tagname) || ( $tagname eq "") ) {
|
236 |
$tagname=$area->name();
|
237 |
}
|
238 |
|
239 |
# -- Add to the DB
|
240 |
$self->scramprojectdb()->addarea($tagname,$version,$area);
|
241 |
}
|
242 |
|
243 |
sub spawnversion {
|
244 |
my $self=shift;
|
245 |
my $version=shift;
|
246 |
|
247 |
my $rv=0;
|
248 |
my $thisversion=$self->getversion();
|
249 |
if ( defined $version ) {
|
250 |
if ( $version ne $thisversion ) {
|
251 |
# first try to use the correct version
|
252 |
if ( -d $self->{scram_top}."/".$version ) {
|
253 |
$ENV{SCRAM_HOME}=$self->{scram_top}."/".$version;
|
254 |
$ENV{TOOL_HOME}="$ENV{SCRAM_HOME}/src";
|
255 |
$self->verbose("Spawning SCRAM version $version");
|
256 |
my $rv=system("scram", @_)/256;
|
257 |
exit $rv;
|
258 |
}
|
259 |
else { # if not then simply warn
|
260 |
print "******* Warning : scram version inconsistent ********\n";
|
261 |
print "This version: $thisversion; Required version: $version\n";
|
262 |
print "*****************************************************\n";
|
263 |
print "\n";
|
264 |
}
|
265 |
}
|
266 |
}
|
267 |
else {
|
268 |
$self->error("Undefined value for version requested");
|
269 |
$rv=1;
|
270 |
}
|
271 |
return $rv;
|
272 |
}
|
273 |
|
274 |
sub globalcache {
|
275 |
my $self=shift;
|
276 |
if ( @_ ) {
|
277 |
$self->{cachedir}=shift;
|
278 |
}
|
279 |
if ( ! defined $self->{globalcache} ) {
|
280 |
$self->{globalcache}=URL::URLcache->new($self->{cachedir});
|
281 |
}
|
282 |
return $self->{globalcache};
|
283 |
}
|
284 |
|
285 |
|
286 |
sub scramprojectdb {
|
287 |
my $self=shift;
|
288 |
if ( @_ ) {
|
289 |
$self->{scramprojectsdbdir}=shift;
|
290 |
}
|
291 |
if ( ! defined $self->{scramprojectsdb} ) {
|
292 |
require Scram::ScramProjectDB;
|
293 |
$self->{scramprojectsdb}=Scram::ScramProjectDB->new(
|
294 |
$self->{scramprojectsdbdir} );
|
295 |
$self->{scramprojectsdb}->verbosity($self->verbosity());
|
296 |
}
|
297 |
return $self->{scramprojectsdb};
|
298 |
}
|
299 |
|
300 |
sub getversion {
|
301 |
my $self=shift;
|
302 |
|
303 |
my $thisversion;
|
304 |
($thisversion=$ENV{SCRAM_HOME})=~s/(.*)\///;
|
305 |
my $scram_top=$1;
|
306 |
my $scram_version=$thisversion;
|
307 |
# deal with links
|
308 |
my $version=readlink $ENV{SCRAM_HOME};
|
309 |
if ( defined $version) {
|
310 |
$scram_version=$version;
|
311 |
}
|
312 |
return $scram_version;
|
313 |
}
|
314 |
|
315 |
sub areatoolbox {
|
316 |
my $self=shift;
|
317 |
my $area=shift;
|
318 |
|
319 |
my $name=$area->location();
|
320 |
if ( ! defined $self->{toolboxes}{$name} ) {
|
321 |
# -- create a new toolbox object
|
322 |
require BuildSystem::ToolBox;
|
323 |
$self->{toolboxes}{$name}=BuildSystem::ToolBox->new($area,
|
324 |
$self->arch());
|
325 |
$self->{toolboxes}{$name}->verbosity($self->verbosity());
|
326 |
}
|
327 |
return $self->{toolboxes}{$name};
|
328 |
}
|
329 |
|
330 |
sub arearequirements {
|
331 |
my $self=shift;
|
332 |
my $area=shift;
|
333 |
|
334 |
my $name=$area->location();
|
335 |
if ( ! defined $self->{requirements}{$name} ) {
|
336 |
# -- create a new toolbox object
|
337 |
require BuildSystem::Requirements;
|
338 |
my $doc=$area->requirementsdoc();
|
339 |
my $cache=$area->cache();
|
340 |
my $db=$area->objectstore();
|
341 |
require ActiveDoc::ActiveStore;
|
342 |
my $astore=ActiveDoc::ActiveStore->new($db,$cache);
|
343 |
$self->{requirements}{$name}=
|
344 |
BuildSystem::Requirements->new($astore,"file:".$doc,
|
345 |
$ENV{SCRAM_ARCH});
|
346 |
$self->{requirements}{$name}->verbosity($self->verbosity());
|
347 |
$self->verbose("Requirements Doc (".$self->{requirements}{$name}.
|
348 |
") for area :\n $name\n initiated from $doc");
|
349 |
}
|
350 |
else {
|
351 |
$self->verbose("Requirements Doc (".$self->{requirements}{$name}.")");
|
352 |
}
|
353 |
return $self->{requirements}{$name};
|
354 |
}
|
355 |
|
356 |
sub arch {
|
357 |
my $self=shift;
|
358 |
|
359 |
@_?$self->{arch}=shift
|
360 |
:$self->{arch};
|
361 |
}
|
362 |
|
363 |
sub scramobjectinterface {
|
364 |
my $self=shift;
|
365 |
my $class=shift;
|
366 |
|
367 |
my $file;
|
368 |
($file=$class."\.pm")=~s/::/\//g;
|
369 |
$file=$ENV{TOOL_HOME}."/".$file;
|
370 |
|
371 |
if ( ! -f $file ) {
|
372 |
$self->error("Unable to find $class in ".$ENV{TOOL_HOME});
|
373 |
}
|
374 |
print "--------------------- $class ------------------\n";
|
375 |
my $fh=FileHandle->new();
|
376 |
$fh->open("<$file");
|
377 |
while ( <$fh> ) {
|
378 |
if ( $_=~/#\s*Interface/g ) {
|
379 |
$intregion=1;
|
380 |
next;
|
381 |
}
|
382 |
if ( $intregion ) { # if we are in the interface documentation
|
383 |
if ( ( $_!~/^#/ ) || ( $_=~/^#\s?-{40}/ ) ) { #moving out of Int doc
|
384 |
$intregion=0;
|
385 |
next;
|
386 |
}
|
387 |
print $_;
|
388 |
if ( $_=~/^#\s*(.*)\((.*)\)?:(.*)/ ) {
|
389 |
$interface=$1;
|
390 |
$args=$2;
|
391 |
$rest=$3;
|
392 |
next if ($interface eq "");
|
393 |
push @interfaces,$interface;
|
394 |
$interfaceargs{$interface}=$args;
|
395 |
}
|
396 |
}
|
397 |
}
|
398 |
print "\n";
|
399 |
undef $fh;
|
400 |
}
|
401 |
|
402 |
# -------------- Support Routines ------------------------------
|
403 |
|
404 |
|
405 |
sub _allprojectinitsearcher {
|
406 |
if ( ! defined $self->{projsearcher} ) {
|
407 |
my $search=_projsearcher();
|
408 |
foreach $proj ( $self->scramprojectdb()->list() ) {
|
409 |
$search->addproject($$proj[0],$$proj[1]);
|
410 |
}
|
411 |
}
|
412 |
return $self->{projsearcher};
|
413 |
}
|
414 |
|
415 |
sub _projsearcher {
|
416 |
if ( ! defined $self->{projsearcher} ) {
|
417 |
require Scram::ProjectSearcher;
|
418 |
$self->{projsearcher}=Scram::ProjectSearcher->new(
|
419 |
$self->scramprojectdb());
|
420 |
}
|
421 |
return $self->{projsearcher};
|
422 |
}
|
423 |
|
424 |
|
425 |
sub _lookupareaindb {
|
426 |
my $self=shift;
|
427 |
|
428 |
my $area=undef;
|
429 |
# -- Look up the area in the databse
|
430 |
my @areas=$self->scramprojectdb()->getarea(@_);
|
431 |
if ( $#areas > 0 ) { #ambigous
|
432 |
# could ask user - for now just error
|
433 |
$self->error("Ambigous request - please be more specific");
|
434 |
}
|
435 |
elsif ( $#areas != 0 ) { #not found
|
436 |
$self->error("The project requested has not been found");
|
437 |
}
|
438 |
else {
|
439 |
$area=$areas[0];
|
440 |
}
|
441 |
return $area;
|
442 |
}
|