Print this page
*** NO COMMENTS ***
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/tools/scripts/ws.sh
+++ new/usr/src/tools/scripts/ws.sh
1 1 #!/bin/ksh -p
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License (the "License").
7 7 # You may not use this file except in compliance with the License.
8 8 #
9 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 # or http://www.opensolaris.org/os/licensing.
11 11 # See the License for the specific language governing permissions
12 12 # and limitations under the License.
13 13 #
14 14 # When distributing Covered Code, include this CDDL HEADER in each
15 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 # If applicable, add the following below this CDDL HEADER, with the
17 17 # fields enclosed by brackets "[]" replaced with your own identifying
18 18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 19 #
20 20 # CDDL HEADER END
21 21 #
22 22 #
23 23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 # Use is subject to license terms.
25 25 #
26 26 # ident "%Z%%M% %I% %E% SMI"
27 27 #
28 28 # This script sets up the environment variables for a SunOS
29 29 # codemgr workspace and spawns a shell with the environment
30 30 # setup.
31 31 #
32 32 # The following Environment variables are set:
33 33 # CODEMGR_WS
34 34 # ONBLD_DIR
35 35 # SRC
36 36 # TSRC
37 37 # ROOT
38 38 # PARENT_ROOT
39 39 # MACH
40 40 # MAKEFLAGS
41 41 # ENVCPPFLAGS{1-4}
42 42 # ENVLDLIBS{1-3}
43 43 #
44 44 # The MAKEFLAGS environment variable is set to force make
45 45 # to read default make variables from the environment.
46 46 #
47 47 # Workspace names can be specified in two forms: pathname
48 48 # and hostname:pathname. If the hostname:pathname form is used
49 49 # the script accesses the environment through the /net automounter
50 50 # map.
51 51 #
52 52
53 53 #
54 54 # function to produce a pathname from a workspace name or subdirectory.
55 55 # The workspace name can have hostname:pathname format.
56 56 #
57 57
58 58 fmtwsname()
59 59 {
60 60 awk -F: '$1 != $0 { print "/net/"$1$2 } \
61 61 $1 == $0 { print $0 }'
62 62 }
63 63
64 64 #
65 65 # Return a valid proto area, if one exists.
66 66 #
67 67 check_proto()
68 68 {
69 69 if [[ -z $1 ]]; then
70 70 return
71 71 fi
72 72
73 73 if [ "$SCM_MODE" = "teamware" ]; then
74 74 # Check for problematic parent specification and adjust
75 75 proto=`echo $1|fmtwsname`
76 76 echo "${proto}/root_${MACH}"
77 77 elif [ "$SCM_MODE" = "mercurial" ]; then
78 78 proto=$1
79 79 #
80 80 # If the proto is a local repository then we can use it
81 81 # to point to the parents proto area. Don't bother to
82 82 # check if it exists or not, we never did for Teamware,
83 83 # since it might appear later anyway.
84 84 #
85 85 if [ "${proto##ssh://}" == "$proto" -a \
86 86 "${proto##http://}" == "$proto" -a \
87 87 "${proto##https://}" == "$proto" ]; then
88 88 echo "${proto}/root_${MACH}"
89 89 fi
90 90 fi
91 91 }
92 92
93 93 cleanup_env()
94 94 {
95 95 # keep the env. clean when returning
96 96 unset setenv osbld_flag os_rev wsosdir protofile wsname ofs proto \
97 97 pwd parent PROTO1 PROTO2 PROTO3 tmpwsname
98 98 return 0
99 99 }
100 100
101 101 if [ "$1" = "-e" ]; then
102 102 setenv=true
103 103 shift
104 104 else
105 105 setenv=false
106 106 fi
107 107
108 108 WHICH_SCM=$(dirname $(whence $0))/which_scm
109 109 if [[ ! -x $WHICH_SCM ]]; then
110 110 WHICH_SCM=which_scm
111 111 fi
112 112
113 113 #
114 114 # No workspace/repository path was given, so try and detect one from our
115 115 # current directory we're in
116 116 #
117 117 if [ $# -lt 1 ]; then
118 118 if env CODEMGR_WS="" $WHICH_SCM | read SCM_MODE tmpwsname && \
119 119 [[ $SCM_MODE != unknown ]]; then
120 120 echo "Defaulting to $SCM_MODE repository $tmpwsname"
121 121 else
122 122 echo "usage: ws [-e] [workspace_name]" >&2
123 123 if $setenv; then
124 124 cleanup_env
125 125 return 1
126 126 else
127 127 exit 1
128 128 fi
129 129 fi
130 130 else
131 131 #
132 132 # A workspace/repository path was passed in, grab it and pop
133 133 # it off the stack
134 134 #
135 135 tmpwsname=$1
136 136 shift
137 137 fi
138 138
139 139 #
140 140 # This variable displays the nested activations of workspaces.
141 141 # This is done here to get the exact name the user entered.
142 142 #
143 143 WS_STACK="$tmpwsname $WS_STACK"; export WS_STACK
144 144
145 145 #
146 146 # Set the workspace name and unset tmpwsname (as we reuse it later)
147 147 #
148 148 wsname=`echo $tmpwsname|fmtwsname`
149 149 unset tmpwsname
150 150
151 151 #
152 152 # Checking for CODEMGR_WSPATH
153 153 #
154 154 if [ "(" "${CODEMGR_WSPATH}x" != "x" ")" -a "(" ! -d $wsname ")" -a \
155 155 "(" `expr "$wsname" : "\/"` = "0" ")" ]
156 156 then
157 157 ofs=$IFS
158 158 IFS=": "
159 159 for i in $CODEMGR_WSPATH
160 160 do
161 161 if [ -d ${i}/${wsname} ]; then
162 162 wsname=${i}/${wsname}
163 163 break
164 164 fi
165 165 done
166 166 IFS=$ofs
167 167 fi
168 168
169 169 #
170 170 # to translate it to an absolute pathname. We need an
171 171 # absolute pathname in order to set CODEMGR_WS.
172 172 #
173 173 if [ `expr "$wsname" : "\/"` = "0" ]
174 174 then
175 175 pwd=`pwd`
176 176 wsname="$pwd/$wsname"
177 177 fi
178 178
179 179 #
180 180 # Check to see if this is a valid workspace
181 181 #
182 182 if [ ! -d $wsname ]; then
183 183 echo "$wsname . . . no such directory" >&2
184 184 if $setenv; then
185 185 cleanup_env
186 186 return 1
187 187 else
188 188 exit 1
189 189 fi
190 190 fi
191 191
192 192 #
193 193 # This catches the case of a passed in workspace path
194 194 # Check which type of SCM is in use by $wsname.
195 195 #
196 196 (cd $wsname && env CODEMGR_WS="" $WHICH_SCM) | read SCM_MODE tmpwsname
197 197 if [[ $? != 0 || "$SCM_MODE" == unknown ]]; then
198 198 echo "Error: Unable to detect a supported SCM repository in $wsname"
199 199 if $setenv; then
200 200 cleanup_env
201 201 return 1
202 202 else
203 203 exit 1
204 204 fi
205 205 fi
206 206
207 207 wsname=$tmpwsname
208 208 CODEMGR_WS=$wsname ; export CODEMGR_WS
209 209 SRC=$wsname/usr/src; export SRC
210 210 TSRC=$wsname/usr/ontest; export TSRC
211 211
212 212 if [ "$SCM_MODE" = "teamware" -a -d ${wsname}/Codemgr_wsdata ]; then
213 213 CM_DATA="Codemgr_wsdata"
214 214 wsosdir=$CODEMGR_WS/$CM_DATA/sunos
215 215 protofile=$wsosdir/protodefs
216 216 elif [ "$SCM_MODE" = "mercurial" -a -d ${wsname}/.hg ]; then
217 217 CM_DATA=".hg"
218 218 wsosdir=$CODEMGR_WS/$CM_DATA
219 219 protofile=$wsosdir/org.opensolaris.protodefs
220 220 else
221 221 echo "$wsname is not a supported workspace; type is $SCM_MODE" >&2
222 222 if $setenv; then
223 223 cleanup_env
224 224 return 1
225 225 else
226 226 exit 1
227 227 fi
228 228 fi
229 229
230 230 MACH=`uname -p`
231 231
232 232 if [ ! -f $protofile ]; then
233 233 if [ ! -w $CODEMGR_WS/$CM_DATA ]; then
234 234 #
235 235 # The workspace doesn't have a protodefs file and I am
236 236 # unable to create one. Tell user and use /tmp instead.
237 237 #
238 238 echo "Unable to create the proto defaults file ($protofile)."
239 239
240 240 # Just make one in /tmp
241 241 wsosdir=/tmp
242 242 protofile=$wsosdir/protodefs
243 243 fi
244 244
245 245 if [ ! -d $wsosdir ]; then
246 246 mkdir $wsosdir
247 247 fi
248 248
249 249 cat << PROTOFILE_EoF > $protofile
250 250 #!/bin/sh
251 251 #
252 252 # Set default proto areas for this workspace
253 253 # NOTE: This file was initially automatically generated.
254 254 #
255 255 # Feel free to edit this file. If this file is removed
256 256 # it will be rebuilt containing default values.
257 257 #
258 258 # The variable CODEMGR_WS is available to this script.
259 259 #
260 260 # PROTO1 is the first proto area searched and is typically set
261 261 # to a proto area associated with the workspace. The ROOT
262 262 # environment variable is set to the same as PROTO1. If you
263 263 # will be doing make installs this proto area needs to be writable.
264 264 #
265 265 # PROTO2 and PROTO3 are set to proto areas to search before the
266 266 # search proceeds to the local machine or the proto area specified by
267 267 # TERMPROTO.
268 268 #
269 269 # TERMPROTO (if specified) is the last place searched. If
270 270 # TERMPROTO is not specified the search will end at the local
271 271 # machine.
272 272 #
273 273
274 274 PROTO1=\$CODEMGR_WS/proto
275 275 PROTOFILE_EoF
276 276
277 277 if [ "$SCM_MODE" = "teamware" ]; then
278 278 cat << PROTOFILE_EoF >> $protofile
279 279 if [ -f "\$CODEMGR_WS/Codemgr_wsdata/parent" ]; then
280 280 #
281 281 # If this workspace has an codemgr parent then set PROTO2 to
282 282 # point to the parents proto space.
283 283 #
284 284 parent=\`workspace parent \$CODEMGR_WS\`
285 285 if [[ -n \$parent ]]; then
286 286 PROTO2=\$parent/proto
287 287 fi
288 288 fi
289 289 PROTOFILE_EoF
290 290 elif [ "$SCM_MODE" = "mercurial" ]; then
291 291 cat << PROTOFILE_EoF >> $protofile
292 292 parent=\`(cd \$CODEMGR_WS && hg path default 2>/dev/null)\`
293 293 if [[ \$? -eq 0 && -n \$parent ]]; then
294 294 [[ -n \$(check_proto \$parent/proto) ]] && PROTO2=\$parent/proto
295 295 fi
296 296 PROTOFILE_EoF
297 297 fi
298 298 fi
299 299
300 300 . $protofile
301 301
302 302 # This means you don't have to type make -e all of the time
303 303
304 304 MAKEFLAGS=e; export MAKEFLAGS
305 305
306 306 #
307 307 # Set up the environment variables
308 308 #
309 309 ROOT=/proto/root_${MACH} # default
310 310
311 311 ENVCPPFLAGS1=
312 312 ENVCPPFLAGS2=
313 313 ENVCPPFLAGS3=
314 314 ENVCPPFLAGS4=
315 315 ENVLDLIBS1=
316 316 ENVLDLIBS2=
317 317 ENVLDLIBS3=
318 318
319 319 PROTO1=`check_proto $PROTO1`
320 320 if [[ -n "$PROTO1" ]]; then # first proto area specifed
321 321 ROOT=$PROTO1
322 322 ENVCPPFLAGS1=-I$ROOT/usr/include
323 323 export ENVCPPFLAGS1
324 324 ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
325 325 export ENVLDLIBS1
326 326
327 327 PROTO2=`check_proto $PROTO2`
328 328 if [[ -n "$PROTO2" ]]; then # second proto area specifed
329 329 ENVCPPFLAGS2=-I$PROTO2/usr/include
330 330 export ENVCPPFLAGS2
331 331 ENVLDLIBS2="-L$PROTO2/lib -L$PROTO2/usr/lib"
332 332 export ENVLDLIBS2
333 333
334 334 PROTO3=`check_proto $PROTO3`
335 335 if [[ -n "$PROTO3" ]]; then # third proto area specifed
336 336 ENVCPPFLAGS3=-I$PROTO3/usr/include
337 337 export ENVCPPFLAGS3
338 338 ENVLDLIBS3="-L$PROTO3/lib -L$PROTO3/usr/lib"
339 339 export ENVLDLIBS3
340 340 fi
341 341 fi
342 342 fi
343 343
344 344 export ROOT
345 345
|
↓ open down ↓ |
345 lines elided |
↑ open up ↑ |
346 346 if [[ -n "$TERMPROTO" ]]; then # fallback area specifed
347 347 TERMPROTO=`check_proto $TERMPROTO`
348 348 ENVCPPFLAGS4="-Y I,$TERMPROTO/usr/include"
349 349 export ENVCPPFLAGS4
350 350 ENVLDLIBS3="$ENVLDLIBS3 -Y P,$TERMPROTO/lib:$TERMPROTO/usr/lib"
351 351 export ENVLDLIBS3
352 352 fi
353 353
354 354 osbld_flag=0
355 355
356 +if [[ -z "$CLOSED_IS_PRESENT" ]]; then
357 + if [[ -d $SRC/../closed ]]; then
358 + export CLOSED_IS_PRESENT="yes"
359 + else
360 + export CLOSED_IS_PRESENT="no"
361 + fi
362 +fi
363 +
356 364 if [[ -z "$ONBLD_DIR" ]]; then
357 365 ONBLD_DIR=$(dirname $(whence $0))
358 366 fi
359 367
360 368 if ! echo ":$PATH:" | grep ":${ONBLD_DIR}:" > /dev/null; then
361 369 PATH="${ONBLD_DIR}:${ONBLD_DIR}/${MACH}:${PATH}"
362 370 osbld_flag=1
363 371 fi
364 372
365 373 export PATH
366 374
367 375 if [[ -n "$PROTO2" ]]; then
368 376 # This should point to the parent's proto
369 377 PARENT_ROOT=$PROTO2
370 378 export PARENT_ROOT
371 379 else
372 380 # Clear it in case it's already in the env.
373 381 PARENT_ROOT=
374 382 fi
375 383 export ONBLD_DIR
376 384 export MACH
377 385
378 386 os_rev=`uname -r`
379 387 os_name=`uname -s`
380 388
381 389 if [[ $os_name != "SunOS" || `expr $os_rev : "5\."` != "2" ]]; then
382 390 #
383 391 # This is not a SunOS 5.x machine - something is wrong
384 392 #
385 393 echo "***WARNING: this script is meant to be run on SunOS 5.x."
386 394 echo " This machine appears to be running: $os_name $os_rev"
387 395 fi
388 396
389 397 echo ""
390 398 echo "Workspace : $wsname"
391 399 if [ -n "$parent" ]; then
392 400 echo "Workspace Parent : $parent"
393 401 fi
394 402 echo "Proto area (\$ROOT) : $ROOT"
395 403 if [ -n "$PARENT_ROOT" ]; then
396 404 echo "Parent proto area (\$PARENT_ROOT) : $PARENT_ROOT"
397 405 fi
398 406 echo "Root of source (\$SRC) : $SRC"
399 407 echo "Root of test source (\$TSRC) : $TSRC"
400 408 if [ $osbld_flag = "1" ]; then
401 409 echo "Prepended to PATH : $ONBLD_DIR"
402 410 fi
403 411 echo "Current directory (\$PWD) : $wsname"
404 412 echo ""
405 413
406 414 cd $wsname
407 415
408 416 if $setenv; then
409 417 cleanup_env
410 418 else
411 419 exec ${SHELL:-sh} "$@"
412 420 fi
|
↓ open down ↓ |
47 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX