#! /bin/ksh -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2010 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Generates the list of source files that would get brought over with the # specified subtree as a result of inc.flg and req.flg files. If no subtree # is named, then the current directory is assumed. # # Based loosely on ON's version of Teamware's def.dir.flp. # setvar ONBLDDIR = $(dirname $(whence $0)) setvar PATH = "/usr/bin:${BUILD_TOOLS:-/opt}/teamware/bin:$ONBLDDIR" export PATH setvar PROG = $(basename $0) # # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout # under certain circumstances, which will screw up consumers of incflg() # (and perhaps other things as well); unset it. # unset CDPATH # # Print the usage message and exit with an error. # proc usage { echo "usage: $PROG [-r] []" > /dev/stderr exit 1 } # # Print the provided failure message and exit with an error. # proc fail { echo $PROG: $ifsjoin(ARGV) > /dev/stderr exit 1 } # Find the files matching the pattern specified by the first argument in the # directories named by the remaining arguments. Unlike def.dir.flp, print # the name of the source file since we want to make a list of source files, # not SCCS files. # proc find_files { setvar pat = "$1" shift if [[ "$SCM_MODE" = "teamware" ]] {for dir in @ARGV { if [[ -d $CODEMGR_WS/$dir ]] { cd $CODEMGR_WS find $dir -name $pat | \ sed -n s:/SCCS/s.:/:p | prpath cd - > /dev/null } } } elif [[ "$SCM_MODE" = "mercurial" || "$SCM_MODE" == "git" ]] { setvar dirs = ""for dir in @ARGV { if [[ -d $CODEMGR_WS/$dir ]] { setvar dirs = ""$dirs|${dir%/}"" } } # Remove leading pipe before it can confuse egrep setvar dirs = ${dirs#\|} echo $FILELIST | egrep "^($dirs)/.*/${pat#s.}\$" | prpath } } # # Echo the filename if it exists in the workspace. # proc echo_file { test -f $CODEMGR_WS/$1 && echo $1 | prpath } # # Source the named script, specified as either a full path or a path relative # to $CODEMGR_WS. Although def.dir.flp allows for situations in which the # script is actually executed (rather than sourced), this feature has never # been used in ON, since it precludes use of echo_file() and find_files(). # proc exec_file { if [[ "${1##/}" = "$1" ]] { source $CODEMGR_WS/$1 } else { source $1 } } # # Iterate up through all directories below the named directory, and # execute any inc.flg's that may exist. # proc incflg { cd $1 for i in [* .*] { match $i { with '*'|.|.. with inc.flg exec_file $1/$i with * if [[ -d $i && ! -h $i ]] { incflg $1/$i cd $1 } } } } # # Convert the absolute pathnames named on input to relative pathnames (if # necessary) and print them. # proc prpath { # # $CURTREE may be a subdirectory of $CODEMGR_WS, or it # may be the root of $CODEMGR_WS. We want to strip it # and end up with a relative path in either case, so the # ?(/) pattern is important. If we don't do that, the # dots/tree loop will go on forever. # setvar reltree = ${CURTREE##$CODEMGR_WS?(/)} while read srcfile { if [[ "$RELPATHS" != y ]] { echo $srcfile continue } setvar dots = '' setvar tree = "$reltree" { setvar dots = "../$dots" setvar tree = $(dirname $tree) test $tree = "." && break } echo ${dots}${srcfile##$tree/} } } which_scm | read SCM_MODE CODEMGR_WS || exit 1 if [[ $SCM_MODE == "unknown" ]] { fail "Unable to determine SCM type currently in use." } elif [[ $SCM_MODE == "mercurial" ]] { setvar FILELIST = $(hg manifest) } elif [[ $SCM_MODE == "git" ]] { setvar FILELIST = $(cd $(dirname $(git rev-parse --git-dir)) && git ls-files) } elif [[ $SCM_MODE != "teamware" ]] { fail "Unsupported SCM in use: $SCM_MODE" } while getopts r flag { match $flag { with r setvar RELPATHS = 'y' with \? usage } } shift $((OPTIND - 1)) test $Argc -gt 1 && usage setvar CURTREE = $(/bin/pwd) # # Determine the subtree being examined. # if [[ $# -eq 0 ]] { setvar SUBTREE = "$CURTREE" } elif [[ -d $1 ]] { setvar SUBTREE = "$1" } elif [[ -d $CODEMGR_WS/$1 ]] { setvar SUBTREE = "$CODEMGR_WS/$1" } else { fail "neither \$CODEMGR_WS/$1 nor $1 exists as a directory" } # # Get the canonical path to the subtree. # cd $SUBTREE setvar SUBTREE = $(/bin/pwd) # # Get the canonical path to the current directory. # cd $CURTREE setvar CURTREE = $(/bin/pwd) # # Get the canonical path to the workspace. # cd $CODEMGR_WS setvar CODEMGR_WS = $(/bin/pwd) if [[ "${SUBTREE##$CODEMGR_WS}" = "$SUBTREE" ]] { fail "$SUBTREE is not a subtree of \$CODEMGR_WS" } if [[ "${CURTREE##$CODEMGR_WS}" = "$CURTREE" ]] { fail "$CURTREE is not a subtree of \$CODEMGR_WS" } # # Find and execute all inc.flg's below our subtree. # incflg $SUBTREE # # Find and execute all req.flg's at or above our subtree. # setvar TREE = "$SUBTREE" { [[ -f $TREE/req.flg ]] && exec_file $TREE/req.flg setvar TREE = $(dirname $TREE) } exit 0