Cleanup package dependencies, incremental build and unit testing scripts

* Removed stale dependency / use of fakeroot unit test invocation.

* Separated incremental build and unit test invocation from
  gen_coverage_html.sh into their own scripts.

* Added checks for required binaries in gen_coverage_html.sh.

* Renamed setup_dev_packages to have a .sh suffix, for uniformity. Also
  requires that it installs packages regardless of whether or not
  they're already installed; this is to prevent a situation where
  packages were removed from the portage tree but happen to still live
  in the local chroot, so the discrepancy goes unnoticed (for example,
  sys-apps/fakeroot and dev-util/lcov).

* Cosmetics: switched to long options when applicable, for clarity.

BUG=None
TEST=Update engine builds, tests, and coverage generation correctly
invoked

CQ-DEPEND=I949f6b4abad52d04245e5982ac95884d1d0a05fc

Change-Id: I439e74eb9772f8f368256a0adf13503e3257e66c
Reviewed-on: https://gerrit.chromium.org/gerrit/23229
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
Commit-Ready: Gilad Arnold <garnold@chromium.org>
diff --git a/gen_coverage_html b/gen_coverage_html
new file mode 100755
index 0000000..93a6f56
--- /dev/null
+++ b/gen_coverage_html
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Builds, runs unit tests, then collects and processes coverage data for update
+# engine binaries. In the case where lcov/genhtml are missing, it will just
+# build and run the unit tests.
+
+DO_COVERAGE=$(which lcov genhtml > /dev/null 2>&1 && echo 1)
+
+set -ex
+
+./build debug=1
+if [[ $DO_COVERAGE ]]; then
+  lcov --directory . --zerocounters
+fi
+./run_unittests
+if [[ $DO_COVERAGE ]]; then
+  lcov --directory . --capture --output-file app.info
+
+  # We try to use genhtml with --no-function-coverage, if it is supported.  The
+  # problem w/ function coverage is that every template instantiation of a
+  # method counts as a different method, so if we instantiate a method twice,
+  # once for testing and once for prod, the method is tested, but it shows only
+  # 50% function coverage b/c it thinks we didn't test the prod version.
+  GENHTML_NO_FUNC_COV=$(genhtml --help | grep -q function-coverage &&
+                        echo --no-function-coverage)
+  genhtml $GENHTML_NO_FUNC_CONV --output-directory html app.info
+  ./local_coverage_rate
+fi