From 0d7f04bd526bf8a6a5e808a29ad49d3cdf1ff0be Mon Sep 17 00:00:00 2001 From: solomocyj Date: Thu, 12 Dec 2024 09:13:33 +0800 Subject: [PATCH] feat: set up macros for buildrequires generation --- data/macros.meson | 5 +++++ data/mesongenbuildreq.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 data/mesongenbuildreq.py diff --git a/data/macros.meson b/data/macros.meson index dcac9d98553c..237f583585ad 100644 --- a/data/macros.meson +++ b/data/macros.meson @@ -45,3 +45,8 @@ --num-processes %{_smp_build_ncpus} \ --print-errorlogs \ %{nil}} + +%meson_buildrequires \ + %{shrink: mesongenbuildreq %{__meson} \ + %{nil}} + diff --git a/data/mesongenbuildreq.py b/data/mesongenbuildreq.py new file mode 100644 index 000000000000..42c28d9bab33 --- /dev/null +++ b/data/mesongenbuildreq.py @@ -0,0 +1,29 @@ +import subprocess +import json +import sys +deps_json = json.loads(subprocess.run([sys.argv[0], "introspect", "--dependencies", "meson.build"], capture_output=True).stdout) +deps = dict(zip([x['name'] for x in deps_json],[x['version'] for x in deps_json])) +deps.pop('', None) +for lib, versions in deps.items() : + # Mapping for special cases + pkg_map = { + 'qt6': 'cmake', + 'KF6WindowSystem': 'cmake', + 'gtk+-3.0': 'pkgconfig', + 'dbus-1': 'pkgconfig', + 'ncursesw': 'pkgconfig', + 'harfbuzz': 'pkgconfig', + 'fribidi': 'pkgconfig', + # Add more mappings as needed + } + # Determine the prefix + prefix = pkg_map.get(lib, 'pkgconfig') + + # Prepare version constraint + version_str = ' ' + ' '.join(versions) if versions else '' + + # Generate BuildRequires line + buildreq = (f"BuildRequires: {prefix}({lib}){version_str}") + if buildreq.split('=')[-1] == '' and '=' in buildreq : + buildreq = buildreq.split('=')[0] + print(buildreq)