cage: add -v argument to print version

This commit is contained in:
Jente Hidskes 2020-01-26 17:49:26 +01:00
parent 5e27683961
commit 15eeb7784e
3 changed files with 27 additions and 5 deletions

10
cage.c
View file

@ -115,6 +115,7 @@ usage(FILE *file, const char *cage)
" -D\t Turn on damage tracking debugging\n"
#endif
" -h\t Display this help message\n"
" -v\t Show the version number and exit\n"
"\n"
" Use -- when you want to pass arguments to APPLICATION\n",
cage);
@ -125,9 +126,9 @@ parse_args(struct cg_server *server, int argc, char *argv[])
{
int c;
#ifdef DEBUG
while ((c = getopt(argc, argv, "drDh")) != -1) {
while ((c = getopt(argc, argv, "drDhv")) != -1) {
#else
while ((c = getopt(argc, argv, "drh")) != -1) {
while ((c = getopt(argc, argv, "drhv")) != -1) {
#endif
switch (c) {
case 'd':
@ -147,6 +148,9 @@ parse_args(struct cg_server *server, int argc, char *argv[])
case 'h':
usage(stdout, argv[0]);
return false;
case 'v':
fprintf(stdout, "Cage version " CAGE_VERSION "\n");
exit(0);
default:
usage(stderr, argv[0]);
return false;
@ -390,7 +394,7 @@ main(int argc, char *argv[])
wlr_log_errno(WLR_ERROR, "Unable to set WAYLAND_DISPLAY.",
"Clients may not be able to connect");
} else {
wlr_log(WLR_DEBUG, "Cage is running on Wayland display %s", socket);
wlr_log(WLR_DEBUG, "Cage " CAGE_VERSION " is running on Wayland display %s", socket);
}
#if CAGE_HAS_XWAYLAND

View file

@ -3,4 +3,6 @@
#mesondefine CAGE_HAS_XWAYLAND
#mesondefine CAGE_VERSION
#endif

View file

@ -76,8 +76,24 @@ else
have_xwayland = false
endif
git = find_program('git', native: true, required: false)
if git.found()
git_commit = run_command([git, 'rev-parse', '--short', 'HEAD'])
git_branch = run_command([git, 'rev-parse', '--abbrev-ref', 'HEAD'])
if git_commit.returncode() == 0 and git_branch.returncode() == 0
version = '@0@-@1@ (branch \'@2@\')'.format(
meson.project_version(),
git_commit.stdout().strip(),
git_branch.stdout().strip(),
)
endif
else
version = '@0@'.format(meson.project_version())
endif
conf_data = configuration_data()
conf_data.set10('CAGE_HAS_XWAYLAND', have_xwayland)
conf_data.set_quoted('CAGE_VERSION', version)
cage_sources = [
'cage.c',
@ -125,9 +141,9 @@ executable(
summary = [
'',
'Cage @0@'.format(meson.project_version()),
'Cage @0@'.format(version),
'',
' xwayland: @0@'.format(conf_data.get('CAGE_HAS_XWAYLAND', false)),
' xwayland: @0@'.format(have_xwayland),
''
]
message('\n'.join(summary))