From 018c0eaa53d44b3d671650ca8886d95bc5952da7 Mon Sep 17 00:00:00 2001 From: Riccardo Schirone Date: Wed, 27 Jan 2021 09:42:47 +0100 Subject: [PATCH] Change how version is reported in -v command flag --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- doc/PACKAGERS.md | 8 ++++++- librz/core/cmd_help.c | 16 +++++--------- librz/include/rz_version.h.in | 3 ++- librz/util/str.c | 32 ++++++++++++++++++++++------ meson.build | 25 +++++++++++++++++----- meson_options.txt | 2 ++ shlr/meson.build | 6 ++---- sys/meson_git_wrapper.py | 27 +++++++++++++++++++++++ 9 files changed, 91 insertions(+), 30 deletions(-) create mode 100755 sys/meson_git_wrapper.py diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index b99917e82c..e76def44b3 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -17,7 +17,7 @@ Make sure you are testing using the latest git version of rizin before submittin | OS/arch/bits (mandatory) | Debian arm 64, Ubuntu x86 32 | File format of the file you reverse (mandatory) | PE, ELF etc. | Architecture/bits of the file (mandatory) | PPC, x86/32, x86/64 etc. -| `rizin -v` full output, **not truncated** (mandatory) | rizin 0.1.0-git 26866 @ linux-x86-64 git.4.5.1-869-g4d01f3c7f commit: 4d01f3c7f6c15c01e19a4e00ac706ffa5f3a3459 build: 2021-01-21__13:00:24 +| `rizin -v` full output, **not truncated** (mandatory) | rizin 0.2.0-git @ linux-x86-64, package: 0.2.0.1 (ret2libc) commit: c875be9afde5a6eed037249854b8a8759517263c, build: 2021-01-26__18:17:13 ### Expected behavior diff --git a/doc/PACKAGERS.md b/doc/PACKAGERS.md index ab2f27b831..7c61c8b011 100644 --- a/doc/PACKAGERS.md +++ b/doc/PACKAGERS.md @@ -24,7 +24,13 @@ Building Rizin uses the `meson` build system. Command line flags passed to meson can change how Rizin is built. -To define the base install location for Rizin use the `--prefix` flag when +First, we suggest you use the options `-Dpackager_version=` +and `-Dpackager=` to help us track the version of Rizin users are +using, because these options are used when you run `rizin -v`. In this way +when a user reports a issue and he provides his `rizin -v` output, we know +how Rizin was built. + +Then, to define the base install location for Rizin use the `--prefix` flag when invoking `meson`. For system installs it is common to use `/usr`. If in doubt check your distributions packaging guidelines. diff --git a/librz/core/cmd_help.c b/librz/core/cmd_help.c index 9bbe6870cc..10fb779498 100644 --- a/librz/core/cmd_help.c +++ b/librz/core/cmd_help.c @@ -860,17 +860,12 @@ RZ_IPI int rz_cmd_help(void *data, const char *input) { case '?': // "?V?" rz_core_cmd_help(core, help_msg_question_V); break; - case 0: // "?V" -#if RZ_VERSION_COMMIT == 0 - rz_cons_printf("%s release\n", RZ_VERSION); -#else - if (!strcmp(RZ_VERSION, RZ_GITTAP)) { - rz_cons_printf("%s %d\n", RZ_VERSION, RZ_VERSION_COMMIT); - } else { - rz_cons_printf("%s aka %s commit %d\n", RZ_VERSION, RZ_GITTAP, RZ_VERSION_COMMIT); - } -#endif + case 0: { // "?V" + char *v = rz_str_version(NULL); + rz_cons_printf("%s\n", v); + free (v); break; + } case 'c': // "?Vc" rz_cons_printf("%d\n", vernum(RZ_VERSION)); break; @@ -881,7 +876,6 @@ RZ_IPI int rz_cmd_help(void *data, const char *input) { pj_ks(pj, "arch", RZ_SYS_ARCH); pj_ks(pj, "os", RZ_SYS_OS); pj_ki(pj, "bits", RZ_SYS_BITS); - pj_ki(pj, "commit", RZ_VERSION_COMMIT); pj_ks(pj, "tap", RZ_GITTAP); pj_ki(pj, "major", RZ_VERSION_MAJOR); pj_ki(pj, "minor", RZ_VERSION_MINOR); diff --git a/librz/include/rz_version.h.in b/librz/include/rz_version.h.in index 799a6481f3..678e7e2c93 100644 --- a/librz/include/rz_version.h.in +++ b/librz/include/rz_version.h.in @@ -5,9 +5,10 @@ #define RZ_VERSION_MINOR @RZ_VERSION_MINOR@ #define RZ_VERSION_PATCH @RZ_VERSION_PATCH@ #define RZ_VERSION_NUMBER @RZ_VERSION_NUMBER@ -#define RZ_VERSION_COMMIT @VERSIONCOMMIT@ #define RZ_VERSION "@RZ_VERSION@" #define RZ_GITTAP "@RZ_GITTAP@" #define RZ_GITTIP "@RZ_GITTIP@" #define RZ_BIRTH "@RZ_BIRTH@" +#mesondefine RZ_PACKAGER_VERSION +#mesondefine RZ_PACKAGER #endif diff --git a/librz/util/str.c b/librz/util/str.c index f82a360522..dac208b37a 100644 --- a/librz/util/str.c +++ b/librz/util/str.c @@ -3810,13 +3810,31 @@ RZ_API RzList *rz_str_wrap(char *str, size_t width) { #define RZ_BIRTH "unknown" #endif +#ifdef RZ_PACKAGER_VERSION +# ifdef RZ_PACKAGER +# define RZ_STR_PKG_VERSION_STRING ", package: " RZ_PACKAGER_VERSION " (" RZ_PACKAGER ")" +# else +# define RZ_STR_PKG_VERSION_STRING ", package: " RZ_PACKAGER_VERSION +# endif +#else +# define RZ_STR_PKG_VERSION_STRING "" +#endif + RZ_API char *rz_str_version(const char *program) { - char *s = rz_str_newf("%s " RZ_VERSION " %d @ " RZ_SYS_OS "-" RZ_SYS_ARCH "-%d git.%s\n", - program, RZ_VERSION_COMMIT, - (RZ_SYS_BITS & 8) ? 64 : 32, - *RZ_GITTAP ? RZ_GITTAP : ""); - if (*RZ_GITTIP) { - s = rz_str_appendf(s, "commit: " RZ_GITTIP " build: " RZ_BIRTH); + RzStrBuf *sb = rz_strbuf_new(NULL); + if (program) { + rz_strbuf_appendf(sb, "%s ", program); } - return s; + rz_strbuf_appendf(sb, RZ_VERSION " @ " RZ_SYS_OS "-" RZ_SYS_ARCH "-%d", + (RZ_SYS_BITS & 8) ? 64 : 32); + 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 ", build: " RZ_BIRTH); + } + return rz_strbuf_drain(sb); } + +#undef RZ_STR_PKG_VERSION_STRING diff --git a/meson.build b/meson.build index 10acf98d79..a65b983f70 100644 --- a/meson.build +++ b/meson.build @@ -7,6 +7,7 @@ pkgconfig_mod = import('pkgconfig') # Python scripts used during the build process create_tags_rz_py = files('sys/create_tags_rz.py') syscall_preprocessing_py = files('sys/syscall_preprocessing.py') +git_exe_repo_py = files('sys/meson_git_wrapper.py') # Get rizin version rizin_version = 'unknown-error' @@ -46,7 +47,7 @@ endif version_commit = '0' gittap = '' -gittip = 'unknown' +gittip = '' git_dir_exists = run_command(py3_exe, '-c', '__import__("sys").exit(0 if __import__("os").path.isdir(".git") else 1)') if git_exe.found() and git_dir_exists.returncode() == 0 @@ -56,19 +57,19 @@ if git_exe.found() and git_dir_exists.returncode() == 0 endif # Get version_commit - git_rev_list = run_command(git_exe, '-C', repo, 'rev-list', '--all', '--count') + git_rev_list = run_command(py3_exe, git_exe_repo_py, git_exe, repo, 'rev-list', '--all', '--count') if git_rev_list.returncode() == 0 version_commit = git_rev_list.stdout().strip() endif # Get gittap - git_describe = run_command(git_exe, '-C', repo, 'describe', '--tags', '--match', '[0-9]*') + git_describe = run_command(py3_exe, git_exe_repo_py, git_exe, repo, 'describe', '--tags', '--match', '[0-9]*') if git_describe.returncode() == 0 gittap = git_describe.stdout().strip() endif # Get gittip - git_rev_parse = run_command(git_exe, '-C', repo, 'rev-parse', 'HEAD') + git_rev_parse = run_command(py3_exe, git_exe_repo_py, git_exe, repo, 'rev-parse', 'HEAD') if git_rev_parse.returncode() == 0 gittip = git_rev_parse.stdout().strip() endif @@ -359,9 +360,17 @@ rz_userconf_h = configure_file( install_dir: rizin_incdir ) +packager = get_option('packager') +packager_version = get_option('packager_version') + +message('Version Major: ' + rizin_version_major) +message('Version Minor: ' + rizin_version_minor) +message('Version Patch: ' + rizin_version_patch) +message('Version GitTap: ' + gittap) +message('Version GitTip: ' + gittip) + versionconf = configuration_data() versionconf.set('MESON_VERSION', meson.version()) -versionconf.set('VERSIONCOMMIT', version_commit) versionconf.set('RZ_VERSION_MAJOR', rizin_version_major) versionconf.set('RZ_VERSION_MINOR', rizin_version_minor) versionconf.set('RZ_VERSION_PATCH', rizin_version_patch) @@ -370,6 +379,12 @@ versionconf.set('RZ_VERSION', rizin_version) versionconf.set('RZ_GITTAP', gittap) versionconf.set('RZ_GITTIP', gittip) versionconf.set('RZ_BIRTH', rizinbirth) +if packager_version != '' + versionconf.set_quoted('RZ_PACKAGER_VERSION', packager_version) + if packager != '' + versionconf.set_quoted('RZ_PACKAGER', packager) + endif +endif rz_version_h = configure_file( input: 'librz/include/rz_version.h.in', output: 'rz_version.h', diff --git a/meson_options.txt b/meson_options.txt index 0e943873fd..e4dc5b329a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,5 @@ +option('packager', type: 'string', value: '', description: 'Extra packager name') +option('packager_version', type: 'string', value: '', description: 'Extra packager version') option('cli', type: 'feature', value: 'auto', description: 'Build CLI programs (“auto” means they will be built when not a subproject)') option('static_runtime', type: 'boolean', value: false) option('local', type: 'feature', value: 'auto', description: 'Adds support for local/side-by-side installation (sets rpath if needed)') diff --git a/shlr/meson.build b/shlr/meson.build index 0845805a7a..bf58dcc5a4 100644 --- a/shlr/meson.build +++ b/shlr/meson.build @@ -44,8 +44,7 @@ if not capstone_dep.found() or not get_option('use_sys_capstone') error('Cannot execute git clone command') endif - reset_cmd_str = '-C @0@ reset --hard @1@'.format(capstone_path, CS_TIP) - reset_cmd = run_command(git_exe, reset_cmd_str.split()) + reset_cmd = run_command(py3_exe, git_exe_repo_py, git_exe, capstone_path, 'reset', '--hard', CS_TIP) if reset_cmd.returncode() != 0 error('Cannot execute git reset command') endif @@ -60,8 +59,7 @@ if not capstone_dep.found() or not get_option('use_sys_capstone') message('Patching capstone with rizin\'s patches') foreach file : patches_files patch_path = join_paths(meson.current_source_dir(), 'capstone-patches', file) - patch_cmd_str = '-C @0@ apply -p1 @1@'.format(capstone_path, patch_path) - patch_cmd = run_command(git_exe, patch_cmd_str.split()) + patch_cmd = run_command(py3_exe, git_exe_repo_py, git_exe, capstone_path, 'apply', '-p1', patch_path) if patch_cmd.returncode() != 0 warning('Cannot apply patch ' + file) endif diff --git a/sys/meson_git_wrapper.py b/sys/meson_git_wrapper.py new file mode 100755 index 0000000000..42cd414dd7 --- /dev/null +++ b/sys/meson_git_wrapper.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +""" Portable python script to execute git -C (even on system where -C is not available) """ + +import os +import sys +import subprocess + +if len(sys.argv) <= 3: + print('Usage: %s [git_args...]') + sys.exit(1) + +git_exe = sys.argv[1] +repo_path = sys.argv[2] +args = sys.argv[3:] + +def isCArgSupported(git_exe, repo_path): + r = subprocess.run([git_exe, '-C', repo_path, 'status'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + return r.returncode == 0 + +if isCArgSupported(git_exe, repo_path): + called = subprocess.run([git_exe, '-C', repo_path] + args) + sys.exit(called.returncode) +else: + os.chdir(repo_path) + called = subprocess.run([git_exe] + args) + sys.exit(called.returncode)