ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/ToolBox.pm
Revision: 1.1.2.7
Committed: Thu Apr 20 12:38:00 2000 UTC (25 years ago) by williamc
Content type: text/plain
Branch: V0_9branch
Changes since 1.1.2.6: +5 -1 lines
Log Message:
Fixes for error reporting

File Contents

# User Rev Content
1 williamc 1.1.2.1 #
2     # ToolBox.pm
3     #
4     # Originally Written by Christopher Williams
5     #
6     # Description
7     # -----------
8     # create tools from clientsettings and interface to access them
9     #
10     # Interface
11     # ---------
12     # new() : A new toolbox object
13     # tools() : return a list of tools (name,version) pairs
14     # defaultversion(tool) : return the default version of the specified tool
15     # gettool(name[,version]) : get the tool object with the given name
16     # returns the default version if version not spec.
17 williamc 1.1.2.3 # returns undef if no setup tool is available
18     # toolsetup(name,version[,doc]) : setup the named tool from the specified doc
19     # if doc not specified try and use previous
20 williamc 1.1.2.7 # document; returns 0=OK 1=no version
21     # 2=setup failed in tool
22 williamc 1.1.2.1
23     package BuildSystem::ToolBox;
24     use FileHandle;
25     use BuildSystem::Tool;
26 williamc 1.1.2.3 use Utilities::Verbose;
27    
28     @ISA=qw(Utilities::Verbose);
29 williamc 1.1.2.1 require 5.004;
30    
31     sub new {
32     my $class=shift;
33     $self={};
34     bless $self, $class;
35     $self->init();
36     return $self;
37     }
38    
39     sub init {
40     my $self=shift;
41 williamc 1.1.2.3 $self->{urlcache}="$ENV{LOCALTOP}/.SCRAM/ToolFiles";
42     $self->{datastore}=$ENV{LOCALTOP}."/.SCRAM/".$ENV{SCRAM_ARCH};
43     AddDir::adddir($self->{datastore});
44     AddDir::adddir($self->{urlcache});
45 williamc 1.1.2.1 $self->_readdefaultsfile($ENV{LOCALTOP}."/".$ENV{projconfigdir}.
46     "/External_Dependencies");
47     }
48    
49     sub tools {
50     my $self=shift;
51     return @{$self->{toollist}};
52     }
53    
54 williamc 1.1.2.3 sub toolsetup {
55     my $self=shift;
56     my $name=shift;
57    
58     my $rv=0;
59     # -- get version
60     my $version;
61     if ( @_ ) {
62     $version=shift;
63     }
64     else {
65     $version=$self->defaultversion($name);
66     if ( ! defined $version ) { $rv=1; return $rv; }
67     }
68    
69     my $url;
70    
71     # -- get a tool object
72     my ($tool)=$self->_toolobject($name,$version);
73    
74     # -- get the url
75     if ( @_ ) {
76     $url=shift;
77     }
78     else {
79     # no url specified - try to get it from the tool
80     $url=$tool->url();
81     if ( ! defined $url ) {
82     $self->error("Unable to determine document for tool ".
83     $name." ".$version);
84     }
85     }
86     $url=$self->_download($url);
87    
88     require BuildSystem::ToolDoc;
89     my $doc=BuildSystem::ToolDoc->new();
90     $doc->tool($tool);
91 williamc 1.1.2.6 $tool->reset();
92 williamc 1.1.2.3 if ( ! $doc->setup($url,$name,$version) ) {
93     $tool->store($self->_toolfile($name,$version));
94 williamc 1.1.2.7 }
95     else {
96     $self->error("Unable to find $name $version in $url");
97 williamc 1.1.2.3 }
98     undef $doc;
99     return $rv;
100     }
101    
102    
103 williamc 1.1.2.1 sub gettool {
104     my $self=shift;
105     my $product=shift;
106     my $version;
107    
108     if ( @_ ) { $version=shift; }
109     else {
110     # lookup the default version
111     $version=$self->defaultversion($product);
112     return undef, if ( ! defined $version );
113     }
114 williamc 1.1.2.3 my ($tool,$rv)=$self->_toolobject($product,$version);
115     return ( $rv==0?$tool:undef ); # only return if already set up
116 williamc 1.1.2.1 }
117    
118     sub defaultversion {
119     my $self=shift;
120     my $product=shift;
121    
122     return $self->{defaults}{$product};
123     }
124    
125 williamc 1.1.2.3 sub _toolfile {
126     my $self=shift;
127     my $name=shift;
128     my $version=shift;
129    
130     return $self->{datastore}."/$name_$version.dat";
131     }
132    
133     sub _download {
134     my $self=shift;
135     my $url=shift;
136    
137     $url=~s/$self->{urlcache}\///;
138     # -- make sure we have a copy of the file
139     if ( ! -e $self->{urlcache}."/".$url ) {
140     &urlhandler::urlhandler("file:$ENV{SCRAM_HOME}/toolbox/"
141     .$url, $self->{urlcache}."/$url") ;
142     }
143     return $self->{urlcache}."/".$url;
144     }
145    
146 williamc 1.1.2.1 sub _readclientsettings {
147     my $self=shift;
148     my $clientfile=shift;
149    
150     my $fh=FileHandle->new();
151     $fh->open("<".$clientfile) or die "Unable to open $clientfile\n";
152     my ($tool,$product,$type,$version,$variable,$value);
153     while ( <$fh> ) {
154     chomp;
155     next if /^#/;
156     next if /^\s*$/;
157     ($product, $version, $type, $variable, $value)=split /:/;
158     next if ( $variable=~/\&/ );
159     $product=~tr[A-Z][a-z];
160 williamc 1.1.2.3 ($tool,$rv)=$self->_toolobject($product,$version);
161 williamc 1.1.2.1 $tool->addfeature($variable,$value);
162 williamc 1.1.2.2 $type=~tr[A-Z][a-z];
163     $tool->type($variable,$type);
164 williamc 1.1.2.1 }
165     undef $fh;
166     }
167    
168     sub _readdefaultsfile {
169     my $self=shift;
170     my $file=shift;
171    
172     my $fh=FileHandle->new();
173     $fh->open("<".$file) or die "Unable to open $file $!\n";
174     while ( <$fh> ) {
175     chomp;
176     next if /^#/;
177     next if /^\s*$/;
178     ($product, $version)=split /:/;
179     $product=~tr[A-Z][a-z];
180     $self->{defaults}{$product}=$version;
181     }
182     undef $fh;
183     }
184    
185 williamc 1.1.2.3
186 williamc 1.1.2.1 sub _toolobject {
187     my $self=shift;
188     my $product=shift;
189     my $version=shift;
190    
191 williamc 1.1.2.5 my $rv=0;
192 williamc 1.1.2.3
193 williamc 1.1.2.1 if ( ! exists $self->{tools}{$product}{$version} ) {
194 williamc 1.1.2.3 $self->verbose("$product $version being Intitialised");
195 williamc 1.1.2.1 $self->{tools}{$product}{$version}=BuildSystem::Tool->new();
196 williamc 1.1.2.3 my $file=$self->_toolfile($product,$version);
197     if ( -f $file ) { # restore it from disk
198     $self->verbose("Recovering $product $version from $file");
199     $self->{tools}{$product}{$version}->restore($file);
200     }
201     else {
202 williamc 1.1.2.5 $rv=1;
203 williamc 1.1.2.3 $self->verbose("Tool $product $version needs set up");
204     }
205 williamc 1.1.2.1 push @{$self->{toollist}}, [$product, $version];
206     }
207 williamc 1.1.2.3 return ($self->{tools}{$product}{$version}, $rv);
208 williamc 1.1.2.1 }