diff --git a/librz/include/rz_version.h.in b/librz/include/rz_version.h.in index 3ae81a72656..dc1b23b1759 100644 --- a/librz/include/rz_version.h.in +++ b/librz/include/rz_version.h.in @@ -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 diff --git a/librz/util/str.c b/librz/util/str.c index 87b5e70f478..eee217c3053 100644 --- a/librz/util/str.c +++ b/librz/util/str.c @@ -4022,10 +4022,6 @@ RZ_API RzList *rz_str_wrap(char *str, size_t width) { #include #include -#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 ")" @@ -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); } diff --git a/meson.build b/meson.build index 0b844839871..9929d0b4939 100644 --- a/meson.build +++ b/meson.build @@ -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) @@ -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') @@ -540,7 +526,6 @@ 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) @@ -548,7 +533,6 @@ 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 != '' @@ -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') diff --git a/meson_options.txt b/meson_options.txt index 4c565ccb3ce..773b12e0043 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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') diff --git a/sys/meson_git_wrapper.py b/sys/meson_git_wrapper.py index 8e73a7fdadc..304dcf7a1b2 100755 --- a/sys/meson_git_wrapper.py +++ b/sys/meson_git_wrapper.py @@ -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)