convert Android.mk to Android.bp for trunks
am: a437be8e97

Change-Id: I1534d271a69fba33a66eb4104359fa9a2dac2cd5
diff --git a/trunks/Android.bp b/trunks/Android.bp
new file mode 100644
index 0000000..43ec7c7
--- /dev/null
+++ b/trunks/Android.bp
@@ -0,0 +1,187 @@
+// Copyright 2017 Google Inc. All rights reserved.
+//
+// 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: "trunks_defaults",
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+        "-DUSE_BINDER_IPC",
+        "-fvisibility=hidden",
+    ],
+    shared_libs: [
+        "libbinder",
+        "libbinderwrapper",
+        "libbrillo",
+        "libbrillo-binder",
+        "libchrome",
+        "libchrome-crypto",
+        "libcrypto",
+        "libprotobuf-cpp-lite",
+        "libutils",
+    ],
+    include_dirs: [
+        "system/tpm",
+    ],
+}
+
+cc_library_static {
+    name: "libtrunks_generated",
+    defaults: ["trunks_defaults"],
+    srcs: [
+        "interface.proto",
+        "aidl/android/trunks/ITrunks.aidl",
+        "aidl/android/trunks/ITrunksClient.aidl",
+    ],
+    proto: {
+        export_proto_headers: true,
+    },
+    aidl: {
+        local_include_dirs: ["aidl"],
+        export_aidl_headers: true,
+    },
+}
+
+cc_library_static {
+    name: "libtrunks_common",
+    defaults: ["trunks_defaults"],
+    srcs: [
+      "background_command_transceiver.cc",
+      "blob_parser.cc",
+      "error_codes.cc",
+      "hmac_authorization_delegate.cc",
+      "hmac_session_impl.cc",
+      "password_authorization_delegate.cc",
+      "policy_session_impl.cc",
+      "scoped_key_handle.cc",
+      "session_manager_impl.cc",
+      "tpm_generated.cc",
+      "tpm_state_impl.cc",
+      "tpm_utility_impl.cc",
+      "trunks_factory_impl.cc",
+    ],
+    static_libs: [
+        "libtrunks_generated",
+    ],
+}
+
+cc_binary {
+    name: "trunksd",
+    defaults: ["trunks_defaults"],
+    srcs: [
+        "resource_manager.cc",
+        "tpm_handle.cc",
+        "tpm_simulator_handle.cc",
+        "trunks_binder_service.cc",
+        "trunksd.cc",
+    ],
+    required: [
+        "trunksd-seccomp.policy",
+    ],
+    init_rc: [
+        "trunksd.rc",
+    ],
+    shared_libs: [
+        "libbrillo-minijail",
+        "libminijail",
+    ],
+    static_libs: [
+        "libtrunks_generated",
+        "libtrunks_common",
+    ],
+}
+
+cc_library_shared {
+    name: "libtrunks",
+    defaults: ["trunks_defaults"],
+    srcs: [
+        "trunks_binder_proxy.cc",
+    ],
+    include_dirs: [
+        "system/tpm",
+    ],
+    shared_libs: [
+        "libbrillo-minijail",
+        "libminijail",
+    ],
+    whole_static_libs: [
+        "libtrunks_generated",
+        "libtrunks_common",
+    ]
+}
+
+cc_binary {
+    name: "trunks_client",
+    defaults: ["trunks_defaults"],
+    srcs: [
+        "trunks_client.cc",
+        "trunks_client_test.cc",
+    ],
+    shared_libs: [
+        "libbrillo-minijail",
+        "libminijail",
+        "libtrunks",
+    ],
+}
+
+cc_library_static {
+    name: "libtrunks_test",
+    defaults: ["trunks_defaults"],
+    shared_libs: [
+        "libbrillo-minijail",
+        "libminijail",
+    ],
+    srcs: [
+        "mock_authorization_delegate.cc",
+        "mock_blob_parser.cc",
+        "mock_command_transceiver.cc",
+        "mock_hmac_session.cc",
+        "mock_policy_session.cc",
+        "mock_session_manager.cc",
+        "mock_tpm.cc",
+        "mock_tpm_state.cc",
+        "mock_tpm_utility.cc",
+        "trunks_factory_for_test.cc",
+    ],
+    static_libs: ["libgmock"],
+}
+
+cc_test {
+    name: "trunks_test",
+    defaults: ["trunks_defaults"],
+    shared_libs: [
+        "libbrillo-minijail",
+        "libminijail",
+    ],
+    srcs: [
+        "mock_authorization_delegate.cc",
+        "mock_blob_parser.cc",
+        "mock_command_transceiver.cc",
+        "mock_hmac_session.cc",
+        "mock_policy_session.cc",
+        "mock_session_manager.cc",
+        "mock_tpm.cc",
+        "mock_tpm_state.cc",
+        "mock_tpm_utility.cc",
+        "trunks_factory_for_test.cc",
+    ],
+    static_libs: [
+        "libBionicGtestMain",
+        "libgmock",
+        "libtrunks_common",
+        "libtrunks_generated",
+        "libtrunks_test",
+    ],
+}
diff --git a/trunks/Android.mk b/trunks/Android.mk
index c801699..7fb7c33 100644
--- a/trunks/Android.mk
+++ b/trunks/Android.mk
@@ -14,108 +14,6 @@
 
 LOCAL_PATH := $(call my-dir)
 
