{"id":1615,"url":"https://patchwork.libcamera.org/api/1.1/patches/1615/?format=json","web_url":"https://patchwork.libcamera.org/patch/1615/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190704145942.17879-3-kieran.bingham@ideasonboard.com>","date":"2019-07-04T14:59:38","name":"[libcamera-devel,v4,2/6] libcamera: Auto generate version information","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"807b65914a5541577bea3f1eea1d87cdc708948b","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/1.1/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1615/mbox/","series":[{"id":405,"url":"https://patchwork.libcamera.org/api/1.1/series/405/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=405","date":"2019-07-04T14:59:36","name":"Automatic Version Generation ++","version":4,"mbox":"https://patchwork.libcamera.org/series/405/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1615/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1615/checks/","tags":{},"headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B44B761570\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Jul 2019 16:59:46 +0200 (CEST)","from localhost.localdomain\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5EF57E21;\n\tThu,  4 Jul 2019 16:59:46 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562252386;\n\tbh=VGqz/AzG41DuC2n0LebX3Xhl3EN3sVPDX8EOHeVAVdI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=otxkXsHNvTmEZ/9jLqPp/smnYOuBal2PCCEtFFU47acAkVVXGUJOWhGz4dQ6lgGnM\n\tyHEX2S92CS81tXkdW4sqlvR1Nu846aPQ93iqqQSWlRIFUDEaa0Z901qKBx8sMlGiKP\n\taHwO9RBM/B5/xCb6vhpR3w9HLiGVLl0iAh09SVoo=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Date":"Thu,  4 Jul 2019 15:59:38 +0100","Message-Id":"<20190704145942.17879-3-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190704145942.17879-1-kieran.bingham@ideasonboard.com>","References":"<20190704145942.17879-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 2/6] libcamera: Auto generate version\n\tinformation","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Thu, 04 Jul 2019 14:59:46 -0000"},"content":"Generate a version string, and provide a global singleton object which\nallows applications to interrogate the current libcamera version\ninformation.\n\nThe version header is automatically updated by meson on each build.\nThe string roughly follows the semver [0] conventions of\nmajor.minor.patch-label as a value.\n\n[0] https://semver.org/\n\nA script (utils/gen-version.sh) is provided which is modelled upon the\nprocessing from autoconf's git-version-gen. The gen-version.sh script\nwill look for tags in the form vX.Y as starting points for the version\nstring. While the repository does not have any matching tags, v0.0 will\nbe assumed, resulting in versions with both major and minor being set to\n'0', and the patch count resulting from the number of patches in the\nhistory to that point.\n\nFinally, a uniquely identifying shortened hash is provided from git:\n\n\tv0.0.509+0ec0edf7\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\nv2:\n  - Store VCS_Tag return reference for dependancy linking\n  - Fix indentation on meson.build\n  - fix shell usage and shellcheck warnings in version-gen\n  - Make LibcameraVersion version global\n  - Sphinx version now explicit as to it's source from\n    Documentation/meson.build\n  - Pass project_version() through api_version\n  - Use Camera object to report version rather than global constructor.\n\nv3:\n - Add dependency to the vcs tag to ensure libcamera builds the header\n - Fix up commit title\n - Rename version-gen to gen-version.sh\n - Append git sha and any -dirty flag with a '+' separator\n - Move version generation to single libcamera/version.h file.\n - Remove version.cpp and store the const std::string version in\n   camera_manager.cpp\n\nv4:\n - Fix commit message\n - Use path_join() to reference gen-version.sh\n - change Docuementation/conf.py comment\n - trivial fixups.\n---\n Documentation/conf.py            |  7 ++----\n Documentation/meson.build        |  7 ++++--\n include/libcamera/meson.build    |  7 ++++++\n include/libcamera/version.h.in   | 22 +++++++++++++++++++\n meson.build                      |  9 +++-----\n src/libcamera/camera_manager.cpp |  8 +++++++\n src/libcamera/meson.build        |  1 +\n utils/gen-version.sh             | 37 ++++++++++++++++++++++++++++++++\n 8 files changed, 85 insertions(+), 13 deletions(-)\n create mode 100644 include/libcamera/version.h.in\n create mode 100755 utils/gen-version.sh","diff":"diff --git a/Documentation/conf.py b/Documentation/conf.py\nindex 970edf3d7298..bffd1d8f1e5d 100644\n--- a/Documentation/conf.py\n+++ b/Documentation/conf.py\n@@ -23,11 +23,8 @@ project = 'libcamera'\n copyright = '2018-2019, The libcamera documentation authors'\n author = u'Kieran Bingham, Jacopo Mondi, Laurent Pinchart, Niklas Söderlund'\n \n-# The short X.Y version\n-version = ''\n-# The full version, including alpha/beta/rc tags\n-release = '0.1'\n-\n+# Version information is provided by the build environment, through the\n+# sphinx command line.\n \n # -- General configuration ---------------------------------------------------\n \ndiff --git a/Documentation/meson.build b/Documentation/meson.build\nindex 629e853120cb..2db80b39989b 100644\n--- a/Documentation/meson.build\n+++ b/Documentation/meson.build\n@@ -1,4 +1,4 @@\n-doc_install_dir = join_paths(get_option('datadir'), 'doc', 'libcamera-@0@'.format(api_version))\n+doc_install_dir = join_paths(get_option('datadir'), 'doc', 'libcamera-@0@'.format(meson.project_version()))\n \n #\n # Doxygen\n@@ -47,8 +47,11 @@ if sphinx.found()\n         'index.rst',\n     ]\n \n+    release = 'release=' + meson.project_version()\n+\n     custom_target('documentation',\n-                  command : [sphinx, '-q', '-W', '-b', 'html', meson.current_source_dir(), '@OUTPUT@'],\n+                  command : [sphinx, '-D', release, '-q', '-W', '-b', 'html',\n+                             meson.current_source_dir(), '@OUTPUT@'],\n                   input : docs_sources,\n                   output : 'html',\n                   build_by_default : true,\ndiff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 3067120a1598..6f81f1117318 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -16,6 +16,13 @@ libcamera_api = files([\n     'timer.h',\n ])\n \n+gen_version = join_paths(meson.source_root(), 'utils', 'gen-version.sh')\n+\n+version_h = vcs_tag(command : [gen_version, meson.current_source_dir()],\n+                    input : 'version.h.in',\n+                    output : 'version.h',\n+                    fallback : 'v0.0')\n+\n gen_header = files('gen-header.sh')\n \n libcamera_h = custom_target('gen-header',\ndiff --git a/include/libcamera/version.h.in b/include/libcamera/version.h.in\nnew file mode 100644\nindex 000000000000..e49b36962aed\n--- /dev/null\n+++ b/include/libcamera/version.h.in\n@@ -0,0 +1,22 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * version.h - Library version information\n+ *\n+ * This file is auto-generated. Do not edit.\n+ */\n+#ifndef __LIBCAMERA_VERSION_H__\n+#define __LIBCAMERA_VERSION_H__\n+\n+#include <string>\n+\n+#define LIBCAMERA_VERSION \"@VCS_TAG@\"\n+\n+namespace libcamera {\n+\n+extern const std::string version;\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_VERSION_H__ */\ndiff --git a/meson.build b/meson.build\nindex a3b0bc820072..342b3cc76a93 100644\n--- a/meson.build\n+++ b/meson.build\n@@ -1,6 +1,8 @@\n project('libcamera', 'c', 'cpp',\n     meson_version : '>= 0.40',\n-    version : '0.1',\n+    version : run_command('utils/gen-version.sh',\n+                          '@0@'.format(meson.source_root()),\n+                          check : true).stdout().strip(),\n     default_options : [\n         'werror=true',\n         'warning_level=2',\n@@ -8,11 +10,6 @@ project('libcamera', 'c', 'cpp',\n     ],\n     license : 'LGPL 2.1+')\n \n-# TODO: Extract this from project.version.\n-#       Ideally the version at Documentation/conf.py should be\n-#       generated from this too.\n-api_version = '0.1'\n-\n cc = meson.get_compiler('c')\n config_h = configuration_data()\n \ndiff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\nindex cf881ce2e641..2df24d44e284 100644\n--- a/src/libcamera/camera_manager.cpp\n+++ b/src/libcamera/camera_manager.cpp\n@@ -9,6 +9,7 @@\n \n #include <libcamera/camera.h>\n #include <libcamera/event_dispatcher.h>\n+#include <libcamera/version.h>\n \n #include \"device_enumerator.h\"\n #include \"event_dispatcher_poll.h\"\n@@ -64,6 +65,11 @@ CameraManager::~CameraManager()\n {\n }\n \n+/**\n+ * \\brief Declare the library global version string\n+ */\n+const std::string version(LIBCAMERA_VERSION);\n+\n /**\n  * \\brief Start the camera manager\n  *\n@@ -79,6 +85,8 @@ int CameraManager::start()\n \tif (enumerator_)\n \t\treturn -EBUSY;\n \n+\tLOG(Camera, Info) << \"libcamera \" << version;\n+\n \tenumerator_ = DeviceEnumerator::create();\n \tif (!enumerator_ || enumerator_->enumerate())\n \t\treturn -ENODEV;\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 8075b1f696f5..336f4f066fac 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -80,6 +80,7 @@ control_types_cpp = custom_target('control_types_cpp',\n libcamera_sources += control_types_cpp\n \n libcamera_deps = [\n+    declare_dependency(sources : version_h),\n     cc.find_library('dl'),\n     libudev,\n ]\ndiff --git a/utils/gen-version.sh b/utils/gen-version.sh\nnew file mode 100755\nindex 000000000000..b3003d7a80d3\n--- /dev/null\n+++ b/utils/gen-version.sh\n@@ -0,0 +1,37 @@\n+#!/bin/sh\n+\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+# Generate a version string using git describe\n+\n+if [ -n \"$1\" ]\n+then\n+\tcd \"$1\" 2>/dev/null || exit 1\n+fi\n+\n+# Get a short description from the tree.\n+version=$(git describe --abbrev=8 --match \"v[0-9]*\" 2>/dev/null)\n+\n+if [ -z \"$version\" ]\n+then\n+\t# Handle an un-tagged repository\n+\tsha=$(git describe --abbrev=8 --always 2>/dev/null)\n+\tcommits=$(git log --oneline | wc -l 2>/dev/null)\n+\tversion=v0.0.$commits.$sha\n+fi\n+\n+# Prevent changed timestamps causing -dirty labels\n+git update-index --refresh > /dev/null 2>&1\n+dirty=$(git diff-index --name-only HEAD 2>/dev/null) || dirty=\n+\n+# Strip the 'g', and replace the preceeding '-' with a '+' to denote a label\n+version=$(echo \"$version\" | sed -e 's/-g/+/g')\n+\n+# Fix the '-' (the patch count) to a '.' as a version increment.\n+version=$(echo \"$version\" | sed -e 's/-/./g')\n+\n+if [ -n \"$dirty\" ]\n+then\n+\tversion=$version-dirty\n+fi\n+\n+echo \"$version\"\n","prefixes":["libcamera-devel","v4","2/6"]}