Skip to content

Commit

Permalink
meson: use vcs_tag for git version information
Browse files Browse the repository at this point in the history
This way, the command is run every time we change the Wayfire version
and not only when meson reconfigures itself.
  • Loading branch information
ammen99 committed Feb 16, 2024
1 parent 5b75e8e commit ce73843
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 23 deletions.
21 changes: 4 additions & 17 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(
'cpp',
version: '0.9.0',
license: 'MIT',
meson_version: '>=0.56.0',
meson_version: '>=0.63.0',
default_options: [
'cpp_std=c++17',
'c_std=c11',
Expand All @@ -13,6 +13,9 @@ project(
],
)

version = '"@0@"'.format(meson.project_version())
add_project_arguments('-DWAYFIRE_VERSION=@0@'.format(version), language: 'cpp')

wayfire_api_inc = include_directories('src/api')

wayland_server = dependency('wayland-server')
Expand Down Expand Up @@ -83,22 +86,6 @@ backtrace = meson.get_compiler('cpp').find_library('execinfo', required: false)

conf_data = configuration_data()

version = '"@0@"'.format(meson.project_version())
git = find_program('git', native: true, required: false)
if git.found()
git_commit = run_command([git, 'rev-parse', '--short', 'HEAD'], check: false)
git_branch = run_command([git, 'rev-parse', '--abbrev-ref', 'HEAD'], check: false)
if git_commit.returncode() == 0 and git_branch.returncode() == 0
version = '"@0@-@1@ (" __DATE__ ", branch \'@2@\')"'.format(
meson.project_version(),
git_commit.stdout().strip(),
git_branch.stdout().strip(),
)
endif
endif
add_project_arguments('-DWAYFIRE_VERSION=@0@'.format(version), language: 'cpp')
conf_data.set('WAYFIRE_VERSION', '-DWAYFIRE_VERSION=@0@'.format(version))

conf_data.set('INSTALL_PREFIX', get_option('prefix'))
conf_data.set('PLUGIN_PATH', join_paths(get_option('prefix'), get_option('libdir'), 'wayfire'))
metadata_dir_suffix = 'share/wayfire/metadata'
Expand Down
10 changes: 10 additions & 0 deletions src/api/wayfire/debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ namespace wf
*/
void dump_scene(scene::node_ptr root = wf::get_core().scene());

/**
* Information about the version that Wayfire was built with.
* Made available at runtime.
*/
namespace version
{
extern std::string git_commit;
extern std::string git_branch;
}

namespace log
{
/**
Expand Down
7 changes: 2 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@
#include <iostream>
#include <getopt.h>
#include <signal.h>
#include <map>
#include <fcntl.h>
#include <filesystem>

#include <unistd.h>
#include <wayfire/debug.hpp>
#include "main.hpp"
#include "wayfire/nonstd/safe-list.hpp"

#include <wayland-server.h>

#include "wayfire/config-backend.hpp"
#include "core/plugin-loader.hpp"
#include "core/core-impl.hpp"
#include "wayfire/output.hpp"

static void print_version()
{
std::cout << WAYFIRE_VERSION << std::endl;
std::cout << WAYFIRE_VERSION << "-" << wf::version::git_commit <<
" (" __DATE__ ") branch " << wf::version::git_branch << std::endl;
exit(0);
}

Expand Down
18 changes: 17 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ if print_trace
debug_arguments += ['-DPRINT_TRACE']
endif

# Generate information about Wayfire version
git = find_program('git', native: true, required: false)
git_commit_info = vcs_tag(
input: 'version/git-commit.cpp.in',
output: 'git-commit.cpp',
replace_string: '@GIT_COMMIT@',
command: git.found() ? [git, 'rev-parse', '--short', 'HEAD'] : ['echo', 'unknown'],
fallback: 'unknown')

git_branch_info = vcs_tag(
input: 'version/git-branch.cpp.in',
output: 'git-branch.cpp',
replace_string: '@GIT_BRANCH@',
command: git.found() ? [git, 'rev-parse', '--abbrev-ref', 'HEAD'] : ['echo', 'unknown'],
fallback: 'unknown')

# First build a static library of all sources, so that it can be reused
# in tests
libwayfire_sta = static_library('libwayfire', wayfire_sources,
Expand All @@ -105,7 +121,7 @@ libwayfire = declare_dependency(link_whole: libwayfire_sta,
tests_include_dirs = include_directories('.')

# Generate main executable
executable('wayfire', ['main.cpp'],
executable('wayfire', ['main.cpp', git_commit_info, git_branch_info],
dependencies: libwayfire,
install: true,
cpp_args: debug_arguments)
Expand Down
9 changes: 9 additions & 0 deletions src/version/git-branch.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <wayfire/debug.hpp>

namespace wf
{
namespace version
{
std::string git_branch = "@GIT_BRANCH@";
}
}
9 changes: 9 additions & 0 deletions src/version/git-commit.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <wayfire/debug.hpp>

namespace wf
{
namespace version
{
std::string git_commit = "@GIT_COMMIT@";
}
}

0 comments on commit ce73843

Please sign in to comment.