AAPT2: Convert Android.mk to Android.bp

Change-Id: I6c563993b57e3f04165ca57743f9a2878aba556c
diff --git a/Android.bp b/Android.bp
index 9088315..81d6dab 100644
--- a/Android.bp
+++ b/Android.bp
@@ -14,6 +14,7 @@
 
 subdirs = [
     "libs/*",
+    "tools/*",
     "native/android",
     "native/graphics/jni",
 ]
diff --git a/tools/aapt2/Android.bp b/tools/aapt2/Android.bp
new file mode 100644
index 0000000..20439cc
--- /dev/null
+++ b/tools/aapt2/Android.bp
@@ -0,0 +1,170 @@
+//
+// Copyright (C) 2015 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.
+//
+
+toolSources = [
+    "compile/Compile.cpp",
+    "diff/Diff.cpp",
+    "dump/Dump.cpp",
+    "link/Link.cpp",
+]
+
+cc_defaults {
+    name: "aapt_defaults",
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+    ],
+    cppflags: [
+        "-Wno-missing-field-initializers",
+        "-fno-exceptions",
+        "-fno-rtti",
+    ],
+    target: {
+        windows: {
+            enabled: true,
+            cflags: ["-Wno-maybe-uninitialized"],
+            static_libs: ["libz"],
+        },
+        darwin: {
+            cflags: ["-D_DARWIN_UNLIMITED_STREAMS"],
+            host_ldlibs: ["-lz"],
+        },
+        linux: {
+            host_ldlibs: ["-lz"],
+        },
+    },
+    static_libs: [
+        "libandroidfw",
+        "libutils",
+        "liblog",
+        "libcutils",
+        "libexpat",
+        "libziparchive",
+        "libpng",
+        "libbase",
+        "libprotobuf-cpp-lite",
+    ],
+    group_static_libs: true,
+}
+
+// ==========================================================
+// NOTE: Do not add any shared libraries.
+// AAPT2 is built to run on many environments
+// that may not have the required dependencies.
+// ==========================================================
+
+// ==========================================================
+// Build the host static library: aapt2
+// ==========================================================
+cc_library_host_static {
+    name: "libaapt2",
+    srcs: [
+        "compile/IdAssigner.cpp",
+        "compile/InlineXmlFormatParser.cpp",
+        "compile/NinePatch.cpp",
+        "compile/Png.cpp",
+        "compile/PngChunkFilter.cpp",
+        "compile/PngCrunch.cpp",
+        "compile/PseudolocaleGenerator.cpp",
+        "compile/Pseudolocalizer.cpp",
+        "compile/XmlIdCollector.cpp",
+        "filter/ConfigFilter.cpp",
+        "flatten/Archive.cpp",
+        "flatten/TableFlattener.cpp",
+        "flatten/XmlFlattener.cpp",
+        "io/File.cpp",
+        "io/FileSystem.cpp",
+        "io/Io.cpp",
+        "io/ZipArchive.cpp",
+        "link/AutoVersioner.cpp",
+        "link/ManifestFixer.cpp",
+        "link/ProductFilter.cpp",
+        "link/PrivateAttributeMover.cpp",
+        "link/ReferenceLinker.cpp",
+        "link/ResourceDeduper.cpp",
+        "link/TableMerger.cpp",
+        "link/VersionCollapser.cpp",
+        "link/XmlNamespaceRemover.cpp",
+        "link/XmlReferenceLinker.cpp",
+        "process/SymbolTable.cpp",
+        "proto/ProtoHelpers.cpp",
+        "proto/TableProtoDeserializer.cpp",
+        "proto/TableProtoSerializer.cpp",
+        "split/TableSplitter.cpp",
+        "unflatten/BinaryResourceParser.cpp",
+        "unflatten/ResChunkPullParser.cpp",
+        "util/BigBuffer.cpp",
+        "util/Files.cpp",
+        "util/Util.cpp",
+        "ConfigDescription.cpp",
+        "Debug.cpp",
+        "DominatorTree.cpp",
+        "Flags.cpp",
+        "java/AnnotationProcessor.cpp",
+        "java/ClassDefinition.cpp",
+        "java/JavaClassGenerator.cpp",
+        "java/ManifestClassGenerator.cpp",
+        "java/ProguardRules.cpp",
+        "Locale.cpp",
+        "Resource.cpp",
+        "ResourceParser.cpp",
+        "ResourceTable.cpp",
+        "ResourceUtils.cpp",
+        "ResourceValues.cpp",
+        "SdkConstants.cpp",
+        "StringPool.cpp",
+        "xml/XmlActionExecutor.cpp",
+        "xml/XmlDom.cpp",
+        "xml/XmlPullParser.cpp",
+        "xml/XmlUtil.cpp",
+        "Format.proto",
+    ],
+    proto: {
+        export_proto_headers: true,
+    },
+    defaults: ["aapt_defaults"],
+}
+
+// ==========================================================
+// Build the host shared library: aapt2_jni
+// ==========================================================
+cc_library_host_shared {
+    name: "libaapt2_jni",
+    srcs: toolSources + ["jni/aapt2_jni.cpp"],
+    static_libs: ["libaapt2"],
+    defaults: ["aapt_defaults"],
+}
+
+// ==========================================================
+// Build the host tests: aapt2_tests
+// ==========================================================
+cc_test_host {
+    name: "aapt2_tests",
+    srcs: ["**/*_test.cpp"],
+    static_libs: ["libaapt2"],
+    defaults: ["aapt_defaults"],
+}
+
+// ==========================================================
+// Build the host executable: aapt2
+// ==========================================================
+cc_binary_host {
+    name: "aapt2",
+    srcs: ["Main.cpp"] + toolSources,
+    static_libs: ["libaapt2"],
+    defaults: ["aapt_defaults"],
+}
diff --git a/tools/aapt2/Android.mk b/tools/aapt2/Android.mk
deleted file mode 100644
index 1efd2ed..0000000
--- a/tools/aapt2/Android.mk
+++ /dev/null
@@ -1,253 +0,0 @@
-#
-# Copyright (C) 2015 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.
-#
-LOCAL_PATH:= $(call my-dir)
-
-# ==========================================================
-# Setup some common variables for the different build
-# targets here.
-# ==========================================================
-
-main := Main.cpp
-sources := \
-	compile/IdAssigner.cpp \
-	compile/InlineXmlFormatParser.cpp \
-	compile/NinePatch.cpp \
-	compile/Png.cpp \
-	compile/PngChunkFilter.cpp \
-	compile/PngCrunch.cpp \
-	compile/PseudolocaleGenerator.cpp \
-	compile/Pseudolocalizer.cpp \
-	compile/XmlIdCollector.cpp \
-	filter/ConfigFilter.cpp \
-	flatten/Archive.cpp \
-	flatten/TableFlattener.cpp \
-	flatten/XmlFlattener.cpp \
-	io/File.cpp \
-	io/FileSystem.cpp \
-	io/Io.cpp \
-	io/ZipArchive.cpp \
-	link/AutoVersioner.cpp \
-	link/ManifestFixer.cpp \
-	link/ProductFilter.cpp \
-	link/PrivateAttributeMover.cpp \
-	link/ReferenceLinker.cpp \
-	link/ResourceDeduper.cpp \
-	link/TableMerger.cpp \
-	link/VersionCollapser.cpp \
-	link/XmlNamespaceRemover.cpp \
-	link/XmlReferenceLinker.cpp \
-	process/SymbolTable.cpp \
-	proto/ProtoHelpers.cpp \
-	proto/TableProtoDeserializer.cpp \
-	proto/TableProtoSerializer.cpp \
-	split/TableSplitter.cpp \
-	unflatten/BinaryResourceParser.cpp \
-	unflatten/ResChunkPullParser.cpp \
-	util/BigBuffer.cpp \
-	util/Files.cpp \
-	util/Util.cpp \
-	ConfigDescription.cpp \
-	Debug.cpp \
-	DominatorTree.cpp \
-	Flags.cpp \
-	java/AnnotationProcessor.cpp \
-	java/ClassDefinition.cpp \
-	java/JavaClassGenerator.cpp \
-	java/ManifestClassGenerator.cpp \
-	java/ProguardRules.cpp \
-	Locale.cpp \
-	Resource.cpp \
-	ResourceParser.cpp \
-	ResourceTable.cpp \
-	ResourceUtils.cpp \
-	ResourceValues.cpp \
-	SdkConstants.cpp \
-	StringPool.cpp \
-	xml/XmlActionExecutor.cpp \
-	xml/XmlDom.cpp \
-	xml/XmlPullParser.cpp \
-	xml/XmlUtil.cpp
-
-sources += Format.proto
-
-sourcesJni := jni/aapt2_jni.cpp
-
-testSources := \
-	compile/IdAssigner_test.cpp \
-	compile/InlineXmlFormatParser_test.cpp \
-	compile/NinePatch_test.cpp \
-	compile/PseudolocaleGenerator_test.cpp \
-	compile/Pseudolocalizer_test.cpp \
-	compile/XmlIdCollector_test.cpp \
-	filter/ConfigFilter_test.cpp \
-	flatten/TableFlattener_test.cpp \
-	flatten/XmlFlattener_test.cpp \
-	link/AutoVersioner_test.cpp \
-	link/ManifestFixer_test.cpp \
-	link/PrivateAttributeMover_test.cpp \
-	link/ProductFilter_test.cpp \
-	link/ReferenceLinker_test.cpp \
-	link/ResourceDeduper_test.cpp \
-	link/TableMerger_test.cpp \
-	link/VersionCollapser_test.cpp \
-	link/XmlNamespaceRemover_test.cpp \
-	link/XmlReferenceLinker_test.cpp \
-	process/SymbolTable_test.cpp \
-	proto/TableProtoSerializer_test.cpp \
-	split/TableSplitter_test.cpp \
-	util/BigBuffer_test.cpp \
-	util/Files_test.cpp \
-	util/Maybe_test.cpp \
-	util/StringPiece_test.cpp \
-	util/Util_test.cpp \
-	ConfigDescription_test.cpp \
-	DominatorTree_test.cpp \
-	java/AnnotationProcessor_test.cpp \
-	java/JavaClassGenerator_test.cpp \
-	java/ManifestClassGenerator_test.cpp \
-	Locale_test.cpp \
-	NameMangler_test.cpp \
-	Resource_test.cpp \
-	ResourceParser_test.cpp \
-	ResourceTable_test.cpp \
-	ResourceUtils_test.cpp \
-	SdkConstants_test.cpp \
-	StringPool_test.cpp \
-	ValueVisitor_test.cpp \
-	xml/XmlActionExecutor_test.cpp \
-	xml/XmlDom_test.cpp \
-	xml/XmlPullParser_test.cpp \
-	xml/XmlUtil_test.cpp
-
-toolSources := \
-	compile/Compile.cpp \
-	diff/Diff.cpp \
-	dump/Dump.cpp \
-	link/Link.cpp
-
-hostLdLibs :=
-
-hostStaticLibs := \
-	libandroidfw \
-	libutils \
-	liblog \
-	libcutils \
-	libexpat \
-	libziparchive \
-	libpng \
-	libbase \
-	libprotobuf-cpp-lite
-
-
-# Statically link libz for MinGW (Win SDK under Linux),
-# and dynamically link for all others.
-hostStaticLibs_windows := libz
-hostLdLibs_linux := -lz
-hostLdLibs_darwin := -lz
-
-cFlags := -Wall -Werror -Wno-unused-parameter
-cFlags_darwin := -D_DARWIN_UNLIMITED_STREAMS
-cFlags_windows := -Wno-maybe-uninitialized # Incorrectly marking use of Maybe.value() as error.
-cppFlags := -Wno-missing-field-initializers -fno-exceptions -fno-rtti
-protoIncludes := $(call generated-sources-dir-for,STATIC_LIBRARIES,libaapt2,HOST)
-
-# ==========================================================
-# NOTE: Do not add any shared libraries.
-# AAPT2 is built to run on many environments
-# that may not have the required dependencies.
-# ==========================================================
-
-# ==========================================================
-# Build the host static library: libaapt2
-# ==========================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := libaapt2
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_MODULE_HOST_OS := darwin linux windows
-LOCAL_CFLAGS := $(cFlags)
-LOCAL_CFLAGS_darwin := $(cFlags_darwin)
-LOCAL_CFLAGS_windows := $(cFlags_windows)
-LOCAL_CPPFLAGS := $(cppFlags)
-LOCAL_C_INCLUDES := $(protoIncludes)
-LOCAL_SRC_FILES := $(sources)
-LOCAL_STATIC_LIBRARIES := $(hostStaticLibs)
-LOCAL_STATIC_LIBRARIES_windows := $(hostStaticLibs_windows)
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-
-# ==========================================================
-# Build the host shared library: libaapt2_jni
-# ==========================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := libaapt2_jni
-LOCAL_MODULE_CLASS := SHARED_LIBRARIES
-LOCAL_MODULE_HOST_OS := darwin linux windows
-LOCAL_CFLAGS := $(cFlags)
-LOCAL_CFLAGS_darwin := $(cFlags_darwin)
-LOCAL_CFLAGS_windows := $(cFlags_windows)
-LOCAL_CPPFLAGS := $(cppFlags)
-LOCAL_C_INCLUDES := $(protoIncludes)
-LOCAL_SRC_FILES := $(toolSources) $(sourcesJni)
-LOCAL_STATIC_LIBRARIES := libaapt2 $(hostStaticLibs)
-LOCAL_STATIC_LIBRARIES_windows := $(hostStaticLibs_windows)
-LOCAL_LDLIBS := $(hostLdLibs)
-LOCAL_LDLIBS_darwin := $(hostLdLibs_darwin)
-LOCAL_LDLIBS_linux := $(hostLdLibs_linux)
-include $(BUILD_HOST_SHARED_LIBRARY)
-
-
-# ==========================================================
-# Build the host tests: libaapt2_tests
-# ==========================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := libaapt2_tests
-LOCAL_MODULE_TAGS := tests
-LOCAL_MODULE_HOST_OS := darwin linux windows
-LOCAL_CFLAGS := $(cFlags)
-LOCAL_CFLAGS_darwin := $(cFlags_darwin)
-LOCAL_CFLAGS_windows := $(cFlags_windows)
-LOCAL_CPPFLAGS := $(cppFlags)
-LOCAL_C_INCLUDES := $(protoIncludes)
-LOCAL_SRC_FILES := $(testSources)
-LOCAL_STATIC_LIBRARIES := libaapt2 $(hostStaticLibs)
-LOCAL_STATIC_LIBRARIES_windows := $(hostStaticLibs_windows)
-LOCAL_LDLIBS := $(hostLdLibs)
-LOCAL_LDLIBS_darwin := $(hostLdLibs_darwin)
-LOCAL_LDLIBS_linux := $(hostLdLibs_linux)
-include $(BUILD_HOST_NATIVE_TEST)
-
-# ==========================================================
-# Build the host executable: aapt2
-# ==========================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := aapt2
-LOCAL_MODULE_HOST_OS := darwin linux windows
-LOCAL_CFLAGS := $(cFlags)
-LOCAL_CFLAGS_darwin := $(cFlags_darwin)
-LOCAL_CFLAGS_windows := $(cFlags_windows)
-LOCAL_CPPFLAGS := $(cppFlags)
-LOCAL_C_INCLUDES := $(protoIncludes)
-LOCAL_SRC_FILES := $(main) $(toolSources)
-LOCAL_STATIC_LIBRARIES := libaapt2 $(hostStaticLibs)
-LOCAL_STATIC_LIBRARIES_windows := $(hostStaticLibs_windows)
-LOCAL_LDLIBS := $(hostLdLibs)
-LOCAL_LDLIBS_darwin := $(hostLdLibs_darwin)
-LOCAL_LDLIBS_linux := $(hostLdLibs_linux)
-include $(BUILD_HOST_EXECUTABLE)
-
-ifeq ($(ONE_SHOT_MAKEFILE),)
-include $(call all-makefiles-under,$(LOCAL_PATH))
-endif
diff --git a/tools/aapt2/proto/ProtoHelpers.h b/tools/aapt2/proto/ProtoHelpers.h
index 735cda0..344e947 100644
--- a/tools/aapt2/proto/ProtoHelpers.h
+++ b/tools/aapt2/proto/ProtoHelpers.h
@@ -23,7 +23,7 @@
 #include "ResourceTable.h"
 #include "Source.h"
 #include "StringPool.h"
-#include "proto/frameworks/base/tools/aapt2/Format.pb.h"
+#include "Format.pb.h"
 
 namespace aapt {