libcamera: Auto generate version information

Generate a version string, and provide a global string object which
allows applications to interrogate 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/

A script (utils/gen-version.sh) is provided which is modelled upon the
processing from autoconf's git-version-gen. The gen-version.sh 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 hash is provided from git:

	v0.0.509+0ec0edf7

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Kieran Bingham 2019-01-18 11:59:40 +00:00
parent 63d50ef0c6
commit b817bcec6b
8 changed files with 85 additions and 13 deletions

View file

@ -23,11 +23,8 @@ project = 'libcamera'
copyright = '2018-2019, The libcamera documentation authors' copyright = '2018-2019, The libcamera documentation authors'
author = u'Kieran Bingham, Jacopo Mondi, Laurent Pinchart, Niklas Söderlund' author = u'Kieran Bingham, Jacopo Mondi, Laurent Pinchart, Niklas Söderlund'
# The short X.Y version # Version information is provided by the build environment, through the
version = '' # sphinx command line.
# The full version, including alpha/beta/rc tags
release = '0.1'
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------

View file

@ -1,4 +1,4 @@
doc_install_dir = join_paths(get_option('datadir'), 'doc', 'libcamera-@0@'.format(api_version)) doc_install_dir = join_paths(get_option('datadir'), 'doc', 'libcamera-@0@'.format(meson.project_version()))
# #
# Doxygen # Doxygen
@ -47,8 +47,11 @@ if sphinx.found()
'index.rst', 'index.rst',
] ]
release = 'release=' + meson.project_version()
custom_target('documentation', custom_target('documentation',
command : [sphinx, '-q', '-W', '-b', 'html', meson.current_source_dir(), '@OUTPUT@'], command : [sphinx, '-D', release, '-q', '-W', '-b', 'html',
meson.current_source_dir(), '@OUTPUT@'],
input : docs_sources, input : docs_sources,
output : 'html', output : 'html',
build_by_default : true, build_by_default : true,

View file

@ -16,6 +16,13 @@ libcamera_api = files([
'timer.h', 'timer.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') gen_header = files('gen-header.sh')
libcamera_h = custom_target('gen-header', libcamera_h = custom_target('gen-header',

View file

@ -0,0 +1,22 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* 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;
} /* namespace libcamera */
#endif /* __LIBCAMERA_VERSION_H__ */

View file

@ -1,6 +1,8 @@
project('libcamera', 'c', 'cpp', project('libcamera', 'c', 'cpp',
meson_version : '>= 0.40', meson_version : '>= 0.40',
version : '0.1', version : run_command('utils/gen-version.sh',
'@0@'.format(meson.source_root()),
check : true).stdout().strip(),
default_options : [ default_options : [
'werror=true', 'werror=true',
'warning_level=2', 'warning_level=2',
@ -8,11 +10,6 @@ project('libcamera', 'c', 'cpp',
], ],
license : 'LGPL 2.1+') license : 'LGPL 2.1+')
# TODO: Extract this from project.version.
# Ideally the version at Documentation/conf.py should be
# generated from this too.
api_version = '0.1'
cc = meson.get_compiler('c') cc = meson.get_compiler('c')
config_h = configuration_data() config_h = configuration_data()

View file

@ -9,6 +9,7 @@
#include <libcamera/camera.h> #include <libcamera/camera.h>
#include <libcamera/event_dispatcher.h> #include <libcamera/event_dispatcher.h>
#include <libcamera/version.h>
#include "device_enumerator.h" #include "device_enumerator.h"
#include "event_dispatcher_poll.h" #include "event_dispatcher_poll.h"
@ -25,6 +26,11 @@ namespace libcamera {
LOG_DEFINE_CATEGORY(Camera) LOG_DEFINE_CATEGORY(Camera)
/**
* \brief The library global version string
*/
const std::string version(LIBCAMERA_VERSION);
/** /**
* \class CameraManager * \class CameraManager
* \brief Provide access and manage all cameras in the system * \brief Provide access and manage all cameras in the system
@ -79,6 +85,8 @@ int CameraManager::start()
if (enumerator_) if (enumerator_)
return -EBUSY; return -EBUSY;
LOG(Camera, Info) << "libcamera " << version;
enumerator_ = DeviceEnumerator::create(); enumerator_ = DeviceEnumerator::create();
if (!enumerator_ || enumerator_->enumerate()) if (!enumerator_ || enumerator_->enumerate())
return -ENODEV; return -ENODEV;

View file

@ -80,6 +80,7 @@ control_types_cpp = custom_target('control_types_cpp',
libcamera_sources += control_types_cpp libcamera_sources += control_types_cpp
libcamera_deps = [ libcamera_deps = [
declare_dependency(sources : version_h),
cc.find_library('dl'), cc.find_library('dl'),
libudev, libudev,
] ]

37
utils/gen-version.sh Executable file
View file

@ -0,0 +1,37 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
# Generate a version string using git describe
if [ -n "$1" ]
then
cd "$1" 2>/dev/null || exit 1
fi
# Get a short description from the tree.
version=$(git describe --abbrev=8 --match "v[0-9]*" 2>/dev/null)
if [ -z "$version" ]
then
# Handle an un-tagged repository
sha=$(git describe --abbrev=8 --always 2>/dev/null)
commits=$(git log --oneline | wc -l 2>/dev/null)
version=v0.0.$commits.$sha
fi
# Prevent changed timestamps causing -dirty labels
git update-index --refresh > /dev/null 2>&1
dirty=$(git diff-index --name-only HEAD 2>/dev/null) || dirty=
# Strip the 'g', and replace the preceeding '-' with a '+' to denote a label
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 [ -n "$dirty" ]
then
version=$version-dirty
fi
echo "$version"