Convert to Android.bp

See build/soong/README.md for more information

Test: mmma hardware/libhardware
Change-Id: Ibb7e2af9d55f581e951d8996cea5e52cd0766b04
diff --git a/modules/sensors/Android.bp b/modules/sensors/Android.bp
index f39ba52..3d14bdf 100644
--- a/modules/sensors/Android.bp
+++ b/modules/sensors/Android.bp
@@ -3,7 +3,7 @@
     vendor: true,
     srcs: [
         "multihal.cpp",
-        "SensorEventQueue.cpp"
+        "SensorEventQueue.cpp",
     ],
     header_libs: [
         "libhardware_headers",
@@ -12,8 +12,28 @@
         "liblog",
         "libcutils",
         "libutils",
-        "libdl"
+        "libdl",
     ],
     export_include_dirs: ["."],
-    cflags: ["-Wall", "-Werror"],
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+}
+
+cc_test_host {
+    name: "sensorstests",
+    gtest: false,
+    srcs: [
+        "SensorEventQueue.cpp",
+        "tests/SensorEventQueue_test.cpp",
+    ],
+    static_libs: [
+        "libcutils",
+        "libutils",
+    ],
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
 }
diff --git a/modules/sensors/Android.mk b/modules/sensors/Android.mk
index f0045af..bc6a21b 100644
--- a/modules/sensors/Android.mk
+++ b/modules/sensors/Android.mk
@@ -45,5 +45,3 @@
 include $(BUILD_SHARED_LIBRARY)
 
 endif # USE_SENSOR_MULTI_HAL
