Find coverage during configure, issue with Debian package
[ganeti-local] / autotools / gen-coverage
index 8d6c2d4..38bdd38 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash
 #
 
-# Copyright (C) 2010 Google Inc.
+# Copyright (C) 2010, 2011 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # 02110-1301, USA.
 
 set -e
+set -u
 
-: ${COVERAGE:=coverage}
 : ${PYTHON:=python}
+: ${COVERAGE:?}
 : ${COVERAGE_FILE:?}
 : ${TEXT_COVERAGE:?}
+: ${HTML_COVERAGE:=}
 : ${GANETI_TEMP_DIR:?}
 
-omit=$($PYTHON -c 'import sys; import os;
-print ",".join("%s/" % i for i in set([sys.prefix, sys.exec_prefix,
-   os.environ["GANETI_TEMP_DIR"] + "/test"]))')
-omit="--omit=$omit"
+reportargs=(
+  '--include=*'
+  '--omit=test/*'
+  )
 
 $COVERAGE erase
 
+if [[ -n "$HTML_COVERAGE" ]]; then
+  if [[ ! -d "$HTML_COVERAGE" ]]; then
+    echo "Not a directory: $HTML_COVERAGE" >&2
+    exit 1
+  fi
+
+  # At least coverage 3.4 fails to overwrite files
+  find "$HTML_COVERAGE" \( -type f -o -type l \) -delete
+fi
+
 for script; do
-  $COVERAGE run --branch --append $script
+  if [[ "$script" == *-runasroot.py ]]; then
+    if [[ -z "$FAKEROOT" ]]; then
+      echo "WARNING: FAKEROOT variable not set: skipping $script" >&2
+      continue
+    fi
+    cmdprefix="$FAKEROOT"
+  else
+    cmdprefix=
+  fi
+  $cmdprefix $COVERAGE run --branch --append "${reportargs[@]}" $script
 done
 
 echo "Writing text report to $TEXT_COVERAGE ..." >&2
-$COVERAGE report $omit | tee "$TEXT_COVERAGE"
+$COVERAGE report "${reportargs[@]}" | tee "$TEXT_COVERAGE"
 
 if [[ -n "$HTML_COVERAGE" ]]; then
   echo "Generating HTML report in $HTML_COVERAGE ..." >&2
-  $COVERAGE html $omit -d "$HTML_COVERAGE"
+  $COVERAGE html "${reportargs[@]}" -d "$HTML_COVERAGE"
 fi