[libcamera-devel,v3,3/3] libcamera: Auto-generate libcamera.h

Message ID 20190522212253.3307-3-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • [libcamera-devel,v3,1/3] meson: Fix coding style in meson.build files
Related show

Commit Message

Laurent Pinchart May 22, 2019, 9:22 p.m. UTC
As shown by two missing includes, keeping the libcamera.h file in sync
when adding or removing headers is an error-prone manual process.
Automate it by generating the header automatically.

The libcamera.h header is also added to the libcamera dependency
libcamera_dep to ensure that the headers gets generated before any
source depending on it gets compiled.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 include/libcamera/gen-header.sh | 27 +++++++++++++++++++++++++++
 include/libcamera/libcamera.h   | 20 --------------------
 include/libcamera/meson.build   | 10 +++++++++-
 src/libcamera/meson.build       |  2 +-
 4 files changed, 37 insertions(+), 22 deletions(-)
 create mode 100755 include/libcamera/gen-header.sh
 delete mode 100644 include/libcamera/libcamera.h

Comments

Kieran Bingham May 23, 2019, 10:11 a.m. UTC | #1
Hi Laurent,

On 22/05/2019 22:22, Laurent Pinchart wrote:
> As shown by two missing includes, keeping the libcamera.h file in sync
> when adding or removing headers is an error-prone manual process.
> Automate it by generating the header automatically.
> 

\o/ Still love this patch :-D

> The libcamera.h header is also added to the libcamera dependency
> libcamera_dep to ensure that the headers gets generated before any
> source depending on it gets compiled.
> 

A question below - but :

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

> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  include/libcamera/gen-header.sh | 27 +++++++++++++++++++++++++++
>  include/libcamera/libcamera.h   | 20 --------------------
>  include/libcamera/meson.build   | 10 +++++++++-
>  src/libcamera/meson.build       |  2 +-
>  4 files changed, 37 insertions(+), 22 deletions(-)
>  create mode 100755 include/libcamera/gen-header.sh
>  delete mode 100644 include/libcamera/libcamera.h
> 
> diff --git a/include/libcamera/gen-header.sh b/include/libcamera/gen-header.sh
> new file mode 100755
> index 000000000000..e171c08c20b8
> --- /dev/null
> +++ b/include/libcamera/gen-header.sh
> @@ -0,0 +1,27 @@
> +#!/bin/sh
> +
> +src_dir="$1"
> +dst_file="$2"
> +
> +cat <<EOF > "$dst_file"
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/* This file is auto-generated, do not edit! */
> +/*
> + * Copyright (C) 2018-2019, Google Inc.
> + *
> + * libcamera.h - libcamera public API
> + */
> +#ifndef __LIBCAMERA_LIBCAMERA_H__
> +#define __LIBCAMERA_LIBCAMERA_H__
> +
> +EOF
> +
> +for header in "$src_dir"/*.h ; do
> +	header=$(basename "$header")
> +	echo "#include <libcamera/$header>" >> "$dst_file"
> +done
> +
> +cat <<EOF >> "$dst_file"
> +
> +#endif /* __LIBCAMERA_LIBCAMERA_H__ */
> +EOF
> diff --git a/include/libcamera/libcamera.h b/include/libcamera/libcamera.h
> deleted file mode 100644
> index dda576e906fb..000000000000
> --- a/include/libcamera/libcamera.h
> +++ /dev/null
> @@ -1,20 +0,0 @@
> -/* SPDX-License-Identifier: LGPL-2.1-or-later */
> -/*
> - * Copyright (C) 2018, Google Inc.
> - *
> - * libcamera.h - libcamera public API
> - */
> -#ifndef __LIBCAMERA_LIBCAMERA_H__
> -#define __LIBCAMERA_LIBCAMERA_H__
> -
> -#include <libcamera/buffer.h>
> -#include <libcamera/camera.h>
> -#include <libcamera/camera_manager.h>
> -#include <libcamera/event_dispatcher.h>
> -#include <libcamera/event_notifier.h>
> -#include <libcamera/request.h>
> -#include <libcamera/signal.h>
> -#include <libcamera/stream.h>
> -#include <libcamera/timer.h>
> -
> -#endif /* __LIBCAMERA_LIBCAMERA_H__ */
> diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
> index cb64f0ca0f8b..1fcf6b509a1e 100644
> --- a/include/libcamera/meson.build
> +++ b/include/libcamera/meson.build
> @@ -6,7 +6,6 @@ libcamera_api = files([
>      'event_notifier.h',
>      'geometry.h',
>      'ipa/ipa_module_info.h',
> -    'libcamera.h',
>      'object.h',
>      'request.h',
>      'signal.h',
> @@ -14,5 +13,14 @@ libcamera_api = files([
>      'timer.h',
>  ])
>  
> +gen_header = join_paths(meson.current_source_dir(), 'gen-header.sh')
> +
> +libcamera_h = custom_target('gen-header',
> +                            input : 'meson.build',
> +                            output : 'libcamera.h',
> +                            command : [gen_header, meson.current_source_dir(), '@OUTPUT@'],
> +                            install : true,
> +                            install_dir : 'include/libcamera')

I'm fine with it staying explicit, but doesn't this file already install
to include/libcamera because it is the current working directory and the
location that the generated file will be output ?

> +
>  install_headers(libcamera_api,
>                  subdir : 'libcamera')
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index 0ebb25bcb821..6a73580d71f5 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -66,6 +66,6 @@ libcamera = shared_library('camera',
>                             include_directories : includes,
>                             dependencies : libudev)
>  
> -libcamera_dep = declare_dependency(sources : libcamera_api,
> +libcamera_dep = declare_dependency(sources : [libcamera_api, libcamera_h],
>                                     include_directories : libcamera_includes,
>                                     link_with : libcamera)
>
Laurent Pinchart May 23, 2019, 10:42 a.m. UTC | #2
Hi Kieran,

On Thu, May 23, 2019 at 11:11:33AM +0100, Kieran Bingham wrote:
> On 22/05/2019 22:22, Laurent Pinchart wrote:
> > As shown by two missing includes, keeping the libcamera.h file in sync
> > when adding or removing headers is an error-prone manual process.
> > Automate it by generating the header automatically.
> > 
> 
> \o/ Still love this patch :-D
> 
> > The libcamera.h header is also added to the libcamera dependency
> > libcamera_dep to ensure that the headers gets generated before any
> > source depending on it gets compiled.
> 
> A question below - but :
> 
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  include/libcamera/gen-header.sh | 27 +++++++++++++++++++++++++++
> >  include/libcamera/libcamera.h   | 20 --------------------
> >  include/libcamera/meson.build   | 10 +++++++++-
> >  src/libcamera/meson.build       |  2 +-
> >  4 files changed, 37 insertions(+), 22 deletions(-)
> >  create mode 100755 include/libcamera/gen-header.sh
> >  delete mode 100644 include/libcamera/libcamera.h
> > 
> > diff --git a/include/libcamera/gen-header.sh b/include/libcamera/gen-header.sh
> > new file mode 100755
> > index 000000000000..e171c08c20b8
> > --- /dev/null
> > +++ b/include/libcamera/gen-header.sh
> > @@ -0,0 +1,27 @@
> > +#!/bin/sh
> > +
> > +src_dir="$1"
> > +dst_file="$2"
> > +
> > +cat <<EOF > "$dst_file"
> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> > +/* This file is auto-generated, do not edit! */
> > +/*
> > + * Copyright (C) 2018-2019, Google Inc.
> > + *
> > + * libcamera.h - libcamera public API
> > + */
> > +#ifndef __LIBCAMERA_LIBCAMERA_H__
> > +#define __LIBCAMERA_LIBCAMERA_H__
> > +
> > +EOF
> > +
> > +for header in "$src_dir"/*.h ; do
> > +	header=$(basename "$header")
> > +	echo "#include <libcamera/$header>" >> "$dst_file"
> > +done
> > +
> > +cat <<EOF >> "$dst_file"
> > +
> > +#endif /* __LIBCAMERA_LIBCAMERA_H__ */
> > +EOF
> > diff --git a/include/libcamera/libcamera.h b/include/libcamera/libcamera.h
> > deleted file mode 100644
> > index dda576e906fb..000000000000
> > --- a/include/libcamera/libcamera.h
> > +++ /dev/null
> > @@ -1,20 +0,0 @@
> > -/* SPDX-License-Identifier: LGPL-2.1-or-later */
> > -/*
> > - * Copyright (C) 2018, Google Inc.
> > - *
> > - * libcamera.h - libcamera public API
> > - */
> > -#ifndef __LIBCAMERA_LIBCAMERA_H__
> > -#define __LIBCAMERA_LIBCAMERA_H__
> > -
> > -#include <libcamera/buffer.h>
> > -#include <libcamera/camera.h>
> > -#include <libcamera/camera_manager.h>
> > -#include <libcamera/event_dispatcher.h>
> > -#include <libcamera/event_notifier.h>
> > -#include <libcamera/request.h>
> > -#include <libcamera/signal.h>
> > -#include <libcamera/stream.h>
> > -#include <libcamera/timer.h>
> > -
> > -#endif /* __LIBCAMERA_LIBCAMERA_H__ */
> > diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
> > index cb64f0ca0f8b..1fcf6b509a1e 100644
> > --- a/include/libcamera/meson.build
> > +++ b/include/libcamera/meson.build
> > @@ -6,7 +6,6 @@ libcamera_api = files([
> >      'event_notifier.h',
> >      'geometry.h',
> >      'ipa/ipa_module_info.h',
> > -    'libcamera.h',
> >      'object.h',
> >      'request.h',
> >      'signal.h',
> > @@ -14,5 +13,14 @@ libcamera_api = files([
> >      'timer.h',
> >  ])
> >  
> > +gen_header = join_paths(meson.current_source_dir(), 'gen-header.sh')
> > +
> > +libcamera_h = custom_target('gen-header',
> > +                            input : 'meson.build',
> > +                            output : 'libcamera.h',
> > +                            command : [gen_header, meson.current_source_dir(), '@OUTPUT@'],
> > +                            install : true,
> > +                            install_dir : 'include/libcamera')
> 
> I'm fine with it staying explicit, but doesn't this file already install
> to include/libcamera because it is the current working directory and the
> location that the generated file will be output ?

include/libcamera/meson.build:18:0: ERROR:  "install_dir" must be specified when installing a target

So, no :-)

> > +
> >  install_headers(libcamera_api,
> >                  subdir : 'libcamera')
> > diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> > index 0ebb25bcb821..6a73580d71f5 100644
> > --- a/src/libcamera/meson.build
> > +++ b/src/libcamera/meson.build
> > @@ -66,6 +66,6 @@ libcamera = shared_library('camera',
> >                             include_directories : includes,
> >                             dependencies : libudev)
> >  
> > -libcamera_dep = declare_dependency(sources : libcamera_api,
> > +libcamera_dep = declare_dependency(sources : [libcamera_api, libcamera_h],
> >                                     include_directories : libcamera_includes,
> >                                     link_with : libcamera)
> >

Patch

diff --git a/include/libcamera/gen-header.sh b/include/libcamera/gen-header.sh
new file mode 100755
index 000000000000..e171c08c20b8
--- /dev/null
+++ b/include/libcamera/gen-header.sh
@@ -0,0 +1,27 @@ 
+#!/bin/sh
+
+src_dir="$1"
+dst_file="$2"
+
+cat <<EOF > "$dst_file"
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/* This file is auto-generated, do not edit! */
+/*
+ * Copyright (C) 2018-2019, Google Inc.
+ *
+ * libcamera.h - libcamera public API
+ */
+#ifndef __LIBCAMERA_LIBCAMERA_H__
+#define __LIBCAMERA_LIBCAMERA_H__
+
+EOF
+
+for header in "$src_dir"/*.h ; do
+	header=$(basename "$header")
+	echo "#include <libcamera/$header>" >> "$dst_file"
+done
+
+cat <<EOF >> "$dst_file"
+
+#endif /* __LIBCAMERA_LIBCAMERA_H__ */
+EOF
diff --git a/include/libcamera/libcamera.h b/include/libcamera/libcamera.h
deleted file mode 100644
index dda576e906fb..000000000000
--- a/include/libcamera/libcamera.h
+++ /dev/null
@@ -1,20 +0,0 @@ 
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-/*
- * Copyright (C) 2018, Google Inc.
- *
- * libcamera.h - libcamera public API
- */
-#ifndef __LIBCAMERA_LIBCAMERA_H__
-#define __LIBCAMERA_LIBCAMERA_H__
-
-#include <libcamera/buffer.h>
-#include <libcamera/camera.h>
-#include <libcamera/camera_manager.h>
-#include <libcamera/event_dispatcher.h>
-#include <libcamera/event_notifier.h>
-#include <libcamera/request.h>
-#include <libcamera/signal.h>
-#include <libcamera/stream.h>
-#include <libcamera/timer.h>
-
-#endif /* __LIBCAMERA_LIBCAMERA_H__ */
diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
index cb64f0ca0f8b..1fcf6b509a1e 100644
--- a/include/libcamera/meson.build
+++ b/include/libcamera/meson.build
@@ -6,7 +6,6 @@  libcamera_api = files([
     'event_notifier.h',
     'geometry.h',
     'ipa/ipa_module_info.h',
-    'libcamera.h',
     'object.h',
     'request.h',
     'signal.h',
@@ -14,5 +13,14 @@  libcamera_api = files([
     'timer.h',
 ])
 
+gen_header = join_paths(meson.current_source_dir(), 'gen-header.sh')
+
+libcamera_h = custom_target('gen-header',
+                            input : 'meson.build',
+                            output : 'libcamera.h',
+                            command : [gen_header, meson.current_source_dir(), '@OUTPUT@'],
+                            install : true,
+                            install_dir : 'include/libcamera')
+
 install_headers(libcamera_api,
                 subdir : 'libcamera')
diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
index 0ebb25bcb821..6a73580d71f5 100644
--- a/src/libcamera/meson.build
+++ b/src/libcamera/meson.build
@@ -66,6 +66,6 @@  libcamera = shared_library('camera',
                            include_directories : includes,
                            dependencies : libudev)
 
-libcamera_dep = declare_dependency(sources : libcamera_api,
+libcamera_dep = declare_dependency(sources : [libcamera_api, libcamera_h],
                                    include_directories : libcamera_includes,
                                    link_with : libcamera)