xref: /titanic_53/usr/src/tools/scripts/flg.flp.sh (revision cdf0c1d55d9b3b6beaf994835440dfb01aef5cf0)
17c478bd9Sstevel@tonic-gate#! /bin/ksh -p
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*cdf0c1d5Smjnelson# Common Development and Distribution License (the "License").
7*cdf0c1d5Smjnelson# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
23*cdf0c1d5Smjnelson# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate# Use is subject to license terms.
257c478bd9Sstevel@tonic-gate#
267c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate#
28*cdf0c1d5Smjnelson#
297c478bd9Sstevel@tonic-gate# Generates the list of source files that would get brought over with the
307c478bd9Sstevel@tonic-gate# specified subtree as a result of inc.flg and req.flg files.  If no subtree
317c478bd9Sstevel@tonic-gate# is named, then the current directory is assumed.
327c478bd9Sstevel@tonic-gate#
337c478bd9Sstevel@tonic-gate# Based loosely on ON's version of Teamware's def.dir.flp.
347c478bd9Sstevel@tonic-gate#
357c478bd9Sstevel@tonic-gate
36*cdf0c1d5SmjnelsonONBLDDIR=$(dirname $(whence $0))
37*cdf0c1d5Smjnelson
38*cdf0c1d5SmjnelsonPATH=/usr/bin:${BUILD_TOOLS:-/opt}/teamware/bin:$ONBLDDIR
39*cdf0c1d5Smjnelsonexport PATH
407c478bd9Sstevel@tonic-gatePROG=`basename $0`
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate#
437c478bd9Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
447c478bd9Sstevel@tonic-gate# under certain circumstances, which will screw up consumers of incflg()
457c478bd9Sstevel@tonic-gate# (and perhaps other things as well); unset it.
467c478bd9Sstevel@tonic-gate#
477c478bd9Sstevel@tonic-gateunset CDPATH
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate#
507c478bd9Sstevel@tonic-gate# Print the usage message and exit with an error.
517c478bd9Sstevel@tonic-gate#
527c478bd9Sstevel@tonic-gateusage()
537c478bd9Sstevel@tonic-gate{
547c478bd9Sstevel@tonic-gate	echo "usage: $PROG [-r] [<dir>]" > /dev/stderr
557c478bd9Sstevel@tonic-gate	exit 1
567c478bd9Sstevel@tonic-gate}
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate#
597c478bd9Sstevel@tonic-gate# Print the provided failure message and exit with an error.
607c478bd9Sstevel@tonic-gate#
617c478bd9Sstevel@tonic-gatefail()
627c478bd9Sstevel@tonic-gate{
637c478bd9Sstevel@tonic-gate	echo $PROG: $@ > /dev/stderr
647c478bd9Sstevel@tonic-gate	exit 1
657c478bd9Sstevel@tonic-gate}
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate# Find the files matching the pattern specified by the first argument in the
687c478bd9Sstevel@tonic-gate# directories named by the remaining arguments.  Unlike def.dir.flp, print
697c478bd9Sstevel@tonic-gate# the name of the source file since we want to make a list of source files,
707c478bd9Sstevel@tonic-gate# not SCCS files.
717c478bd9Sstevel@tonic-gate#
727c478bd9Sstevel@tonic-gatefind_files()
737c478bd9Sstevel@tonic-gate{
747c478bd9Sstevel@tonic-gate   	pat=$1
757c478bd9Sstevel@tonic-gate   	shift
767c478bd9Sstevel@tonic-gate
77*cdf0c1d5Smjnelson	if [ "$SCM_MODE" = "teamware" ] ; then
787c478bd9Sstevel@tonic-gate		for dir; do
797c478bd9Sstevel@tonic-gate			if [ -d $CODEMGR_WS/$dir ]; then
807c478bd9Sstevel@tonic-gate				cd $CODEMGR_WS
81*cdf0c1d5Smjnelson				find $dir -name "$pat" | \
82*cdf0c1d5Smjnelson					sed -n s:/SCCS/s.:/:p | prpath
837c478bd9Sstevel@tonic-gate				cd - > /dev/null
847c478bd9Sstevel@tonic-gate			fi
857c478bd9Sstevel@tonic-gate		done
86*cdf0c1d5Smjnelson	elif [ "$SCM_MODE" = "mercurial" ]; then
87*cdf0c1d5Smjnelson		dirs=""
88*cdf0c1d5Smjnelson		for dir; do
89*cdf0c1d5Smjnelson			if [ -d $CODEMGR_WS/$dir ]; then
90*cdf0c1d5Smjnelson				dirs="$dirs|${dir%/}"
91*cdf0c1d5Smjnelson			fi
92*cdf0c1d5Smjnelson		done
93*cdf0c1d5Smjnelson
94*cdf0c1d5Smjnelson		# Remove leading pipe before it can confuse egrep
95*cdf0c1d5Smjnelson		dirs=${dirs#\|}
96*cdf0c1d5Smjnelson		echo "$FILELIST" | egrep "^($dirs)/.*/${pat#s.}\$" | prpath
97*cdf0c1d5Smjnelson	fi
987c478bd9Sstevel@tonic-gate}
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate#
1017c478bd9Sstevel@tonic-gate# Echo the filename if it exists in the workspace.
1027c478bd9Sstevel@tonic-gate#
1037c478bd9Sstevel@tonic-gateecho_file()
1047c478bd9Sstevel@tonic-gate{
1057c478bd9Sstevel@tonic-gate	[ -f $CODEMGR_WS/$1 ] && echo $1 | prpath
1067c478bd9Sstevel@tonic-gate}
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate#
1097c478bd9Sstevel@tonic-gate# Source the named script, specified as either a full path or a path relative
1107c478bd9Sstevel@tonic-gate# to $CODEMGR_WS.  Although def.dir.flp allows for situations in which the
1117c478bd9Sstevel@tonic-gate# script is actually executed (rather than sourced), this feature has never
1127c478bd9Sstevel@tonic-gate# been used in ON, since it precludes use of echo_file() and find_files().
1137c478bd9Sstevel@tonic-gate#
1147c478bd9Sstevel@tonic-gateexec_file()
1157c478bd9Sstevel@tonic-gate{
1167c478bd9Sstevel@tonic-gate	if [ "${1##/}" = "$1" ]; then
1177c478bd9Sstevel@tonic-gate		. $CODEMGR_WS/$1
1187c478bd9Sstevel@tonic-gate	else
1197c478bd9Sstevel@tonic-gate		. $1
1207c478bd9Sstevel@tonic-gate	fi
1217c478bd9Sstevel@tonic-gate}
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate#
1247c478bd9Sstevel@tonic-gate# Iterate up through all directories below the named directory, and
1257c478bd9Sstevel@tonic-gate# execute any inc.flg's that may exist.
1267c478bd9Sstevel@tonic-gate#
1277c478bd9Sstevel@tonic-gateincflg()
1287c478bd9Sstevel@tonic-gate{
1297c478bd9Sstevel@tonic-gate	cd $1
1307c478bd9Sstevel@tonic-gate	for i in * .*; 	do
1317c478bd9Sstevel@tonic-gate    		case $i in
1327c478bd9Sstevel@tonic-gate		'*'|.|..)
1337c478bd9Sstevel@tonic-gate			;;
1347c478bd9Sstevel@tonic-gate		inc.flg)
1357c478bd9Sstevel@tonic-gate			exec_file $1/$i
1367c478bd9Sstevel@tonic-gate			;;
1377c478bd9Sstevel@tonic-gate		*)
1387c478bd9Sstevel@tonic-gate			if [ -d $i -a ! -h $i ]; then
1397c478bd9Sstevel@tonic-gate				incflg $1/$i
1407c478bd9Sstevel@tonic-gate				cd $1
1417c478bd9Sstevel@tonic-gate			fi
1427c478bd9Sstevel@tonic-gate			;;
1437c478bd9Sstevel@tonic-gate		esac
1447c478bd9Sstevel@tonic-gate	done
1457c478bd9Sstevel@tonic-gate}
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate#
1487c478bd9Sstevel@tonic-gate# Convert the absolute pathnames named on input to relative pathnames (if
1497c478bd9Sstevel@tonic-gate# necessary) and print them.
1507c478bd9Sstevel@tonic-gate#
1517c478bd9Sstevel@tonic-gateprpath()
1527c478bd9Sstevel@tonic-gate{
153*cdf0c1d5Smjnelson	#
154*cdf0c1d5Smjnelson	# $CURTREE may be a subdirectory of $CODEMGR_WS, or it
155*cdf0c1d5Smjnelson	# may be the root of $CODEMGR_WS.  We want to strip it
156*cdf0c1d5Smjnelson	# and end up with a relative path in either case, so the
157*cdf0c1d5Smjnelson	# ?(/) pattern is important.  If we don't do that, the
158*cdf0c1d5Smjnelson	# dots/tree loop will go on forever.
159*cdf0c1d5Smjnelson	#
160*cdf0c1d5Smjnelson	reltree=${CURTREE##$CODEMGR_WS?(/)}
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate	while read srcfile; do
1637c478bd9Sstevel@tonic-gate		if [ "$RELPATHS" != y ]; then
1647c478bd9Sstevel@tonic-gate			echo $srcfile
1657c478bd9Sstevel@tonic-gate			continue
1667c478bd9Sstevel@tonic-gate		fi
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate		dots=
1697c478bd9Sstevel@tonic-gate		tree=$reltree
1707c478bd9Sstevel@tonic-gate		while [ "${srcfile##$tree}" = "$srcfile" ]; do
1717c478bd9Sstevel@tonic-gate			dots=../$dots
1727c478bd9Sstevel@tonic-gate			tree=`dirname $tree`
1737c478bd9Sstevel@tonic-gate		done
1747c478bd9Sstevel@tonic-gate		echo ${dots}${srcfile##$tree/}
1757c478bd9Sstevel@tonic-gate	done
1767c478bd9Sstevel@tonic-gate}
1777c478bd9Sstevel@tonic-gate
178*cdf0c1d5Smjnelsonwhich_scm | read SCM_MODE CODEMGR_WS || exit 1
179*cdf0c1d5Smjnelson
180*cdf0c1d5Smjnelsonif [[ $SCM_MODE == "unknown" ]]; then
181*cdf0c1d5Smjnelson	fail "Unable to determine SCM type currently in use."
182*cdf0c1d5Smjnelsonelif [[ $SCM_MODE == "mercurial" ]]; then
183*cdf0c1d5Smjnelson	FILELIST=`hg manifest`
184*cdf0c1d5Smjnelsonelif [[ $SCM_MODE != "teamware" ]]; then
185*cdf0c1d5Smjnelson	fail "Unsupported SCM in use: $SCM_MODE"
186*cdf0c1d5Smjnelsonfi
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gatewhile getopts r flag; do
1897c478bd9Sstevel@tonic-gate	case $flag in
1907c478bd9Sstevel@tonic-gate	r)
1917c478bd9Sstevel@tonic-gate		RELPATHS=y
1927c478bd9Sstevel@tonic-gate		;;
1937c478bd9Sstevel@tonic-gate	\?)
1947c478bd9Sstevel@tonic-gate		usage
1957c478bd9Sstevel@tonic-gate		;;
1967c478bd9Sstevel@tonic-gate	esac
1977c478bd9Sstevel@tonic-gatedone
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gateshift $((OPTIND - 1))
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate[ $# -gt 1 ] && usage
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gateCURTREE=`/bin/pwd`
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate#
2067c478bd9Sstevel@tonic-gate# Determine the subtree being examined.
2077c478bd9Sstevel@tonic-gate#
2087c478bd9Sstevel@tonic-gateif [ $# -eq 0 ]; then
2097c478bd9Sstevel@tonic-gate	SUBTREE=$CURTREE
2107c478bd9Sstevel@tonic-gateelif [ -d $1 ]; then
2117c478bd9Sstevel@tonic-gate	SUBTREE=$1
2127c478bd9Sstevel@tonic-gateelif [ -d $CODEMGR_WS/$1 ]; then
2137c478bd9Sstevel@tonic-gate	SUBTREE=$CODEMGR_WS/$1
2147c478bd9Sstevel@tonic-gateelse
2157c478bd9Sstevel@tonic-gate	fail "neither \$CODEMGR_WS/$1 nor $1 exists as a directory"
2167c478bd9Sstevel@tonic-gatefi
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate#
2197c478bd9Sstevel@tonic-gate# Get the canonical path to the subtree.
2207c478bd9Sstevel@tonic-gate#
2217c478bd9Sstevel@tonic-gatecd $SUBTREE
2227c478bd9Sstevel@tonic-gateSUBTREE=`/bin/pwd`
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate#
2257c478bd9Sstevel@tonic-gate# Get the canonical path to the current directory.
2267c478bd9Sstevel@tonic-gate#
2277c478bd9Sstevel@tonic-gatecd $CURTREE
2287c478bd9Sstevel@tonic-gateCURTREE=`/bin/pwd`
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate#
2317c478bd9Sstevel@tonic-gate# Get the canonical path to the workspace.
2327c478bd9Sstevel@tonic-gate#
2337c478bd9Sstevel@tonic-gatecd $CODEMGR_WS
2347c478bd9Sstevel@tonic-gateCODEMGR_WS=`/bin/pwd`
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gateif [ "${SUBTREE##$CODEMGR_WS}" = "$SUBTREE" ]; then
2377c478bd9Sstevel@tonic-gate	fail "$SUBTREE is not a subtree of \$CODEMGR_WS"
2387c478bd9Sstevel@tonic-gatefi
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gateif [ "${CURTREE##$CODEMGR_WS}" = "$CURTREE" ]; then
2417c478bd9Sstevel@tonic-gate	fail "$CURTREE is not a subtree of \$CODEMGR_WS"
2427c478bd9Sstevel@tonic-gatefi
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate#
2457c478bd9Sstevel@tonic-gate# Find and execute all inc.flg's below our subtree.
2467c478bd9Sstevel@tonic-gate#
2477c478bd9Sstevel@tonic-gateincflg $SUBTREE
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate#
2507c478bd9Sstevel@tonic-gate# Find and execute all req.flg's at or above our subtree.
2517c478bd9Sstevel@tonic-gate#
2527c478bd9Sstevel@tonic-gateTREE=$SUBTREE
2537c478bd9Sstevel@tonic-gatewhile [ $TREE != $CODEMGR_WS ]; do
2547c478bd9Sstevel@tonic-gate	[ -f $TREE/req.flg ] && exec_file $TREE/req.flg
2557c478bd9Sstevel@tonic-gate	TREE=`dirname $TREE`
2567c478bd9Sstevel@tonic-gatedone
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gateexit 0
259