[libcamera-devel] android: mm: Stub libhardware for build tests
diff mbox series

Message ID 20230530144719.2711-1-laurent.pinchart@ideasonboard.com
State Accepted
Commit b9ecd85ed1fee2e9d715368b24592ad3009131d8
Headers show
Series
  • [libcamera-devel] android: mm: Stub libhardware for build tests
Related show

Commit Message

Laurent Pinchart May 30, 2023, 2:47 p.m. UTC
Commit 66c618f378aa ("android: mm: generic: use
GRALLOC_HARDWARE_MODULE_ID") made libhardware a required dependency for
the Android camera HAL on non-Chrome OS platforms. This isn't an issue
for real devices, as Android provides libhardware, but it prevents
compile-testing the camera HAL on traditional Linux systems.

To restore the compile-test coverage, stub the libhardware function used
by the camera HAL when libhardware isn't found.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/android/mm/libhardware_stub.c | 17 +++++++++++++++++
 src/android/mm/meson.build        | 12 ++++++++----
 2 files changed, 25 insertions(+), 4 deletions(-)
 create mode 100644 src/android/mm/libhardware_stub.c


base-commit: 76e1cb9f7176b4e7a935295d4e633ee24a0fef67
prerequisite-patch-id: 2e7126df41498860ace9c0cd6b1e2ed748bac2f9

Comments

Mattijs Korpershoek May 30, 2023, 3:21 p.m. UTC | #1
Hi Laurent,

Thank you for this patch. I was about to look into this. You are making
my life easier :)


On mar., mai 30, 2023 at 17:47, Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote:

