[{"id":2172,"web_url":"https://patchwork.libcamera.org/comment/2172/","msgid":"<20190704205834.GE5024@pendragon.ideasonboard.com>","date":"2019-07-04T20:58:34","subject":"Re: [libcamera-devel] [PATCH v4 2/6] libcamera: Auto generate\n\tversion information","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Thu, Jul 04, 2019 at 03:59:38PM +0100, Kieran Bingham wrote:\n> Generate a version string, and provide a global singleton object which\n> allows applications to interrogate the current libcamera version\n> information.\n> \n> The version header is automatically updated by meson on each build.\n> The string roughly follows the semver [0] conventions of\n> major.minor.patch-label as a value.\n> \n> [0] https://semver.org/\n> \n> A script (utils/gen-version.sh) is provided which is modelled upon the\n> processing from autoconf's git-version-gen. The gen-version.sh script\n> will look for tags in the form vX.Y as starting points for the version\n> string. While the repository does not have any matching tags, v0.0 will\n> be 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\n> history to that point.\n> \n> Finally, a uniquely identifying shortened hash is provided from git:\n> \n> \tv0.0.509+0ec0edf7\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> v2:\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> \n> v3:\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> \n> v4:\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\n> \n> diff --git a/Documentation/conf.py b/Documentation/conf.py\n> index 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>  \n> diff --git a/Documentation/meson.build b/Documentation/meson.build\n> index 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,\n> diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\n> index 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',\n> diff --git a/include/libcamera/version.h.in b/include/libcamera/version.h.in\n> new file mode 100644\n> index 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__ */\n> diff --git a/meson.build b/meson.build\n> index 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>  \n> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\n> index 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\ns/Declare the/The/\n\n> + */\n> +const std::string version(LIBCAMERA_VERSION);\n> +\n\nI would move this above the CameraManager class definition, not put it\nin the middle.\n\nWith these small issues addressed,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nThere are however multiple strategies to handle version information, and\nI think we should discuss them, but that's not a reason to delay this\nseries.\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;\n> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> index 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>  ]\n> diff --git a/utils/gen-version.sh b/utils/gen-version.sh\n> new file mode 100755\n> index 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\"","headers":{"Return-Path":"<laurent.pinchart@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 DC0516156B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Jul 2019 22:58:55 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5E4A224B;\n\tThu,  4 Jul 2019 22:58:55 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562273935;\n\tbh=EdCTlZRl042KtKU9zINebiLWVTqzZ5SIuWSo2kRgIdw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=jtUps6pVF+OJ1j4Oq9OYCt+fVeS/AiDK6XUebGktFvDaFBKLF3ED1GVh0/T2jIukm\n\t9yM41T8VcTuT7Jj3IDoIQja1VHnVuhblUJ7jAPL1iEQC+0YkYl6HwiufY6F0tmqlr3\n\t1lCRjXZMvtLufcW8wBSDnoNmLFBEqAUvKtyEIflM=","Date":"Thu, 4 Jul 2019 23:58:34 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20190704205834.GE5024@pendragon.ideasonboard.com>","References":"<20190704145942.17879-1-kieran.bingham@ideasonboard.com>\n\t<20190704145942.17879-3-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190704145942.17879-3-kieran.bingham@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v4 2/6] libcamera: Auto generate\n\tversion information","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 20:58:56 -0000"}}]