ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/ToolBox.pm
Revision: 1.1.2.1
Committed: Fri Apr 7 08:12:48 2000 UTC (25 years, 1 month ago) by williamc
Content type: text/plain
Branch: V0_9branch
CVS Tags: V0_11_1, V0_11_0
Changes since 1.1: +115 -0 lines
Log Message:
reworked to interface with toolbox unit

File Contents

# User Rev Content
1 williamc 1.1.2.1 #
2     # ToolBox.pm
3     #
4     # Originally Written by Christopher Williams
5     #
6     # Description
7     # -----------
8     # create tools from clientsettings and interface to access them
9     #
10     # Interface
11     # ---------
12     # new() : A new toolbox object
13     # tools() : return a list of tools (name,version) pairs
14     # defaultversion(tool) : return the default version of the specified tool
15     # gettool(name[,version]) : get the tool object with the given name
16     # returns the default version if version not spec.
17    
18     package BuildSystem::ToolBox;
19     use FileHandle;
20     use BuildSystem::Tool;
21     require 5.004;
22    
23     sub new {
24     my $class=shift;
25     $self={};
26     bless $self, $class;
27     $self->init();
28     return $self;
29     }
30    
31     sub init {
32     my $self=shift;
33     $self->_readclientsettings($ENV{LOCALTOP}."/.SCRAM/".$ENV{SCRAM_ARCH}.
34     "/clientsettings");
35     $self->_readdefaultsfile($ENV{LOCALTOP}."/".$ENV{projconfigdir}.
36     "/External_Dependencies");
37     }
38    
39     sub tools {
40     my $self=shift;
41     return @{$self->{toollist}};
42     }
43    
44     sub gettool {
45     my $self=shift;
46     my $product=shift;
47     my $version;
48    
49     if ( @_ ) { $version=shift; }
50     else {
51     # lookup the default version
52     $version=$self->defaultversion($product);
53     return undef, if ( ! defined $version );
54     }
55     return (exists $self->{tools}{$product}{$version})?
56     $self->{tools}{$product}{$version}:undef;
57     }
58    
59     sub defaultversion {
60     my $self=shift;
61     my $product=shift;
62    
63     return $self->{defaults}{$product};
64     }
65    
66     sub _readclientsettings {
67     my $self=shift;
68     my $clientfile=shift;
69    
70     my $fh=FileHandle->new();
71     $fh->open("<".$clientfile) or die "Unable to open $clientfile\n";
72     my ($tool,$product,$type,$version,$variable,$value);
73     while ( <$fh> ) {
74     chomp;
75     next if /^#/;
76     next if /^\s*$/;
77     ($product, $version, $type, $variable, $value)=split /:/;
78     next if ( $variable=~/\&/ );
79     $product=~tr[A-Z][a-z];
80     $tool=$self->_toolobject($product,$version);
81     $tool->addfeature($variable,$value);
82     }
83     undef $fh;
84     }
85    
86     sub _readdefaultsfile {
87     my $self=shift;
88     my $file=shift;
89    
90     my $fh=FileHandle->new();
91     $fh->open("<".$file) or die "Unable to open $file $!\n";
92     while ( <$fh> ) {
93     chomp;
94     next if /^#/;
95     next if /^\s*$/;
96     ($product, $version)=split /:/;
97     $product=~tr[A-Z][a-z];
98     $self->{defaults}{$product}=$version;
99     }
100     undef $fh;
101     }
102    
103     sub _toolobject {
104     my $self=shift;
105     my $product=shift;
106     my $version=shift;
107    
108     if ( ! exists $self->{tools}{$product}{$version} ) {
109     $self->{tools}{$product}{$version}=BuildSystem::Tool->new();
110     $self->{tools}{$product}{$version}->name($product);
111     $self->{tools}{$product}{$version}->version($version);
112     push @{$self->{toollist}}, [$product, $version];
113     }
114     return $self->{tools}{$product}{$version};
115     }