ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/ToolSettingValidator.pm
Revision: 1.7
Committed: Tue Oct 18 14:59:28 2011 UTC (13 years, 6 months ago) by muzaffar
Content type: text/plain
Branch: MAIN
CVS Tags: V2_2_5_pre2, V2_2_5_pre1, V2_2_4, V2_2_4_pre9, V2_2_4_pre8, V2_2_4_pre7, V2_2_4_pre6, V2_2_4_pre5, V2_2_4_pre4, V2_2_4_pre3, V2_2_4_pre2, V2_2_4_pre1, HEAD
Changes since 1.6: +0 -3 lines
Log Message:
removed cvs $id statement

File Contents

# Content
1 #____________________________________________________________________
2 # File: BuildSystem::ToolSettingValidator.pm
3 #____________________________________________________________________
4 #
5 # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6 # Copyright: 2004 (C) Shaun Ashby
7 #
8 #--------------------------------------------------------------------
9 package BuildSystem::ToolSettingValidator;
10 require 5.004;
11 use SCRAM::MsgLog;
12 use Exporter;
13 @ISA=qw(Exporter);
14 @EXPORT_OK=qw( );
15
16 sub new()
17 ###############################################################
18 # new #
19 ###############################################################
20 # modified : Thu Oct 14 10:16:25 2004 / SFA #
21 # params : #
22 # : #
23 # function : #
24 # : #
25 ###############################################################
26 {
27 my $proto=shift;
28 my $class=ref($proto) || $proto;
29 my $self={};
30
31 # Store the list of known environments:
32 my ($environments,$toolname) = @_;
33
34 $self->{TOOLNAME} = $toolname;
35 $self->{ENVIRONMENT} = $environments->{ENVIRONMENT};
36 $self->{RUNTIME} = $environments->{RUNTIME};
37 $self->{VARDATA} = {};
38 $self->{LOCALENV} = \%ENV;
39 $self->{STATUS} = { 0 => $main::good."[OK]".$main::normal, 1 => $main::error."[FAIL]".$main::normal, 2 => $main::good."[OK (but currently missing)]".$main::normal };
40
41 bless $self,$class;
42 return $self;
43 }
44
45 sub findvalue()
46 {
47 my $self=shift;
48 my ($name, $data) = @_;
49 my $stringtoeval;
50 my $path;
51
52 my $handlertype;
53
54 # See if there's a default/value in our data element:
55 if ($self->checkdefaults($data,\$stringtoeval,\$handlertype))
56 {
57 $path = $self->_expandvars($stringtoeval);
58 if ($self->validatepath($path,$handlertype) )
59 {
60 $self->savevalue($name,$path);
61 }
62 else
63 {
64 $self->promptuser($name,$path);
65 }
66 }
67 else
68 {
69 $self->promptuser($name,$path);
70 }
71 return $path;
72 }
73
74 sub savevalue()
75 {
76 my $self = shift;
77 my ($varname, $path) = @_;
78
79 if ($varname && $path)
80 {
81 $self->{VARDATA}->{$varname} = $path;
82 }
83
84 return;
85 }
86
87 sub environment()
88 {
89 my $self = shift;
90 my ($type, $varname) = @_;
91
92 if ($type && $varname)
93 {
94 if (exists($self->{uc($type)}->{$varname}))
95 {
96 return $self->{uc($type)}->{$varname};
97 }
98 else
99 {
100 return 0;
101 }
102 }
103 elsif ($type)
104 {
105 return $self->{uc($type)};
106 }
107 else
108 {
109 die "SCRAM: Unknown tag type/var name: $type/$varname\n";
110 }
111 }
112
113 sub validatepath()
114 {
115 my $self = shift;
116 my ($path,$handlertype) = @_;
117 scramlogmsg("\tChecks "), if ($path);
118
119 # This is done so that some paths can be added which include ".":
120 if (($path =~ /^\.:.*/ || $path =~ /^\.$/) || ( -f $path ) || (-d $path))
121 {
122 scramlogmsg($self->{STATUS}->{0}." for $path","\n");
123 return 1;
124 }
125 elsif ($handlertype =~ /^[Ww].*$/)
126 {
127 scramlogmsg($self->{STATUS}->{2}." for $path","\n");
128 return 1;
129 }
130 scramlogmsg($self->{STATUS}->{1}." for $path","\n"), unless ($path eq '');
131 return 0;
132 }
133
134 sub checkdefaults()
135 {
136 my $self=shift;
137 my ($vardata,$pathtoevalref,$handlertyperef) = @_;
138
139 if (ref($vardata) eq 'ARRAY')
140 {
141 $data = $vardata->[0];
142 }
143 else
144 {
145 $data = $vardata;
146 }
147
148 if (exists($data->{'handler'}))
149 {
150 $$handlertyperef = $data->{'handler'};
151 }
152
153 if (exists($data->{'value'}))
154 {
155 $$pathtoevalref = $data->{'value'};
156 }
157 elsif (exists($data->{'default'}))
158 {
159 $$pathtoevalref = $data->{'default'};
160 }
161 else
162 {
163 return 0;
164 }
165
166 return 1;
167 }
168
169 sub _expandvars()
170 {
171 my $self=shift;
172 my ($string) = @_;
173
174 return "" , if ( ! defined $string );
175
176 $string =~ s{\$\((\w+)\)}
177 {
178 if (defined $self->{VARDATA}->{$1})
179 {
180 $self->_expandvars($self->{VARDATA}->{$1});
181 }
182 elsif (defined $self->{LOCALENV}->{$1})
183 {
184 $self->_expandvars($self->{LOCALENV}->{$1});
185 }
186 else
187 {
188 "\$$1";
189 }
190 }egx;
191
192 $string =~ s{\$(\w+)}
193 {
194 if (defined $self->{VARDATA}->{$1})
195 {
196 $self->_expandvars($self->{VARDATA}->{$1});
197 }
198 elsif (defined $self->{LOCALENV}->{$1})
199 {
200 $self->_expandvars($self->{LOCALENV}->{$1});
201 }
202 else
203 {
204 "\$$1";
205 }
206 }egx;
207
208 ($string =~ /\$/) ? return undef : return $string;
209 }
210
211 sub promptuser()
212 {
213 my ($self,$name,$path)=@_;
214 if ($path) { print "**** ERROR: No such file or directory: $path\n"; }
215 die " SCRAM does not allow prompting for user input anymore.\n",
216 " Please fix the tool file for \"",$self->{TOOLNAME},"\" and provide a valid value for \"$name\".\n";
217 }
218
219 1;