Skip to content

Commit

Permalink
misc: print better versions
Browse files Browse the repository at this point in the history
Print both version number and git commit hash, not just one of either.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
  • Loading branch information
yshui committed Aug 29, 2024
1 parent ecc3dc3 commit 6a678cb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 23 deletions.
40 changes: 27 additions & 13 deletions man/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,32 @@ mans = ['picom.1', 'picom-inspect.1', 'picom-trans.1']
if get_option('with_docs')
a2x = find_program('asciidoctor')
foreach m : mans
custom_target(m, output: [m], input: [m+'.adoc'],
command: [a2x, '-a',
'picom-version='+version,
'--backend', 'manpage', '@INPUT@', '-D',
meson.current_build_dir()],
install: true,
install_dir: join_paths(get_option('mandir'), 'man1'))
custom_target(m+'.html', output: [m+'.html'], input: [m+'.adoc'],
command: [a2x, '-a',
'picom-version='+version,
'--backend', 'html', '@INPUT@', '-D',
meson.current_build_dir()],
install_dir: get_option('datadir') / 'doc' / 'picom')
custom_target(
m,
output: [m],
input: [m + '.adoc'],
command: [
a2x,
'-a', 'picom-version=v' + meson.project_version(),
'--backend', 'manpage',
'@INPUT@',
'-D', meson.current_build_dir(),
],
install: true,
install_dir: join_paths(get_option('mandir'), 'man1'),
)
custom_target(
m + '.html',
output: [m + '.html'],
input: [m + '.adoc'],
command: [
a2x,
'-a', 'picom-version=v' + meson.project_version(),
'--backend', 'html',
'@INPUT@',
'-D', meson.current_build_dir(),
],
install_dir: get_option('datadir') / 'doc' / 'picom',
)
endforeach
endif
26 changes: 20 additions & 6 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,33 @@ project('picom', 'c', version: '11',

cc = meson.get_compiler('c')

# use project version by default
version = 'v'+meson.project_version()

# use git describe if that's available
git = find_program('git', required: false)
if git.found()
gitv = run_command('git', 'rev-parse', '--short=5', 'HEAD', check: false)
gitv = run_command('git', 'rev-parse', '--short=7', 'HEAD', check: false)
if gitv.returncode() == 0
version = 'vgit-'+gitv.stdout().strip()
commit_hash_short = gitv.stdout().strip()
endif
git_upstream = run_command('git', 'rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}', check: false)
if git_upstream.returncode() == 0
remote = git_upstream.stdout().strip().split('/')[0]
else
remote = 'origin'
endif
git_repository = run_command('git', 'remote', 'get-url', remote, check: false)
if git_repository.returncode() == 0
repository = git_repository.stdout().strip()
endif
endif

add_global_arguments('-DPICOM_VERSION="'+version+'"', language: 'c')
add_global_arguments('-DPICOM_VERSION="v'+meson.project_version()+'"', language: 'c')
if is_variable('repository')
add_global_arguments('-DPICOM_FULL_VERSION="v'+meson.project_version()+' ('+repository+' revision '+commit_hash_short+')"', language: 'c')
elif is_variable('commit_hash_short')
add_global_arguments('-DPICOM_FULL_VERSION="v'+meson.project_version()+' (revision '+commit_hash_short+')"', language: 'c')
else
add_global_arguments('-DPICOM_FULL_VERSION="v'+meson.project_version()+'"', language: 'c')
endif

if get_option('buildtype') == 'release'
add_global_arguments('-DNDEBUG', language: 'c')
Expand Down
2 changes: 1 addition & 1 deletion src/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ cdbus_process_opts_get(session_t *ps, DBusMessage *msg, DBusMessage *reply, DBus
return DBUS_HANDLER_RESULT_HANDLED;
}

append(version, string, PICOM_VERSION);
append(version, string, PICOM_FULL_VERSION);
append(pid, int32, getpid());
append(display, string, DisplayString(ps->c.dpy));
append(config_file, string, "Unknown");
Expand Down
2 changes: 1 addition & 1 deletion src/diagnostic.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "picom.h"

void print_diagnostics(session_t *ps, const char *config_file, bool compositor_running) {
printf("**Version:** " PICOM_VERSION "\n");
printf("**Version:** " PICOM_FULL_VERSION "\n");
// printf("**CFLAGS:** %s\n", "??");
printf("\n### Extensions:\n\n");
printf("* Shape: %s\n", ps->shape_exists ? "Yes" : "No");
Expand Down
4 changes: 2 additions & 2 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ void print_help(const char *help, size_t indent, size_t curr_indent, size_t line
*/
static void usage(const char *argv0, int ret) {
FILE *f = (ret ? stderr : stdout);
fprintf(f, "picom (%s)\n", PICOM_VERSION);
fprintf(f, "picom " PICOM_FULL_VERSION "\n");
fprintf(f, "Standalone X11 compositor\n");
fprintf(f, "Please report bugs to https://github.com/yshui/picom\n\n");

Expand Down Expand Up @@ -775,7 +775,7 @@ bool get_early_config(int argc, char *const *argv, char **config_file, bool *all
} else if (o == 314) {
*all_xerrors = true;
} else if (o == 318) {
printf("%s\n", PICOM_VERSION);
printf(PICOM_FULL_VERSION "\n");
return true;
} else if (o == 307) {
// --plugin
Expand Down

0 comments on commit 6a678cb

Please sign in to comment.