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 |
williamc |
1.1.2.2 |
$type=~tr[A-Z][a-z];
|
83 |
|
|
$tool->type($variable,$type);
|
84 |
williamc |
1.1.2.1 |
}
|
85 |
|
|
undef $fh;
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
sub _readdefaultsfile {
|
89 |
|
|
my $self=shift;
|
90 |
|
|
my $file=shift;
|
91 |
|
|
|
92 |
|
|
my $fh=FileHandle->new();
|
93 |
|
|
$fh->open("<".$file) or die "Unable to open $file $!\n";
|
94 |
|
|
while ( <$fh> ) {
|
95 |
|
|
chomp;
|
96 |
|
|
next if /^#/;
|
97 |
|
|
next if /^\s*$/;
|
98 |
|
|
($product, $version)=split /:/;
|
99 |
|
|
$product=~tr[A-Z][a-z];
|
100 |
|
|
$self->{defaults}{$product}=$version;
|
101 |
|
|
}
|
102 |
|
|
undef $fh;
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
sub _toolobject {
|
106 |
|
|
my $self=shift;
|
107 |
|
|
my $product=shift;
|
108 |
|
|
my $version=shift;
|
109 |
|
|
|
110 |
|
|
if ( ! exists $self->{tools}{$product}{$version} ) {
|
111 |
|
|
$self->{tools}{$product}{$version}=BuildSystem::Tool->new();
|
112 |
|
|
$self->{tools}{$product}{$version}->name($product);
|
113 |
|
|
$self->{tools}{$product}{$version}->version($version);
|
114 |
|
|
push @{$self->{toollist}}, [$product, $version];
|
115 |
|
|
}
|
116 |
|
|
return $self->{tools}{$product}{$version};
|
117 |
|
|
}
|