-# Common variables
-# ========================================================
-trunksCppExtension := .cc
-trunksCFlags := \
-  -Wall -Werror \
-  -Wno-unused-parameter \
-  -DUSE_BINDER_IPC \
-  -fvisibility=hidden
-trunksIncludes := $(LOCAL_PATH)/..
-trunksSharedLibraries := \
-  libbinder \
-  libbinderwrapper \
-  libbrillo \
-  libbrillo-binder \
-  libchrome \
-  libchrome-crypto \
-  libcrypto \
-  libprotobuf-cpp-lite \
-  libutils
-
-# libtrunks_generated
-# ========================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := libtrunks_generated
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_CPP_EXTENSION := $(trunksCppExtension)
-LOCAL_CFLAGS := $(trunksCFlags)
-LOCAL_CLANG := true
-proto_include := $(call local-generated-sources-dir)/proto/$(LOCAL_PATH)/..
-aidl_include := $(call local-generated-sources-dir)/aidl-generated/include
-LOCAL_C_INCLUDES := $(proto_include) $(aidl_include) $(trunksIncludes)
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(proto_include) $(aidl_include)
-LOCAL_SHARED_LIBRARIES := $(trunksSharedLibraries)
-LOCAL_SRC_FILES := \
-  interface.proto \
-  aidl/android/trunks/ITrunks.aidl \
-  aidl/android/trunks/ITrunksClient.aidl
-LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/aidl
-include $(BUILD_STATIC_LIBRARY)
-
-# libtrunks_common
-# ========================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := libtrunks_common
-LOCAL_CPP_EXTENSION := $(trunksCppExtension)
-LOCAL_CFLAGS := $(trunksCFlags)
-LOCAL_CLANG := true
-LOCAL_C_INCLUDES := $(trunksIncludes)
-LOCAL_SHARED_LIBRARIES := $(trunksSharedLibraries)
-LOCAL_STATIC_LIBRARIES := libtrunks_generated
-LOCAL_SRC_FILES := \
-  background_command_transceiver.cc \
-  blob_parser.cc \
-  error_codes.cc \
-  hmac_authorization_delegate.cc \
-  hmac_session_impl.cc \
-  password_authorization_delegate.cc \
-  policy_session_impl.cc \
-  scoped_key_handle.cc \
-  session_manager_impl.cc \
-  tpm_generated.cc \
-  tpm_state_impl.cc \
-  tpm_utility_impl.cc \
-  trunks_factory_impl.cc
-include $(BUILD_STATIC_LIBRARY)
-
-# trunksd
-# ========================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := trunksd
-LOCAL_CPP_EXTENSION := $(trunksCppExtension)
-LOCAL_CFLAGS := $(trunksCFlags)
-ifeq ($(BRILLOEMULATOR),true)
-LOCAL_CFLAGS += -DUSE_SIMULATOR
-endif
-LOCAL_CLANG := true
-ifeq ($(BRILLOEMULATOR),true)
-LOCAL_INIT_RC := trunksd-simulator.rc
-else
-LOCAL_INIT_RC := trunksd.rc
-endif
-LOCAL_C_INCLUDES := $(trunksIncludes)
-LOCAL_SHARED_LIBRARIES := \
-  $(trunksSharedLibraries) \
-  libbrillo-minijail \
-  libminijail
-ifeq ($(BRILLOEMULATOR),true)
-LOCAL_SHARED_LIBRARIES += libtpm2
-endif
-LOCAL_STATIC_LIBRARIES := \
-  libtrunks_generated \
-  libtrunks_common
-LOCAL_REQUIRED_MODULES := \
-  trunksd-seccomp.policy
-LOCAL_SRC_FILES := \
-  resource_manager.cc \
-  tpm_handle.cc \
-  tpm_simulator_handle.cc \
-  trunks_binder_service.cc \
-  trunksd.cc
-include $(BUILD_EXECUTABLE)
-
 # trunksd-seccomp.policy
 # ========================================================
 include $(CLEAR_VARS)
