Skip to content

Commit

Permalink
core: build: Add capabilities string to the version information.
Browse files Browse the repository at this point in the history
This will be printed out with the --version command line argument.

Signed-off-by: Naushir Patuck <[email protected]>
  • Loading branch information
naushir committed Oct 14, 2024
1 parent 673ee33 commit 6de1ab6
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 26 deletions.
19 changes: 0 additions & 19 deletions core/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,6 @@ core_headers = files([
'video_options.hpp',
])

# Generate a version string.
version_cmd = [meson.project_source_root() / 'utils' / 'version.py', meson.project_version()]

# Check if a version.gen file is present.
# This would have been generated from the meson dist command.
fs = import('fs')
dist_version_file = meson.project_source_root() / 'version.gen'
if fs.is_file(dist_version_file)
version_cmd += fs.read(dist_version_file)
endif

version_cpp = vcs_tag(command : version_cmd,
replace_string: '@VER@',
input : 'version.cpp.in',
output : 'version.cpp',
fallback : meson.project_version())

rpicam_app_src += version_cpp

install_headers(core_headers, subdir: meson.project_name() / 'core')

# Install symlinks to the old header directories and names for legacy purposes.
Expand Down
1 change: 1 addition & 0 deletions core/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ bool Options::Parse(int argc, char *argv[])
if (version)
{
std::cout << "rpicam-apps build: " << RPiCamAppsVersion() << std::endl;
std::cout << "rpicam-apps capabilites: " << RPiCamAppsCapabilities() << std::endl;
std::cout << "libcamera build: " << libcamera::CameraManager::version() << std::endl;
return false;
}
Expand Down
40 changes: 37 additions & 3 deletions core/version.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,43 @@
*/
#include "core/version.hpp"

static const std::string versionString {"@VER@"};
#if LIBEGL_PRESENT
static constexpr int egl = 1;
#else
static constexpr int egl = 0;
#endif

const std::string& RPiCamAppsVersion()
#if QT_PRESENT
static constexpr int qt = 1;
#else
static constexpr int qt = 0;
#endif

#if LIBDRM_PRESENT
static constexpr int drm = 1;
#else
static constexpr int drm = 0;
#endif

#if LIBAV_PRESENT
static int libav = 1;
#else
static int libav = 0;
#endif

static const std::string version {"@VER@"};

static const std::string caps {"egl:" + std::to_string(egl) +
" qt:" + std::to_string(qt) +
" drm:" + std::to_string(drm) +
" libav:" + std::to_string(libav)};

const std::string &RPiCamAppsVersion()
{
return version;
}

const std::string &RPiCamAppsCapabilities()
{
return versionString;
return caps;
}
3 changes: 2 additions & 1 deletion core/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

#include <string>

const std::string& RPiCamAppsVersion();
const std::string &RPiCamAppsVersion();
const std::string &RPiCamAppsCapabilities();
20 changes: 20 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ project('rpicam-apps', 'c', 'cpp',

meson.add_dist_script('utils' / 'gen-dist.sh')

fs = import('fs')

cpp_arguments = ['-pedantic', '-Wno-unused-parameter', '-faligned-new']

# Needed for file sizes > 32-bits.
Expand Down Expand Up @@ -55,6 +57,24 @@ add_project_arguments(cpp_arguments, language : 'cpp')
# Must be put after add_project_arguments as it defines shared library targets.
subdir('post_processing_stages')

# Generate a version string.
version_cmd = [meson.project_source_root() / 'utils' / 'version.py', meson.project_version()]

# Check if a version.gen file is present.
# This would have been generated from the meson dist command.
dist_version_file = meson.project_source_root() / 'version.gen'
if fs.is_file(dist_version_file)
version_cmd += fs.read(dist_version_file)
endif

version_cpp = vcs_tag(command : version_cmd,
replace_string: '@VER@',
input : meson.project_source_root() / 'core' / 'version.cpp.in',
output : 'version.cpp',
fallback : meson.project_version())

rpicam_app_src += version_cpp

rpicam_app = library(
'rpicam_app',
rpicam_app_src,
Expand Down
4 changes: 1 addition & 3 deletions utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ def generate_version():
else:
raise RuntimeError('Invalid number of command line arguments')

commit = f'v{sys.argv[1]} {commit}'

except RuntimeError as e:
print(f'ERR: {e}', file=sys.stderr)
commit = '0' * digits + '-invalid'

finally:
print(f'{commit} {datetime.now().strftime("%d-%m-%Y (%H:%M:%S)")}', end="")
print(f'v{sys.argv[1]} {commit} {datetime.now().strftime("%d-%m-%Y (%H:%M:%S)")}', end="")


if __name__ == "__main__":
Expand Down

0 comments on commit 6de1ab6

Please sign in to comment.