From eb5a1bc7561150ce8bc8f1fdf3f28d863a412c44 Mon Sep 17 00:00:00 2001
From: Hirokazu Honda <hiroh@google.com>
Date: Mon, 28 May 2018 19:14:19 +0900
Subject: [PATCH] v4l2_codec2: Convert Android.mk to Android.bp

libv4l2_codec2_vda and libv4l2_code2_arcva_factory are required to be imported by
device/google/cheets/codec2/allocators/Android.bp. The allocators is also required to be imported by
device/google/cheets/codec2/vdastore/Android.bp.
Because shared library built by Android.mk is not visible by Android.bp. There is a need to convert
Android.mk in external/v4l2_codec2 to Android.bp.

Bug: 32691050
Test: build Android image

Change-Id: Ie7878393511c862c42f4d76c65c296fe8700243e
---
 Android.bp       | 105 +++++++++++++++++++++++++++++++++++++++++++++++
 Android.mk       |  97 -------------------------------------------
 cmds/Android.bp  |  36 ++++++++++++++++
 cmds/Android.mk  |  42 -------------------
 tests/Android.bp |  65 +++++++++++++++++++++++++++++
 tests/Android.mk |  78 -----------------------------------
 vda/Android.bp   |  53 ++++++++++++++++++++++++
 vda/Android.mk   |  50 ----------------------
 8 files changed, 259 insertions(+), 267 deletions(-)
 create mode 100644 Android.bp
 delete mode 100644 Android.mk
 create mode 100644 cmds/Android.bp
 delete mode 100644 cmds/Android.mk
 create mode 100644 tests/Android.bp
 delete mode 100644 tests/Android.mk
 create mode 100644 vda/Android.bp
 delete mode 100644 vda/Android.mk

diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..4335e61
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,105 @@
+soong_namespace {
+    imports: [
+        "device/google/cheets2/codec2",
+        "hardware/google/av",
+    ],
+}
+
+cc_library_shared {
+    name: "libv4l2_codec2_arcva_factory",
+    vendor_available: true,
+    product_variables: {
+        arc: {
+            srcs: ["C2ArcVideoAcceleratorFactory.cpp"],
+
+            shared_libs: [
+                "libarcbridge",
+                "libarcbridgeservice",
+                "libarcvideobridge",
+                "libbinder",
+                "libchrome",
+                "liblog",
+                "libmojo",
+                "libutils",
+            ],
+
+            // -Wno-unused-parameter is needed for libchrome/base codes
+            cflags: [
+                "-Wall",
+                "-Werror",
+                "-Wno-unused-parameter",
+                "-std=c++14",
+            ],
+        },
+    },
+    clang: true,
+    export_include_dirs: [
+        "include",
+    ],
+}
+
+cc_library_shared {
+    name: "libv4l2_codec2",
+
+    srcs: [
+        "C2VDAComponent.cpp",
+        "C2VDAAdaptor.cpp",
+    ],
+
+    shared_libs: [
+        "libbinder",
+        "libchrome",
+        "liblog",
+        "libmedia",
+        "libstagefright",
+        "libstagefright_codec2",
+        "libstagefright_codec2_vndk",
+        "libstagefright_foundation",
+        "libstagefright_simple_c2component",
+        "libutils",
+        "libv4l2_codec2_vda",
+        "libvda_c2componentstore",
+    ],
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unknown-warning-option",
+        "-Wno-unused-lambda-capture",
+        "-Wno-unused-parameter",
+        "-std=c++14",
+    ],
+
+    clang: true,
+
+    sanitize: {
+        misc_undefined: [
+            "unsigned-integer-overflow",
+            "signed-integer-overflow",
+        ],
+    },
+
+    ldflags: [
+        "-Wl",
+        "-Bsymbolic",
+    ],
+
+    product_variables: {
+        arc: {
+            srcs: ["C2VDAAdaptorProxy.cpp"],
+            exclude_srcs : ["C2VDAAdaptor.cpp"],
+            shared_libs: [
+                "libarcbridge",
+                "libarcbridgeservice",
+                "libmojo",
+                "libv4l2_codec2_arcva_factory",
+            ],
+            cflags: [
+                "-DV4L2_CODEC2_ARC",
+            ],
+        }
+    },
+    export_include_dirs: [
+        "include",
+    ],
+}
diff --git a/Android.mk b/Android.mk
deleted file mode 100644
index 0ba1e46..0000000
--- a/Android.mk
+++ /dev/null
@@ -1,97 +0,0 @@
-# Build only if both hardware/google/av and device/google/cheets2/codec2 are
-# visible; otherwise, don't build any target under this repository.
-ifneq (,$(findstring hardware/google/av,$(PRODUCT_SOONG_NAMESPACES)))
-ifneq (,$(findstring device/google/cheets2/codec2,$(PRODUCT_SOONG_NAMESPACES)))
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-# Build C2ArcVideoAcceleratorFactory only in cheets build.
-ifneq (,$(findstring cheets_,$(TARGET_PRODUCT)))
-LOCAL_SRC_FILES:= \
-                   C2ArcVideoAcceleratorFactory.cpp \
-
-LOCAL_C_INCLUDES := \
-        $(TOP)/external/gtest/include \
-        $(TOP)/external/libchrome \
-        $(TOP)/external/v4l2_codec2/include \
-
-LOCAL_MODULE:= libv4l2_codec2_arcva_factory
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SHARED_LIBRARIES += libarcbridge \
-                          libarcbridgeservice \
-                          libarcvideobridge \
-                          libbinder \
-                          libchrome \
-                          liblog \
-                          libmojo \
-                          libutils \
-
-# -Wno-unused-parameter is needed for libchrome/base codes
-LOCAL_CFLAGS := -Werror -Wall -Wno-unused-parameter -std=c++14
-LOCAL_CLANG := true
-
-include $(BUILD_SHARED_LIBRARY)
-include $(CLEAR_VARS)
-endif # ifneq (,$(findstring cheets_,$(TARGET_PRODUCT)))
-
-LOCAL_SRC_FILES:= \
-        C2VDAComponent.cpp \
-        C2VDAAdaptor.cpp   \
-
-LOCAL_C_INCLUDES += \
-        $(TOP)/device/google/cheets2/codec2/vdastore/include \
-        $(TOP)/external/libchrome \
-        $(TOP)/external/gtest/include \
-        $(TOP)/external/v4l2_codec2/include \
-        $(TOP)/external/v4l2_codec2/vda \
-        $(TOP)/frameworks/av/media/libstagefright/include \
-        $(TOP)/hardware/google/av/codec2/include \
-        $(TOP)/hardware/google/av/codec2/vndk/include \
-        $(TOP)/hardware/google/av/media/codecs/base/include \
-
-LOCAL_MODULE:= libv4l2_codec2
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SHARED_LIBRARIES := libbinder \
-                          libchrome \
-                          liblog \
-                          libmedia \
-                          libstagefright \
-                          libstagefright_codec2 \
-                          libstagefright_codec2_vndk \
-                          libstagefright_simple_c2component \
-                          libstagefright_foundation \
-                          libutils \
-                          libv4l2_codec2_vda \
-                          libvda_c2componentstore \
-
-# -Wno-unused-parameter is needed for libchrome/base codes
-LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -std=c++14
-LOCAL_CFLAGS += -Wno-unused-lambda-capture -Wno-unknown-warning-option
-LOCAL_CLANG := true
-LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow
-
-LOCAL_LDFLAGS := -Wl,-Bsymbolic
-
-# Build C2VDAAdaptorProxy only for ARC++ case.
-ifneq (,$(findstring cheets_,$(TARGET_PRODUCT)))
-LOCAL_CFLAGS += -DV4L2_CODEC2_ARC
-LOCAL_SRC_FILES += \
-                   C2VDAAdaptorProxy.cpp \
-
-LOCAL_SRC_FILES := $(filter-out C2VDAAdaptor.cpp, $(LOCAL_SRC_FILES))
-LOCAL_SHARED_LIBRARIES += libarcbridge \
-                          libarcbridgeservice \
-                          libmojo \
-                          libv4l2_codec2_arcva_factory \
-
-endif # ifneq (,$(findstring cheets_,$(TARGET_PRODUCT)))
-
-include $(BUILD_SHARED_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
-
-endif  #ifneq (,$(findstring device/google/cheets2/codec2,$(PRODUCT_SOONG_NAMESPACES)))
-endif  #ifneq (,$(findstring hardware/google/av,$(PRODUCT_SOONG_NAMESPACES)))
diff --git a/cmds/Android.bp b/cmds/Android.bp
new file mode 100644
index 0000000..c7e7b16
--- /dev/null
+++ b/cmds/Android.bp
@@ -0,0 +1,36 @@
+cc_binary {
+    name: "v4l2_codec2_testapp",
+    srcs: ["codec2.cpp"],
+
+    include_dirs: [
+        "frameworks/native/include",
+    ],
+
+    shared_libs: [
+        "android.hardware.media.bufferpool@1.0",
+        "libbinder",
+        "libchrome",
+        "libcutils",
+        "libgui",
+        "liblog",
+        "libmedia",
+        "libmediaextractor",
+        "libstagefright",
+        "libstagefright_codec2",
+        "libstagefright_codec2_vndk",
+        "libstagefright_foundation",
+        "libstagefright_simple_c2component",
+        "libui",
+        "libutils",
+        "libv4l2_codec2",
+        "libv4l2_codec2_vda",
+    ],
+
+    // -Wno-unused-parameter is needed for libchrome/base codes
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+    ],
+    clang: true,
+}
diff --git a/cmds/Android.mk b/cmds/Android.mk
deleted file mode 100644
index 6cc84ae..0000000
--- a/cmds/Android.mk
+++ /dev/null
@@ -1,42 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-        codec2.cpp \
-
-LOCAL_C_INCLUDES += \
-        $(TOP)/external/libchrome \
-        $(TOP)/external/gtest/include \
-        $(TOP)/external/v4l2_codec2/include \
-        $(TOP)/external/v4l2_codec2/vda \
-        $(TOP)/frameworks/av/media/libstagefright/include \
-        $(TOP)/frameworks/native/include \
-        $(TOP)/hardware/google/av/codec2/include \
-        $(TOP)/hardware/google/av/codec2/vndk/include \
-	$(TOP)/hardware/google/av/media/codecs/base/include \
-
-LOCAL_MODULE := v4l2_codec2_testapp
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SHARED_LIBRARIES := libbinder \
-                          libchrome \
-                          libcutils \
-                          libgui \
-                          liblog \
-                          libmedia \
-                          libmediaextractor \
-                          libstagefright \
-                          libstagefright_codec2 \
-                          libstagefright_foundation \
-                          libstagefright_codec2_vndk \
-                          libui \
-                          libutils \
-                          libv4l2_codec2 \
-                          libv4l2_codec2_vda \
-                          android.hardware.media.bufferpool@1.0 \
-
-# -Wno-unused-parameter is needed for libchrome/base codes
-LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter
-LOCAL_CLANG := true
-
-include $(BUILD_EXECUTABLE)
diff --git a/tests/Android.bp b/tests/Android.bp
new file mode 100644
index 0000000..6c80002
--- /dev/null
+++ b/tests/Android.bp
@@ -0,0 +1,65 @@
+cc_test {
+    name: "C2VDACompIntf_test",
+
+    srcs: ["C2VDACompIntf_test.cpp"],
+
+    shared_libs: [
+        "libchrome",
+        "libcutils",
+        "liblog",
+        "libstagefright_codec2",
+        "libstagefright_codec2_vndk",
+        "libstagefright_simple_c2component",
+        "libutils",
+        "libv4l2_codec2",
+        "libv4l2_codec2_vda",
+    ],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+        "-std=c++14",
+    ],
+    clang: true,
+
+    ldflags: [
+        "-Wl",
+        "-Bsymbolic",
+    ],
+}
+
+cc_test {
+    name: "C2VDAComponent_test",
+    srcs: ["C2VDAComponent_test.cpp"],
+
+    shared_libs: [
+        "android.hardware.media.bufferpool@1.0",
+        "libchrome",
+        "libcutils",
+        "liblog",
+        "libmedia",
+        "libmediaextractor",
+        "libstagefright",
+        "libstagefright_codec2",
+        "libstagefright_codec2_vndk",
+        "libstagefright_foundation",
+        "libstagefright_simple_c2component",
+        "libutils",
+        "libv4l2_codec2",
+        "libv4l2_codec2_vda",
+    ],
+
+    // -Wno-unused-parameter is needed for libchrome/base codes
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+        "-std=c++14",
+    ],
+    clang: true,
+
+    ldflags: [
+        "-Wl",
+        "-Bsymbolic",
+    ],
+}
diff --git a/tests/Android.mk b/tests/Android.mk
deleted file mode 100644
index 4bafb4a..0000000
--- a/tests/Android.mk
+++ /dev/null
@@ -1,78 +0,0 @@
-# Build the unit tests.
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_MODULE := C2VDACompIntf_test
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := \
-  C2VDACompIntf_test.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-  libchrome \
-  libcutils \
-  liblog \
-  libstagefright_codec2 \
-  libstagefright_codec2_vndk \
-  libutils \
-  libv4l2_codec2 \
-  libv4l2_codec2_vda \
-
-LOCAL_C_INCLUDES += \
-  $(TOP)/external/v4l2_codec2/include \
-  $(TOP)/external/v4l2_codec2/vda \
-  $(TOP)/hardware/google/av/codec2/include \
-  $(TOP)/hardware/google/av/codec2/vndk/include \
-  $(TOP)/hardware/google/av/media/codecs/base/include \
-
-LOCAL_CFLAGS += -Werror -Wall -std=c++14
-LOCAL_CLANG := true
-
-LOCAL_LDFLAGS := -Wl,-Bsymbolic
-
-include $(BUILD_NATIVE_TEST)
-
-
-include $(CLEAR_VARS)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_MODULE := C2VDAComponent_test
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := \
-  C2VDAComponent_test.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-  libchrome \
-  libcutils \
-  liblog \
-  libmedia \
-  libmediaextractor \
-  libstagefright \
-  libstagefright_codec2 \
-  libstagefright_codec2_vndk \
-  libstagefright_foundation \
-  libutils \
-  libv4l2_codec2 \
-  libv4l2_codec2_vda \
-  android.hardware.media.bufferpool@1.0 \
-
-LOCAL_C_INCLUDES += \
-  $(TOP)/external/libchrome \
-  $(TOP)/external/v4l2_codec2/include \
-  $(TOP)/external/v4l2_codec2/vda \
-  $(TOP)/frameworks/av/media/libstagefright/include \
-  $(TOP)/hardware/google/av/codec2/include \
-  $(TOP)/hardware/google/av/codec2/vndk/include \
-  $(TOP)/hardware/google/av/media/codecs/base/include \
-
-# -Wno-unused-parameter is needed for libchrome/base codes
-LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -std=c++14
-LOCAL_CLANG := true
-
-LOCAL_LDFLAGS := -Wl,-Bsymbolic
-
-include $(BUILD_NATIVE_TEST)
diff --git a/vda/Android.bp b/vda/Android.bp
new file mode 100644
index 0000000..5f84535
--- /dev/null
+++ b/vda/Android.bp
@@ -0,0 +1,53 @@
+cc_library_shared {
+    name: "libv4l2_codec2_vda",
+    srcs: [
+        "bit_reader.cc",
+        "bit_reader_core.cc",
+        "bitstream_buffer.cc",
+        "h264_bit_reader.cc",
+        "h264_decoder.cc",
+        "h264_dpb.cc",
+        "h264_parser.cc",
+        "native_pixmap_handle.cc",
+        "picture.cc",
+        "ranges.cc",
+        "shared_memory_region.cc",
+        "v4l2_device.cc",
+        "v4l2_slice_video_decode_accelerator.cc",
+        "v4l2_video_decode_accelerator.cc",
+        "video_codecs.cc",
+        "video_decode_accelerator.cc",
+        "vp8_bool_decoder.cc",
+        "vp8_decoder.cc",
+        "vp8_parser.cc",
+        "vp8_picture.cc",
+        "vp9_bool_decoder.cc",
+        "vp9_compressed_header_parser.cc",
+        "vp9_decoder.cc",
+        "vp9_parser.cc",
+        "vp9_picture.cc",
+        "vp9_raw_bits_reader.cc",
+        "vp9_uncompressed_header_parser.cc",
+    ],
+
+    shared_libs: ["libchrome"],
+    // -Wno-unused-parameter is needed for libchrome/base codes
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+    ],
+    clang: true,
+    sanitize: {
+        misc_undefined: [
+            "unsigned-integer-overflow",
+            "signed-integer-overflow",
+        ],
+    },
+
+    ldflags: [
+        "-Wl",
+        "-Bsymbolic",
+    ],
+    export_include_dirs: ["."],
+}
diff --git a/vda/Android.mk b/vda/Android.mk
deleted file mode 100644
index 12f0ea1..0000000
--- a/vda/Android.mk
+++ /dev/null
@@ -1,50 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_CPP_EXTENSION:= .cc
-LOCAL_SRC_FILES:= \
-        bit_reader.cc       \
-        bit_reader_core.cc  \
-        bitstream_buffer.cc \
-        h264_bit_reader.cc  \
-        h264_decoder.cc     \
-        h264_dpb.cc         \
-        h264_parser.cc      \
-        native_pixmap_handle.cc \
-        picture.cc          \
-        ranges.cc           \
-        shared_memory_region.cc \
-        v4l2_device.cc      \
-        v4l2_slice_video_decode_accelerator.cc \
-        v4l2_video_decode_accelerator.cc \
-        video_codecs.cc     \
-        video_decode_accelerator.cc \
-        vp8_bool_decoder.cc \
-        vp8_decoder.cc      \
-        vp8_parser.cc       \
-        vp8_picture.cc      \
-        vp9_bool_decoder.cc \
-        vp9_compressed_header_parser.cc \
-        vp9_decoder.cc      \
-        vp9_parser.cc       \
-        vp9_picture.cc      \
-        vp9_raw_bits_reader.cc \
-        vp9_uncompressed_header_parser.cc \
-
-# gtest/include is for included file from libchrome/base/gtest_prod_util.h
-LOCAL_C_INCLUDES += \
-        $(TOP)/external/libchrome \
-        $(TOP)/external/gtest/include \
-
-LOCAL_MODULE:= libv4l2_codec2_vda
-
-LOCAL_SHARED_LIBRARIES := libchrome \
-
-# -Wno-unused-parameter is needed for libchrome/base codes
-LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter
-LOCAL_CLANG := true
-LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow
-
-LOCAL_LDFLAGS := -Wl,-Bsymbolic
-
-include $(BUILD_SHARED_LIBRARY)
-- 
GitLab