Build unittests in Brillo.

Many unittests do not pass for simple reasons that will be addressed
later. This CL includes all the changes to make the unittests build.
In particular, the generated DBus mocks, required to build several
unittests are now included here.

The dbus-constants.h files were moved to the system_api repo, so they
can be removed from here.

The unittest build is only enabled for Brillo targets, since non-Brillo
targets don't even build DBus.

Bug: 26955860
TEST=`mmma` on edison-eng (and aosp_arm-eng).

Change-Id: Ib38241f0a6eb99b1d60d72db6bcfd125d38e3fad
diff --git a/include/update_includes.sh b/include/update_includes.sh
new file mode 100755
index 0000000..6008d59
--- /dev/null
+++ b/include/update_includes.sh
@@ -0,0 +1,79 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+DBUS_GENERATOR=$(which dbus-binding-generator)
+MY_DIR=$(dirname "$0")
+
+if [[ -z "${ANDROID_HOST_OUT}" ]]; then
+  echo "You must run envsetup.sh and lunch first." >&2
+  exit 1
+fi
+
+if [[ -z "${DBUS_GENERATOR}" ]]; then
+  echo "DBus bindings generator not found." >&2
+  exit 1
+fi
+
+set -e
+
+# generate <kind> <dir> <xml> [xml ...]
+# Generate a DBus proxy and/or proxy mock in the passed |dir| for the provided
+# |xml| service files.
+# The parameter |kind| determines whether it should generate the mock only
+# (mock), the proxy only (proxy) or both (both).
+generate() {
+  local kind="$1"
+  local dir="$2"
+  local xmls=("${@:3}")
+
+  mkdir -p "${MY_DIR}/${dir}"
+  local outdir=$(realpath "${MY_DIR}/${dir}")
+  local proxyh="${outdir}/dbus-proxies.h"
+  local mockh="${outdir}/dbus-proxy-mocks.h"
+
+  ${DBUS_GENERATOR} "${xmls[@]}" --mock="${mockh}" --proxy="${proxyh}"
+
+  # Fix the include path to the dbus-proxies.h to include ${dir}.
+  sed "s,include \"dbus-proxies.h\",include \"${dir}/dbus-proxies.h\"," \
+    -i "${mockh}"
+
+  # Fix the header guards to be independent from the checkout location.
+  local guard=$(realpath "${MY_DIR}/../.." | tr '[:lower:]/ ' '[:upper:]__')
+  for header in "${mockh}" "${proxyh}"; do
+    sed "s,___CHROMEOS_DBUS_BINDING__${guard},___CHROMEOS_DBUS_BINDING__," \
+      -i "${header}"
+  done
+
+  # Remove the files not requested.
+  if [[ "${kind}" ==  "mock" ]]; then
+    rm -f "${proxyh}"
+  elif [[ "${kind}" == "proxy" ]]; then
+    rm -f "${mockh}"
+  fi
+}
+
+UE_DIR=$(realpath "${MY_DIR}/..")
+SHILL_DIR=$(realpath "${UE_DIR}/../connectivity/shill")
+
+generate mock "libcros" \
+  "${UE_DIR}/dbus_bindings/org.chromium.LibCrosService.dbus-xml"
+
+generate mock "shill" \
+  "${SHILL_DIR}"/dbus_bindings/org.chromium.flimflam.{Manager,Service}.dbus-xml
+
+echo "Done."