forked from AcademySoftwareFoundation/rez
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrez-env
executable file
·266 lines (217 loc) · 6.45 KB
/
rez-env
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/bin/bash
#
# rez-env
#
# A tool for invoking a shell based on a configuration request.
#
. _set-rez-env
##############################################################################
# parse args
##############################################################################
IFS='
'
cmdlin=`!REZ_PYTHON_BINARY! $REZ_PATH/python/rez/rez_env_cmdlin.py $*`
if [ $? -ne 0 ]; then
!REZ_PYTHON_BINARY! $REZ_PATH/python/rez/rez_env_cmdlin.py $*
exit $?
fi
pkgs=
for ln in $cmdlin
do
ln=`echo $ln | tr -d '\n'`
if [ "$pkgs" == "" ]; then
pkgs=$ln
else
eval "$ln"
fi
done
unset IFS
autowrappers=`echo $* | grep '('`
if [ "$_REZ_ENV_OPT_ADD_LOOSE" == "True" -o "$_REZ_ENV_OPT_ADD_STRICT" == "True" ]; then
if [ "$autowrappers" != "" ]; then
echo "Patching of auto-wrapper environments is not yet supported." >&2
exit 1
fi
if [ "`echo $REZ_RAW_REQUEST | grep '('`" != "" ]; then
echo "Patching from auto-wrapper environments is not yet supported." >&2
exit 1
fi
fi
tmpdir=$_REZ_ENV_OPT_TMPDIR
##############################################################################
# switch to auto-wrapper rez-env if bracket syntax is detected
# TODO patching of wrapper envs is not yet supported.
##############################################################################
if [ "$autowrappers" != "" ]; then
if [ "$tmpdir" == "" ]; then
tmpdir=`mktemp -d`
fi
export REZ_TMP_DIR=$tmpdir
rez-env-autowrappers $tmpdir $*
if [ $? -ne 0 ]; then
exit 1
fi
raw_request=$pkgs
export REZ_PACKAGES_PATH=$tmpdir:$REZ_PACKAGES_PATH
new_pkgs=`cat $tmpdir/packages.txt`
unset _REZ_ENV_OPT_ADD_LOOSE
unset _REZ_ENV_OPT_ADD_STRICT
_REZ_ENV_OPT_NO_CACHE=True
set -- $new_pkgs
else
set -- $pkgs
fi
##############################################################################
# apply patching, if any
##############################################################################
pkg_list=
print_pkgs=
ctxt_pkg_list=
if [ "$_REZ_ENV_OPT_ADD_LOOSE" == "True" ]; then
ctxt_pkg_list=$REZ_REQUEST
print_pkgs=1
elif [ "$_REZ_ENV_OPT_ADD_STRICT" == "True" ]; then
ctxt_pkg_list=$REZ_RESOLVE
print_pkgs=1
fi
if [ "$ctxt_pkg_list" == "" ]; then
pkg_list="$@"
else
pkg_list=`rez-merge-requests "$ctxt_pkg_list | $@"`
fi
if [ "$print_pkgs" != "" ] && [ "$_REZ_ENV_OPT_QUIET" != "True" ]; then
quotedpkgs=`echo $pkg_list | sed "s/ /' '/g"`
echo "request: '"$quotedpkgs"'"
fi
##############################################################################
# call rez-config, and write env into bake file
##############################################################################
tmpd=$tmpdir
if [ "$tmpd" == "" ]; then
tmpd="/tmp"
fi
tmpf=`mktemp -p $tmpd .rez-context.XXXXXXXXXX`
tmpf2=$tmpf".source"
tmpf3=$tmpf".dot"
if [ "$_REZ_ENV_OPT_BUILD" == "True" ]; then
buildreq_flag="--build-requires"
fi
if [ "$_REZ_ENV_OPT_NO_OS" == "True" ]; then
no_os_flag="--no-os"
fi
if [ "$_REZ_ENV_OPT_NO_LOCAL" == "True" ]; then
no_local_flag="--no-local"
fi
if [ "$_REZ_ENV_OPT_IGNORE_BLACKLIST" == "True" ]; then
use_blacklist_flag="--ignore-blacklist"
fi
if [ "$_REZ_ENV_OPT_IGNORE_ARCHIVING" == "True" ]; then
ignore_archiving_flag="--ignore-archiving"
fi
if [ "$_REZ_ENV_OPT_NO_ASSUME_DT" == "True" ]; then
dt_flag="--no-assume-dt"
fi
if [ "$_REZ_ENV_OPT_VIEW_FAIL" != "-1" ]; then
max_fails_flag="--max-fails="$_REZ_ENV_OPT_VIEW_FAIL
fi
if [ "$_REZ_ENV_OPT_NO_CACHE" == "True" ]; then
no_cache_flag="--no-cache"
fi
rez-config --time=$_REZ_ENV_OPT_TIME --print-env --meta-info=tools --meta-info-shallow=tools \
--dot-file=$tmpf3 --mode=$_REZ_ENV_OPT_MODE $max_fails_flag $dt_flag $ignore_archiving_flag \
$use_blacklist_flag $buildreq_flag $no_os_flag $no_local_flag $no_cache_flag $pkg_list > $tmpf
ret=$?
if [ $ret -ne 0 ] && [ "$_REZ_ENV_OPT_VIEW_FAIL" != "-1" ]; then
rez-dot -c $tmpf3
rm -f $tmpf
rm -f $tmpf3
exit 1
fi
if [ "$autowrappers" != "" ]; then
echo "export REZ_RAW_REQUEST='$raw_request'" >> $tmpf
fi
function on_exit {
child_procs=`jobs -p`
if [ "$child_procs" != "" ]; then
kill $child_procs
fi
rm -f $tmpf
rm -f $tmpf2
rm -f $tmpf3
}
trap 'on_exit' EXIT
##############################################################################
# spawn the new shell, sourcing the bake file
##############################################################################
if [ $ret -eq 0 ]; then
if [ "$REZ_RAW_REQUEST" == "" ]; then
export REZ_RAW_REQUEST="$@"
fi
export REZ_CONTEXT_FILE=$tmpf
export REZ_ENV_PROMPT="$REZ_ENV_PROMPT$_REZ_ENV_OPT_PROMPT"
if [ "$_REZ_ENV_OPT_STDIN" == "True" ]; then
source $tmpf
if [ "$_REZ_ENV_OPT_RCFILE" == "" ]; then
if [ -f ~/.bashrc ]; then
source ~/.bashrc &> /dev/null
fi
else
source $_REZ_ENV_OPT_RCFILE
if [ $? -ne 0 ]; then
exit 1
fi
fi
# ensure that rez-config is available no matter what (eg .bashrc might not exist,
# rcfile might not source rez-config)
source $REZ_PATH/init.sh
bash -s
ret=$?
elif [ "$_REZ_ENV_OPT_CMD" != "" ]; then
source $tmpf
if [ "$_REZ_ENV_OPT_RCFILE" == "" ]; then
if [ -f ~/.bashrc ]; then
source ~/.bashrc &> /dev/null
fi
else
source $_REZ_ENV_OPT_RCFILE
if [ $? -ne 0 ]; then
exit 1
fi
fi
# ensure that rez-config is available no matter what (eg .bashrc might not exist,
# rcfile might not source rez-config)
source $REZ_PATH/init.sh
$_REZ_ENV_OPT_CMD
ret=$?
else
echo "source $tmpf" > $tmpf2
if [ "$_REZ_ENV_OPT_RCFILE" != "" ]; then
echo "source $_REZ_ENV_OPT_RCFILE" >> $tmpf2
fi
echo "source rez-env-bashrc" >> $tmpf2
if [ "$_REZ_ENV_OPT_QUIET" == "False" ]; then
echo "echo" >> $tmpf2
echo "echo You are now in a new environment." >> $tmpf2
echo "rez-context-info" >> $tmpf2
fi
bash --rcfile $tmpf2
ret=$?
fi
fi
exit $ret
# Copyright 2008-2012 Dr D Studios Pty Limited (ACN 127 184 954) (Dr. D Studios)
#
# This file is part of Rez.
#
# Rez is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Rez is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Rez. If not, see <http://www.gnu.org/licenses/>.