5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
26 # Copyright 2011 Nexenta Systems, Inc. All rights reserved.
28 # This script sets up the environment variables for a SunOS
29 # codemgr workspace and spawns a shell with the environment
32 # The following Environment variables are set:
44 # The MAKEFLAGS environment variable is set to force make
45 # to read default make variables from the environment.
47 # Workspace names can be specified in two forms: pathname
48 # and hostname:pathname. If the hostname:pathname form is used
49 # the script accesses the environment through the /net automounter
54 # function to produce a pathname from a workspace name or subdirectory.
55 # The workspace name can have hostname:pathname format.
60 awk -F: '$1 != $0 { print "/net/"$1$2 } \
61 $1 == $0 { print $0 }'
65 # Return a valid proto area, if one exists.
73 if [[ "$SCM_MODE" = "teamware" ]]; then
74 # Check for problematic parent specification and adjust
75 proto
=`echo $1|fmtwsname`
76 echo "${proto}/root_${MACH}"
77 elif [[ "$SCM_MODE" = "mercurial" ]]; then
80 # If the proto is a local repository then we can use it
81 # to point to the parents proto area. Don't bother to
82 # check if it exists or not, we never did for Teamware,
83 # since it might appear later anyway.
85 if [[ "${proto##ssh://}" == "$proto" && \
86 "${proto##http://}" == "$proto" && \
87 "${proto##https://}" == "$proto" ]]; then
88 echo "${proto}/root_${MACH}"
90 elif [[ "$SCM_MODE" = "git" ]]; then
92 # For git, we make no attempt to deal with the possibility of
93 # remote parent workspaces because, in the protodefs file, we
94 # don't actually acknowledge the concept of a parent workspace
95 # at all, in keeping with the rest of our git support.
97 echo "${1}/root_${MACH}"
103 # keep the env. clean when returning
104 unset setenv osbld_flag os_rev wsosdir protofile wsname ofs proto \
105 pwd parent PROTO1 PROTO2 PROTO3 tmpwsname
109 if [[ "$1" = "-e" ]]; then
116 WHICH_SCM
=$
(/bin
/dirname $
(whence
$0))/which_scm
117 if [[ ! -x $WHICH_SCM ]]; then
122 # No workspace/repository path was given, so try and detect one from our
123 # current directory we're in
125 if [[ $# -lt 1 ]]; then
126 if env CODEMGR_WS
="" $WHICH_SCM |
read SCM_MODE tmpwsname
&& \
127 [[ $SCM_MODE != unknown
]]; then
128 echo "Defaulting to $SCM_MODE repository $tmpwsname"
130 echo "usage: ws [-e] [workspace_name]" >&2
140 # A workspace/repository path was passed in, grab it and pop
148 # This variable displays the nested activations of workspaces.
149 # This is done here to get the exact name the user entered.
151 WS_STACK
="$tmpwsname $WS_STACK"; export WS_STACK
154 # Set the workspace name and unset tmpwsname (as we reuse it later)
156 wsname
=`echo $tmpwsname|fmtwsname`
160 # Checking for CODEMGR_WSPATH
162 if [[ -n ${CODEMGR_WSPATH} && ( ! -d $wsname ) && \
163 ( `expr "$wsname" : "\/"` = "0" ) ]]
167 for i
in $CODEMGR_WSPATH
169 if [[ -d ${i}/${wsname} ]]; then
170 wsname
=${i}/${wsname}
178 # to translate it to an absolute pathname. We need an
179 # absolute pathname in order to set CODEMGR_WS.
181 if [[ `expr "$wsname" : "\/"` = "0" ]]
184 wsname
="$pwd/$wsname"
188 # Check to see if this is a valid workspace
190 if [[ ! -d $wsname ]]; then
191 echo "$wsname . . . no such directory" >&2
201 # This catches the case of a passed in workspace path
202 # Check which type of SCM is in use by $wsname.
204 (cd $wsname && env CODEMGR_WS
="" $WHICH_SCM) |
read SCM_MODE tmpwsname
205 if [[ $?
!= 0 ||
"$SCM_MODE" == unknown
]]; then
206 echo "Error: Unable to detect a supported SCM repository in $wsname"
216 CODEMGR_WS
=$wsname ; export CODEMGR_WS
217 SRC
=$wsname/usr
/src
; export SRC
218 TSRC
=$wsname/usr
/ontest
; export TSRC
220 if [[ "$SCM_MODE" = "teamware" && -d ${wsname}/Codemgr_wsdata
]]; then
221 CM_DATA
="Codemgr_wsdata"
222 wsosdir
=$CODEMGR_WS/$CM_DATA/sunos
223 protofile
=$wsosdir/protodefs
224 elif [[ "$SCM_MODE" = "mercurial" && -d ${wsname}/.hg
]]; then
226 wsosdir
=$CODEMGR_WS/$CM_DATA
227 protofile
=$wsosdir/org.opensolaris.protodefs
228 elif [[ "$SCM_MODE" = "git" && -d ${wsname}/.git
]]; then
230 wsosdir
=$CODEMGR_WS/$CM_DATA
231 protofile
=$wsosdir/org.opensolaris.protodefs
233 echo "$wsname is not a supported workspace; type is $SCM_MODE" >&2
244 if [[ ! -f $protofile ]]; then
245 if [[ ! -w $CODEMGR_WS/$CM_DATA ]]; then
247 # The workspace doesn't have a protodefs file and I am
248 # unable to create one. Tell user and use /tmp instead.
250 echo "Unable to create the proto defaults file ($protofile)."
252 # Just make one in /tmp
254 protofile
=$wsosdir/protodefs
257 if [[ ! -d $wsosdir ]]; then
261 cat << PROTOFILE_EoF > $protofile
264 # Set default proto areas for this workspace
265 # NOTE: This file was initially automatically generated.
267 # Feel free to edit this file. If this file is removed
268 # it will be rebuilt containing default values.
270 # The variable CODEMGR_WS is available to this script.
272 # PROTO1 is the first proto area searched and is typically set
273 # to a proto area associated with the workspace. The ROOT
274 # environment variable is set to the same as PROTO1. If you
275 # will be doing make installs this proto area needs to be writable.
277 # PROTO2 and PROTO3 are set to proto areas to search before the
278 # search proceeds to the local machine or the proto area specified by
281 # TERMPROTO (if specified) is the last place searched. If
282 # TERMPROTO is not specified the search will end at the local
286 PROTO1=\$CODEMGR_WS/proto
289 if [[ "$SCM_MODE" = "teamware" ]]; then
290 cat << PROTOFILE_EoF >> $protofile
291 if [[ -f "\$CODEMGR_WS/Codemgr_wsdata/parent" ]]; then
293 # If this workspace has an codemgr parent then set PROTO2 to
294 # point to the parents proto space.
296 parent=\`workspace parent \$CODEMGR_WS\`
297 if [[ -n \$parent ]]; then
298 PROTO2=\$parent/proto
302 elif [[ "$SCM_MODE" = "mercurial" ]]; then
303 cat << PROTOFILE_EoF >> $protofile
304 parent=\`(cd \$CODEMGR_WS && hg path default 2>/dev/null)\`
305 if [[ \$? -eq 0 && -n \$parent ]]; then
306 [[ -n \$(check_proto \$parent/proto) ]] && PROTO2=\$parent/proto
314 # This means you don't have to type make -e all of the time
316 MAKEFLAGS
=e
; export MAKEFLAGS
319 # Set up the environment variables
321 ROOT
=/proto
/root_
${MACH} # default
331 PROTO1
=`check_proto $PROTO1`
332 if [[ -n "$PROTO1" ]]; then # first proto area specifed
334 ENVCPPFLAGS1
=-I$ROOT/usr
/include
336 ENVLDLIBS1
="-L$ROOT/lib -L$ROOT/usr/lib"
339 PROTO2
=`check_proto $PROTO2`
340 if [[ -n "$PROTO2" ]]; then # second proto area specifed
341 ENVCPPFLAGS2
=-I$PROTO2/usr
/include
343 ENVLDLIBS2
="-L$PROTO2/lib -L$PROTO2/usr/lib"
346 PROTO3
=`check_proto $PROTO3`
347 if [[ -n "$PROTO3" ]]; then # third proto area specifed
348 ENVCPPFLAGS3
=-I$PROTO3/usr
/include
350 ENVLDLIBS3
="-L$PROTO3/lib -L$PROTO3/usr/lib"
358 if [[ -n "$TERMPROTO" ]]; then # fallback area specifed
359 TERMPROTO
=`check_proto $TERMPROTO`
360 ENVCPPFLAGS4
="-Y I,$TERMPROTO/usr/include"
362 ENVLDLIBS3
="$ENVLDLIBS3 -Y P,$TERMPROTO/lib:$TERMPROTO/usr/lib"
368 if [[ -z "$ONBLD_DIR" ]]; then
369 ONBLD_DIR
=$
(/bin
/dirname $
(whence
$0))
372 if ! echo ":$PATH:" |
grep ":${ONBLD_DIR}:" > /dev
/null
; then
373 PATH
="${ONBLD_DIR}:${ONBLD_DIR}/${MACH}:${PATH}"
379 if [[ -n "$PROTO2" ]]; then
380 # This should point to the parent's proto
384 # Clear it in case it's already in the env.
393 if [[ $os_name != "SunOS" ||
`expr $os_rev : "5\."` != "2" ]]; then
395 # This is not a SunOS 5.x machine - something is wrong
397 echo "***WARNING: this script is meant to be run on SunOS 5.x."
398 echo " This machine appears to be running: $os_name $os_rev"
402 echo "Workspace : $wsname"
403 if [[ -n "$parent" ]]; then
404 echo "Workspace Parent : $parent"
406 echo "Proto area (\$ROOT) : $ROOT"
407 if [[ -n "$PARENT_ROOT" ]]; then
408 echo "Parent proto area (\$PARENT_ROOT) : $PARENT_ROOT"
410 echo "Root of source (\$SRC) : $SRC"
411 echo "Root of test source (\$TSRC) : $TSRC"
412 if [[ $osbld_flag = "1" ]]; then
413 echo "Prepended to PATH : $ONBLD_DIR"
415 echo "Current directory (\$PWD) : $wsname"
423 exec ${SHELL:-sh} "$@"