From 852692aee08ee1f41177640bcc456fb9043bbc91 Mon Sep 17 00:00:00 2001 From: Giridhar Prasath R Date: Sat, 21 Sep 2024 05:30:20 -0400 Subject: [PATCH] fix subproject compiling --- meson.build | 9 ++++ sys/check_meson_subproject.py | 77 +++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 sys/check_meson_subproject.py diff --git a/meson.build b/meson.build index e0bd4bb..f229b1f 100644 --- a/meson.build +++ b/meson.build @@ -6,6 +6,10 @@ project('rz_solver', 'c', cc = meson.get_compiler('c') rz_core_dep = dependency('rz_core') +py3_exe = import('python').find_installation() +check_meson_subproject_py = files('sys/check_meson_subproject.py') +subproject_clean_error_msg = 'Subprojects are not updated. Please run `git clean -dxff subprojects/` to delete all local subprojects directories.' + # handle z3 library sys_z3_opt = get_option('use_sys_z3') z3_dep = disabler() @@ -20,6 +24,11 @@ if (sys_z3_opt.auto() and not z3_dep.found()) or sys_z3_opt.disabled() z3_dep = z3_proj.get_variable('z3_dep') endif +r = run_command(py3_exe, check_meson_subproject_py, 'z3', check: false) +if r.returncode() == 1 + error(subproject_clean_error_msg) +endif + rz_solver_deps = [ rz_core_dep, #rz_rop_dep, diff --git a/sys/check_meson_subproject.py b/sys/check_meson_subproject.py new file mode 100644 index 0000000..de8a539 --- /dev/null +++ b/sys/check_meson_subproject.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python +# +# SPDX-FileCopyrightText: 2021 ret2libc +# SPDX-FileCopyrightText: 2021 deroad +# SPDX-License-Identifier: LGPL-3.0-only +# +# NOTE: Lifted from rizinorg/rizin project +# This script is necessary to make sure people notice a subproject has been +# changed and need to be updated. Meson does not warn you now (0.56.0) + +""" Portable python script to check if subproject is up-to-date and warn if not """ + +import filecmp +import os +import sys + +subproject = sys.argv[1] +meson_root = os.environ["MESON_SOURCE_ROOT"] + +subproject_filename = os.path.join(meson_root, "subprojects", subproject + ".wrap") + +try: + with open(subproject_filename, "r", encoding="utf8") as f: + is_wrap_git = False + revision = None + directory = subproject + patch_directory = subproject + for l in f: + if "wrap-git" in l: + is_wrap_git = True + elif "wrap-file" in l: + is_wrap_file = True + elif l.startswith("revision"): + revision = l.split("=")[1].strip() + elif l.startswith("directory"): + directory = l.split("=")[1].strip() + elif l.startswith("patch_directory"): + patch_directory = l.split("=")[1].strip() + + if is_wrap_git: + if not revision: + sys.exit(0) + + subproject_dir = os.path.join(meson_root, "subprojects", directory) + subproject_git_dir = os.path.join(subproject_dir, ".git") + if os.path.isdir(subproject_dir) and os.path.isdir(subproject_git_dir): + with open( + os.path.join(subproject_git_dir, "HEAD"), "r", encoding="utf8" + ) as f: + head = f.read().strip() + # when using a branch name, head is 'refs/heads/' + if head != revision and revision not in head: + sys.exit(1) + + if not patch_directory: + sys.exit(0) + + subproject_dir = os.path.join(meson_root, "subprojects", directory) + patch_subproject_dir = os.path.join( + meson_root, "subprojects", "packagefiles", patch_directory + ) + if os.path.isdir(patch_subproject_dir) and os.path.isdir(subproject_dir): + for root, dirs, files in os.walk(patch_subproject_dir, topdown=False): + for name in files: + subproject_f = os.path.join(root, name) + subproject_p_f = subproject_f.replace( + patch_subproject_dir, subproject_dir + ) + if not os.path.isfile(subproject_f): + sys.exit(2) + + if not filecmp.cmp(subproject_p_f, subproject_f): + sys.exit(3) + + sys.exit(0) +except FileNotFoundError: + sys.exit(0)