Skip to content

Commit

Permalink
Update on every build the git hash shown by rizin -v (rizinorg#2863)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazarmy authored and wingdeans committed Aug 3, 2022
1 parent f211ba2 commit be37c9f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
1 change: 0 additions & 1 deletion librz/include/rz_version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define RZ_VERSION_PATCH @RZ_VERSION_PATCH@
#define RZ_VERSION_NUMBER @RZ_VERSION_NUMBER@
#define RZ_VERSION "@RZ_VERSION@"
#define RZ_GITTIP "@RZ_GITTIP@"
#mesondefine RZ_PACKAGER_VERSION
#mesondefine RZ_PACKAGER
#endif
20 changes: 13 additions & 7 deletions librz/util/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -4022,10 +4022,6 @@ RZ_API RzList *rz_str_wrap(char *str, size_t width) {
#include <rz_userconf.h>
#include <rz_util.h>

#ifndef RZ_GITTIP
#define RZ_GITTIP ""
#endif

#ifdef RZ_PACKAGER_VERSION
#ifdef RZ_PACKAGER
#define RZ_STR_PKG_VERSION_STRING ", package: " RZ_PACKAGER_VERSION " (" RZ_PACKAGER ")"
Expand All @@ -4046,10 +4042,20 @@ RZ_API char *rz_str_version(const char *program) {
if (RZ_STR_ISNOTEMPTY(RZ_STR_PKG_VERSION_STRING)) {
rz_strbuf_append(sb, RZ_STR_PKG_VERSION_STRING);
}
if (RZ_STR_ISNOTEMPTY(RZ_GITTIP)) {
rz_strbuf_append(sb, "\n");
rz_strbuf_append(sb, "commit: " RZ_GITTIP);
char *gittip_pathname = rz_str_newf("%s" RZ_SYS_DIR "gittip", rz_path_bindir());
char *gittip = NULL;
if (!gittip_pathname) {
goto done;
}
gittip = rz_file_slurp(gittip_pathname, NULL);
if (!gittip || !*rz_str_trim_head_ro(gittip)) {
goto done;
}
rz_strbuf_append(sb, "\n");
rz_strbuf_appendf(sb, "commit: %s", gittip);
done:
free(gittip_pathname);
free(gittip);
return rz_strbuf_drain(sb);
}

Expand Down
29 changes: 12 additions & 17 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,6 @@ if meson.is_subproject()
endif
endif

gittip = ''

fs = import('fs')
if git_exe.found() and fs.exists('.git')
# Get gittip
git_rev_parse = run_command(py3_exe, git_exe_repo_py, git_exe, repo, 'rev-parse', 'HEAD', check: true)
if git_rev_parse.returncode() == 0
gittip = git_rev_parse.stdout().strip()
endif
endif

if get_option('rizin_gittip') != ''
gittip = get_option('rizin_gittip')
endif

rizin_libversion = '@0@.@1@'.format(rizin_version_major, rizin_version_minor)
message('rizin lib version: ' + rizin_libversion)

Expand Down Expand Up @@ -147,6 +132,7 @@ if (b_sanitize_opt.contains('address') or b_sanitize_opt.contains('undefined'))
add_global_link_arguments('-shared-libasan', language: 'c', native: true)
endif

fs = import('fs')
rizin_prefix = get_option('prefix')
rizin_bindir = get_option('bindir')
rizin_libdir = get_option('libdir')
Expand Down Expand Up @@ -540,15 +526,13 @@ packager_version = get_option('packager_version')
message('Version Major: @0@0'.format(rizin_version_major))
message('Version Minor: @0@0'.format(rizin_version_minor))
message('Version Patch: @0@0'.format(rizin_version_patch))
message('Version GitTip: @0@0'.format(gittip))

versionconf = configuration_data()
versionconf.set('RZ_VERSION_MAJOR', rizin_version_major)
versionconf.set('RZ_VERSION_MINOR', rizin_version_minor)
versionconf.set('RZ_VERSION_PATCH', rizin_version_patch)
versionconf.set('RZ_VERSION_NUMBER', rizin_version_number)
versionconf.set('RZ_VERSION', rizin_version)
versionconf.set('RZ_GITTIP', gittip)
if packager_version != ''
versionconf.set_quoted('RZ_PACKAGER_VERSION', packager_version)
if packager != ''
Expand All @@ -562,6 +546,17 @@ rz_version_h = configure_file(
install_dir: rizin_incdir
)

if git_exe.found() and fs.exists('.git')
gittip_file = custom_target('gittip_file',
build_always_stale: true,
build_by_default: true,
output: 'gittip',
command: [py3_exe, git_exe_repo_py, git_exe, repo, 'rev-parse', 'HEAD'],
install: true,
install_dir: rizin_bindir
)
endif

# handle zlib dependency
zlib_dep = disabler()
if get_option('use_zlib')
Expand Down
1 change: 0 additions & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ option('rizin_hud', type: 'string', value: '', description: 'Install path for hu
option('rizin_plugins', type: 'string', value: '', description: 'Path where plugins are expected to be found')
option('rizin_bindings', type: 'string', value: '', description: 'Path where rizin bindings are expected to be found')

option('rizin_gittip', type: 'string', value: '')
option('checks_level', type: 'integer', value: 9999, description: 'Value between 0 and 3 to enable different level of assert (see RZ_CHECKS_LEVEL). By default its value depends on buildtype (2 on debug, 1 on release).')
option('use_sys_capstone', type: 'feature', value: 'disabled')
option('use_capstone_version', type: 'combo', choices: ['v3', 'v4', 'next', 'bundled'], value: 'bundled', description: 'Specify which version of capstone to use')
Expand Down
4 changes: 3 additions & 1 deletion sys/meson_git_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def isCArgSupported(executable, path):

def simple_git_execution(args):
try:
called = subprocess.run(args, check=True)
called = subprocess.run(args, check=True, capture_output=True)
with open("gittip", "w", encoding="utf8") as f:
f.write(called.stdout.decode("utf8").strip())
sys.exit(called.returncode)
except subprocess.CalledProcessError as e:
sys.exit(e.returncode)
Expand Down

0 comments on commit be37c9f

Please sign in to comment.