ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Scram/ScramFunctions.pm
Revision: 1.4
Committed: Wed Aug 30 09:47:39 2000 UTC (24 years, 8 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.3: +6 -1 lines
Log Message:
Workaround for dealing with old broken areas

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 williamc 1.4 my $areaname=undef;
102 williamc 1.2 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 williamc 1.4 }
111    
112     # -- fix for old broken areas
113     if ( (! defined $relarea->version()) || ($relarea->version() eq "") ) {
114     $relarea->version($version);
115 williamc 1.2 }
116    
117     # -- create satellite
118     my $area=$relarea->satellite($installarea,$areaname);
119     $area->archname($self->arch());
120    
121     # -- copy setup info - deprecated by toolbox copy method
122     #$relarea->copysetup($area->location());
123    
124     # -- copy toolbox
125     my $rtb=$self->areatoolbox($relarea);
126     my $tb=$self->areatoolbox($area);
127     $rtb->copytools($tb);
128    
129     # -- copy configuration directory
130     if ( ! -d $area->location()."/".$area->configurationdir() ) {
131     use Utilities::AddDir;
132     AddDir::copydir($relarea->location()."/".$relarea->configurationdir(),
133     $area->location()."/".$area->configurationdir() );
134     }
135    
136     # -- copy RequirementsDoc
137     if ( ! -f $area->requirementsdoc() ) {
138 williamc 1.3 use File::Copy;
139 williamc 1.2 copy( $relarea->requirementsdoc() , $area->requirementsdoc());
140     }
141    
142     return $area;
143     }
144    
145     sub addareatoDB {
146     my $self=shift;
147     my $area=shift;
148     my $tagname=shift;
149     my $version=shift;
150    
151     # -- create defaults if necessary
152     if ( (! defined $version) || ( $version eq "") ) {
153     $version=$area->version();
154     }
155     if ( (! defined $tagname) || ( $tagname eq "") ) {
156     $tagname=$area->name();
157     }
158    
159     # -- Add to the DB
160     $self->scramprojectdb()->addarea($tagname,$version,$area);
161     }
162    
163     sub globalcache {
164     my $self=shift;
165     if ( @_ ) {
166     $self->{cachedir}=shift;
167     }
168     if ( ! defined $self->{globalcache} ) {
169     $self->{globalcache}=URL::URLcache->new($self->{cachedir});
170     }
171     return $self->{globalcache};
172     }
173    
174    
175     sub scramprojectdb {
176     my $self=shift;
177     if ( @_ ) {
178     $self->{scramprojectsdbdir}=shift;
179     }
180     if ( ! defined $self->{scramprojectsdb} ) {
181     require Scram::ScramProjectDB;
182     $self->{scramprojectsdb}=Scram::ScramProjectDB->new(
183     $self->{scramprojectsdbdir} );
184     $self->{scramprojectsdb}->verbosity($self->verbosity());
185     }
186     return $self->{scramprojectsdb};
187     }
188    
189     sub areatoolbox {
190     my $self=shift;
191     my $area=shift;
192    
193     my $name=$area->location();
194     if ( ! defined $self->{toolboxes}{$name} ) {
195     # -- create a new toolbox object
196     require BuildSystem::ToolBox;
197     $self->{toolboxes}{$name}=BuildSystem::ToolBox->new($area);
198     $self->{toolboxes}{$name}->verbosity($self->verbosity());
199     }
200     return $self->{toolboxes}{$name};
201     }
202    
203     sub arearequirements {
204     my $self=shift;
205     my $area=shift;
206    
207     my $name=$area->location();
208     if ( ! defined $self->{requirements}{$name} ) {
209     # -- create a new toolbox object
210     require BuildSystem::Requirements;
211     my $doc=$area->requirementsdoc();
212     my $cache=$area->cache();
213     my $db=$area->objectstore();
214     require ActiveDoc::ActiveStore;
215     my $astore=ActiveDoc::ActiveStore->new($db,$cache);
216     $self->{requirements}{$name}=
217     BuildSystem::Requirements->new($astore,"file:".$doc,
218     $ENV{SCRAM_ARCH});
219     $self->{requirements}{$name}->verbosity($self->verbosity());
220     $self->verbose("Requirements Doc (".$self->{requirements}{$name}.
221     ") for area :\n $name\n initiated from $doc");
222     }
223     else {
224     $self->verbose("Requirements Doc (".$self->{requirements}{$name}.")");
225     }
226     return $self->{requirements}{$name};
227     }
228    
229     sub arch {
230     my $self=shift;
231    
232     @_?$self->{arch}=shift
233     :$self->{arch};
234     }
235    
236     # -------------- Support Routines ------------------------------
237    
238    
239     sub _allprojectinitsearcher {
240     if ( ! defined $self->{projsearcher} ) {
241     my $search=_projsearcher();
242     foreach $proj ( $self->scramprojectdb()->list() ) {
243     $search->addproject($$proj[0],$$proj[1]);
244     }
245     }
246     }
247    
248     sub _projsearcher {
249     if ( ! defined $self->{projsearcher} ) {
250     require Scram::ProjectSearcher;
251     $self->{projsearcher}=Scram::ProjectSearcher->new(
252     $self->scramprojectdb());
253     }
254     return $self->{projsearcher};
255     }
256    
257    
258     sub _lookupareaindb {
259     my $self=shift;
260    
261     my $area=undef;
262     # -- Look up the area in the databse
263     my @areas=$self->scramprojectdb()->getarea(@_);
264     if ( $#areas > 0 ) { #ambigous
265     # could ask user - for now just error
266     $self->error("Ambigous request - please be more specific");
267     }
268     elsif ( $#areas != 0 ) { #not found
269     $self->error("The project requested has not been found");
270     }
271     else {
272     $area=$areas[0];
273     }
274     return $area;
275     }