Update bootstrap
[m6w6/libmemcached] / bootstrap.sh
index 6dee9557d91616db2a5204ecbf2fc31f0b35c319..cd8c5d12dd8c78267edffae2b266a124022da944 100755 (executable)
@@ -188,9 +188,15 @@ function set_VENDOR_DISTRIBUTION ()
 function set_VENDOR_RELEASE ()
 {
   local release=`echo "$1" | tr '[A-Z]' '[a-z]'`
-  case "$VENDOR_DISTRIBUTION" in
+
+  if $DEBUG; then 
+    echo "VENDOR_DISTRIBUTION:$VENDOR_DISTRIBUTION"
+    echo "VENDOR_RELEASE:$release"
+  fi
+
+  case $VENDOR_DISTRIBUTION in
     darwin)
-      case "$VENDOR_DISTRIBUTION" in
+      case $release in
         10.6*)
           VENDOR_RELEASE='snow_leopard'
           ;;
@@ -200,10 +206,12 @@ function set_VENDOR_RELEASE ()
         mountain)
           VENDOR_RELEASE='mountain'
           ;;
-        10.8*)
+        10.8.*)
+          echo "mountain_lion"
           VENDOR_RELEASE='mountain_lion'
           ;;
         *)
+          echo $VENDOR_RELEASE
           VENDOR_RELEASE='unknown'
           ;;
       esac
@@ -217,12 +225,17 @@ function set_VENDOR_RELEASE ()
     rhel)
       VENDOR_RELEASE="$release"
       ;;
+    debian)
+      VENDOR_RELEASE="$release"
+      ;;
     ubuntu)
       VENDOR_RELEASE="$release"
       if [[ "x$VENDOR_RELEASE" == 'x12.04' ]]; then
         VENDOR_RELEASE="precise"
       elif [[ "x$VENDOR_RELEASE" == 'x12.10' ]]; then
         VENDOR_RELEASE="quantal"
+      elif [[ "x$VENDOR_RELEASE" == 'x13.04' ]]; then
+        VENDOR_RELEASE="raring"
       fi
       ;;
     opensuse)
@@ -372,11 +385,16 @@ function run_configure ()
   local BUILD_CONFIGURE_ARG= 
 
   # If ENV DEBUG is set we enable both debug and asssert, otherwise we see if this is a VCS checkout and if so enable assert
-  # Set ENV ASSERT in order to enable assert
-  if $DEBUG; then 
-    BUILD_CONFIGURE_ARG+=' --enable-debug --enable-assert'
-  elif [[ -n "$VCS_CHECKOUT" ]]; then
-    BUILD_CONFIGURE_ARG+=' --enable-assert'
+  # Set ENV ASSERT in order to enable assert.
+  # If we are doing a valgrind run, we always compile with assert disabled
+  if $valgrind_run; then
+    BUILD_CONFIGURE_ARG+= '--enable-assert=no'
+  else
+    if $DEBUG; then 
+      BUILD_CONFIGURE_ARG+=' --enable-debug --enable-assert'
+    elif [[ -n "$VCS_CHECKOUT" ]]; then
+      BUILD_CONFIGURE_ARG+=' --enable-assert'
+    fi
   fi
 
   if [[ -n "$CONFIGURE_ARG" ]]; then 
