ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Scram/ScramFunctions.pm
Revision: 1.3
Committed: Wed Aug 30 09:31:31 2000 UTC (24 years, 8 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.2: +1 -0 lines
Log Message:
Give context for copy

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    
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     if ( ! defined $area ) {
54     $self->error("Unable to create project area");
55     }
56     $area->archname($self->arch());
57    
58     # -- download all tool description files
59     my $req=$self->arearequirements($area);
60     if ( defined $req ) {
61     $req->download($self->areatoolbox($area));
62     }
63    
64     return $area;
65     }
66    
67     sub setuptoolsinarea {
68     my $self=shift;
69     my $area=shift;
70    
71     # -- initialise
72     $self->_allprojectinitsearcher();
73    
74     # -- create a new toolbox object
75     my $toolbox=$self->areatoolbox($area);
76     $toolbox->searcher($self->_projsearcher());
77    
78     if ( @_ ) {
79     # -- specific tool specified
80     if ( my $rv=$toolbox->toolsetup(@_) ) {
81     if ( $rv eq 1 ) {
82     print "Unknown tool $toolname @ARGV\n";
83     exit 1;
84     }
85     }
86     }
87     else {
88     # -- setup all tools specified in the requirements doc
89     my $reqs=$self->arearequirements($area);
90     $self->verbose("Setup ToolBox from Requirements doc ($reqs)");
91     $reqs->setup($toolbox);
92     }
93     }
94    
95     sub satellite {
96     my $self=shift;
97     my $name=shift;
98     my $version=shift;
99     my $installarea=shift;
100    
101     my $areaname="";
102     if ( @_ ) {
103     $areaname=shift;
104     }
105    
106     # -- look up scram database for location
107     my $relarea=$self->_lookupareaindb($name,$version);
108     if ( ! defined $relarea ) {
109     $self->error("Unable to Find Project $name $version");
110     }
111    
112     # -- create satellite
113     my $area=$relarea->satellite($installarea,$areaname);
114     $area->archname($self->arch());
115    
116     # -- copy setup info - deprecated by toolbox copy method
117     #$relarea->copysetup($area->location());
118    
119     # -- copy toolbox
120     my $rtb=$self->areatoolbox($relarea);
121     my $tb=$self->areatoolbox($area);
122     $rtb->copytools($tb);
123    
124     # -- copy configuration directory
125     if ( ! -d $area->location()."/".$area->configurationdir() ) {
126     use Utilities::AddDir;
127     AddDir::copydir($relarea->location()."/".$relarea->configurationdir(),
128     $area->location()."/".$area->configurationdir() );
129     }
130    
131     # -- copy RequirementsDoc
132     if ( ! -f $area->requirementsdoc() ) {
133 williamc 1.3 use File::Copy;
134 williamc 1.2 copy( $relarea->requirementsdoc() , $area->requirementsdoc());
135     }
136    
137     return $area;
138     }
139    
140     sub addareatoDB {
141     my $self=shift;
142     my $area=shift;
143     my $tagname=shift;
144     my $version=shift;
145    
146     # -- create defaults if necessary
147     if ( (! defined $version) || ( $version eq "") ) {
148     $version=$area->version();
149     }
150     if ( (! defined $tagname) || ( $tagname eq "") ) {
151     $tagname=$area->name();
152     }
153    
154     # -- Add to the DB
155     $self->scramprojectdb()->addarea($tagname,$version,$area);
156     }
157    
158     sub globalcache {
159     my $self=shift;
160     if ( @_ ) {
161     $self->{cachedir}=shift;
162     }
163     if ( ! defined $self->{globalcache} ) {
164     $self->{globalcache}=URL::URLcache->new($self->{cachedir});
165     }
166     return $self->{globalcache};
167     }
168    
169    
170     sub scramprojectdb {
171     my $self=shift;
172     if ( @_ ) {
173     $self->{scramprojectsdbdir}=shift;
174     }
175     if ( ! defined $self->{scramprojectsdb} ) {
176     require Scram::ScramProjectDB;
177     $self->{scramprojectsdb}=Scram::ScramProjectDB->new(
178     $self->{scramprojectsdbdir} );
179     $self->{scramprojectsdb}->verbosity($self->verbosity());
180     }
181     return $self->{scramprojectsdb};
182     }
183    
184     sub areatoolbox {
185     my $self=shift;
186     my $area=shift;
187    
188     my $name=$area->location();
189     if ( ! defined $self->{toolboxes}{$name} ) {
190     # -- create a new toolbox object
191     require BuildSystem::ToolBox;
192     $self->{toolboxes}{$name}=BuildSystem::ToolBox->new($area);
193     $self->{toolboxes}{$name}->verbosity($self->verbosity());
194     }
195     return $self->{toolboxes}{$name};
196     }
197    
198     sub arearequirements {
199     my $self=shift;
200     my $area=shift;
201    
202     my $name=$area->location();
203     if ( ! defined $self->{requirements}{$name} ) {
204     # -- create a new toolbox object
205     require BuildSystem::Requirements;
206     my $doc=$area->requirementsdoc();
207     my $cache=$area->cache();
208     my $db=$area->objectstore();
209     require ActiveDoc::ActiveStore;
210     my $astore=ActiveDoc::ActiveStore->new($db,$cache);
211     $self->{requirements}{$name}=
212     BuildSystem::Requirements->new($astore,"file:".$doc,
213     $ENV{SCRAM_ARCH});
214     $self->{requirements}{$name}->verbosity($self->verbosity());
215     $self->verbose("Requirements Doc (".$self->{requirements}{$name}.
216     ") for area :\n $name\n initiated from $doc");
217     }
218     else {
219     $self->verbose("Requirements Doc (".$self->{requirements}{$name}.")");
220     }
221     return $self->{requirements}{$name};
222     }
223    
224     sub arch {
225     my $self=shift;
226    
227     @_?$self->{arch}=shift
228     :$self->{arch};
229     }
230    
231     # -------------- Support Routines ------------------------------
232    
233    
234     sub _allprojectinitsearcher {
235     if ( ! defined $self->{projsearcher} ) {
236     my $search=_projsearcher();
237     foreach $proj ( $self->scramprojectdb()->list() ) {
238     $search->addproject($$proj[0],$$proj[1]);
239     }
240     }
241     }
242    
243     sub _projsearcher {
244     if ( ! defined $self->{projsearcher} ) {
245     require Scram::ProjectSearcher;
246     $self->{projsearcher}=Scram::ProjectSearcher->new(
247     $self->scramprojectdb());
248     }
249     return $self->{projsearcher};
250     }
251    
252    
253     sub _lookupareaindb {
254     my $self=shift;
255    
256     my $area=undef;
257     # -- Look up the area in the databse
258     my @areas=$self->scramprojectdb()->getarea(@_);
259     if ( $#areas > 0 ) { #ambigous
260     # could ask user - for now just error
261     $self->error("Ambigous request - please be more specific");
262     }
263     elsif ( $#areas != 0 ) { #not found
264     $self->error("The project requested has not been found");
265     }
266     else {
267     $area=$areas[0];
268     }
269     return $area;
270     }