Add a fork of the emugen host tool

This change also adds a fork of the emugen host tool from external/qemu
799a545 to enable the generation of wrapper code using the emulator
library templates.

To regenerate the wrappers, use the following commands:

$ emugen_cuttlefish -W eglwrapper -i eglwrapper egl
$ emugen_cuttlefish -W eglwrapper -i eglwrapper gles1
$ emugen_cuttlefish -W eglwrapper -i eglwrapper gles3

Bug: 76027192
Bug: 74573450
Bug: 74572414
Bug: 74571771
Bug: 73780279
Test: this change is completely untested
Change-Id: Ib5e26ff824fd073a670971174014ea4c1b86c9f6
diff --git a/host/commands/Android.bp b/host/commands/Android.bp
new file mode 100644
index 0000000..8aebc1d
--- /dev/null
+++ b/host/commands/Android.bp
@@ -0,0 +1,21 @@
+//
+// Copyright (C) 2017 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.
+
+subdirs = [
+    "emugen",
+    "launch",
+    "stop_cvd",
+    "record_audio",
+]
diff --git a/host/commands/emugen/Android.bp b/host/commands/emugen/Android.bp
new file mode 100644
index 0000000..717a966
--- /dev/null
+++ b/host/commands/emugen/Android.bp
@@ -0,0 +1,13 @@
+cc_binary_host {
+    name: "emugen_cuttlefish",
+    srcs: [
+        "ApiGen.cpp",
+        "EntryPoint.cpp",
+        "main.cpp",
+        "Parser.cpp",
+        "strUtils.cpp",
+        "TypeFactory.cpp",
+    ],
+    cflags: ["-Wno-unused-parameter"],
+    defaults: ["cuttlefish_host_only"],
+}
diff --git a/host/commands/emugen/README.md b/host/commands/emugen/README.md
new file mode 100644
index 0000000..dfc130a
--- /dev/null
+++ b/host/commands/emugen/README.md
@@ -0,0 +1,17 @@
+# emugen (cuttlefish)
+
+This directory contains a fork of the emugen tool from the external/qemu project
+on the emu-master-dev branch. The tool is unmodified except for the following
+changes:
+
+1) The android/base/EnumFlags.h header has been forked, to avoid having to copy
+   over all of the host-side android-base port.
+
+2) The unittest infrastructure and all unittests have been removed.
+
+3) This README.md file replaces the upstream README file.
+
+4) The binary builds to `emugen_cuttlefish` so as to avoid conflicts.
+
+Do not contribute change only to this project; contribute them to external/qemu
+upstream, then cherry-pick them over.
diff --git a/host/commands/emugen/android/base/EnumFlags.h b/host/commands/emugen/android/base/EnumFlags.h
new file mode 100644
index 0000000..fec56b9
--- /dev/null
+++ b/host/commands/emugen/android/base/EnumFlags.h
@@ -0,0 +1,117 @@
+// Copyright 2015 The Android Open Source Project
+//
+// This software is licensed under the terms of the GNU General Public
+// License version 2, as published by the Free Software Foundation, and
+// may be copied, distributed, and modified under those terms.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+#pragma once
+
+#include <type_traits>
+
+// This header defines some utitily methods to manipulate scoped enums as flags
+// C++11 scoped enums by default don't support flag operations (e.g. if (a & b))
+// We need to define bitwise operations for them to be able to have strongly
+// typed flags in our code.
+//
+// To enable the flag operators for your enum, most probably you just need to
+// include this file. The only exception is if your enum is located in some
+// namespace other than android, android::base or global. In that case you also
+// need to add the following using to bring in the operators:
+//
+// using namespace ::android::base::EnumFlags;
+
+namespace android {
+namespace base {
+namespace EnumFlags {
+
+// A predicate which checks if template agument is a scoped enum
+template<class E>
+using is_scoped_enum = std::integral_constant<
+        bool,
+        std::is_enum<E>::value && !std::is_convertible<E, int>::value>;
+
+template <class E>
+using underlying_enum_type = typename std::underlying_type<E>::type;
+
+template <class E, class Res = E>
+using enable_if_scoped_enum =
+    typename std::enable_if<is_scoped_enum<E>::value, Res>::type;
+
+template <class E>
+enable_if_scoped_enum<E> operator|(E l, E r) {
+    return static_cast<E>(static_cast<underlying_enum_type<E>>(l)
+                          | static_cast<underlying_enum_type<E>>(r));
+}
+
+template <class E>
+enable_if_scoped_enum<E> operator&(E l, E r) {
+    return static_cast<E>(static_cast<underlying_enum_type<E>>(l)
+                          & static_cast<underlying_enum_type<E>>(r));
+}
+
+template <class E>
+enable_if_scoped_enum<E> operator~(E e) {
+    return static_cast<E>(~static_cast<underlying_enum_type<E>>(e));
+}
+
+template <class E>
+enable_if_scoped_enum<E> operator|=(E& l, E r) {
+    return l = (l | r);
+}
+
+template <class E>
+enable_if_scoped_enum<E> operator&=(E& l, E r) {
+    return l = (l & r);
+}
+
+template <class E>
+enable_if_scoped_enum<E, bool> operator!(E e) {
+    return !static_cast<underlying_enum_type<E>>(e);
+}
+
+template <class E>
+enable_if_scoped_enum<E, bool> operator!=(E e, int val) {
+    return static_cast<underlying_enum_type<E>>(e) !=
+            static_cast<underlying_enum_type<E>>(val);
+}
+
+template <class E>
+enable_if_scoped_enum<E, bool> operator!=(int val, E e) {
+    return e != val;
+}
+
+template <class E>
+enable_if_scoped_enum<E, bool> operator==(E e, int val) {
+    return static_cast<underlying_enum_type<E>>(e) ==
+            static_cast<underlying_enum_type<E>>(val);
+}
+
+template <class E>
+enable_if_scoped_enum<E, bool> operator==(int val, E e) {
+    return e == val;
+}
+
+template <class E>
+enable_if_scoped_enum<E, bool> nonzero(E e) {
+    return static_cast<underlying_enum_type<E>>(e) != 0;
+}
+
+}  // namespace EnumFlags
+
+// For the ADL to kick in let's make sure we bring all the operators into our
+// main AndroidEmu namespaces...
+using namespace ::android::base::EnumFlags;
+
+}  // namespace base
+
+using namespace ::android::base::EnumFlags;
+
+}  // namespace android
+
+// ... and into the global one, where most of the client functions are
+using namespace ::android::base::EnumFlags;