root/juggler/tags/1.1_dr_3/JugglerConfigure.pm

Revision 9416, 5.2 kB (checked in by patrickh, 6 years ago)

Bug fixed: Depending on a given module definition, the same dependency

could be added multiple times. This resulted in repeated
configurations and builds of the same module(s).

The circumstances by which this bug could have arisen are best described
by the following example:

VPR
{

modules/vapor: VPR_CONFIG=vpr-config, VPR_BASE_DIR=instlinks;
external; // For Boost

}

Sonix
{

depend VPR;
modules/sonix: SNX_CONFIG=sonix-config, SNX_BASE_DIR=install-clone;
external; // For GMTL

}

Both depend on 'external', and as a result, external was being configured
twice.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 # ************** <auto-copyright.pl BEGIN do not edit this line> **************
2 #
3 # VR Juggler is (C) Copyright 1998-2002 by Iowa State University
4 #
5 # Original Authors:
6 #   Allen Bierbaum, Christopher Just,
7 #   Patrick Hartling, Kevin Meinert,
8 #   Carolina Cruz-Neira, Albert Baker
9 #
10 # This library is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Library General Public
12 # License as published by the Free Software Foundation; either
13 # version 2 of the License, or (at your option) any later version.
14 #
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # Library General Public License for more details.
19 #
20 # You should have received a copy of the GNU Library General Public
21 # License along with this library; if not, write to the
22 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 # Boston, MA 02111-1307, USA.
24 #
25 # -----------------------------------------------------------------
26 # File:          $RCSfile$
27 # Date modified: $Date$
28 # Version:       $Revision$
29 # -----------------------------------------------------------------
30 #
31 # *************** <auto-copyright.pl END do not edit this line> ***************
32
33 package JugglerConfigure;
34
35 use strict 'vars';
36 use vars qw($DEFAULT_MODULE);
37
38 sub parseConfigFile($);
39
40 $DEFAULT_MODULE = '';
41 my %MODULES     = ();
42
43 sub parseConfigFile ($)
44 {
45    my $cfg = shift;
46    open(CFG, "$cfg") or die "ERROR: Could not read from $cfg: $!\n";
47
48    my($cfg_file, $line);
49    while ( $line = <CFG> )
50    {
51       $line =~ s/(#|\/\/).*$//;
52       $cfg_file .= "$line";
53    }
54
55    close(CFG);
56
57    while ( $cfg_file !~ /^\s*$/ )
58    {
59       if ( $cfg_file =~ /^\s*(\S+)\s*{(.+?)}\s*/s )
60       {
61          my $mod   = "$1";
62          my $deps  = "$2";
63          $cfg_file = $';
64
65          $MODULES{"$mod"} = new JugglerModule("$mod");
66
67          while ( $deps !~ /^\s*$/ )
68          {
69             # Match a dependency on another module.
70             if ( $deps =~ /^\s*depend\s+(\S+);/ )
71             {
72                $deps = $';
73                my $module_name = "$1";
74
75                die "ERROR: No such module $module_name for $mod dependency\n"
76                   unless defined($MODULES{"$module_name"});
77
78                $MODULES{"$mod"}->addDependencies($MODULES{"$module_name"}->getDependencies());
79             }
80             # Match a dependency on a package.  This may have environment
81             # variable settings, or it may just be a path.
82             elsif ( $deps =~ /\s*(\S.+?)(:\s+(.+?)|\s*);/ )
83             {
84                $deps = $';
85
86                my $dep_path = "$1";
87                my %vars = ();
88
89                if ( defined($3) )
90                {
91                   my @var_list = split(/\s*,\s*/, "$3");
92
93                   my $var;
94                   foreach $var ( @var_list )
95                   {
96                      $var =~ /\s*(\w+)=(\S+)\s*/;
97                      $vars{"$1"} = "$2";
98                   }
99                }
100
101                $MODULES{"$mod"}->addDependency(new ModuleDependency("$dep_path",
102                                                                     \%vars));
103             }
104             else
105             {
106                # XXX: Not quite right...
107                $deps ='';
108             }
109          }
110       }
111       elsif ( $cfg_file =~ /^Default:\s+(\S+)\s*$/m )
112       {
113          $DEFAULT_MODULE = "$1";
114          $cfg_file       = $';
115       }
116
117       $cfg_file =~ s/^\s*//;
118    }
119
120    return %MODULES;
121 }
122
123 package JugglerModule;
124
125 sub new ($$)
126 {
127    my $class = shift;
128    my $name  = shift;
129
130    return bless
131    {
132       'name' => $name,          # Name of this module
133       'deps' => []              # Array of ModuleDependecy objects
134    }, $class;
135 }
136
137 sub getName ($)
138 {
139    my $this = shift;
140    return $this->{'name'};
141 }
142
143 sub getDependencies ($)
144 {
145    my $this = shift;
146    return @{$this->{'deps'}};
147 }
148
149 sub addDependency ($$)
150 {
151    my $this = shift;
152    my $dep  = shift;
153    push(@{$this->{'deps'}}, $dep) unless $this->hasDependency($dep);
154 }
155
156 sub addDependencies ($@)
157 {
158    my $this = shift;
159
160    # The $MODULES entry for $module_name contains an array of hash references.
161    # We just copy those references into the array for the current module
162    # ($this).  Simple, no?
163    my $dep;
164    foreach $dep ( @_ )
165    {
166       $this->addDependency($dep) unless $this->hasDependency($dep);
167    }
168 }
169
170 sub hasDependency ($$)
171 {
172    my $this    = shift;
173    my $new_dep = shift;
174
175    my $has_dependency = 0;
176
177    my $cur_dep;
178    foreach $cur_dep ( $this->getDependencies() )
179    {
180       if ( $cur_dep->getPath() eq $new_dep->getPath() )
181       {
182          $has_dependency = 1;
183          last;
184       }
185    }
186
187    return $has_dependency;
188 }
189
190 package ModuleDependency;
191
192 sub new ($$;$)
193 {
194    my $class = shift;
195    my $path  = shift;
196    my $env   = shift || {};
197    
198    return bless
199    {
200       'path' => $path,          # Path to this dependency
201       'env'  => $env            # Reference to environment variable hash
202    }, $class;
203 }
204
205 sub getPath ($)
206 {
207    my $this = shift;
208    return $this->{'path'};
209 }
210
211 sub getEnvironment ($)
212 {
213    my $this = shift;
214    return %{$this->{'env'}};
215 }
216
217 sub getEnvironmentValue ($$)
218 {
219    my $this = shift;
220    my $key  = shift;
221
222    return ${$this->{'env'}}{"$key"};
223 }
224
225 1;
Note: See TracBrowser for help on using the browser.