ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/clientfile.pm
Revision: 1.6
Committed: Fri Mar 19 14:33:58 1999 UTC (26 years, 1 month ago) by williamc
Content type: text/plain
Branch: MAIN
CVS Tags: V0_1
Changes since 1.5: +3 -0 lines
Log Message:
Copy across clientsettings_reqs too

File Contents

# User Rev Content
1 williamc 1.1 # Make a client specific file for external products
2     #
3     #
4    
5     package clientfile;
6 williamc 1.2 require 5.001;
7 williamc 1.1 require Exporter;
8     @ISA = qw(Exporter);
9     @EXPORT = qw(BuildClientFile);
10    
11     $scramdir="$ENV{INTwork}/SCRAM";
12     $Arch=1;
13     push @ARCHBLOCK, $Arch;
14    
15 williamc 1.4 sub BuildClientFile {
16 williamc 1.1 my $projectfile=shift;
17     my $archdir=".SCRAM/$ENV{SCRAM_ARCH}";
18     my $clientfile="$archdir/clientsettings";
19 williamc 1.2 use Utilities::AddDir;
20 williamc 1.1 use ToolBox;
21    
22 williamc 1.3 AddDir::adddir($archdir);
23 williamc 1.1 initialiseclient($clientfile) or return; # get out if it already exists
24     $toolbox=ToolBox->new();
25     open ( CLIENT, ">$ENV{LOCALTOP}/$clientfile" ) ||
26     die "clientfile: Cannot open clientsettings file "
27     ."$clientfile $!\n";
28 williamc 1.3 open ( CLIENT2, ">$ENV{LOCALTOP}/".$clientfile."_reqs" ) ||
29     die "clientfile: Cannot open clientsettings file "
30     ."$clientfile $!\n";
31 williamc 1.1 open (INSTALLLOG, ">$archdir/installation_log")
32     || die "clientfile: Cannot open log file $!\n";
33     print CLIENT "# Machine Generated File - do not edit\n";
34     _ParseProjectReqs($projectfile);
35     close INSTALLLOG;
36     close CLIENT;
37 williamc 1.3 close CLIENT2;
38 williamc 1.1 }
39    
40 williamc 1.4 sub _ParseProjectReqs {
41 williamc 1.1 my $reqfile=shift;
42 williamc 1.2 use Utilities::Switcher;
43 williamc 1.1
44     $taglist={
45     'require' => 'none',
46     'require_starttag' => \&Require_start
47     };
48    
49     $switch=Switcher->new($taglist,"$reqfile");
50     $switch->parse();
51     }
52    
53     sub Require_start {
54     my $name=shift;
55     my @vars=@_;
56     my $hashref;
57    
58     $hashref=$switch->SetupValueHash(\@vars);
59    
60     push @toollist, $$hashref{'name'};
61     if ( ! ( defined $$hashref{'version'} ) ) {
62     print INSTALLLOG "Error : Undefined version for $$hashref{'name'}\n";
63     exit;
64     }
65     if ( ! ( defined $$hashref{'url'} ) ) { #must be local if not defined
66     $$hashref{'url'}="file:$$hashref{'name'}";
67     }
68     _tool($$hashref{'url'});
69     }
70    
71    
72     #---------------------------------------------------------------------------
73     # ToolFile Parsing
74     #
75     #---------------------------------------------------------------------------
76    
77 williamc 1.4 sub _gettool {
78 williamc 1.1 # set the $toolfile variable
79     my $toolurl=shift;
80     my @toolpath= split /:/, $ENV{SCRAM_BootStrapFiles};
81     my $method;
82     my $tool;
83    
84     ( $method, $tool )=split /:/, $toolurl;
85     # file method - refers to a file in a PATH type variable
86     if ( $method=~/file/i ) {
87     foreach $path ( @toolpath ) {
88     if ( -e $path."/".$tool ) {
89     $toolfile=$path."/".$tool;
90     return 0;
91     }
92     }
93     return 1;
94     }
95     else {
96     print "Only 'file:' method supported in this version\n";
97     return 1;
98     }
99     }
100    
101     # process the tool files
102     # Assume a libtool context for now - i.e Compiler Implied
103     sub _tool {
104     my $name=shift;
105     my $toollist;
106    
107     if ( (_gettool($name))) {
108     die "Warning : Could not locate $name description file\n";
109     return;
110     }
111     $toollist={
112     'Tool_StartTag' => \&_toolsetting,
113     'Tool_EndTag' => \&_toolunset,
114     'Tool' => 'none',
115     'Environment' => \&Env,
116     'Environment_StartTag' => \&Env_start,
117     'Environment_EndTag' => \&Env_finish,
118     'Type' => 'none',
119     'Type_StartTag' => \&type_start,
120     'Type_EndTag' => \&type_end,
121     'System' => \&system_body,
122     'Splice' => 'none',
123     'Splice_starttag' => \&splice_start,
124     'Client' => 'none',
125     'LIB' => 'none',
126     'LIB_StartTag' => \&lib_start,
127     'Architecture_StartTag' => \&Arch_Start,
128     'Architecture_EndTag' => \&Arch_End,
129     'Architecture' => 'none',
130     'Function' => 'none',
131     'Function_StartTag' => \&Function_start,
132 williamc 1.3 'Function_EndTag' => \&Function_end,
133     'External' => 'none',
134     'External_StartTag' => \&External_client,
135 williamc 1.1 };
136     # 'INCLUDE_StartTag' => \&INCLUDE_start ,
137    
138 williamc 1.2 use Utilities::Switcher;
139 williamc 1.1 $toolswitch=Switcher->new($toollist,$toolfile);
140     $toolswitch->parse();
141    
142    
143     }
144    
145     # If weve got an include and we are in client context
146     # then search for the string
147     # multiple defaults can be specified > colon seperated
148     #
149 williamc 1.3
150     sub External_client {
151     my $name=shift;
152     my @vars=@_;
153     my $hashref;
154    
155     $hashref=$toolswitch->SetupValueHash( \@vars );
156     $toolswitch->checkparam( $hashref, $name, 'ref' );
157     print CLIENT2 <<ENDTEXT;
158     ifdef $toolname
159 williamc 1.5 $$hashref{ref}=true
160 williamc 1.3 endif
161     ENDTEXT
162     }
163 williamc 1.1
164     sub Arch_Start {
165     my $name=shift;
166     my @vars=@_;
167     my $hashref;
168    
169     $hashref=$toolswitch->SetupValueHash( \@vars );
170     $toolswitch->checkparam($hashref, $name, 'name');
171     #( ($$hashref{name}=~/$ENV{SCRAM_ARCH}/) )?$Arch=1:$Arch=0;
172     ( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($Arch=1) : ($Arch=0);
173     push @ARCHBLOCK, $Arch;
174     }
175     sub Arch_End {
176     my $name=shift;
177     my @vars=@_;
178    
179     $Arch=pop @ARCHBLOCK;
180     }
181    
182     sub lib_start {
183     my $name=shift;
184     my @vars=@_;
185     my $hashref;
186    
187     $hashref=$toolswitch->SetupValueHash( \@vars );
188     $toolswitch->checkparam($hashref, $name, 'name');
189     push @{$Envtype{lib}}, $$hashref{'name'};
190     outclient($name,$$hashref{'name'},"D");
191     }
192    
193     sub Env_start {
194     my $name=shift;
195     my @vars=@_;
196     $Envhashref;
197    
198     if ( $toolswitch->context("environment") ) {
199     print "clientfile Error: Missing </environment> tag on line ".
200     "$toolswitch->{linecount} in file $toolswitch->{filename}\n";
201     exit 1;
202     }
203     if ( $Arch ) {
204     $Envhashref=$toolswitch->SetupValueHash( \@vars );
205     $toolswitch->checkparam($Envhashref, $name, 'name');
206     if ( $$Envhashref{'value'} eq "" ) {
207     SWITCH: {
208     #try and get from the environment
209     if ( defined $ENV{$$Envhashref{'name'}} ) {
210     $$Envhashref{'value'}=$ENV{$$Envhashref{'name'}};
211     outclient( $$Envhashref{'name'}, $$Envhashref{'value'}, "E");
212     last SWITCH;
213     }
214     # try the default locations specified by default flag
215     if ( (&checkdefault($Envhashref))) {
216     $$Envhashref{'value'}=$$Envhashref{'default'};
217     outclient( $$Envhashref{'name'}, $$Envhashref{'default'}, "D");
218     last SWITCH;
219     }
220     print "\nCannot Determine value $$Envhashref{'name'} :\n";
221     } #end SWITCH
222     }
223     else {
224     $$Envhashref{'value'}=&expandvars($$Envhashref{'value'});
225     outclient( $$Envhashref{'name'}, $$Envhashref{'value'}, "D" );
226     }
227     }
228     }
229    
230     sub Env {
231     my $name=shift;
232     my @vars=@_;
233    
234     if ( $Arch ) {
235     if ( $$Envhashref{'value'} eq "" ) {
236     print @vars;
237     }
238     }
239    
240     }
241     sub Env_finish {
242     my $name=shift;
243     my @vars=@_;
244     my $hashref;
245    
246     if ( $Arch ) {
247     $testarrayref=undef;
248     if ( $$Envhashref{'value'} eq "" ) {
249     $$Envhashref{'value'} = &askuser("Please Enter the Value Below:",
250     $$Envhashref{'name'}, $Envhashref);
251     }
252     $ToolEnv{$$Envhashref{'name'}}=$$Envhashref{'value'};
253     }
254     }
255    
256     #
257     # Ask User for a specific value
258     #
259    
260     sub askuser {
261     my $querystring=shift;
262     my $varname=shift;
263     my $hashref=shift;
264     my $path;
265    
266     for ( ;; ) {
267     print "\n".$querystring." (RETURN to log as missing)\nset $varname = ";
268     $path=<STDIN>;
269     chomp $path;
270     if ( $path ne "" ) {
271     if ( $toolswitch->context('client')) { # must be a location
272     if ( &_testlocation($path , "H", $hashref) ) {
273     return $path;
274     }
275     print "Error : ".$path." does not exist.\n";
276     next;
277     }
278     else {
279     outclient($varname, $path, "H");
280     return $path;
281     }
282     }
283     else {
284     print INSTALLLOG "Warning: Missing $varname for $toolname\n";
285     outclient($varname, "UNDEFINED", "U");
286     return;
287     }
288     } #end while
289     }
290    
291     #
292     # Output to Screen and Install Log
293     #
294    
295     sub outclient {
296     my $name=shift;
297     my $value=shift;
298     my $tag=shift;
299    
300     print CLIENT $toolkey."::$name:".expandvars($value).":$tag\n";
301     print INSTALLLOG "$name set to $value\n";
302     }
303    
304     #
305     #
306     #
307    
308     sub checkdefault {
309     my $hashref=shift;
310    
311     if ( defined $$hashref{'default'} ) { #check default
312     my $default;
313     foreach $default ( split /:/, $$hashref{'default'} ) {
314     $default=~s/\"//;
315     if ( _testlocation($default,
316     $Envtype{$$hashref{'type'}})) { return 1; }
317     }
318     }
319     return 0;
320     }
321    
322     #
323     #
324     #
325     sub _dirchecktest {
326     $var=shift;
327     my @vars=@_;
328     my $hashref;
329     my $key;
330    
331     if ( $Arch ) {
332     $hashref=$toolswitch->SetupValueHash( \@vars );
333     if ( $toolswitch->context('client')=='0' ) {
334     # outside client context - abort for now
335     print "Error :- $var outside of CLIENT\n";
336     exit
337     }
338     # In client context we need to setup the client file
339     testblock: {
340     if ( defined $site{$toolkey.":".$var} ) {
341     last testblock
342     if _testlocation($site{$toolkey.":".$var}, undef);
343     }
344     print "Searching for $var relating to $toolname $toolversion\n";
345     #
346     # Check Base Release
347     #
348     #
349     # Check The Default Location
350     #
351     if ( defined $$hashref{'default'} ) { #check default
352     my $default;
353     foreach $default ( split /:/, $$hashref{'default'} ) {
354     $default=~s/\"//;
355     last testblock if _testlocation($default, undef);
356     }
357     }
358     #
359     # last resort - ask the user
360     #
361     print "Unable to find $var for $toolname\n";
362     askuser("Please Enter the $var path", $var, $hashref);
363     } # end testblock
364     }
365     }
366    
367     #
368     #
369     #
370     sub _toolsetting {
371     my $var=shift;
372     my @vars=@_;
373     my $hashref;
374    
375     $hashref=$toolswitch->SetupValueHash( \@vars );
376     $toolswitch->checkparam($hashref, $var, 'name');
377     $toolname=$$hashref{'name'};
378     $toolversion=$$hashref{'version'};
379     $toolkey=$toolname.":".$toolversion;
380     $ToolEnv{'SCRAMtoolname'}=$toolname;
381     $ToolEnv{'SCRAMtoolversion'}=$toolversion;
382     %Envtype=(); # reset file types hash;
383     print "\n";
384     print "--------------- Setting up $toolname $toolversion ----------\n";
385     }
386    
387     #
388     #
389     #
390     sub _toolunset {
391     $toolname=undef;
392     $toolversion=undef;
393     $toolkey=undef;
394     %ToolEnv=();
395     %Envtype=();
396     }
397    
398     #
399     # Add some functionality to modify environment variables at build time
400     #
401     sub splice_start {
402     my $var=shift;
403     my @vars=@_;
404     my $hashref;
405    
406     $hashref=$toolswitch->SetupValueHash( \@vars );
407     $toolswitch->checkparam($hashref, $var, 'variable');
408     $toolswitch->checkparam($hashref, $var, 'operator');
409    
410     print CLIENT $toolkey."::&tool_splice($$hashref{variable},".
411     "\"$$hashref{operator}\")\n";
412    
413     }
414    
415     sub type_start {
416     my $var=shift;
417     my @vars=@_;
418     my $hashref;
419    
420     $hashref=$toolswitch->SetupValueHash( \@vars );
421     $toolswitch->checkparam($hashref, $var, 'name');
422     $toolswitch->checkparam($hashref, $var, 'variable');
423     $toolswitch->checkparam($hashref, $var, 'value');
424    
425     push @{$TypeEnvHash{$$hashref{'variable'}}}, $$hashref{value};
426     push @{$TypeName{$$hashref{'variable'}}}, $$hashref{name};
427     push @TypeStack, $$hashref{variable};
428     #$TypeToolEnv{$$hashref{'variable'}}=$$hashref{'variable'};
429     print CLIENT $toolkey.":$$hashref{name}:&tool_splice(outfile,".
430     "\"s/(.*)/\\1__$$hashref{name}/\")\n";
431     }
432    
433     sub type_end {
434     my $temp;
435     $temp=pop @TypeStack;
436     pop @{$TypeEnvHash{$temp}};
437     pop @{$TypeNameHash{$temp}};
438     }
439    
440     sub Function_start {
441     my $var=shift;
442     my @vars=@_;
443     my $hashref;
444    
445     $hashref=$toolswitch->SetupValueHash( \@vars );
446     $toolswitch->checkparam($hashref, $var, 'out');
447     $toolswitch->checkparam($hashref, $var, 'in');
448     $functin=$$hashref{in};
449     $functout=$$hashref{out};
450    
451     push @functinStack, $functin;
452     push @functoutStack, $functout;
453     }
454    
455     sub Function_end {
456     pop @functinStack;
457     pop @functoutStack;
458     }
459    
460     # utility routine for sytem tag
461     sub _localenvset($) {
462     my $num=shift;
463     my $fail=0;
464     my $var;
465     foreach $var ( keys %TypeEnvHash ) {
466     $TypeLocalHash{$var}=undef;
467     $TypeLocalName{$var}=undef;
468     if ( $#{$TypeEnvHash{$var}} > $num ) {
469     $fail=1;
470     $TypeLocalHash{$var}=${$TypeEnvHash{$var}}[$num];
471     $TypeLocalName{$var}=${$TypeName{$var}}[$num];
472     }
473     }
474     return $fail;
475     }
476    
477     sub system_body {
478     my $name=shift;
479     my @vars=@_;
480     my $string;
481     my $var;
482     my $var2;
483     my @typelist;
484     use ToolBox;
485    
486     $string=join '', @_;
487    
488     # Replace any newlines with semicolons
489     $string=~s/\n/\;/g;
490     # Get rid of any multiple semicolons
491     $string=~s/\;\;*/\;/g;
492     # Now cycle over all the possible variable values for each type
493     # to substitute the $type:: markers
494     my $n=0;
495     %TypeLocalHash=();
496     %TypeLocalName=();
497     while ( _localenvset($n) ) {
498     foreach $var ( keys %TypeLocalHash) {
499     @typelist=();
500     foreach $var2 ( keys %TypeLocalHash ) {
501     if ( $var2 ne $var ) {
502     push @typelist, $TypeLocalName{$var2};
503     }
504     }
505     my $temp=$TypeLocalHash{$var};
506     my $nv=0;
507     foreach $value ( @{$TypeEnvHash{$var}} ) {
508     $TypeLocalHash{$var}=$value;
509     my @names=(@typelist, $TypeName{$var}[$nv++]);
510     ($thisstring=$string)
511     =~s/\$type::(.*?)( |\/|\Z)/$TypeLocalHash{$1}$2/g;
512     $toolbox->addtotoolbox($functout, $functin, $toolkey,
513     $thisstring, @names);
514     }
515     $TypeLocalHash{$var}=$temp;
516     }
517     $n++;
518     }
519     }
520    
521     #
522     # Tests $path directory for filenames with the words in testfiles array.
523     #
524    
525     sub _testlocation($path, \@testfiles) {
526     my $default=shift;
527     my $testfiles=shift;
528     my $OK='false';
529     my $file;
530    
531     chomp $default;
532     $default=&expandvars($default);
533     print "Trying $default .... ";
534     opendir DIRHANDLE, $default or do { print "No\n"; return 0; };
535     ($#{$testfiles}==-1) ? $OK='false' : $OK='true';
536     print "\n";
537     my @files=readdir DIRHANDLE;
538     close DIRHANDLE;
539     foreach $file ( @$testfiles ) {
540     print " Checking for $file .... ";
541     # now check that the required files are actually there
542     if ( ( $number = grep /$file/, @files) == 0 ) {
543     $OK='false';
544     print "not found\n";
545     last;
546     }
547     print "found\n";
548     }
549     if ( $OK eq 'true' ) {
550     print "Directory Check Complete\n";
551     return 1
552     }
553     return 0
554     }
555    
556     #
557     # Expand any variables defined with $ in the string (local context of tool only)
558     #
559    
560     sub expandvars ($string) {
561     my $string=shift;
562     $string=~s/\$(.*?)( |\/|\Z)/$ToolEnv{$1}$2/g;
563     return $string;
564     }
565    
566     sub initialiseclient {
567     my $clientfile=shift;
568     use File::Copy;
569     my ( $name, $version, $var, @rest);
570    
571     #if it dosnt exist locally try and get a copy from the releasetop
572     if ( ! (-f "$ENV{LOCALTOP}/$clientfile" ) ) {
573     copy ( "$ENV{RELEASETOP}/$clientfile","$ENV{LOCALTOP}/$clientfile" );
574     }
575 williamc 1.6 if ( ! (-f "$ENV{LOCALTOP}/".$clientfile."_reqs" ) ) {
576     copy ( "$ENV{RELEASETOP}/".$clientfile."_reqs","$ENV{LOCALTOP}/".$clientfile."_reqs" );
577     }
578 williamc 1.1 # now read it in to memory for future reference
579     open (CLIENTFILEIN, "<$ENV{LOCALTOP}/$clientfile") or return 1;
580     ($name, $version, $var, @rest ) = split /:/;
581     $key="$name:$version:$var";
582     $site{$key}=@rest;
583     close CLIENTFILEIN;
584     return 0;
585     }
586