1 |
sashby |
1.2 |
#____________________________________________________________________
|
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 |
muzaffar |
1.5 |
use SCRAM::MsgLog;
|
12 |
sashby |
1.2 |
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 |
muzaffar |
1.6 |
my ($environments,$toolname) = @_;
|
33 |
sashby |
1.2 |
|
34 |
|
|
$self->{TOOLNAME} = $toolname;
|
35 |
|
|
$self->{ENVIRONMENT} = $environments->{ENVIRONMENT};
|
36 |
|
|
$self->{RUNTIME} = $environments->{RUNTIME};
|
37 |
muzaffar |
1.6 |
$self->{VARDATA} = {};
|
38 |
sashby |
1.2 |
$self->{LOCALENV} = \%ENV;
|
39 |
sashby |
1.4 |
$self->{STATUS} = { 0 => $main::good."[OK]".$main::normal, 1 => $main::error."[FAIL]".$main::normal, 2 => $main::good."[OK (but currently missing)]".$main::normal };
|
40 |
sashby |
1.2 |
|
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 |
sashby |
1.4 |
|
52 |
|
|
my $handlertype;
|
53 |
muzaffar |
1.6 |
|
54 |
sashby |
1.2 |
# See if there's a default/value in our data element:
|
55 |
sashby |
1.4 |
if ($self->checkdefaults($data,\$stringtoeval,\$handlertype))
|
56 |
sashby |
1.2 |
{
|
57 |
|
|
$path = $self->_expandvars($stringtoeval);
|
58 |
sashby |
1.4 |
if ($self->validatepath($path,$handlertype) )
|
59 |
sashby |
1.2 |
{
|
60 |
|
|
$self->savevalue($name,$path);
|
61 |
|
|
}
|
62 |
|
|
else
|
63 |
|
|
{
|
64 |
muzaffar |
1.6 |
$self->promptuser($name,$path);
|
65 |
sashby |
1.2 |
}
|
66 |
|
|
}
|
67 |
|
|
else
|
68 |
|
|
{
|
69 |
muzaffar |
1.6 |
$self->promptuser($name,$path);
|
70 |
sashby |
1.2 |
}
|
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 |
muzaffar |
1.6 |
die "SCRAM: Unknown tag type/var name: $type/$varname\n";
|
110 |
sashby |
1.2 |
}
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
sub validatepath()
|
114 |
|
|
{
|
115 |
|
|
my $self = shift;
|
116 |
muzaffar |
1.6 |
my ($path,$handlertype) = @_;
|
117 |
muzaffar |
1.5 |
scramlogmsg("\tChecks "), if ($path);
|
118 |
sashby |
1.4 |
|
119 |
sashby |
1.3 |
# This is done so that some paths can be added which include ".":
|
120 |
muzaffar |
1.6 |
if (($path =~ /^\.:.*/ || $path =~ /^\.$/) || ( -f $path ) || (-d $path))
|
121 |
sashby |
1.3 |
{
|
122 |
muzaffar |
1.5 |
scramlogmsg($self->{STATUS}->{0}." for $path","\n");
|
123 |
sashby |
1.3 |
return 1;
|
124 |
|
|
}
|
125 |
sashby |
1.4 |
elsif ($handlertype =~ /^[Ww].*$/)
|
126 |
|
|
{
|
127 |
muzaffar |
1.5 |
scramlogmsg($self->{STATUS}->{2}." for $path","\n");
|
128 |
sashby |
1.4 |
return 1;
|
129 |
|
|
}
|
130 |
muzaffar |
1.6 |
scramlogmsg($self->{STATUS}->{1}." for $path","\n"), unless ($path eq '');
|
131 |
|
|
return 0;
|
132 |
sashby |
1.2 |
}
|
133 |
|
|
|
134 |
|
|
sub checkdefaults()
|
135 |
|
|
{
|
136 |
|
|
my $self=shift;
|
137 |
sashby |
1.4 |
my ($vardata,$pathtoevalref,$handlertyperef) = @_;
|
138 |
sashby |
1.2 |
|
139 |
|
|
if (ref($vardata) eq 'ARRAY')
|
140 |
|
|
{
|
141 |
|
|
$data = $vardata->[0];
|
142 |
|
|
}
|
143 |
|
|
else
|
144 |
|
|
{
|
145 |
|
|
$data = $vardata;
|
146 |
|
|
}
|
147 |
|
|
|
148 |
sashby |
1.4 |
if (exists($data->{'handler'}))
|
149 |
|
|
{
|
150 |
|
|
$$handlertyperef = $data->{'handler'};
|
151 |
|
|
}
|
152 |
muzaffar |
1.6 |
|
153 |
|
|
if (exists($data->{'value'}))
|
154 |
sashby |
1.2 |
{
|
155 |
muzaffar |
1.6 |
$$pathtoevalref = $data->{'value'};
|
156 |
sashby |
1.2 |
}
|
157 |
muzaffar |
1.6 |
elsif (exists($data->{'default'}))
|
158 |
sashby |
1.2 |
{
|
159 |
muzaffar |
1.6 |
$$pathtoevalref = $data->{'default'};
|
160 |
sashby |
1.2 |
}
|
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 |
muzaffar |
1.6 |
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 |
sashby |
1.2 |
}
|
218 |
|
|
|
219 |
|
|
1;
|