From patchwork Tue Jun 11 20:14:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1395 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AECFE61FB7 for ; Tue, 11 Jun 2019 22:14:18 +0200 (CEST) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 25D8DFA0; Tue, 11 Jun 2019 22:14:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1560284058; bh=poC7n5GNhItFhm/AzwSlLX7yEbzdObQfBOcMJc1XuYw=; h=From:To:Cc:Subject:Date:From; b=Yb6JuQLAM8icCMRHOWI3poE+LHPsyAcGjfkbjhEcqGNCOaXVZk5rvnMzotGJ3IwWo 70hTS4q73CAcGu92fciLHzB5m2RUx8dmFXWuj1hLpXcXHPvHHzNdc4Gsb0hGcxHxWe O8cZ7j2eOqzQgdPaiok8Muh5Im8Cgp4y8+RGJfTU= From: Kieran Bingham To: LibCamera Devel Date: Tue, 11 Jun 2019 21:14:11 +0100 Message-Id: <20190611201411.16369-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: Auto generate version information X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Jun 2019 20:14:18 -0000 Generate a version string, and provide a global singleton object which allows applications to interogate the current libcamera version information. The version header is automatically updated by meson on each build. The string roughly follows the semver [0] conventions of major.minor.patch-label as a value. [0] https://semver.org/ The utils/version-gen script will look for tags in the form vX.Y as starting points for the version string. While the repository does not have any matching tags, v0.0 will be assumed, resulting in versions with both major and minor being set to '0', and the patch count resulting from the number of patches in the history to that point. Finally, a uniquely identifying shortened checksum is provided from git: v0.0.509.c544 Signed-off-by: Kieran Bingham --- Documentation/conf.py | 6 ++++-- include/libcamera/meson.build | 1 + include/libcamera/version.h | 23 ++++++++++++++++++++ meson.build | 9 +++++++- src/libcamera/meson.build | 1 + src/libcamera/version.cpp | 40 +++++++++++++++++++++++++++++++++++ utils/version-gen | 36 +++++++++++++++++++++++++++++++ version.h.in | 3 +++ 8 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 include/libcamera/version.h create mode 100644 src/libcamera/version.cpp create mode 100755 utils/version-gen create mode 100644 version.h.in diff --git a/Documentation/conf.py b/Documentation/conf.py index 970edf3d7298..e5980b98216d 100644 --- a/Documentation/conf.py +++ b/Documentation/conf.py @@ -23,10 +23,12 @@ project = 'libcamera' copyright = '2018-2019, The libcamera documentation authors' author = u'Kieran Bingham, Jacopo Mondi, Laurent Pinchart, Niklas Söderlund' +# Vesion information is provided by the build environment. +# # The short X.Y version -version = '' +# version = '' # The full version, including alpha/beta/rc tags -release = '0.1' +# release = '0.1' # -- General configuration --------------------------------------------------- diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index 1b86fdc7fca4..201832105457 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -12,6 +12,7 @@ libcamera_api = files([ 'signal.h', 'stream.h', 'timer.h', + 'version.h', ]) gen_header = join_paths(meson.current_source_dir(), 'gen-header.sh') diff --git a/include/libcamera/version.h b/include/libcamera/version.h new file mode 100644 index 000000000000..ad21f148e748 --- /dev/null +++ b/include/libcamera/version.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * version.h - Library version information + */ +#ifndef __LIBCAMERA_VERSION_H__ +#define __LIBCAMERA_VERSION_H__ + +namespace libcamera { + +class LibcameraVersion +{ +public: + LibcameraVersion(); + std::string toString(); +}; + +extern LibcameraVersion version; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_VERSION_H__ */ diff --git a/meson.build b/meson.build index 4d3e99d3e58f..5182546382c5 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,8 @@ project('libcamera', 'c', 'cpp', meson_version : '>= 0.40', - version : '0.1', + version : run_command('utils/version-gen', + '@0@'.format(meson.source_root()), + check : true).stdout().strip(), default_options : [ 'werror=true', 'warning_level=2', @@ -13,6 +15,11 @@ project('libcamera', 'c', 'cpp', # generated from this too. api_version = '0.1' +vcs_tag(command: ['utils/version-gen', '.'], + input: 'version.h.in', + output: 'version.h', + fallback: '') + cc = meson.get_compiler('c') config_h = configuration_data() diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 1ca1083cf5c7..b9a4153839c9 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -25,6 +25,7 @@ libcamera_sources = files([ 'utils.cpp', 'v4l2_device.cpp', 'v4l2_subdevice.cpp', + 'version.cpp', ]) libcamera_headers = files([ diff --git a/src/libcamera/version.cpp b/src/libcamera/version.cpp new file mode 100644 index 000000000000..81f692f7cae7 --- /dev/null +++ b/src/libcamera/version.cpp @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * version.cpp - Version information + */ + +#include + +#include "log.h" + +/* The version header is automatically generated at the base of the project. */ +#include "../../version.h" + +namespace libcamera { + +LOG_DEFINE_CATEGORY(Version) + +/** + * \class LibcameraVersion + * + * Reports library version information + */ + +LibcameraVersion::LibcameraVersion() +{ + LOG(Version, Info) << "Libcamera Version " << toString(); +} + +/** + * \brief Return the library version as a string + */ +std::string LibcameraVersion::toString() +{ + return LIBCAMERA_VERSION; +} + +static LibcameraVersion version; + +} /* namespace libcamera */ diff --git a/utils/version-gen b/utils/version-gen new file mode 100755 index 000000000000..b8e53d77b63e --- /dev/null +++ b/utils/version-gen @@ -0,0 +1,36 @@ +#!/bin/sh + +if test -n "$1" +then + cd "$1" +fi + +# No fall back is provided for tarball releases or such, as we do not yet provide releases. + +# Get a short description from the tree. +version=$(git describe --abbrev=4 --match "v[0-9]*" 2>/dev/null) + +if test -z "$version" +then + # Handle an un-tagged repository + sha=$(git describe --abbrev=4 --always 2>/dev/null) + commits=$(git log --oneline | wc -l 2>/dev/null) + version=v0.0.$commits.$sha +fi + + +git update-index --refresh > /dev/null 2>&1 +dirty=`sh -c 'git diff-index --name-only HEAD' 2>/dev/null` || dirty= + +# Strip the 'g' +version=$(echo "$version" | sed -e 's/-g/-/g') + +# Fix the '-' (the patch count) to a '.' as a version increment. +version=$(echo "$version" | sed -e 's/-/./g') + +if test -n "$dirty" +then + version=$version-dirty +fi + +echo $version diff --git a/version.h.in b/version.h.in new file mode 100644 index 000000000000..142819645b64 --- /dev/null +++ b/version.h.in @@ -0,0 +1,3 @@ +#pragma once + +#define LIBCAMERA_VERSION "@VCS_TAG@"