@@ -124,90 +22,3 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT)/usr/share/policy/
 LOCAL_SRC_FILES := trunksd-seccomp-$(TARGET_ARCH).policy
 include $(BUILD_PREBUILT)
-
-# libtrunks
-# ========================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := libtrunks
-LOCAL_CPP_EXTENSION := $(trunksCppExtension)
-LOCAL_CFLAGS := $(trunksCFlags)
-LOCAL_CLANG := true
-LOCAL_C_INCLUDES := $(trunksIncludes)
-LOCAL_SHARED_LIBRARIES := $(trunksSharedLibraries)
-LOCAL_WHOLE_STATIC_LIBRARIES := \
-  libtrunks_common \
-  libtrunks_generated
-LOCAL_SRC_FILES := \
-  trunks_binder_proxy.cc
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/..
-include $(BUILD_SHARED_LIBRARY)
-
-# trunks_client
-# ========================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := trunks_client
-LOCAL_CPP_EXTENSION := $(trunksCppExtension)
-LOCAL_CFLAGS := $(trunksCFlags)
-LOCAL_CLANG := true
-LOCAL_C_INCLUDES := $(trunksIncludes)
-LOCAL_SHARED_LIBRARIES := $(trunksSharedLibraries) libtrunks
-LOCAL_SRC_FILES := \
-  trunks_client.cc \
-  trunks_client_test.cc
-include $(BUILD_EXECUTABLE)
-
-# libtrunks_test
-# ========================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := libtrunks_test
-LOCAL_MODULE_TAGS := eng
-LOCAL_CPP_EXTENSION := $(trunksCppExtension)
-LOCAL_CFLAGS := $(trunksCFlags)
-LOCAL_CLANG := true
-LOCAL_C_INCLUDES := $(trunksIncludes)
-LOCAL_SHARED_LIBRARIES := $(trunksSharedLibraries)
-LOCAL_SRC_FILES := \
-  mock_authorization_delegate.cc \
-  mock_blob_parser.cc \
-  mock_command_transceiver.cc \
-  mock_hmac_session.cc \
-  mock_policy_session.cc \
-  mock_session_manager.cc \
-  mock_tpm.cc \
-  mock_tpm_state.cc \
-  mock_tpm_utility.cc \
-  trunks_factory_for_test.cc
-LOCAL_STATIC_LIBRARIES := \
-  libgmock
-include $(BUILD_STATIC_LIBRARY)
-
-# Target unit tests
-# ========================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := trunks_test
-LOCAL_MODULE_TAGS := eng
-LOCAL_CPP_EXTENSION := $(trunksCppExtension)
-LOCAL_CFLAGS := $(trunksCFlags)
-LOCAL_CLANG := true
-LOCAL_C_INCLUDES := $(trunksIncludes)
-LOCAL_SHARED_LIBRARIES := $(trunksSharedLibraries)
-LOCAL_SRC_FILES := \
-  background_command_transceiver_test.cc \
-  hmac_authorization_delegate_test.cc \
-  hmac_session_test.cc \
-  password_authorization_delegate_test.cc \
-  policy_session_test.cc \
-  resource_manager.cc \
-  resource_manager_test.cc \
-  scoped_key_handle_test.cc \
-  session_manager_test.cc \
-  tpm_generated_test.cc \
-  tpm_state_test.cc \
-  tpm_utility_test.cc
-LOCAL_STATIC_LIBRARIES := \
-  libBionicGtestMain \
-  libgmock \
-  libtrunks_common \
-  libtrunks_generated \
-  libtrunks_test
-include $(BUILD_NATIVE_TEST)
diff --git a/trunks/trunks_binder_proxy.cc b/trunks/trunks_binder_proxy.cc
index 5c7590c..eda09df 100644
--- a/trunks/trunks_binder_proxy.cc
+++ b/trunks/trunks_binder_proxy.cc
@@ -26,7 +26,7 @@
 #include "android/trunks/BpTrunks.h"
 #include "trunks/binder_interface.h"
 #include "trunks/error_codes.h"
-#include "trunks/interface.pb.h"
+#include "interface.pb.h"
 
 namespace {
 
diff --git a/trunks/trunks_binder_service.cc b/trunks/trunks_binder_service.cc
index b8b72b5..174d818 100644
--- a/trunks/trunks_binder_service.cc
+++ b/trunks/trunks_binder_service.cc
@@ -24,7 +24,7 @@
 #include "trunks/binder_interface.h"
 #include "trunks/command_transceiver.h"
 #include "trunks/error_codes.h"
-#include "trunks/interface.pb.h"
+#include "interface.pb.h"
 
 namespace {