#!/bin/bash -e # Checks the dependencies of all checked out packages #set -x ############################################################################## # Pre-setup ############################################################################## case `uname` in Darwin) ECHO=echo ;; *) ECHO="echo -e" ;; esac usage () { $ECHO "git icedust-check [options]" $ECHO $ECHO "Options:" $ECHO "-h, --help \tthis help message" $ECHO $ECHO "-H, --home \tProvide ICEDUST_HOME directory" $ECHO "-d, --debug \tenable debug output" $ECHO "-f, --file FILE \tread the list of packages to be checkoed out from FILE" $ECHO "-q, --quiet, -z \tdo not print out progress" $ECHO "--skip-setup \tdon't run git icedust-init, useful when used in other scripts" exit $1 } VERBOSE=1 VERBOSE_STREAM=/dev/stderr DEBUG_STREAM=/dev/null verbose () { if [ "X$VERBOSE" = X1 ]; then $ECHO "$@" fi } ############################################################################## # Parse options ############################################################################## INITOPTIONS="" ICEDUST_HOME="$ICEDUST_HOME" PACKAGES=( ) SKIP_INIT=false while [ "$#" != 0 ]; do case "$1" in -h | --help ) usage 0;; -d | --debug ) INITOPTIONS="$INITOPTIONS $1" shift; set -x; DEBUG_STREAM=/dev/stderr ;; -H | --home ) shift; ICEDUST_HOME="`readlink -f "$1"`" shift ;; -q | --quiet | -z ) INITOPTIONS="$INITOPTIONS $1" shift; set +x; VERBOSE=0; VERBOSE_STREAM=/dev/null ;; --skip-setup) SKIP_INIT=true; shift;; -t) INITOPTIONS="$INITOPTIONS $1"; shift;; -*) $ECHO Unknown option $1 ; usage 1 ;; *) PACKAGES=( "$1" "${PACKAGES[@]}" ) shift ;; esac done if [ -z "$INTERNAL_CALL_CHECKDEPS" ];then tmp="`git icedust-home`" ICEDUST_HOME=`sed 's!^.*ICEDUST_HOME=\([^;]\+\);.*!\1!' <<<$tmp` ICEDUST_PROJECT=`sed 's!^.*ICEDUST_PROJECT=\([^;]\+\);.*!\1!' <<<$tmp` echo tmp unset tmp fi PackageDirectory="$ICEDUST_HOME/$ICEDUST_PROJECT/packages" ExternalDirectory="$PackageDirectory/EXTERNALS" ############################################################################## # Find dependencies for a single cmt/requirements file ############################################################################## function GetCMTDependencies(){ _package="$1" _file="$1/cmt/requirements" if [ -r "$_file" ];then cat "$_file"| grep '^[[:space:]]*use[[:space:]]\+[[:alnum:]]\+' | tee -a $DEBUG_STREAM | sed -e 's!^\s*use \+\(\S\+\).*!\1!' fi } function PassOnceOverPackages(){ local Outfile="$1" # check the dependencies of each dependency file for Package in "$PackageDirectory/"* "$ExternalDirectory/"*; do GetCMTDependencies $Package >> $Outfile done # remove duplicates local Sorted="`sort -u $Outfile`" echo "" > "$Outfile" # remove already obtained packages for Package in $Sorted;do if [ -f "$PackageDirectory/$Package/README" ] || [ -f "$ExternalDirectory/$Package/README" ] ; then continue fi $ECHO "$Package " |tee "$DEBUG_STREAM" >> "$Outfile" done # Get all the new packages if [ `grep -v '^\s*$' $Outfile|wc -l` -gt 0 ];then git icedust-add $INITOPTIONS -f "$Outfile" --skip-setup fi } ############################################################################## # Main body ############################################################################## if ! $SKIP_INIT; then git icedust-setup $INITOPTIONS fi TmpFile1=`mktemp` TmpFile2=`mktemp` # make one pass PassOnceOverPackages $TmpFile1 # As long as we keep adding packages keep going while ! `diff -w -B -q "$TmpFile1" "$TmpFile2" >> $DEBUG_STREAM`;do mv -f "$TmpFile1" "$TmpFile2" PassOnceOverPackages "$TmpFile1" done