#!/bin/ksh # # TM_FLIST # # Print list of files used in a TM5 project, as defined by an RC # file. # # # ARGUMENT : RCFILE : rc file # ---------- (default is $RCDEFAULT, set in "settings" # section of the code. If it does not exists, the most # recent rc file is used) # # SETTING : specify your TM5 dir and default rc file in the SETTINGS # --------- section # # REQUIREMENT : the "without" flags in your rc file should be grouped into a "my.without" rc key. # ------------- # # EXAMPLES: Assuming that the script is in your $PATH (add current dir to it) : # --------- # # # (1) Print the listing # # get_tmflist # default rc file # get_tmflist mytm5.rc # pycasso rc file # # # # (2) Save the listing, so it can be used in grep/find: # # tmfiles=$(get_tmflist my.rc) # # grep -i something $tmfiles # find $tmfiles -name [Tt]racer* # # # LIMITATIONS # ----------- # # Filenames that include .svn are not seen. # # 3 Jan 2011 - P. Le Sager - v0 # 27 Sep 2011 - P. Le Sager - added rule #3 (applied only for pycasso cases, see REQUIREMENT) # 11 Jan 2013 - P. Le Sager - bug fix in location of rc.py # 13 Oct 2014 - Ph. Le Sager - adapted for new repository # ######################################################## USAGE="\ usage: ${0##*/} [-d ROOTDIR] [RCFILE] " #---------------- # DEFAULT SETTINGS #---------------- # TM5 dir TM=$HOME/TM5MP # default RC file (leave empty to use the latest .rc, if you do not pass an # argument). Filename is relative to $TM. #rcdefault='base/trunk/rc/pycasso-tm5_chembase.rc' rcdefault='vais.rc' pycasso=1 # ------------------------------ # rule #3... # ------------------------------ function to_remove { # Return list of files to remove according to rc file settings. # From rc/expert-default.rc, we should limit the file list if some flags are not used: aa="with_tmm_tmpp \ with_tmm_tm5 with_tmm_ecmwf \ with_tmm_ncep with_tmm_msc \ with_prism with_tendencies \ with_budgets with_cariolle with_ecearth_optics with_gribex with_grib_api \ with_udunits with_cf_output with_optics with_pm" # used macro used=$($cmd $rcfile build.configure.macro.define) # find the not used flags, and get list of files associated with them printf "%s\n" $aa | sort > temp1 printf "%s\n" $used | sort > temp2 notused=$(comm -23 temp1 temp2) for flag in $notused; do nofiles="$nofiles $($cmd $rcfile build.configure.remove.ifndef.$flag)" done # the "without" without=$($cmd $rcfile my.without) for wo in $without; do nofiles="$nofiles $($cmd $rcfile build.configure.remove.ifdef.$wo)" done \rm -f temp1 temp2 print $nofiles return 0 } # ------------------------------ # options # ------------------------------ while getopts :d: OPT; do case $OPT in d) TM="$OPTARG" ;; *) print -u2 "$USAGE" exit 2 esac done shift $(( OPTIND - 1 )) cd $TM # use the latest rc.py cmd=${TM}/tools/ttb/bin/rc.py # default RC file, if not passed rcfile=${1-${rcdefault}} # Use the most recent rc file if not passed and default does not exist [[ -f $rcfile ]] || rcfile=$(ls -1trL *.rc | tail -1) [[ -z $rcfile ]] && echo "No RC file. Returning..." && return 1 # ----------------------------------------- # dirs = Array of source directories (rule #1) # ----------------------------------------- set -A dirs $($cmd $rcfile build.copy.dirs) # ----------------------------------------- # List of files in the project (ignoring .svn dir and swap files). # Ordered by starting from end of the dir list. # ----------------------------------------- tempfile=todelete.$$ klm=$((${#dirs[*]}-1)) if [[ $klm -eq 0 ]]; then echo " no source directory found" exit 1 fi while [[ ${klm} -ge 0 ]]; do # debug # echo $klm ${dirs[$klm]} searchdir=$TM/${dirs[$klm]} [[ ! -e $searchdir ]] && ((klm-=1)) && continue find "$searchdir" -name \.svn -prune -o \( -type f ! -name "*~" \) | egrep -v "\.svn" >> $tempfile ((klm-=1)) done # ----------------------------------------- # Remove overwritten files (rule #2) and to-remove files (rule #3) # ----------------------------------------- toremove=$(to_remove) # printf '%s\n' $toremove # print "" ii=0 unset list qlist TM5_FLIST { while read fname do # rule #2 : effective name according to TM5 rules nfile=$(basename "$fname" | sed "s,__.*\.,\.,") # rule #3 if echo $toremove | grep " $nfile " > /dev/null; then continue; fi # build lists with uniq file names if [[ $ii == 0 ]]; then list[$ii]=$nfile qlist[$ii]=$fname jj=$ii else noskip=1 for k in $(seq 0 $jj) ; do if [[ $nfile == ${list[$k]} ]]; then noskip=0 break fi done (( $noskip )) && ((jj+=1)) && list[$jj]=$nfile && qlist[$jj]=$fname fi ((ii+=1)) done } < $tempfile # export array # export TM5_FLIST=$( printf "%s " "${qlist[@]}" ) # export TM5_RCFILE=$rcfile # cleanup & output \rm -f $tempfile printf '%s\n' ${qlist[*]} return