> Commit 66c618f378aa ("android: mm: generic: use
> GRALLOC_HARDWARE_MODULE_ID") made libhardware a required dependency for
> the Android camera HAL on non-Chrome OS platforms. This isn't an issue
> for real devices, as Android provides libhardware, but it prevents
> compile-testing the camera HAL on traditional Linux systems.
>
> To restore the compile-test coverage, stub the libhardware function used
> by the camera HAL when libhardware isn't found.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> # meson build test

> ---
>  src/android/mm/libhardware_stub.c | 17 +++++++++++++++++
>  src/android/mm/meson.build        | 12 ++++++++----
>  2 files changed, 25 insertions(+), 4 deletions(-)
>  create mode 100644 src/android/mm/libhardware_stub.c
>
> diff --git a/src/android/mm/libhardware_stub.c b/src/android/mm/libhardware_stub.c
> new file mode 100644
> index 000000000000..00f15cd90cac
> --- /dev/null
> +++ b/src/android/mm/libhardware_stub.c
> @@ -0,0 +1,17 @@
> +/* SPDX-License-Identifier: Apache-2.0 */
> +/*
> + * Copyright (C) 2023, Ideas on Board
> + *
> + * libhardware_stub.c - Android libhardware stub for test compilation
> + */
> +
> +#include <errno.h>
> +
> +#include <hardware/hardware.h>
> +
> +int hw_get_module(const char *id __attribute__((__unused__)),
> +		  const struct hw_module_t **module)
> +{
> +	*module = NULL;
> +	return -ENOTSUP;
> +}
> diff --git a/src/android/mm/meson.build b/src/android/mm/meson.build
> index 85f12f910198..e3e0484c3720 100644
> --- a/src/android/mm/meson.build
> +++ b/src/android/mm/meson.build
> @@ -4,10 +4,14 @@ platform = get_option('android_platform')
>  if platform == 'generic'
>      android_hal_sources += files(['generic_camera_buffer.cpp',
>                                    'generic_frame_buffer_allocator.cpp'])
> -    android_deps += [
> -        libdl,
> -        dependency('libhardware'),
> -    ]
> +    android_deps += [libdl]
> +
> +    libhardware = dependency('libhardware', required : false)
> +    if libhardware.found()
> +        android_deps += [libhardware]
> +    else
> +        android_hal_sources += files(['libhardware_stub.c'])
> +    endif
>  elif platform == 'cros'
>      android_hal_sources += files(['cros_camera_buffer.cpp',
>                                    'cros_frame_buffer_allocator.cpp'])
>
> base-commit: 76e1cb9f7176b4e7a935295d4e633ee24a0fef67
> prerequisite-patch-id: 2e7126df41498860ace9c0cd6b1e2ed748bac2f9
> -- 
> Regards,
>
> Laurent Pinchart
Kieran Bingham May 30, 2023, 3:22 p.m. UTC | #2
Quoting Laurent Pinchart (2023-05-30 15:47:19)
> Commit 66c618f378aa ("android: mm: generic: use
> GRALLOC_HARDWARE_MODULE_ID") made libhardware a required dependency for
> the Android camera HAL on non-Chrome OS platforms. This isn't an issue
> for real devices, as Android provides libhardware, but it prevents
> compile-testing the camera HAL on traditional Linux systems.
> 
> To restore the compile-test coverage, stub the libhardware function used
> by the camera HAL when libhardware isn't found.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  src/android/mm/libhardware_stub.c | 17 +++++++++++++++++
>  src/android/mm/meson.build        | 12 ++++++++----
>  2 files changed, 25 insertions(+), 4 deletions(-)
>  create mode 100644 src/android/mm/libhardware_stub.c
> 
> diff --git a/src/android/mm/libhardware_stub.c b/src/android/mm/libhardware_stub.c
> new file mode 100644
> index 000000000000..00f15cd90cac
> --- /dev/null
> +++ b/src/android/mm/libhardware_stub.c
> @@ -0,0 +1,17 @@
> +/* SPDX-License-Identifier: Apache-2.0 */
> +/*
> + * Copyright (C) 2023, Ideas on Board
> + *
> + * libhardware_stub.c - Android libhardware stub for test compilation
> + */
> +
> +#include <errno.h>
> +
> +#include <hardware/hardware.h>
> +
> +int hw_get_module(const char *id __attribute__((__unused__)),
> +                 const struct hw_module_t **module)
> +{
> +       *module = NULL;
> +       return -ENOTSUP;
> +}
> diff --git a/src/android/mm/meson.build b/src/android/mm/meson.build
> index 85f12f910198..e3e0484c3720 100644
> --- a/src/android/mm/meson.build
> +++ b/src/android/mm/meson.build
> @@ -4,10 +4,14 @@ platform = get_option('android_platform')
>  if platform == 'generic'
>      android_hal_sources += files(['generic_camera_buffer.cpp',
>                                    'generic_frame_buffer_allocator.cpp'])
> -    android_deps += [
> -        libdl,
> -        dependency('libhardware'),
> -    ]
> +    android_deps += [libdl]
> +
> +    libhardware = dependency('libhardware', required : false)
> +    if libhardware.found()
> +        android_deps += [libhardware]
> +    else
> +        android_hal_sources += files(['libhardware_stub.c'])
> +    endif

LGTM,


Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

>  elif platform == 'cros'
>      android_hal_sources += files(['cros_camera_buffer.cpp',
>                                    'cros_frame_buffer_allocator.cpp'])
> 
> base-commit: 76e1cb9f7176b4e7a935295d4e633ee24a0fef67
> prerequisite-patch-id: 2e7126df41498860ace9c0cd6b1e2ed748bac2f9
> -- 
> Regards,
> 
> Laurent Pinchart
>

Patch
diff mbox series

diff --git a/src/android/mm/libhardware_stub.c b/src/android/mm/libhardware_stub.c
new file mode 100644
index 000000000000..00f15cd90cac
--- /dev/null
+++ b/src/android/mm/libhardware_stub.c
@@ -0,0 +1,17 @@ 
+/* SPDX-License-Identifier: Apache-2.0 */
+/*
+ * Copyright (C) 2023, Ideas on Board
+ *
+ * libhardware_stub.c - Android libhardware stub for test compilation
+ */
+
+#include <errno.h>
+
+#include <hardware/hardware.h>
+
+int hw_get_module(const char *id __attribute__((__unused__)),
+		  const struct hw_module_t **module)
+{
+	*module = NULL;
+	return -ENOTSUP;
+}
diff --git a/src/android/mm/meson.build b/src/android/mm/meson.build
index 85f12f910198..e3e0484c3720 100644
--- a/src/android/mm/meson.build
+++ b/src/android/mm/meson.build
@@ -4,10 +4,14 @@  platform = get_option('android_platform')
 if platform == 'generic'
     android_hal_sources += files(['generic_camera_buffer.cpp',
                                   'generic_frame_buffer_allocator.cpp'])
-    android_deps += [
-        libdl,
-        dependency('libhardware'),
-    ]
+    android_deps += [libdl]
+
+    libhardware = dependency('libhardware', required : false)
+    if libhardware.found()
+        android_deps += [libhardware]
+    else
+        android_hal_sources += files(['libhardware_stub.c'])
+    endif
 elif platform == 'cros'
     android_hal_sources += files(['cros_camera_buffer.cpp',
                                   'cros_frame_buffer_allocator.cpp'])