[PATCH build] Implement auto-clone.

Trevor Woerner twoerner at gmail.com
Sat Sep 18 20:05:28 PDT 2010


From: Trevor Woerner <twoerner at gmail.com>

If the module/component to be processed doesn't exist, assume it
needs to be cloned from the repository first. Removes the need for
an explicit clone command.

Signed-off-by: Trevor Woerner <twoerner at gmail.com>
---
 build.sh |   84 +++++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 54 insertions(+), 30 deletions(-)

diff --git a/build.sh b/build.sh
index 10f716b..412d2de 100755
--- a/build.sh
+++ b/build.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+DEFAULT_GITROOT="git://anongit.freedesktop.org/git"
+
 envoptions() {
 cat << EOF
 global environment variables you may set:
@@ -12,8 +14,8 @@ global environment variables you may set to replace default functionality:
   MAKE:     program to use instead of 'make' (default: make)
   FONTPATH: font path to use (defaults under: \$PREFIX/\$LIBDIR...)
   LIBDIR:   path under \$PREFIX for libraries (e.g., lib64) (default: lib)
-  GITROOT:  path to freedesktop.org git root, only needed for --clone
-            (default: git://anongit.freedesktop.org/git)
+  GITROOT:  path to git root from which to clone
+            (usually freedesktop.org: $DEFAULT_GITROOT)
 
 global environment variables you may set to augment functionality:
   CONFFLAGS:  additional flags to pass to all configure scripts
@@ -139,7 +141,24 @@ checkfortars() {
     done
 }
 
+# the git clone command needs special proessing in order to correctly
+# map the module name back to the source git repository as per the
+# layout currently being used by freedesktop.org-like repositories
+# arguments:
+#   $1 - module (required)
+#   $2 - component (optional)
+# returns:
+#   0 - good
+#   (anything else) - bad
 clone() {
+    local rtn
+
+    # preconds
+    if [ -z "$1" ]; then
+	echo "clone() precondition failure: required argument \$1 not provided"
+	return 1
+    fi
+
     case $1 in
         "pixman")
         BASEDIR=""
@@ -159,22 +178,26 @@ clone() {
     esac
 
     DIR="$1/$2"
-    GITROOT=${GITROOT:="git://anongit.freedesktop.org/git"}
+    GITROOT=${GITROOT:=$DEFAULT_GITROOT}
 
-    if [ ! -d "$DIR" ]; then
-        git clone "$GITROOT/$BASEDIR$DIR" "$DIR"
-        if [ $? -ne 0 ] && [ ! -d "$DIR" ]; then
-            return 1
-        fi
-    else
-        # git cannot clone into an existing directory
+    if [ -d "$DIR" ]; then
+	echo "can not clone into existing directory/repository"
 	return 1
     fi
 
-    return 0
+    git clone "$GITROOT/$BASEDIR$DIR" "$DIR"
+    rtn=$?
+
+    if [ $rtn -ne 0 ]; then
+	echo "failed to clone module \"$1/$2\""
+	clonefailed_components="$clonefailed_components $1/$2"
+    fi
+    return $rtn
 }
 
 build() {
+    local need_config=1
+
     if [ -n "$LISTONLY" ]; then
 	echo "$1/$2"
 	return 0
@@ -190,23 +213,28 @@ build() {
 	fi
     fi
 
+    # do we need to configure?
+    if [ -n "$NOAUTOGEN" ]; then
+	need_config=0
+    fi
+
+    # do we need to clone?
+    if [ ! -d "$1/$2" ]; then
+	need_config=1
+	clone $1 $2
+	if [ $? -ne 0 ]; then
+	    if [ -n "$BUILD_ONE" ]; then
+		exit 1
+	    fi
+	    return
+	fi
+    fi
+
     SRCDIR=""
     CONFCMD=""
     if [ -f $1/$2/autogen.sh ]; then
         SRCDIR="$1/$2"
         CONFCMD="autogen.sh"
-    elif [ -n "$CLONE" ]; then
-        clone $1 $2
-        if [ $? -ne 0 ]; then
-            echo "Failed to clone $1 module component $2. Ignoring."
-            clonefailed_components="$clonefailed_components $1/$2"
-            if [ -n "$BUILD_ONE" ]; then
-                exit 1
-            fi
-            return
-        fi
-        SRCDIR="$1/$2"
-        CONFCMD="autogen.sh"
     else
         checkfortars $1 $2
         CONFCMD="configure"
@@ -254,7 +282,7 @@ build() {
     fi
 
     # Use "sh autogen.sh" since some scripts are not executable in CVS
-    if [ -z "$NOAUTOGEN" ]; then
+    if [ $need_config -eq 1 ]; then
         sh ${DIR_CONFIG}/${CONFCMD} --prefix=${PREFIX} ${LIB_FLAGS} \
 	    ${MOD_SPECIFIC} ${QUIET:+--quiet} \
 	    ${CACHE:+--cache-file=}${CACHE} ${CONFFLAGS} "$CONFCFLAGS" || \
@@ -734,7 +762,6 @@ usage() {
     echo "  -p : run git pull on each component"
     echo "  -r module/component : resume building with this component"
     echo "  -s sudo-command : sudo command to use"
-    echo "  --clone : clone non-existing repositories (uses \$GITROOT if set)"
     echo "  --autoresume file : autoresume from file"
     echo "  --check : run make check in addition to others"
     echo ""
@@ -750,7 +777,7 @@ DIR_CONFIG="."
 LIB_ONLY=0
 
 # Process command line args
-CMDLINE=`getopt -o abcdDf:ghlno:pr:s:L --long check,clone,help,autoresume: -n $0 -- "$@"`
+CMDLINE=`getopt -o abcdDf:ghlno:pr:s:L --long check,help,autoresume: -n $0 -- "$@"`
 if [ $? != 0 ]; then
     echo "getopt(1) invocation error"
     exit 1
@@ -771,9 +798,6 @@ while [ 1 ]; do
     --check)
 	CHECK=1
 	;;
-    --clone)
-	CLONE=1
-	;;
     -d)
 	DISTCHECK=1
 	;;
@@ -890,7 +914,7 @@ if [ -n "$failed_components" ]; then
     echo ""
 fi
 
-if [ -n "$CLONE" ] && [ -n "$clonefailed_components" ];  then
+if [ -n "$clonefailed_components" ];  then
     echo ""
     echo "***** Components failed to clone *****"
     echo "$clonefailed_components"
-- 
1.7.3.rc2



More information about the xorg-devel mailing list