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 6cdf0c1d5Smjnelson# Common Development and Distribution License (the "License"). 7cdf0c1d5Smjnelson# 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# 2383d7a252SJohn Beck# Copyright 2010 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate# Use is subject to license terms. 257c478bd9Sstevel@tonic-gate# 26b1374179SBill Sommerfeld# Copyright 2024 Bill Sommerfeld <sommerfeld@hamachi.org> 27b1374179SBill Sommerfeld# 28cdf0c1d5Smjnelson# 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. 32b1374179SBill Sommerfeld# 337c478bd9Sstevel@tonic-gate# Based loosely on ON's version of Teamware's def.dir.flp. 347c478bd9Sstevel@tonic-gate# 357c478bd9Sstevel@tonic-gate 36cdf0c1d5SmjnelsonONBLDDIR=$(dirname $(whence $0)) 37cdf0c1d5Smjnelson 38cdf0c1d5SmjnelsonPATH=/usr/bin:${BUILD_TOOLS:-/opt}/teamware/bin:$ONBLDDIR 39cdf0c1d5Smjnelsonexport PATH 40b1374179SBill SommerfeldPROG=$(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. 46b1374179SBill Sommerfeld# 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{ 74b1374179SBill Sommerfeld pat=$1 75b1374179SBill Sommerfeld shift 767c478bd9Sstevel@tonic-gate 77b1374179SBill Sommerfeld if [[ "$SCM_MODE" == "teamware" ]]; then 78cdf0c1d5Smjnelson for dir; do 798bcea973SRichard Lowe if [[ -d $CODEMGR_WS/$dir ]]; then 80cdf0c1d5Smjnelson cd $CODEMGR_WS 81cdf0c1d5Smjnelson find $dir -name "$pat" | \ 82cdf0c1d5Smjnelson sed -n s:/SCCS/s.:/:p | prpath 83cdf0c1d5Smjnelson cd - > /dev/null 84cdf0c1d5Smjnelson fi 85cdf0c1d5Smjnelson done 86b1374179SBill Sommerfeld elif [[ "$SCM_MODE" == "mercurial" || "$SCM_MODE" == "git" ]]; then 87cdf0c1d5Smjnelson dirs="" 88cdf0c1d5Smjnelson for dir; do 898bcea973SRichard Lowe if [[ -d $CODEMGR_WS/$dir ]]; then 90cdf0c1d5Smjnelson dirs="$dirs|${dir%/}" 91cdf0c1d5Smjnelson fi 92cdf0c1d5Smjnelson done 93cdf0c1d5Smjnelson 94cdf0c1d5Smjnelson # Remove leading pipe before it can confuse egrep 95cdf0c1d5Smjnelson dirs=${dirs#\|} 96cdf0c1d5Smjnelson echo "$FILELIST" | egrep "^($dirs)/.*/${pat#s.}\$" | prpath 97cdf0c1d5Smjnelson 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{ 116b1374179SBill Sommerfeld 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 130b1374179SBill Sommerfeld for i in * .*; do 131b1374179SBill Sommerfeld 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 *) 1388bcea973SRichard Lowe if [[ -d $i && ! -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{ 153cdf0c1d5Smjnelson # 154cdf0c1d5Smjnelson # $CURTREE may be a subdirectory of $CODEMGR_WS, or it 155cdf0c1d5Smjnelson # may be the root of $CODEMGR_WS. We want to strip it 156cdf0c1d5Smjnelson # and end up with a relative path in either case, so the 157cdf0c1d5Smjnelson # ?(/) pattern is important. If we don't do that, the 158cdf0c1d5Smjnelson # dots/tree loop will go on forever. 159cdf0c1d5Smjnelson # 160cdf0c1d5Smjnelson reltree=${CURTREE##$CODEMGR_WS?(/)} 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate while read srcfile; do 1638bcea973SRichard Lowe 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 170b1374179SBill Sommerfeld while [[ "${srcfile##$tree}" == "$srcfile" ]]; do 1717c478bd9Sstevel@tonic-gate dots=../$dots 172b1374179SBill Sommerfeld tree=$(dirname $tree) 17383d7a252SJohn Beck [ "$tree" = "." ] && break 1747c478bd9Sstevel@tonic-gate done 1757c478bd9Sstevel@tonic-gate echo ${dots}${srcfile##$tree/} 1767c478bd9Sstevel@tonic-gate done 1777c478bd9Sstevel@tonic-gate} 1787c478bd9Sstevel@tonic-gate 179cdf0c1d5Smjnelsonwhich_scm | read SCM_MODE CODEMGR_WS || exit 1 180cdf0c1d5Smjnelson 181cdf0c1d5Smjnelsonif [[ $SCM_MODE == "unknown" ]]; then 182cdf0c1d5Smjnelson fail "Unable to determine SCM type currently in use." 183cdf0c1d5Smjnelsonelif [[ $SCM_MODE == "mercurial" ]]; then 1848bcea973SRichard Lowe FILELIST=$(hg manifest) 1858bcea973SRichard Loweelif [[ $SCM_MODE == "git" ]]; then 186*9af2fe54SBill Sommerfeld FILELIST=$(cd $(git rev-parse --show-toplevel) && git ls-files) 187cdf0c1d5Smjnelsonelif [[ $SCM_MODE != "teamware" ]]; then 188cdf0c1d5Smjnelson fail "Unsupported SCM in use: $SCM_MODE" 189cdf0c1d5Smjnelsonfi 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gatewhile getopts r flag; do 1927c478bd9Sstevel@tonic-gate case $flag in 1937c478bd9Sstevel@tonic-gate r) 1947c478bd9Sstevel@tonic-gate RELPATHS=y 1957c478bd9Sstevel@tonic-gate ;; 1967c478bd9Sstevel@tonic-gate \?) 1977c478bd9Sstevel@tonic-gate usage 1987c478bd9Sstevel@tonic-gate ;; 1997c478bd9Sstevel@tonic-gate esac 2007c478bd9Sstevel@tonic-gatedone 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gateshift $((OPTIND - 1)) 2037c478bd9Sstevel@tonic-gate 204b1374179SBill Sommerfeld(( $# > 1 )) && usage 2057c478bd9Sstevel@tonic-gate 206b1374179SBill SommerfeldCURTREE=$(/bin/pwd) 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate# 2097c478bd9Sstevel@tonic-gate# Determine the subtree being examined. 2107c478bd9Sstevel@tonic-gate# 211b1374179SBill Sommerfeldif (( $# == 0 )); then 2127c478bd9Sstevel@tonic-gate SUBTREE=$CURTREE 2138bcea973SRichard Loweelif [[ -d $1 ]]; then 2147c478bd9Sstevel@tonic-gate SUBTREE=$1 215b1374179SBill Sommerfeldelif [[ -d "$CODEMGR_WS/$1" ]]; then 216b1374179SBill Sommerfeld SUBTREE="$CODEMGR_WS/$1" 2177c478bd9Sstevel@tonic-gateelse 2187c478bd9Sstevel@tonic-gate fail "neither \$CODEMGR_WS/$1 nor $1 exists as a directory" 2197c478bd9Sstevel@tonic-gatefi 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate# 2227c478bd9Sstevel@tonic-gate# Get the canonical path to the subtree. 2237c478bd9Sstevel@tonic-gate# 2247c478bd9Sstevel@tonic-gatecd $SUBTREE 225b1374179SBill SommerfeldSUBTREE=$(/bin/pwd) 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate# 2287c478bd9Sstevel@tonic-gate# Get the canonical path to the current directory. 2297c478bd9Sstevel@tonic-gate# 2307c478bd9Sstevel@tonic-gatecd $CURTREE 231b1374179SBill SommerfeldCURTREE=$(/bin/pwd) 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate# 2347c478bd9Sstevel@tonic-gate# Get the canonical path to the workspace. 2357c478bd9Sstevel@tonic-gate# 2367c478bd9Sstevel@tonic-gatecd $CODEMGR_WS 237b1374179SBill SommerfeldCODEMGR_WS=$(/bin/pwd) 2387c478bd9Sstevel@tonic-gate 239b1374179SBill Sommerfeldif [[ "${SUBTREE##$CODEMGR_WS}" == "$SUBTREE" ]]; then 2407c478bd9Sstevel@tonic-gate fail "$SUBTREE is not a subtree of \$CODEMGR_WS" 2417c478bd9Sstevel@tonic-gatefi 2427c478bd9Sstevel@tonic-gate 243b1374179SBill Sommerfeldif [[ "${CURTREE##$CODEMGR_WS}" == "$CURTREE" ]]; then 2447c478bd9Sstevel@tonic-gate fail "$CURTREE is not a subtree of \$CODEMGR_WS" 2457c478bd9Sstevel@tonic-gatefi 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate# 2487c478bd9Sstevel@tonic-gate# Find and execute all inc.flg's below our subtree. 2497c478bd9Sstevel@tonic-gate# 2507c478bd9Sstevel@tonic-gateincflg $SUBTREE 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate# 2537c478bd9Sstevel@tonic-gate# Find and execute all req.flg's at or above our subtree. 2547c478bd9Sstevel@tonic-gate# 2557c478bd9Sstevel@tonic-gateTREE=$SUBTREE 2568bcea973SRichard Lowewhile [[ $TREE != $CODEMGR_WS ]]; do 2578bcea973SRichard Lowe [[ -f $TREE/req.flg ]] && exec_file $TREE/req.flg 258b1374179SBill Sommerfeld TREE=$(dirname $TREE) 2597c478bd9Sstevel@tonic-gatedone 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gateexit 0 262