forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctunattach.pl
More file actions
251 lines (237 loc) · 7.52 KB
/
ctunattach.pl
File metadata and controls
251 lines (237 loc) · 7.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
require "$tool/built/include/ctquery.pl" ;
$shell_type = "csh" ;
if ( $ENV{"SHELL_TYPE"} ne "" ) {
if ( $ENV{"SHELL_TYPE"} eq "sh" ) {
$shell_type = "sh" ;
}
}
# remove a value from a variable. If it is the only thing remaining in the
# variable, add it to the unset list.
# input is in:
# $_[0] = variable
# $_[1] = value
#
# output is in:
# %newenv = an image of how we want the environment to be
# @unset = a list of variables to unset
sub CTUnattachMod {
&CTUDebug( "in CTUnattachMod\n" ) ;
local( $done ) = 0 ;
# if we didn't get any data, nothing really to do
if ( $_[0] eq "" ) { $done = 1 ; }
if ( $_[1] eq "" ) { $done = 1 ; }
# if the variable is already set to be unset, nothing really to do
if ( join( " ", @unset ) =~ /$_[0]/ ) { $done = 1 ; }
# if the variable isn't in newenv, move it there, if it's empty mark it
# for unsetting
if ( $newenv{$_[0]} eq "" ) {
$newenv{$_[0]} = &CTSpoolEnv( $_[0] ) ;
if ( $newenv{$_[0]} eq "" ) {
push( @unset, $_[0] ) ;
delete $newenv{$_[0]} ;
$done = 1 ;
}
}
# if the value does not appear in the variable, nothing really to do
if ( ! ( $newenv{$_[0]} =~ /$_[1]/ ) ) { $done = 1 ; }
# now down to the real work
if ( ! $done ) {
# if the variable is exactly the value, mark it for unsetting
if ( $newenv{$_[0]} eq $_[1] ) {
push( @unset, $_[0] ) ;
delete $newenv{$_[0]} ;
} elsif ( $newenv{$_[0]} =~ / $_[1]/ ) {
local( $tmp ) = $newenv{$_[0]} ;
$tmp =~ s/ $_[1]// ;
$newenv{$_[0]} = $tmp ;
} elsif ( $newenv{$_[0]} =~ /$_[1] / ) {
local( $tmp ) = $newenv{$_[0]} ;
$tmp =~ s/$_[1] // ;
$newenv{$_[0]} = $tmp ;
} else {
print STDERR "ERROR: variable '" . $_[0] . "' contains '" .
$_[1] . "' (in '" . $newenv{$_[0]} .
"'), but I am too stupid to figure out how to remove it.\n" ;
}
}
}
# given the project and flavor, build the lists of variables to set/modify
# input is in:
# $_[0] = project
# $_[1] = flavor
#
# output is in:
# return value is config line
# %newenv = an image of what we want the environment to look like
# @unset = list of variables to be unset
# %envsep = seperator
# %envcmd = set or setenv
# %envpostpend = flag that variable should be postpended
sub CTUnattachCompute {
&CTUDebug( "in CTUnattachCompute\n" ) ;
local( $flav ) = $_[1] ;
local( $spec ) = &CTResolveSpec( $_[0], $flav ) ;
local( $root ) = &CTComputeRoot( $_[0], $flav, $spec ) ;
if ( $spec ne "" ) {
local( $proj ) = $_[0] ;
$proj =~ tr/a-z/A-Z/ ;
local( $item ) ;
# since we don't have to worry about sub-attaches, it doesn't matter
# if we scan the .init file first or not. So we won't.
&CTUDebug( "extending paths\n" ) ;
$item = $root . "/built/bin" ;
&CTUnattachMod( "PATH", $item ) ;
$item = $root . "/built/lib" ;
if ( $ENV{"PENV"} eq "WIN32" ) {
&CTUnattachMod( "PATH", $item ) ;
}
&CTUnattachMod( "LD_LIBRARY_PATH", $item ) ;
&CTUnattachMod( "DYLD_LIBRARY_PATH", $item ) ;
#$item = $root . "/src/all" ;
#&CTUnattachMod( "CDPATH", $item ) ;
$item = $root . "/built/include" ;
&CTUnattachMod( "CT_INCLUDE_PATH", $item ) ;
$item = $root . "/built/etc" ;
&CTUnattachMod( "ETC_PATH", $item ) ;
$item = $proj . ":" . $flav ;
&CTUnattachMod( "CTPROJS", $item ) ;
push( @unset, $proj ) ;
if ( -e "$root/built/etc/$_[0].init" ) {
&CTUDebug( "scanning $_[0].init file\n" ) ;
local( @linesplit ) ;
local( $linetmp ) ;
local( $loop );
local( *INITFILE ) ;
if ( -x "$root/built/etc/$_[0].init" ) {
open( INITFILE, "$root/built/etc/$_[0].init $_[0] $_[1] $root |" ) ;
} else {
open( INITFILE, "< $root/built/etc/$_[0].init" ) ;
}
while ( <INITFILE> ) {
s/\n$// ;
@linesplit = split( /\#/ ) ;
$_ = $linesplit[0] ;
if ( $_ =~ /^MODABS/ ) {
@linesplit = split ;
$linetmp = $linesplit[1] ;
shift( @linesplit ) ;
shift( @linesplit ) ;
foreach $loop ( @linesplit ) {
&CTUnattachMod( $linetmp, $loop ) ;
}
} elsif ( $_ =~ /^MODREL/ ) {
@linesplit = split ;
$linetmp = $linesplit[1] ;
shift( @linesplit ) ;
shift( @linesplit ) ;
foreach $loop ( @linesplit ) {
&CTUnattachMod( $linetmp, $root . "/" . $loop ) ;
}
} elsif ( $_ =~ /^SETABS/ ) {
@linesplit = split ;
$linetmp = $linesplit[1] ;
push( @unset, $linetmp ) ;
} elsif ( $_ =~ /^SETREL/ ) {
@linesplit = split ;
$linetmp = $linesplit[1] ;
push( @unset, $linetmp ) ;
} elsif ( $_ =~ /^SEP/ ) {
@linesplit = split ;
$envsep{$linesplit[1]} = $linesplit[2] ;
} elsif ( $_ =~ /^CMD/ ) {
@linesplit = split ;
$envcmd{$linesplit[1]} = $linesplit[2] ;
} elsif ( $_ =~ /^DOCSH/ ) {
&CTUDebug( "ignoring DO command in .init file\n" ) ;
} elsif ( $_ =~ /^DOSH/ ) {
&CTUDebug( "ignoring DO command in .init file\n" ) ;
} elsif ( $_ =~ /^DO/ ) {
&CTUDebug( "ignoring DO command in .init file\n" ) ;
} elsif ( $_ =~ /^POSTPEND/ ) {
@linesplit = split ;
$envpospend{$linesplit[1]} = 1 ;
} elsif ( $_ =~ /^ATTACH/ ) {
&CTUDebug( "ignoring ATTACH command in .init file\n" ) ;
} else {
print STDERR "Unknown .init directive '$_'\n" ;
}
}
close( INITFILE ) ;
}
}
&CTUDebug( "out of CTUnattachCompute\n" ) ;
$spec ;
}
# write a script to setup the environment
# Input is:
# $_[0] = filename
sub CTUnattachWriteScript {
&CTUDebug( "in CTAttachWriteScript\n" ) ;
local( *OUTFILE ) ;
open( OUTFILE, ">$_[0]" ) ;
print OUTFILE "#!/bin/" . $shell_type . " -f\n" ;
local( $item ) ;
#local( $unsetcdpath ) = 0 ;
#local( $modcdpath ) = 0 ;
foreach $item ( @unset ) {
#if ( $item eq "CDPATH" ) { $unsetcdpath = 1 ; }
if ( $shell_type eq "sh" ) {
print OUTFILE "$item=\n" ;
if ( $envcmd{$item} ne "set" ) {
print OUTFILE "export $item\n" ;
}
} else {
if ( $envcmd{$item} ne "" ) {
print OUTFILE "un" . $envcmd{$item} . " $item\n" ;
} else {
print OUTFILE "unsetenv $item\n" ;
}
}
}
foreach $item ( keys %newenv ) {
#if ( $item eq "CDPATH" ) { $modcdpath = 1 ; }
local( $sep ) = " " ;
if ( $envsep{$item} ne "" ) {
$sep = $envsep{$item} ;
}
local( @splitlist ) = split( / +/, $newenv{$item} ) ;
local( $outval ) = join( $sep, @splitlist ) ;
if ( $shell_type eq "sh" ) {
print OUTFILE "$item=\"" . $outval . "\"\n" ;
if ( $envcmd{$item} ne "set" ) {
print OUTFILE "export $item\n" ;
}
} else {
if ( $envcmd{$item} ne "" ) {
PRINT OUTFILE $envcmd{$item} . " $item " ;
if ( $envcmd{$item} eq "set" ) {
print OUTFILE " = ( " ;
}
print OUTFILE $outval ;
if ( $envcmd{$item} eq "set" ) {
print OUTFILE ")" ;
}
print OUTFILE "\n" ;
} else {
print OUTFILE "setenv $item \"$outval\"\n" ;
}
}
}
#if ( $unsetcdpath ) {
# if ( $shell_type ne "sh" ) {
# print OUTFILE "unset cdpath\n" ;
# }
#} elsif ( $modcdpath ) {
# if ( $shell_type ne "sh" ) {
# print OUTFILE "set cdpath = ( \$" . "CDPATH )\n" ;
# }
#}
if (! $ctdebug) {
print OUTFILE "rm -f $_[0]\n" ;
} else {
print STDERR "no self-destruct script '" . $_[0] . "'\n" ;
}
close( OUTFILE ) ;
&CTUDebug( "out of CTUnattachWriteScript\n" ) ;
}
1;