@@ -428,7 +446,7 @@ function setup_gdb_command () {
 function setup_valgrind_command () {
   VALGRIND_PROGRAM=`type -p valgrind`
   if [[ -n "$VALGRIND_PROGRAM" ]]; then
-    VALGRIND_COMMAND="$VALGRIND_PROGRAM --error-exitcode=1 --leak-check=yes --show-reachable=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE"
+    VALGRIND_COMMAND="$VALGRIND_PROGRAM --error-exitcode=1 --leak-check=yes --malloc-fill=A5 --free-fill=DE --xml=yes --xml-file=\"valgrind-%p.xml\" --gen-suppressions=yes --log-file=\"valgrind-%p.txt\""
   fi
 }
 
@@ -528,11 +546,6 @@ function safe_popd ()
 
 function make_valgrind ()
 {
-  if [[ "$VENDOR_DISTRIBUTION" == 'darwin' ]]; then
-    make_darwin_malloc
-    return
-  fi
-
   # If the env VALGRIND_COMMAND is set then we assume it is valid
   local valgrind_was_set=false
   if [[ -z "$VALGRIND_COMMAND" ]]; then
@@ -552,20 +565,35 @@ function make_valgrind ()
 
   save_BUILD
 
+  valgrind_run=true
+
   # If we are required to run configure, do so now
-  run_configure_if_required
+  run_configure
 
   # If we don't have a configure, then most likely we will be missing libtool
   assert_file 'configure'
-  if [[ -f 'libtool' ]]; then
+  if [[ -x 'libtool' ]]; then
     TESTS_ENVIRONMENT="./libtool --mode=execute $VALGRIND_COMMAND"
   else
     TESTS_ENVIRONMENT="$VALGRIND_COMMAND"
   fi
 
-  make_target 'check' || return 1
+  make_target 'all'
+  make_target 'check'
+  ret=$?
+
+  # If we aren't going to error, we will clean up our environment
+  if [ "$ret" -eq 0 ]; then
+     make 'distclean'
+  fi
+
+  valgrind_run=false
 
   restore_BUILD
+
+  if [ "$ret" -ne 0 ]; then
+    return 1
+  fi
 }
 
 function make_install_system ()
@@ -616,32 +644,21 @@ function make_darwin_malloc ()
   MallocScribble=$old_MallocScribble
 }
 
-function snapshot_check ()
-{
-  if [ ! -f "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
-    make_for_snapshot
-  fi
-
-  if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
-    assert_file "$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed'
-  fi
-}
-
 # This will reset our environment, and make sure built files are available.
 function make_for_snapshot ()
 {
-  # Make sure it is clean
-  make_maintainer_clean
+  # Lets make sure we have a clean environment
+  assert_no_file 'Makefile'
+  assert_no_file 'configure'
+  assert_no_directory 'autom4te.cache'
 
   run_configure
-  make_target 'dist'
+  make_target 'all'
   make_target 'distclean'
 
   # We should have a configure, but no Makefile at the end of this exercise
   assert_no_file 'Makefile'
   assert_exec_file 'configure'
-
-  snapshot_check
 }
 
 function check_mingw ()
@@ -810,7 +827,7 @@ function make_for_clang_analyzer ()
 function check_for_jenkins ()
 {
   if ! $jenkins_build_environment; then
-    echo "Not inside of jenkins"
+    echo "Not inside of jenkins, simulating environment"
 
     if [ -f 'configure' ]; then
       make_maintainer_clean
@@ -839,6 +856,13 @@ function make_universe ()
   make_install_system
 }
 
+function check_snapshot ()
+{
+  if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
+    assert_file "$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed'
+  fi
+}
+
 function make_for_continuus_integration ()
 {
   # Setup the environment if we are local
@@ -850,7 +874,11 @@ function make_for_continuus_integration ()
   # Platforms which require bootstrap should have some setup done before we hit this stage.
   # If we are building locally, skip this step, unless we are just testing locally. 
   if $BOOTSTRAP_SNAPSHOT; then
-    snapshot_check
+    if $BOOTSTRAP_SNAPSHOT; then
+      assert_file 'configure'
+    fi
+
+    check_snapshot
   else
     # If we didn't require a snapshot, then we should not have a configure
     assert_no_file 'configure'
@@ -874,34 +902,7 @@ function make_for_continuus_integration ()
         make_rpm
       elif [[ -d rpm ]]; then
         make_rpm
-      else
-        make_distcheck
       fi
-
-      assert_exec_file 'configure'
-      assert_file 'Makefile'
-
-      make_install_system
-      ;;
-    *-precise-*)
-      run_configure
-
-      assert_exec_file 'configure'
-      assert_file 'Makefile'
-
-      make_target 'all'
-
-      make_distcheck
-
-      assert_exec_file 'configure'
-      assert_file 'Makefile'
-
-      make_valgrind
-
-      assert_exec_file 'configure'
-      assert_file 'Makefile'
-
-      make_install_system
       ;;
     *)
       make_jenkins_default
@@ -1071,6 +1072,13 @@ function run_configure_if_required ()
   assert_file 'Makefile' 'configure did not produce a Makefile'
 }
 
