diff --git a/functions.lua b/functions.lua index 41eaa0b..f41b829 100644 --- a/functions.lua +++ b/functions.lua @@ -43,3 +43,18 @@ function string.split(str, sep) string.gsub(str, '[^'..sep..']+', func) return res end + +function arg_compat() + --[[ + Compat macro as workaround for older rpm not having function + arguments available as table arg(uments) + --]] + local arg_count = rpm.expand("%#") + local arg = {} + + for arg_num = 1,arg_count do + arg[arg_num] = rpm.expand(("%" .. arg_num)) + end + + return arg +end diff --git a/macros.lua b/macros.lua index dc0fd5d..d1c97cf 100644 --- a/macros.lua +++ b/macros.lua @@ -32,6 +32,12 @@ function treesitter_grammars() local treesitter_grammar_names = "" local treesitter_grammar_libnames = "" + local arg = arg + local suse_version = tonumber(rpm.expand("%suse_version")) + if suse_version < 1600 then + arg = arg_compat() + end + for arg_num = 1,#arg do treesitter_grammar_libnames=treesitter_grammar_libnames .. base_libname .. "-" .. arg[arg_num] .. ".so " end @@ -42,7 +48,6 @@ function treesitter_grammars() print("Provides: treesitter_grammar(" .. base_name .. "-" .. arg[arg_num] .. ")\n") end rpm.define("treesitter_grammar_names " .. treesitter_grammar_names) - end @@ -76,6 +81,11 @@ function treesitter_build() rpm.expand("%_treesitter_macro_init") local basename = rpm.expand("%{_treesitter_grammar_base_libname}") local grammar_names = rpm.expand("%treesitter_grammar_names") + local arg = arg + local suse_version = tonumber(rpm.expand("%suse_version")) + if suse_version < 1600 then + arg = arg_compat() + end local left_over_args = arg[1] local grammar_arg_binding = "" @@ -170,6 +180,12 @@ function treesitter_devel_install() return end + local arg = arg + local suse_version = tonumber(rpm.expand("%suse_version")) + if suse_version < 1600 then + arg = arg_compat() + end + if #arg > 0 then --[[ FIXME: This maybe not be the best solution if packages can have a single grammar but also addon files diff --git a/tree-sitter.changes b/tree-sitter.changes index a4521ef..010423c 100644 --- a/tree-sitter.changes +++ b/tree-sitter.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Mar 25 21:58:38 UTC 2024 - Björn Bidar + +- Add workaround to packaging macros for RPM being to old on current Leap +- Add workaround for Python below 3.9 on Leap + ------------------------------------------------------------------- Fri Mar 22 19:35:31 UTC 2024 - Björn Bidar diff --git a/treesitter_grammar.req b/treesitter_grammar.req index 910ec77..aa4efd3 100644 --- a/treesitter_grammar.req +++ b/treesitter_grammar.req @@ -7,12 +7,23 @@ # pylint: disable=invalid-name +import platform import fileinput import re from typing import Optional from pathlib import Path +if platform.sys.version_info.minor < 9: + def remove_prefix(text, prefix): + if text.startswith(prefix): + return text[len(prefix):] + return text + def remove_suffix(text, suffix): + if text.endswith(suffix): + return text[:-len(suffix):] + return text + treeSitterGrammarSrcPath = "/usr/include/tree_sitter" treeSitterGrammarSymbolToken = "treesitter_grammar_src" grammarPaths = [] @@ -57,10 +68,17 @@ def dummyRequire(requiredFile_fd: str, maxDepth: Optional[int] = 5 ) -> str: requiredLvl2 = re.match(require_re, r_line) #print(r_line) if requiredLvl2 is not None: - requiredLvl2_grp_cleaned = \ - requiredLvl2.group(1).removeprefix("'").removesuffix("'") - requiredLvl2_grp_cleaned = \ - requiredLvl2_grp_cleaned.removeprefix("\"").removesuffix("\"") + if platform.sys.version_info.minor < 9: + requiredLvl2_grp_cleaned = \ + remove_suffix(remove_prefix(requiredLvl2.group(1), "'"), "'") + requiredLvl2_grp_cleaned = \ + remove_suffix(remove_prefix(requiredLvl2_grp_cleaned, "\""), + "\"") + else: + requiredLvl2_grp_cleaned = \ + requiredLvl2.group(1).removeprefix("'").removesuffix("'") + requiredLvl2_grp_cleaned = \ + requiredLvl2_grp_cleaned.removeprefix("\"").removesuffix("\"") if not requiredLvl2_grp_cleaned.split('/')[0] == "..": # Don't emit dependencies which are local pass diff --git a/vendor.tar.zst b/vendor.tar.zst index 04dbb9d..d612809 100644 --- a/vendor.tar.zst +++ b/vendor.tar.zst @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8158ba3e18b25a81d41e6937d120597630a57181996355154197e6988d632030 -size 30391447 +oid sha256:636609804ef5535c53a60e42ff1fac0a35d29aac4df98bd308fe2e7b25492b60 +size 30401756