1 |
#
|
2 |
# ConfigArea.pm
|
3 |
#
|
4 |
# Written by Christopher Williams
|
5 |
#
|
6 |
# Description
|
7 |
# -----------
|
8 |
# creates and manages a configuration area
|
9 |
#
|
10 |
# Options
|
11 |
# -------
|
12 |
# ConfigArea_location
|
13 |
# ConfigArea_name
|
14 |
#
|
15 |
# Interface
|
16 |
# ---------
|
17 |
# new() : A new ConfigArea object
|
18 |
# location([dir]) : set/return the location of the work area
|
19 |
# bootstrapfromlocation([location]) : bootstrap the object based on location.
|
20 |
# no location specified - cwd used
|
21 |
# return 0 if succesful 1 otherwise
|
22 |
# requirementsdoc() : get set the requirements doc
|
23 |
# searchlocation([startdir]) : returns the location directory. search starts
|
24 |
# from cwd if not specified
|
25 |
# defaultdirname() : return the default directory name string
|
26 |
# scramversion() : return the scram version associated with
|
27 |
# area
|
28 |
# configurationdir() : return the location of the project
|
29 |
# configuration directory
|
30 |
# copy(location) : copy a configuration
|
31 |
# copysetup(location) : copy the architecture specific tool setup
|
32 |
# returns 0 if successful, 1 otherwise
|
33 |
# copyenv($ref) : copy the areas environment into the hashref
|
34 |
# toolbox() : return the areas toolbox object
|
35 |
# - temporary
|
36 |
# align() : adjust hard paths to suit local loaction
|
37 |
|
38 |
package Configuration::ConfigArea;
|
39 |
require 5.004;
|
40 |
use Utilities::AddDir;
|
41 |
use Utilities::Verbose;
|
42 |
use Cwd;
|
43 |
@ISA=qw(Utilities::Verbose);
|
44 |
|
45 |
sub new {
|
46 |
my $class=shift;
|
47 |
my $self={};
|
48 |
bless $self, $class;
|
49 |
|
50 |
# data init
|
51 |
$self->{admindir}=".SCRAM";
|
52 |
|
53 |
return $self;
|
54 |
}
|
55 |
|
56 |
sub configurationdir {
|
57 |
my $self=shift;
|
58 |
if ( @_ ) {
|
59 |
$self->{configurationdir}=shift;
|
60 |
}
|
61 |
if ( ! defined $self->{configurationdir} ) {
|
62 |
$self->_LoadEnvFile();
|
63 |
$self->{configurationdir}=$self->{ENV}{projconfigdir};
|
64 |
}
|
65 |
return $self->{configurationdir};
|
66 |
}
|
67 |
|
68 |
sub toolbox {
|
69 |
my $self=shift;
|
70 |
if ( ! defined $self->{toolbox} ) {
|
71 |
$self->{toolbox}=BuildSystem::ToolBox->new($self);
|
72 |
}
|
73 |
return $self->{toolbox};
|
74 |
}
|
75 |
|
76 |
sub requirementsdoc {
|
77 |
my $self=shift;
|
78 |
if ( @_ ) {
|
79 |
$self->{reqdoc}=shift;
|
80 |
}
|
81 |
if ( ! defined $self->{reqdoc} ) {
|
82 |
$self->_LoadEnvFile();
|
83 |
$self->{reqdoc}=$self->{ENV}{SCRAM_ProjReqsDoc};
|
84 |
}
|
85 |
return $self->{reqdoc};
|
86 |
}
|
87 |
|
88 |
sub scramversion {
|
89 |
my $self=shift;
|
90 |
if ( ! defined $self->{scramversion} ) {
|
91 |
my $filename=$self->location()."/".$self->configurationdir()."/".
|
92 |
"scram_version";
|
93 |
if ( -f $filename ) {
|
94 |
use FileHandle;
|
95 |
$fh=FileHandle->new();
|
96 |
open ($fh, "<".$filename);
|
97 |
my $version=<$fh>;
|
98 |
chomp $version;
|
99 |
$self->{scramversion}=$version;
|
100 |
undef $fh;
|
101 |
}
|
102 |
}
|
103 |
return $self->{scramversion};
|
104 |
}
|
105 |
|
106 |
sub bootstrapfromlocation {
|
107 |
my $self=shift;
|
108 |
|
109 |
my $rv=0;
|
110 |
|
111 |
my $location;
|
112 |
if ( ! defined ($location=$self->searchlocation(@_)) ) {
|
113 |
$rv=1;
|
114 |
$self->verbose("Unable to locate the top of local configuration area");
|
115 |
}
|
116 |
else {
|
117 |
$self->location($location);
|
118 |
$self->verbose("Found top ".$self->location());
|
119 |
my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat";
|
120 |
$self->_LoadEnvFile();
|
121 |
}
|
122 |
return $rv;
|
123 |
}
|
124 |
|
125 |
sub location {
|
126 |
my $self=shift;
|
127 |
|
128 |
if ( @_ ) {
|
129 |
$self->{location}=shift;
|
130 |
}
|
131 |
elsif ( ! defined $self->{location} ) {
|
132 |
# try and find the release location
|
133 |
$self->{location}=$self->searchlocation();
|
134 |
}
|
135 |
return $self->{location};
|
136 |
}
|
137 |
|
138 |
sub searchlocation {
|
139 |
my $self=shift;
|
140 |
|
141 |
#start search in current directory if not specified
|
142 |
my $thispath;
|
143 |
if ( @_ ) {
|
144 |
$thispath=shift
|
145 |
}
|
146 |
else {
|
147 |
$thispath=cwd();
|
148 |
}
|
149 |
|
150 |
my $rv=0;
|
151 |
|
152 |
# chop off any files - we only want dirs
|
153 |
if ( -f $thispath ) {
|
154 |
$thispath=~s/(.*)\/.*/$1/;
|
155 |
}
|
156 |
Sloop:{
|
157 |
do {
|
158 |
$self->verbose("Searching $thispath");
|
159 |
if ( -e "$thispath/".$self->{admindir} ) {
|
160 |
$self->verbose("Found\n");
|
161 |
$rv=1;
|
162 |
last Sloop;
|
163 |
}
|
164 |
} while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
|
165 |
|
166 |
return $rv?$thispath:undef;
|
167 |
}
|
168 |
|
169 |
sub copy {
|
170 |
my $self=shift;
|
171 |
my $destination=shift;
|
172 |
|
173 |
# copy across the admin dir
|
174 |
my $temp=$self->location()."/".$self->{admindir};
|
175 |
AddDir::copydir($temp,"$destination/".$self->{admindir});
|
176 |
}
|
177 |
|
178 |
sub align {
|
179 |
my $self=shift;
|
180 |
use File::Copy;
|
181 |
|
182 |
$self->_LoadEnvFile();
|
183 |
my $Envfile=$self->location()."/".$self->{admindir}."/Environment";
|
184 |
my $tmpEnvfile=$Envfile.".bak";
|
185 |
my $rel=$self->{ENV}{RELEASETOP};
|
186 |
my $local=$self->location();
|
187 |
|
188 |
rename( $Envfile, $tmpEnvfile );
|
189 |
use FileHandle;
|
190 |
my $fh=FileHandle->new();
|
191 |
my $fout=FileHandle->new();
|
192 |
open ( $fh, "<".$tmpEnvfile ) or
|
193 |
$self->error("Cannot find Environment file. Area Corrupted? ("
|
194 |
.$self->location().")\n $!");
|
195 |
open ( $fout, ">".$Envfile ) or
|
196 |
$self->error("Cannot find Environment file. Area Corrupted? ("
|
197 |
.$self->location().")\n $!");
|
198 |
while ( <$fh> ) {
|
199 |
$_=~s/\Q$rel\L/$local/g;
|
200 |
print $fout $_;
|
201 |
}
|
202 |
undef $fh;
|
203 |
undef $fout;
|
204 |
}
|
205 |
|
206 |
sub copysetup {
|
207 |
my $self=shift;
|
208 |
my $dest=shift;
|
209 |
|
210 |
my $rv=1;
|
211 |
# copy across the admin dir
|
212 |
my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
|
213 |
my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
|
214 |
if ( $temp ne $temp2 ) {
|
215 |
if ( -d $temp ) {
|
216 |
AddDir::copydir($temp,$temp2);
|
217 |
$rv=0;
|
218 |
}
|
219 |
}
|
220 |
return $rv;
|
221 |
}
|
222 |
|
223 |
sub copyenv {
|
224 |
my $self=shift;
|
225 |
my $hashref=shift;
|
226 |
|
227 |
foreach $elem ( keys %{$self->{ENV}} ) {
|
228 |
$$hashref{$elem}=$self->{ENV}{$elem};
|
229 |
}
|
230 |
}
|
231 |
|
232 |
sub arch {
|
233 |
my $self=shift;
|
234 |
return $ENV{SCRAM_ARCH};
|
235 |
}
|
236 |
|
237 |
# ---- support routines
|
238 |
sub _LoadEnvFile {
|
239 |
my $self=shift;
|
240 |
|
241 |
use FileHandle;
|
242 |
my $fh=FileHandle->new();
|
243 |
open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
|
244 |
"Environment" ) or
|
245 |
$self->error("Cannot find Environment file. Area Corrupted? ("
|
246 |
.$self->location().")\n $!");
|
247 |
while ( <$fh> ) {
|
248 |
chomp;
|
249 |
next if /^#/;
|
250 |
next if /^\s*$/ ;
|
251 |
($name, $value)=split /=/;
|
252 |
eval "\$self->{ENV}{${name}}=\"$value\"";
|
253 |
}
|
254 |
undef $fh;
|
255 |
}
|