+function run_make_maintainer_clean_if_possible () 
+{
+  if [ -f 'Makefile' ]; then
+    make_maintainer_clean
+  fi
+}
+
 function run_autoreconf_if_required () 
 {
   if [ ! -x 'configure' ]; then
@@ -1092,7 +1100,7 @@ function run_autoreconf ()
     run $BOOTSTRAP_LIBTOOLIZE '--copy' '--install' '--force' || die "Cannot execute $BOOTSTRAP_LIBTOOLIZE"
   fi
 
-  run $AUTORECONF || die "Cannot execute $AUTORECONF"
+  run $AUTORECONF $AUTORECONF_ARGS || die "Cannot execute $AUTORECONF"
 
   eval 'bash -n configure' || die "autoreconf generated a malformed configure"
 }
@@ -1273,12 +1281,16 @@ function autoreconf_setup ()
         fi
       fi
     fi
+
     if $VERBOSE; then
       LIBTOOLIZE_OPTIONS="--verbose $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
     fi
+
     if $DEBUG; then
       LIBTOOLIZE_OPTIONS="--debug $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
     fi
+
+    # Here we set LIBTOOLIZE to true since we are going to invoke it via BOOTSTRAP_LIBTOOLIZE
     LIBTOOLIZE=true
   fi
 
@@ -1316,7 +1328,7 @@ function autoreconf_setup ()
     fi
 
     if [[ -n "$GNU_BUILD_FLAGS" ]]; then
-      AUTORECONF="$AUTORECONF $GNU_BUILD_FLAGS"
+      AUTORECONF_ARGS="$GNU_BUILD_FLAGS"
     fi
   fi
 
@@ -1474,18 +1486,21 @@ function check_make_target()
       ;;
     'clang-analyzer')
       ;;
-    'test-*')
+    test-*)
       ;;
-    'valgrind-*')
+    valgrind-*)
       ;;
-    'gdb-*')
+    gdb-*)
       ;;
     'dist')
       ;;
     *)
-      die "Unknown MAKE_TARGET option: $1"
+      echo "Matched default"
+      return 1
       ;;
   esac
+
+  return 0
 }
 
 function bootstrap ()
@@ -1533,8 +1548,15 @@ function bootstrap ()
     # If we are running inside of Jenkins, we want to only run some of the possible tests
     if $jenkins_build_environment; then
       check_make_target $target
+      ret=$?
+      if [ $ret -ne 0 ]; then
+        die "Unknown MAKE_TARGET option: $target"
+      fi
     fi
 
+    local snapshot_run=false
+    local valgrind_run=false
+
     case $target in
       'self')
         self_test
@@ -1592,11 +1614,17 @@ function bootstrap ()
         ;;
       'snapshot')
         make_for_snapshot
+        snapshot_run=true
+        check_snapshot
         ;;
       'rpm')
         make_rpm
         ;;
+      'darwin_malloc')
+        make_darwin_malloc
+        ;;
       'valgrind')
+        make_maintainer_clean 
         make_valgrind
         ;;
       'universe')
@@ -1610,6 +1638,13 @@ function bootstrap ()
         make_target "$target"
         ;;
     esac
+
+    if $jenkins_build_environment; then
+      if ! $snapshot_run; then
+        run_make_maintainer_clean_if_possible
+      fi
+    fi
+
   done
 }
 
@@ -1678,7 +1713,22 @@ function main ()
   # We don't want Jenkins overriding other variables, so we NULL them.
   if [ -z "$MAKE_TARGET" ]; then
     if $jenkins_build_environment; then
-      MAKE_TARGET='jenkins'
+      if [[ -n "$label" ]]; then
+        check_make_target $label
+        if [ $? -eq 0 ]; then
+          MAKE_TARGET="$label"
+        fi
+      fi
+      if [[ -n "$LABEL" ]]; then
+        check_make_target $LABEL
+        if [ $? -eq 0 ]; then
+          MAKE_TARGET="$LABEL"
+        fi
+      fi
+
+      if [ -z "$MAKE_TARGET" ]; then
+        MAKE_TARGET='jenkins'
+      fi
     fi
   fi