From dc8cd44db4ae1d6c1ac5cf5b47f7cb553304ea4d Mon Sep 17 00:00:00 2001 From: Khairul Azhar Kasmiran Date: Sat, 6 Aug 2022 21:21:07 +0800 Subject: [PATCH] gittip: Use `subprocess.PIPE` instead for Python 3.6 compatibility (#2873) --- librz/util/str.c | 1 - meson.build | 1 - sys/meson_git_wrapper.py | 11 ++++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/librz/util/str.c b/librz/util/str.c index 6285e2c28bb..1842ac3b276 100644 --- a/librz/util/str.c +++ b/librz/util/str.c @@ -4067,7 +4067,6 @@ RZ_API char *rz_str_version(const char *program) { if (!gittip || !*rz_str_trim_head_ro(gittip)) { goto done; } - rz_str_trim(gittip); rz_strbuf_append(sb, "\n"); rz_strbuf_appendf(sb, "commit: %s", gittip); done: diff --git a/meson.build b/meson.build index 406e4059196..f049a34304b 100644 --- a/meson.build +++ b/meson.build @@ -524,7 +524,6 @@ if git_exe.found() and fs.exists('.git') build_by_default: true, output: 'gittip', command: [py3_exe, git_exe_repo_py, git_exe, repo, 'rev-parse', 'HEAD'], - capture: true, install: true, install_dir: rizin_bindir ) diff --git a/sys/meson_git_wrapper.py b/sys/meson_git_wrapper.py index 8e73a7fdadc..60d7213bc62 100755 --- a/sys/meson_git_wrapper.py +++ b/sys/meson_git_wrapper.py @@ -23,9 +23,13 @@ def isCArgSupported(executable, path): return False -def simple_git_execution(args): +def simple_git_execution(args, gittip_dir=None): try: - called = subprocess.run(args, check=True) + called = subprocess.run(args, check=True, stdout=subprocess.PIPE) + if gittip_dir is not None: + os.chdir(gittip_dir) + 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) @@ -53,8 +57,9 @@ def main(): if isCArgSupported(git_exe, repo_path): simple_git_execution([git_exe, "-C", repo_path] + args) else: + gittip_dir = os.getcwd() os.chdir(repo_path) - simple_git_execution([git_exe] + args) + simple_git_execution([git_exe] + args, gittip_dir) if __name__ == "__main__":