8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / tools / scripts / flg.flp.sh
blob55095dd1005eb697118e73cf9a715c6204d9fcf1
1 #! /bin/ksh -p
3 # CDDL HEADER START
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]
20 # CDDL HEADER END
23 # Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
27 # Generates the list of source files that would get brought over with the
28 # specified subtree as a result of inc.flg and req.flg files. If no subtree
29 # is named, then the current directory is assumed.
31 # Based loosely on ON's version of Teamware's def.dir.flp.
34 ONBLDDIR=$(dirname $(whence $0))
36 PATH=/usr/bin:${BUILD_TOOLS:-/opt}/teamware/bin:$ONBLDDIR
37 export PATH
38 PROG=`basename $0`
41 # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
42 # under certain circumstances, which will screw up consumers of incflg()
43 # (and perhaps other things as well); unset it.
45 unset CDPATH
48 # Print the usage message and exit with an error.
50 usage()
52 echo "usage: $PROG [-r] [<dir>]" > /dev/stderr
53 exit 1
57 # Print the provided failure message and exit with an error.
59 fail()
61 echo $PROG: $@ > /dev/stderr
62 exit 1
65 # Find the files matching the pattern specified by the first argument in the
66 # directories named by the remaining arguments. Unlike def.dir.flp, print
67 # the name of the source file since we want to make a list of source files,
68 # not SCCS files.
70 find_files()
72 pat=$1
73 shift
75 if [[ "$SCM_MODE" = "teamware" ]]; then
76 for dir; do
77 if [[ -d $CODEMGR_WS/$dir ]]; then
78 cd $CODEMGR_WS
79 find $dir -name "$pat" | \
80 sed -n s:/SCCS/s.:/:p | prpath
81 cd - > /dev/null
83 done
84 elif [[ "$SCM_MODE" = "mercurial" || "$SCM_MODE" == "git" ]]; then
85 dirs=""
86 for dir; do
87 if [[ -d $CODEMGR_WS/$dir ]]; then
88 dirs="$dirs|${dir%/}"
90 done
92 # Remove leading pipe before it can confuse egrep
93 dirs=${dirs#\|}
94 echo "$FILELIST" | egrep "^($dirs)/.*/${pat#s.}\$" | prpath
99 # Echo the filename if it exists in the workspace.
101 echo_file()
103 [ -f $CODEMGR_WS/$1 ] && echo $1 | prpath
107 # Source the named script, specified as either a full path or a path relative
108 # to $CODEMGR_WS. Although def.dir.flp allows for situations in which the
109 # script is actually executed (rather than sourced), this feature has never
110 # been used in ON, since it precludes use of echo_file() and find_files().
112 exec_file()
114 if [[ "${1##/}" = "$1" ]]; then
115 . $CODEMGR_WS/$1
116 else
117 . $1
122 # Iterate up through all directories below the named directory, and
123 # execute any inc.flg's that may exist.
125 incflg()
127 cd $1
128 for i in * .*; do
129 case $i in
130 '*'|.|..)
132 inc.flg)
133 exec_file $1/$i
136 if [[ -d $i && ! -h $i ]]; then
137 incflg $1/$i
138 cd $1
141 esac
142 done
146 # Convert the absolute pathnames named on input to relative pathnames (if
147 # necessary) and print them.
149 prpath()
152 # $CURTREE may be a subdirectory of $CODEMGR_WS, or it
153 # may be the root of $CODEMGR_WS. We want to strip it
154 # and end up with a relative path in either case, so the
155 # ?(/) pattern is important. If we don't do that, the
156 # dots/tree loop will go on forever.
158 reltree=${CURTREE##$CODEMGR_WS?(/)}
160 while read srcfile; do
161 if [[ "$RELPATHS" != y ]]; then
162 echo $srcfile
163 continue
166 dots=
167 tree=$reltree
168 while [[ "${srcfile##$tree}" = "$srcfile" ]]; do
169 dots=../$dots
170 tree=`dirname $tree`
171 [ "$tree" = "." ] && break
172 done
173 echo ${dots}${srcfile##$tree/}
174 done
177 which_scm | read SCM_MODE CODEMGR_WS || exit 1
179 if [[ $SCM_MODE == "unknown" ]]; then
180 fail "Unable to determine SCM type currently in use."
181 elif [[ $SCM_MODE == "mercurial" ]]; then
182 FILELIST=$(hg manifest)
183 elif [[ $SCM_MODE == "git" ]]; then
184 FILELIST=$(cd $(dirname $(git rev-parse --git-dir)) && git ls-files)
185 elif [[ $SCM_MODE != "teamware" ]]; then
186 fail "Unsupported SCM in use: $SCM_MODE"
189 while getopts r flag; do
190 case $flag in
192 RELPATHS=y
195 usage
197 esac
198 done
200 shift $((OPTIND - 1))
202 [ $# -gt 1 ] && usage
204 CURTREE=`/bin/pwd`
207 # Determine the subtree being examined.
209 if [[ $# -eq 0 ]]; then
210 SUBTREE=$CURTREE
211 elif [[ -d $1 ]]; then
212 SUBTREE=$1
213 elif [[ -d $CODEMGR_WS/$1 ]]; then
214 SUBTREE=$CODEMGR_WS/$1
215 else
216 fail "neither \$CODEMGR_WS/$1 nor $1 exists as a directory"
220 # Get the canonical path to the subtree.
222 cd $SUBTREE
223 SUBTREE=`/bin/pwd`
226 # Get the canonical path to the current directory.
228 cd $CURTREE
229 CURTREE=`/bin/pwd`
232 # Get the canonical path to the workspace.
234 cd $CODEMGR_WS
235 CODEMGR_WS=`/bin/pwd`
237 if [[ "${SUBTREE##$CODEMGR_WS}" = "$SUBTREE" ]]; then
238 fail "$SUBTREE is not a subtree of \$CODEMGR_WS"
241 if [[ "${CURTREE##$CODEMGR_WS}" = "$CURTREE" ]]; then
242 fail "$CURTREE is not a subtree of \$CODEMGR_WS"
246 # Find and execute all inc.flg's below our subtree.
248 incflg $SUBTREE
251 # Find and execute all req.flg's at or above our subtree.
253 TREE=$SUBTREE
254 while [[ $TREE != $CODEMGR_WS ]]; do
255 [[ -f $TREE/req.flg ]] && exec_file $TREE/req.flg
256 TREE=`dirname $TREE`
257 done
259 exit 0