ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Scram/ScramFunctions.pm
Revision: 1.1.2.6
Committed: Mon Aug 21 18:41:52 2000 UTC (24 years, 8 months ago) by williamc
Content type: text/plain
Branch: HPWbranch
Changes since 1.1.2.5: +6 -2 lines
Log Message:
Add changes for RequirementsDoc int change

File Contents

# User Rev Content
1 williamc 1.1.2.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 williamc 1.1.2.4 # arch() : get/set the architecture string
21 williamc 1.1.2.1
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 williamc 1.1.2.2 $self->{cachedir}=$ENV{HOME}."/.SCRAM/globalcache";
35 williamc 1.1.2.1 $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 williamc 1.1.2.5 $self->verbose("BootStrapping $url");
52 williamc 1.1.2.1 my $area=$bs->boot($url,$areaname);
53 williamc 1.1.2.6 if ( ! defined $area ) {
54     $self->error("Unable to create project area");
55     }
56 williamc 1.1.2.4 $area->archname($self->arch());
57 williamc 1.1.2.1
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 williamc 1.1.2.3 if ( my $rv=$toolbox->toolsetup(@_) ) {
81 williamc 1.1.2.1 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 williamc 1.1.2.4 $area->archname($self->arch());
115 williamc 1.1.2.1
116 williamc 1.1.2.4 # -- 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 williamc 1.1.2.1
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     copy( $relarea->requirementsdoc() , $area->requirementsdoc());
134     }
135    
136     return $area;
137     }
138    
139     sub addareatoDB {
140     my $self=shift;
141     my $area=shift;
142     my $tagname=shift;
143     my $version=shift;
144    
145     # -- create defaults if necessary
146     if ( (! defined $version) || ( $version eq "") ) {
147     $version=$area->version();
148     }
149     if ( (! defined $tagname) || ( $tagname eq "") ) {
150     $tagname=$area->name();
151     }
152    
153     # -- Add to the DB
154     $self->scramprojectdb()->addarea($tagname,$version,$area);
155     }
156    
157     sub globalcache {
158     my $self=shift;
159     if ( @_ ) {
160     $self->{cachedir}=shift;
161     }
162     if ( ! defined $self->{globalcache} ) {
163     $self->{globalcache}=URL::URLcache->new($self->{cachedir});
164     }
165     return $self->{globalcache};
166     }
167    
168    
169     sub scramprojectdb {
170     my $self=shift;
171     if ( @_ ) {
172     $self->{scramprojectsdbdir}=shift;
173     }
174     if ( ! defined $self->{scramprojectsdb} ) {
175     require Scram::ScramProjectDB;
176     $self->{scramprojectsdb}=Scram::ScramProjectDB->new(
177     $self->{scramprojectsdbdir} );
178     $self->{scramprojectsdb}->verbosity($self->verbosity());
179     }
180     return $self->{scramprojectsdb};
181     }
182 williamc 1.1.2.6
183 williamc 1.1.2.1 sub areatoolbox {
184     my $self=shift;
185     my $area=shift;
186    
187     my $name=$area->location();
188     if ( ! defined $self->{toolboxes}{$name} ) {
189     # -- create a new toolbox object
190     require BuildSystem::ToolBox;
191     $self->{toolboxes}{$name}=BuildSystem::ToolBox->new($area);
192     $self->{toolboxes}{$name}->verbosity($self->verbosity());
193     }
194     return $self->{toolboxes}{$name};
195     }
196    
197     sub arearequirements {
198     my $self=shift;
199     my $area=shift;
200    
201     my $name=$area->location();
202     if ( ! defined $self->{requirements}{$name} ) {
203     # -- create a new toolbox object
204     require BuildSystem::Requirements;
205     my $doc=$area->requirementsdoc();
206     my $cache=$area->cache();
207 williamc 1.1.2.6 my $db=$area->objectstore();
208 williamc 1.1.2.1 $self->{requirements}{$name}=
209 williamc 1.1.2.6 BuildSystem::Requirements->new("file:".$doc,$cache,$db);
210 williamc 1.1.2.1 $self->{requirements}{$name}->verbosity($self->verbosity());
211     $self->verbose("Requirements Doc (".$self->{requirements}{$name}.
212     ") for area :\n $name\n initiated from $doc");
213     }
214     else {
215     $self->verbose("Requirements Doc (".$self->{requirements}{$name}.")");
216     }
217     return $self->{requirements}{$name};
218 williamc 1.1.2.4 }
219    
220     sub arch {
221     my $self=shift;
222    
223     @_?$self->{arch}=shift
224     :$self->{arch};
225 williamc 1.1.2.1 }
226    
227     # -------------- Support Routines ------------------------------
228    
229    
230     sub _allprojectinitsearcher {
231     if ( ! defined $self->{projsearcher} ) {
232     my $search=_projsearcher();
233     foreach $proj ( $self->scramprojectdb()->list() ) {
234     $search->addproject($$proj[0],$$proj[1]);
235     }
236     }
237     }
238    
239     sub _projsearcher {
240     if ( ! defined $self->{projsearcher} ) {
241     require Scram::ProjectSearcher;
242     $self->{projsearcher}=Scram::ProjectSearcher->new(
243     $self->scramprojectdb());
244     }
245     return $self->{projsearcher};
246     }
247    
248    
249     sub _lookupareaindb {
250     my $self=shift;
251    
252     my $area=undef;
253     # -- Look up the area in the databse
254     my @areas=$self->scramprojectdb()->getarea(@_);
255     if ( $#areas > 0 ) { #ambigous
256     # could ask user - for now just error
257     $self->error("Ambigous request - please be more specific");
258     }
259     elsif ( $#areas != 0 ) { #not found
260     $self->error("The project requested has not been found");
261     }
262     else {
263     $area=$areas[0];
264     }
265     return $area;
266     }