Move to Android.bp

Test: Build, boot bullhead
Test: libavb_host_unittest, image_handler_unittest.py, libavb_symbols_test

Change-Id: I86b0176f4c3f64a15a18e2c0f44fccfb64cedeb9
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..4495b9e
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,215 @@
+//
+// 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.
+//
+
+cc_defaults {
+    name: "avb_defaults",
+    cflags: [
+        "-D_FILE_OFFSET_BITS=64",
+        "-D_POSIX_C_SOURCE=199309L",
+        "-Wa,--noexecstack",
+        "-Werror",
+        "-Wall",
+        "-Wextra",
+        "-Wformat=2",
+        "-Wno-psabi",
+        "-Wno-unused-parameter",
+        "-ffunction-sections",
+        "-fstack-protector-strong",
+        "-g",
+        "-DAVB_ENABLE_DEBUG",
+        "-DAVB_COMPILATION",
+    ],
+    cppflags: [
+        "-Wnon-virtual-dtor",
+        "-fno-strict-aliasing",
+    ],
+    ldflags: [
+        "-Wl,--gc-sections",
+        "-rdynamic",
+    ],
+    target: {
+        darwin: {
+            enabled: false,
+        },
+    },
+}
+
+cc_defaults {
+    name: "avb_sources",
+    srcs: [
+        "libavb/avb_chain_partition_descriptor.c",
+        "libavb/avb_crc32.c",
+        "libavb/avb_crypto.c",
+        "libavb/avb_descriptor.c",
+        "libavb/avb_footer.c",
+        "libavb/avb_hash_descriptor.c",
+        "libavb/avb_hashtree_descriptor.c",
+        "libavb/avb_kernel_cmdline_descriptor.c",
+        "libavb/avb_property_descriptor.c",
+        "libavb/avb_rsa.c",
+        "libavb/avb_sha256.c",
+        "libavb/avb_sha512.c",
+        "libavb/avb_slot_verify.c",
+        "libavb/avb_util.c",
+        "libavb/avb_vbmeta_image.c",
+        "libavb/avb_version.c",
+    ],
+}
+
+cc_prebuilt_binary {
+    name: "avbtool",
+    srcs: ["avbtool"],
+    required: ["fec"],
+    device_supported: false,
+    host_supported: true,
+    target: {
+        darwin: {
+            enabled: false,
+        },
+    },
+}
+
+// Build libavb - this is a static library that depends
+// on only libc and doesn't drag in any other dependencies.
+cc_library_static {
+    name: "libavb",
+    defaults: [
+        "avb_defaults",
+        "avb_sources",
+    ],
+    host_supported: true,
+    export_include_dirs: ["."],
+    target: {
+        android: {
+            srcs: ["libavb/avb_sysdeps_posix.c"],
+        },
+        linux: {
+            cflags: ["-fno-stack-protector"],
+        },
+    },
+}
+
+// Build libavb_user for the target - in addition to libavb, it
+// includes libavb_ab, libavb_user and also depends on libbase and
+// libfs_mgr.
+cc_library_static {
+    name: "libavb_user",
+    defaults: [
+        "avb_defaults",
+        "avb_sources",
+    ],
+    export_include_dirs: ["."],
+    shared_libs: ["libbase"],
+    static_libs: ["libfs_mgr"],
+    srcs: [
+        "libavb/avb_sysdeps_posix.c",
+        "libavb_ab/avb_ab_flow.c",
+        "libavb_user/avb_ops_user.c",
+        "libavb_user/avb_user_verity.c",
+    ],
+}
+
+cc_binary {
+    name: "avbctl",
+    defaults: ["avb_defaults"],
+    static_libs: [
+        "libavb_user",
+        "libfs_mgr",
+    ],
+    shared_libs: ["libbase"],
+    srcs: ["tools/avbctl/avbctl.cc"],
+}
+
+cc_library_host_static {
+    name: "libavb_ab_host",
+    defaults: ["avb_defaults"],
+    export_include_dirs: ["."],
+    cflags: [
+        "-fno-stack-protector",
+    ],
+    srcs: ["libavb_ab/avb_ab_flow.c"],
+}
+
+cc_library_host_static {
+    name: "libavb_atx_host",
+    defaults: ["avb_defaults"],
+    export_include_dirs: ["."],
+    cflags: [
+        "-fno-stack-protector",
+    ],
+    srcs: ["libavb_atx/avb_atx_validate.c"],
+}
+
+cc_library_host_static {
+    name: "libavb_host_sysdeps",
+    defaults: ["avb_defaults"],
+    export_include_dirs: ["."],
+    srcs: ["libavb/avb_sysdeps_posix.c"],
+}
+
+cc_test_host {
+    name: "libavb_host_unittest",
+    defaults: ["avb_defaults"],
+    required: [
+        "simg2img",
+        "img2simg",
+        "avbtool",
+    ],
+    static_libs: [
+        "libavb",
+        "libavb_ab_host",
+        "libavb_atx_host",
+        "libgmock_host",
+        "libgtest_host",
+    ],
+    shared_libs: [
+        "libchrome",
+        "libcrypto",
+    ],
+    srcs: [
+        "test/avb_ab_flow_unittest.cc",
+        "test/avb_atx_validate_unittest.cc",
+        "test/avb_slot_verify_unittest.cc",
+        "test/avb_unittest_util.cc",
+        "test/avb_util_unittest.cc",
+        "test/avb_vbmeta_image_unittest.cc",
+        "test/avbtool_unittest.cc",
+        "test/fake_avb_ops.cc",
+        "test/avb_sysdeps_posix_testing.cc",
+    ],
+    host_ldlibs: ["-lrt"],
+}
+
+cc_library_host_static {
+    name: "libavb_host_user_code_test",
+    defaults: ["avb_defaults"],
+    srcs: ["test/user_code_test.cc"],
+}
+
+cc_library {
+    name: "bootctrl.avb",
+    defaults: ["avb_defaults"],
+    relative_install_path: "hw",
+    static_libs: [
+        "libavb_user",
+        "libfs_mgr",
+    ],
+    shared_libs: [
+        "libbase",
+        "libcutils",
+    ],
+    srcs: ["boot_control/boot_control_avb.c"],
+}
diff --git a/Android.mk b/Android.mk
deleted file mode 100644
index e053be6..0000000
--- a/Android.mk
+++ /dev/null
@@ -1,249 +0,0 @@
-#
-# Copyright 2016, The Android Open Source Project
-#
-# Permission is hereby granted, free of charge, to any person
-# obtaining a copy of this software and associated documentation
-# files (the "Software"), to deal in the Software without
-# restriction, including without limitation the rights to use, copy,
-# modify, merge, publish, distribute, sublicense, and/or sell copies
-# of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
-# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
-# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-#
-
-LOCAL_PATH := $(my-dir)
-
-avb_common_cflags := \
-    -D_FILE_OFFSET_BITS=64 \
-    -D_POSIX_C_SOURCE=199309L \
-    -Wa,--noexecstack \
-    -Werror \
-    -Wall \
-    -Wextra \
-    -Wformat=2 \
-    -Wno-psabi \
-    -Wno-unused-parameter \
-    -ffunction-sections \
-    -fstack-protector-strong \
-    -g
-avb_common_cppflags := \
-    -Wnon-virtual-dtor \
-    -fno-strict-aliasing
-avb_common_ldflags := \
-    -Wl,--gc-sections \
-    -rdynamic
-
-# The sources that make up libavb (excluding sysdeps).
-libavb_sources := \
-    libavb/avb_chain_partition_descriptor.c \
-    libavb/avb_crc32.c \
-    libavb/avb_crypto.c \
-    libavb/avb_descriptor.c \
-    libavb/avb_footer.c \
-    libavb/avb_hash_descriptor.c \
-    libavb/avb_hashtree_descriptor.c \
-    libavb/avb_kernel_cmdline_descriptor.c \
-    libavb/avb_property_descriptor.c \
-    libavb/avb_rsa.c \
-    libavb/avb_sha256.c \
-    libavb/avb_sha512.c \
-    libavb/avb_slot_verify.c \
-    libavb/avb_util.c \
-    libavb/avb_vbmeta_image.c \
-    libavb/avb_version.c
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := avbtool
-LOCAL_MODULE_CLASS := EXECUTABLES
-LOCAL_REQUIRED_MODULES := fec
-LOCAL_IS_HOST_MODULE := true
-LOCAL_MODULE := avbtool
-include $(BUILD_PREBUILT)
-
-# Build libavb for the target - this is a static library that depends
-# on only libc and doesn't drag in any other dependencies.
-include $(CLEAR_VARS)
-LOCAL_MODULE := libavb
-LOCAL_MODULE_HOST_OS := linux
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-LOCAL_CLANG := true
-LOCAL_CFLAGS := $(avb_common_cflags) -DAVB_ENABLE_DEBUG -DAVB_COMPILATION
-LOCAL_LDFLAGS := $(avb_common_ldflags)
-LOCAL_SRC_FILES := \
-    $(libavb_sources) \
-    libavb/avb_sysdeps_posix.c
-include $(BUILD_STATIC_LIBRARY)
-
-# Build libavb_user for the target - in addition to libavb, it
-# includes libavb_ab, libavb_user and also depends on libbase and
-# libfs_mgr.
-include $(CLEAR_VARS)
-LOCAL_MODULE := libavb_user
-LOCAL_MODULE_HOST_OS := linux
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-LOCAL_CLANG := true
-LOCAL_CFLAGS := $(avb_common_cflags) -DAVB_ENABLE_DEBUG -DAVB_COMPILATION
-LOCAL_LDFLAGS := $(avb_common_ldflags)
-LOCAL_SHARED_LIBRARIES := \
-    libbase
-LOCAL_STATIC_LIBRARIES := \
-    libfs_mgr
-LOCAL_SRC_FILES := \
-    $(libavb_sources) \
-    libavb/avb_sysdeps_posix.c \
-    libavb_ab/avb_ab_flow.c \
-    libavb_user/avb_ops_user.c \
-    libavb_user/avb_user_verity.c
-include $(BUILD_STATIC_LIBRARY)
-
-# Build avbctl for the target.
-include $(CLEAR_VARS)
-LOCAL_MODULE := avbctl
-LOCAL_MODULE_CLASS := EXECUTABLES
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-LOCAL_CPP_EXTENSION := .cc
-LOCAL_CLANG := true
-LOCAL_CFLAGS := $(avb_common_cflags) -DAVB_COMPILATION -DAVB_ENABLE_DEBUG
-LOCAL_CPPFLAGS := $(avb_common_cppflags)
-LOCAL_LDFLAGS := $(avb_common_ldflags)
-LOCAL_STATIC_LIBRARIES := \
-    libavb_user \
-    libfs_mgr
-LOCAL_SHARED_LIBRARIES := \
-    libbase
-LOCAL_SRC_FILES := \
-    tools/avbctl/avbctl.cc
-include $(BUILD_EXECUTABLE)
-
-# Build libavb for the host (for unit tests).
-include $(CLEAR_VARS)
-LOCAL_MODULE := libavb_host
-LOCAL_MODULE_HOST_OS := linux
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_CLANG := true
-LOCAL_CFLAGS := $(avb_common_cflags) -fno-stack-protector -DAVB_ENABLE_DEBUG -DAVB_COMPILATION
-LOCAL_LDFLAGS := $(avb_common_ldflags)
-LOCAL_SRC_FILES := \
-    $(libavb_sources) \
-    libavb/avb_version.c
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-# Build libavb_ab for the host (for unit tests).
-include $(CLEAR_VARS)
-LOCAL_MODULE := libavb_ab_host
-LOCAL_REQUIRED_MODULES := libavb_host
-LOCAL_MODULE_HOST_OS := linux
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_CLANG := true
-LOCAL_CFLAGS := $(avb_common_cflags) -fno-stack-protector -DAVB_ENABLE_DEBUG -DAVB_COMPILATION
-LOCAL_LDFLAGS := $(avb_common_ldflags)
-LOCAL_SRC_FILES := \
-    libavb_ab/avb_ab_flow.c
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-# Build libavb_atx for the host (for unit tests).
-include $(CLEAR_VARS)
-LOCAL_MODULE := libavb_atx_host
-LOCAL_REQUIRED_MODULES := libavb_host
-LOCAL_MODULE_HOST_OS := linux
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_CLANG := true
-LOCAL_CFLAGS := $(avb_common_cflags) -fno-stack-protector -DAVB_ENABLE_DEBUG -DAVB_COMPILATION
-LOCAL_LDFLAGS := $(avb_common_ldflags)
-LOCAL_SRC_FILES := \
-    libavb_atx/avb_atx_validate.c
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := libavb_host_sysdeps
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-LOCAL_MODULE_HOST_OS := linux
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_CLANG := true
-LOCAL_CFLAGS := $(avb_common_cflags) -DAVB_ENABLE_DEBUG -DAVB_COMPILATION
-LOCAL_LDFLAGS := $(avb_common_ldflags)
-LOCAL_SRC_FILES := \
-    libavb/avb_sysdeps_posix.c
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := libavb_host_unittest
-LOCAL_REQUIRED_MODULES := simg2img img2simg avbtool
-LOCAL_MODULE_HOST_OS := linux
-LOCAL_CPP_EXTENSION := .cc
-LOCAL_CLANG := true
-LOCAL_CFLAGS := $(avb_common_cflags) -DAVB_ENABLE_DEBUG -DAVB_COMPILATION
-LOCAL_CPPFLAGS := $(avb_common_cppflags)
-LOCAL_LDFLAGS := $(avb_common_ldflags)
-LOCAL_STATIC_LIBRARIES := \
-    libavb_host \
-    libavb_ab_host \
-    libavb_atx_host \
-    libgmock_host \
-    libgtest_host
-LOCAL_SHARED_LIBRARIES := \
-    libchrome \
-    libcrypto
-LOCAL_SRC_FILES := \
-    test/avb_ab_flow_unittest.cc \
-    test/avb_atx_validate_unittest.cc \
-    test/avb_slot_verify_unittest.cc \
-    test/avb_unittest_util.cc \
-    test/avb_util_unittest.cc \
-    test/avb_vbmeta_image_unittest.cc \
-    test/avbtool_unittest.cc \
-    test/fake_avb_ops.cc \
-    test/avb_sysdeps_posix_testing.cc
-LOCAL_LDLIBS_linux := -lrt
-include $(BUILD_HOST_NATIVE_TEST)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := libavb_host_user_code_test
-LOCAL_MODULE_HOST_OS := linux
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_CPP_EXTENSION := .cc
-LOCAL_CLANG := true
-LOCAL_CFLAGS := $(avb_common_cflags)
-LOCAL_CPPFLAGS := $(avb_common_cppflags)
-LOCAL_LDFLAGS := $(avb_common_ldflags)
-LOCAL_SRC_FILES := test/user_code_test.cc
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := bootctrl.avb
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_SRC_FILES := \
-    boot_control/boot_control_avb.c
-LOCAL_CLANG := true
-LOCAL_CFLAGS := $(avb_common_cflags) -DAVB_COMPILATION
-LOCAL_LDFLAGS := $(avb_common_ldflags)
-LOCAL_SHARED_LIBRARIES := \
-    libbase \
-    libcutils
-LOCAL_STATIC_LIBRARIES := \
-    libavb_user \
-    libfs_mgr
-LOCAL_POST_INSTALL_CMD := \
-	$(hide) mkdir -p $(TARGET_OUT_SHARED_LIBRARIES)/hw && \
-	ln -sf bootctrl.avb.so $(TARGET_OUT_SHARED_LIBRARIES)/hw/bootctrl.default.so
-include $(BUILD_SHARED_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := libavb_host_symbols_test
-LOCAL_MODULE_TAGS := debug
-LOCAL_ADDITIONAL_DEPENDENCIES := libavb_ab_host
-include $(BUILD_HOST_PREBUILT)
diff --git a/README.md b/README.md
index 51ccf54..9b7fc5b 100644
--- a/README.md
+++ b/README.md
@@ -185,7 +185,7 @@
 * `boot_control/`
     + An implementation of the Android `boot_control` HAL for use with
       boot loaders using the experimental `libavb_ab` A/B stack.
-* `Android.mk`
+* `Android.bp`
     + Build instructions for building `libavb` (a static library for use
       on the device), host-side libraries (for unit tests), and unit
       tests.
diff --git a/test/avbtool_signing_helper_test.py b/test/avbtool_signing_helper_test.py
index 8705403..c9bb660 100755
--- a/test/avbtool_signing_helper_test.py
+++ b/test/avbtool_signing_helper_test.py
@@ -24,7 +24,7 @@
 # SOFTWARE.
 #
 
-# This shell-script checks the symbols in libavb_host.a and fails
+# This shell-script checks the symbols in libavb.a and fails
 # if a reference not starting with avb_ is referenced. It's intended
 # to catch mistakes where the standard C library is inadvertently
 # used.
diff --git a/test/libavb_host_symbols_test b/test/libavb_host_symbols_test
index db0dcb0..874f505 100755
--- a/test/libavb_host_symbols_test
+++ b/test/libavb_host_symbols_test
@@ -24,18 +24,18 @@
 # SOFTWARE.
 #
 
-# This shell-script checks the symbols in libavb_host.a and fails
+# This shell-script checks the symbols in libavb.a and fails
 # if a reference not starting with avb_ is referenced. It's intended
 # to catch mistakes where the standard C library is inadvertently
 # used.
 
 set -e
 
-SYMBOLS_FILE=$(mktemp /tmp/libavb_host_symbols.XXXXXXXXXX)
+SYMBOLS_FILE=$(mktemp /tmp/libavb_symbols.XXXXXXXXXX)
 
 trap "rm -f '${SYMBOLS_FILE}'" EXIT
 
-readelf --symbols --wide "${ANDROID_HOST_OUT}/obj/STATIC_LIBRARIES/libavb_host_intermediates/libavb_host.a" | \
+readelf --symbols --wide "${ANDROID_HOST_OUT}/obj/STATIC_LIBRARIES/libavb_intermediates/libavb.a" | \
   awk '$7 == "UND" && $8 != "" {print $8}' | \
   grep -v ^avb_ | \
   sort -u > "${SYMBOLS_FILE}"
@@ -43,7 +43,7 @@
 # If this file is non-empty, it means that the library is using
 # symbols not starting with "avb_".
 if [ -s "${SYMBOLS_FILE}" ] ; then
-  echo "ERROR: $0: Unexpected symbols in libavb_host:" >&2
+  echo "ERROR: $0: Unexpected symbols in libavb:" >&2
   cat "${SYMBOLS_FILE}" >&2
   exit 1
 fi