ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Scram/ScramFunctions.pm
Revision: 1.5.2.1
Committed: Thu Sep 21 12:45:19 2000 UTC (24 years, 7 months ago) by williamc
Content type: text/plain
Branch: V0_15branch
CVS Tags: V0_16_0, V0_15_1, V0_15_0, V0_15_0beta
Branch point for: V0_16branch
Changes since 1.5: +52 -1 lines
Log Message:
Add scram version routines + new ToolBox interface

File Contents

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