[libcamera-devel] [PATCH] libcamera: Rework automatic version generation to avoid rebuilds
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Fri Jul 5 10:29:16 CEST 2019
Commit b817bcec6b53 ("libcamera: Auto generate version information")
generates version information in order to automatically include it
various locations (Sphinx and Doxygen documentation, libcamera::version
variable available at runtime, and version.h available at compile time).
Unfortunately this causes lots of unnecessary rebuilds when modifying
the git tree state, which hinders development.
The problem is caused by the generated version.h being listed as a
dependency for the whole libcamera. This is required as meson (to the
best of my knowledge) doesn't provide a way to explicitly specify the
dependency of a single object file (camera_manager.o in this case, as
camera_manager.cpp is the only consumer of the generated version string)
on the custom target used to generate version.h. The dependency can't be
automatically detected at build time, like dependencies on normal
headers that are generated by parsing the source, because the version.h
header may not exist yet. The build could then fail in a racy way.
This change attempts at solving the issue by generating a version.cpp
instead of a version.h. This minimises the number of files that need to
be rebuild when then git tree state changes, while retaining the main
purpose of the original automatic version generation, the ability to
access the git-based version string at runtime.
The Sphinx and Doxygen documentation however lose git-based version
information, to prevent a full documentation rebuild for every commit.
We may want to investigate how to preserve detailed version information
there, as well as how to make it available in a header file for
applications. For the time being, this commit should be a good
compromise to avoid unnecessary recompilation, and additional features
can be built on top of it after taking the time to consider and test
them carefully.
Fixes: b817bcec6b53 ("libcamera: Auto generate version information")
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
Documentation/Doxyfile.in | 4 ++-
include/libcamera/meson.build | 8 +-----
include/libcamera/{version.h.in => version.h} | 4 ---
meson.build | 4 +--
src/libcamera/camera_manager.cpp | 5 ----
{utils => src/libcamera}/gen-version.sh | 0
src/libcamera/meson.build | 8 +++++-
src/libcamera/version.cpp.in | 25 +++++++++++++++++++
8 files changed, 37 insertions(+), 21 deletions(-)
rename include/libcamera/{version.h.in => version.h} (79%)
rename {utils => src/libcamera}/gen-version.sh (100%)
create mode 100644 src/libcamera/version.cpp.in
diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in
index cad85ff979f8..ed111909b603 100644
--- a/Documentation/Doxyfile.in
+++ b/Documentation/Doxyfile.in
@@ -791,7 +791,9 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.
-INPUT = "@TOP_SRCDIR@/include/libcamera" "@TOP_SRCDIR@/src/libcamera"
+INPUT = "@TOP_SRCDIR@/include/libcamera" \
+ "@TOP_SRCDIR@/src/libcamera" \
+ "@TOP_BUILDDIR@/src/libcamera"
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
index 6f81f1117318..bafa103d141b 100644
--- a/include/libcamera/meson.build
+++ b/include/libcamera/meson.build
@@ -14,15 +14,9 @@ libcamera_api = files([
'signal.h',
'stream.h',
'timer.h',
+ 'version.h',
])
-gen_version = join_paths(meson.source_root(), 'utils', 'gen-version.sh')
-
-version_h = vcs_tag(command : [gen_version, meson.current_source_dir()],
- input : 'version.h.in',
- output : 'version.h',
- fallback : 'v0.0')
-
gen_header = files('gen-header.sh')
libcamera_h = custom_target('gen-header',
diff --git a/include/libcamera/version.h.in b/include/libcamera/version.h
similarity index 79%
rename from include/libcamera/version.h.in
rename to include/libcamera/version.h
index e49b36962aed..75d57d48af0d 100644
--- a/include/libcamera/version.h.in
+++ b/include/libcamera/version.h
@@ -3,16 +3,12 @@
* Copyright (C) 2019, Google Inc.
*
* version.h - Library version information
- *
- * This file is auto-generated. Do not edit.
*/
#ifndef __LIBCAMERA_VERSION_H__
#define __LIBCAMERA_VERSION_H__
#include <string>
-#define LIBCAMERA_VERSION "@VCS_TAG@"
-
namespace libcamera {
extern const std::string version;
diff --git a/meson.build b/meson.build
index 342b3cc76a93..271b538bdae8 100644
--- a/meson.build
+++ b/meson.build
@@ -1,8 +1,6 @@
project('libcamera', 'c', 'cpp',
meson_version : '>= 0.40',
- version : run_command('utils/gen-version.sh',
- '@0@'.format(meson.source_root()),
- check : true).stdout().strip(),
+ version : 'v0.0',
default_options : [
'werror=true',
'warning_level=2',
diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
index c5da46b4062d..69503c6e8726 100644
--- a/src/libcamera/camera_manager.cpp
+++ b/src/libcamera/camera_manager.cpp
@@ -26,11 +26,6 @@ namespace libcamera {
LOG_DEFINE_CATEGORY(Camera)
-/**
- * \brief The library global version string
- */
-const std::string version(LIBCAMERA_VERSION);
-
/**
* \class CameraManager
* \brief Provide access and manage all cameras in the system
diff --git a/utils/gen-version.sh b/src/libcamera/gen-version.sh
similarity index 100%
rename from utils/gen-version.sh
rename to src/libcamera/gen-version.sh
diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
index 336f4f066fac..c35ecb988d72 100644
--- a/src/libcamera/meson.build
+++ b/src/libcamera/meson.build
@@ -79,8 +79,14 @@ control_types_cpp = custom_target('control_types_cpp',
libcamera_sources += control_types_cpp
+version_cpp = vcs_tag(command : ['gen-version.sh', meson.source_root()],
+ input : 'version.cpp.in',
+ output : 'version.cpp',
+ fallback : meson.project_version())
+
+libcamera_sources += version_cpp
+
libcamera_deps = [
- declare_dependency(sources : version_h),
cc.find_library('dl'),
libudev,
]
diff --git a/src/libcamera/version.cpp.in b/src/libcamera/version.cpp.in
new file mode 100644
index 000000000000..055dc0b5c5ad
--- /dev/null
+++ b/src/libcamera/version.cpp.in
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * version.cpp - libcamera version
+ *
+ * This file is auto-generated. Do not edit.
+ */
+
+#include <libcamera/version.h>
+
+/**
+ * \file version.h
+ * \brief libcamera version
+ */
+
+namespace libcamera {
+
+/**
+ * \var libcamera::version
+ * \brief The library global version string
+ */
+const std::string version("@VCS_TAG@");
+
+} /* namespace libcamera */
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list