ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Configuration/ConfigArea.pm
Revision: 1.13.2.5
Committed: Thu May 4 07:53:17 2000 UTC (25 years ago) by williamc
Content type: text/plain
Branch: V0_9branch
CVS Tags: V0_12_6, V0_12_5, V0_12_4, V0_12_3
Changes since 1.13.2.4: +22 -0 lines
Log Message:
new initialaisations

File Contents

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