ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/clientfile.pm
Revision: 1.10
Committed: Thu Mar 25 13:59:08 1999 UTC (26 years, 1 month ago) by williamc
Content type: text/plain
Branch: MAIN
CVS Tags: V0_5, V0_4, V0_3, V0_2
Changes since 1.9: +1 -0 lines
Log Message:
Ensure Externals are cpecified in LOWER case

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