-
-include $(call all-makefiles-under, $(LOCAL_PATH))
diff --git a/modules/sensors/dynamic_sensor/Android.bp b/modules/sensors/dynamic_sensor/Android.bp
new file mode 100644
index 0000000..214d97c
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/Android.bp
@@ -0,0 +1,134 @@
+// 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: "dynamic_sensor_defaults",
+
+    // intended to be integrated into hal, thus vendor
+    vendor: true,
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wextra",
+    ],
+    export_include_dirs: ["."],
+
+    shared_libs: [
+        "libhidparser",
+    ],
+
+    target: {
+        android: {
+            srcs: [
+                "BaseDynamicSensorDaemon.cpp",
+                "BaseSensorObject.cpp",
+                "ConnectionDetector.cpp",
+                "DummyDynamicAccelDaemon.cpp",
+                "DynamicSensorManager.cpp",
+                "HidRawDevice.cpp",
+                "HidRawSensor.cpp",
+                "HidRawSensorDaemon.cpp",
+                "HidRawSensorDevice.cpp",
+                "RingBuffer.cpp",
+            ],
+            shared_libs: [
+                "libbase",
+                "libcutils",
+                "liblog",
+                "libutils",
+            ],
+            header_libs: [
+                "libhardware_headers",
+                "libstagefright_foundation_headers",
+            ],
+        },
+
+        host: {
+            local_include_dirs: [
+                "test",
+                "HidUtils/test",
+            ],
+        },
+
+        // host test is targeting linux host only
+        darwin: {
+            enabled: false,
+        },
+    },
+}
+
+//
+// There are two ways to utilize the dynamic sensor module:
+//   1. Use as an extension in an existing hal: declare dependency on libdynamic_sensor_ext shared
+//      library in existing sensor hal.
+//   2. Use as a standalone sensor HAL and configure multihal to combine it with sensor hal that
+//      hosts other sensors: add dependency on sensors.dynamic_sensor_hal in device level makefile and
+//      write multihal configuration file accordingly.
+//
+// Please take only one of these two options to avoid conflict over hardware resource.
+//
+//
+// Option 1: sensor extension module
+//
+cc_library_shared {
+    name: "libdynamic_sensor_ext",
+    defaults: ["dynamic_sensor_defaults"],
+
+    cflags: ["-DLOG_TAG=\"DynamicSensorExt\""],
+}
+
+//
+// Option 2: independent sensor hal
+//
+cc_library_shared {
+    name: "sensors.dynamic_sensor_hal",
+    defaults: ["dynamic_sensor_defaults"],
+    relative_install_path: "hw",
+
+    cflags: ["-DLOG_TAG=\"DynamicSensorHal\""],
+
+    srcs: ["sensors.cpp"],
+}
+
+//
+// Host test for HidRawSensor. Test with dummy test HID descriptors.
+//
+cc_binary_host {
+    name: "hidrawsensor_host_test",
+    defaults: ["dynamic_sensor_defaults"],
+
+    srcs: [
+        "HidRawSensor.cpp",
+        "BaseSensorObject.cpp",
+        "HidUtils/test/TestHidDescriptor.cpp",
+        "test/HidRawSensorTest.cpp",
+    ],
+}
+
+//
+// Host test for HidRawDevice and HidRawSensor. Test with hidraw
+// device node.
+//
+cc_binary_host {
+    name: "hidrawdevice_host_test",
+    defaults: ["dynamic_sensor_defaults"],
+
+    srcs: [
+        "HidRawDevice.cpp",
+        "HidRawSensor.cpp",
+        "BaseSensorObject.cpp",
+        "test/HidRawDeviceTest.cpp",
+    ],
+}
diff --git a/modules/sensors/dynamic_sensor/Android.mk b/modules/sensors/dynamic_sensor/Android.mk
deleted file mode 100644
index 52809dc..0000000
--- a/modules/sensors/dynamic_sensor/Android.mk
+++ /dev/null
@@ -1,138 +0,0 @@
-# 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.
-
-LOCAL_PATH := $(call my-dir)
-COMMON_CFLAGS := -Wall -Werror -Wextra
-
-dynamic_sensor_src := \
-    BaseDynamicSensorDaemon.cpp \
-    BaseSensorObject.cpp \
-    ConnectionDetector.cpp \
-    DummyDynamicAccelDaemon.cpp \
-    DynamicSensorManager.cpp \
-    HidRawDevice.cpp \
-    HidRawSensor.cpp \
-    HidRawSensorDaemon.cpp \
-    HidRawSensorDevice.cpp \
-    RingBuffer.cpp
-
-dynamic_sensor_shared_lib := \
-    libbase \
-    libcutils \
-    libhidparser \
-    liblog \
-    libutils
-#
-# There are two ways to utilize the dynamic sensor module:
-#   1. Use as an extension in an existing hal: declare dependency on libdynamic_sensor_ext shared
-#      library in existing sensor hal.
-#   2. Use as a standalone sensor HAL and configure multihal to combine it with sensor hal that
-#      hosts other sensors: add dependency on sensors.dynamic_sensor_hal in device level makefile and
-#      write multihal configuration file accordingly.
-#
-# Please take only one of these two options to avoid conflict over hardware resource.
-#
-#
-# Option 1: sensor extension module
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := libdynamic_sensor_ext
-LOCAL_MODULE_TAGS := optional
-# intended to be integrated into hal, thus proprietary
-LOCAL_PROPRIETARY_MODULE := true
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS) -DLOG_TAG=\"DynamicSensorExt\"
-
-LOCAL_SRC_FILES := $(dynamic_sensor_src)
-
-LOCAL_HEADER_LIBRARIES := \
-    libhardware_headers \
-    libstagefright_foundation_headers \
-
-LOCAL_SHARED_LIBRARIES := $(dynamic_sensor_shared_lib)
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-
-include $(BUILD_SHARED_LIBRARY)
-
-#
-# Option 2: independent sensor hal
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := sensors.dynamic_sensor_hal
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_MODULE_TAGS := optional
-# hal module, thus proprietary
-LOCAL_PROPRIETARY_MODULE := true
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS) -DLOG_TAG=\"DynamicSensorHal\"
-
-LOCAL_SRC_FILES := $(dynamic_sensor_src) sensors.cpp
-
-LOCAL_HEADER_LIBRARIES := \
-    libhardware_headers \
-    libstagefright_foundation_headers \
-
-LOCAL_SHARED_LIBRARIES := $(dynamic_sensor_shared_lib)
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-
-include $(BUILD_SHARED_LIBRARY)
-
-#
-# Host test for HidRawSensor. Test with dummy test HID descriptors.
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := hidrawsensor_host_test
-LOCAL_MODULE_TAGS := optional
-# host test is targeting linux host only
-LOCAL_MODULE_HOST_OS := linux
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS)
-
-LOCAL_SRC_FILES := \
-    HidRawSensor.cpp \
-    BaseSensorObject.cpp \
-    HidUtils/test/TestHidDescriptor.cpp \
-    test/HidRawSensorTest.cpp
-
-LOCAL_SHARED_LIBRARIES := libhidparser_host
-
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/test $(LOCAL_PATH)/HidUtils/test
-include $(BUILD_HOST_EXECUTABLE)
-
-#
-# Host test for HidRawDevice and HidRawSensor. Test with hidraw
-# device node.
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := hidrawdevice_host_test
-LOCAL_MODULE_TAGS := optional
-# host test is targeting linux host only
-LOCAL_MODULE_HOST_OS := linux
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS)
-
-LOCAL_SRC_FILES := \
-    HidRawDevice.cpp \
-    HidRawSensor.cpp \
-    BaseSensorObject.cpp \
-    test/HidRawDeviceTest.cpp
-
-LOCAL_SHARED_LIBRARIES := libhidparser_host
-
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/test $(LOCAL_PATH)/HidUtils/test
-include $(BUILD_HOST_EXECUTABLE)
-
-include $(LOCAL_PATH)/HidUtils/Android.mk
diff --git a/modules/sensors/dynamic_sensor/HidUtils/Android.bp b/modules/sensors/dynamic_sensor/HidUtils/Android.bp
new file mode 100644
index 0000000..0eb43f8
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/HidUtils/Android.bp
@@ -0,0 +1,92 @@
+// 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: "hid_defaults",
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wextra",
+    ],
+}
+
+cc_library {
+    name: "libhidparser",
+    defaults: ["hid_defaults"],
+    host_supported: true,
+
+    // indended to be used by hal components, thus vendor
+    vendor: true,
+
+    srcs: [
+        "HidGlobal.cpp",
+        "HidItem.cpp",
+        "HidLocal.cpp",
+        "HidParser.cpp",
+        "HidReport.cpp",
+        "HidTree.cpp",
+    ],
+    export_include_dirs: ["."],
+
+    target: {
+        android: {
+            cflags: ["-DLOG_TAG=\"HidUtil\""],
+            shared_libs: ["libbase"],
+        },
+    },
+}
+
+//
+// Example of HidParser
+//
+cc_binary_host {
+    name: "hidparser_example",
+    defaults: ["hid_defaults"],
+
+    srcs: [
+        "test/HidParserExample.cpp",
+        "test/TestHidDescriptor.cpp",
+    ],
+    static_libs: ["libhidparser"],
+
+    local_include_dirs: ["test"],
+}
+
+//
+// Another example of HidParser
+//
+cc_binary_host {
+    name: "hidparser_example2",
+    defaults: ["hid_defaults"],
+
+    srcs: [
+        "test/HidParserExample2.cpp",
+        "test/TestHidDescriptor.cpp",
+    ],
+    static_libs: ["libhidparser"],
+
+    local_include_dirs: ["test"],
+}
+
+//
+// Test for TriState template
+//
+cc_test_host {
+    name: "tristate_test",
+    defaults: ["hid_defaults"],
+
+    srcs: ["test/TriStateTest.cpp"],
+
+    local_include_dirs: ["test"],
+}
diff --git a/modules/sensors/dynamic_sensor/HidUtils/Android.mk b/modules/sensors/dynamic_sensor/HidUtils/Android.mk
deleted file mode 100644
index 5a1d890..0000000
--- a/modules/sensors/dynamic_sensor/HidUtils/Android.mk
+++ /dev/null
@@ -1,99 +0,0 @@
-# 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.
-
-LOCAL_PATH := $(call my-dir)
-COMMON_CFLAGS := -Wall -Werror -Wextra
-
-hidparser_src := \
-    HidGlobal.cpp \
-    HidItem.cpp \
-    HidLocal.cpp \
-    HidParser.cpp \
-    HidReport.cpp \
-    HidTree.cpp
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := libhidparser
-LOCAL_MODULE_TAGS := optional
-# indended to be used by hal components, thus propietary
-LOCAL_PROPRIETARY_MODULE := true
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS) -DLOG_TAG=\"HidUtil\"
-LOCAL_SRC_FILES := $(hidparser_src)
-LOCAL_SHARED_LIBRARIES := libbase
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-include $(BUILD_SHARED_LIBRARY)
-
-#
-# host side shared library (for host test, example, etc)
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := libhidparser_host
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS)
-
-LOCAL_SRC_FILES := $(hidparser_src)
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-include $(BUILD_HOST_SHARED_LIBRARY)
-
-#
-# Example of HidParser
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := hidparser_example
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS)
-LOCAL_SRC_FILES := \
-    $(hidparser_src) \
-    test/HidParserExample.cpp \
-    test/TestHidDescriptor.cpp
-
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/test
-include $(BUILD_HOST_EXECUTABLE)
-
-#
-# Another example of HidParser
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := hidparser_example2
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS)
-LOCAL_SRC_FILES := \
-    $(hidparser_src) \
-    test/HidParserExample2.cpp \
-    test/TestHidDescriptor.cpp
-
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/test
-include $(BUILD_HOST_EXECUTABLE)
-
-#
-# Test for TriState template
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := tristate_test
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS)
-LOCAL_SRC_FILES := test/TriStateTest.cpp
-
-LOCAL_STATIC_LIBRARIES := \
-     libgtest \
-     libgtest_main
-
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/test
-include $(BUILD_HOST_NATIVE_TEST)
diff --git a/modules/sensors/tests/Android.mk b/modules/sensors/tests/Android.mk
deleted file mode 100644
index dcf4f24..0000000
--- a/modules/sensors/tests/Android.mk
+++ /dev/null
@@ -1,17 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-	SensorEventQueue_test.cpp
-
-LOCAL_CFLAGS := -Wall -Werror
-LOCAL_MODULE := sensorstests
-
-LOCAL_STATIC_LIBRARIES := libcutils libutils
-
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. bionic
-
-LOCAL_LDLIBS += -lpthread
-
-include $(BUILD_HOST_EXECUTABLE)
diff --git a/modules/sensors/tests/SensorEventQueue_test.cpp b/modules/sensors/tests/SensorEventQueue_test.cpp
index d3d75ee..07db4c0 100644
--- a/modules/sensors/tests/SensorEventQueue_test.cpp
+++ b/modules/sensors/tests/SensorEventQueue_test.cpp
@@ -4,14 +4,14 @@
 #include <pthread.h>
 #include <cutils/atomic.h>
 
-#include "SensorEventQueue.cpp"
+#include "SensorEventQueue.h"
 
 // Unit tests for the SensorEventQueue.
 
 // Run it like this:
 //
-// make sensorstests -j32 && \
-// out/host/linux-x86/obj/EXECUTABLES/sensorstests_intermediates/sensorstests
+// m sensorstests && \
+// out/host/linux-x86/nativetest64/sensorstests/sensorstests
 
 bool checkWritableBufferSize(SensorEventQueue* queue, int requested, int expected) {
     sensors_event_t* buffer;