7
0
forked from pool/lua-macros

14 Commits

Author SHA256 Message Date
521e3b1dc4 fix: convert %lua_provides to pure Lua for better control
Converts the logic within the %lua_provides macro from a
multi-line string of RPM macros to native Lua code. This allows
for more robust conditional logic, especially when checking for
default Lua versions and handling provides/obsoletes.
2025-11-03 01:21:47 +01:00
d1f0f1035b One level down to copy. 2025-10-21 00:38:19 +02:00
60b20c88fb Rewrite %luarocks_install to use a shell script
install-lua-rock.sh, which is packaged as well.
2025-10-21 00:05:32 +02:00
6e7d7d058f Fix %luarocks_* macros. 2025-10-15 03:04:59 +02:00
8ee4d34fad fix: we cannot use %global in a macro file 2025-10-14 14:50:29 +02:00
c1d442702b Fix %%lua_provides. 2025-10-14 12:38:25 +02:00
d4f21b0c0c Quote %%lua_archdir macro. 2025-10-13 19:20:45 +02:00
984b4bf4f2 feat: Rework Lua version and path macros using RPM Lua blocks
The `%lua_version`, `%lua_version_nodots`, and `%lua_noarchdir`
macros have been refactored to use the RPM internal Lua
interpreter blocks (`%{lua:...}`) instead of relying solely on
shell command execution (`%()`).

This change offers several benefits:
1. Consistency: Standardizes the approach, as other macros like
   `%lua_version_default` already use RPM Lua blocks.
2. Robustness: Improves path handling by explicitly trimming
   whitespace/newlines from the `pkgconf` output in
   `%lua_noarchdir`.
3. Clarity: Simplifies the logic for extracting the version
   number and calculating the no-dots version.

The `%lua_noarchdir` logic was also improved to correctly handle
a failure of the `pkgconf` command (e.g., when the package isn't
installed) by checking for `f == nil`.

A comment was also added to `%lua_provides` to clarify the
required definition of `%mod_name`.
2025-10-12 01:17:14 +02:00
21cfcf02e2 chore: I can use a good Makefile for some testing 2025-10-11 01:29:30 +02:00
22fe4289a4 Make %{lua_noarchdir} work even without lua-devel installed. 2025-10-10 12:56:20 +02:00
db9766d6bd Make definition of variables dynamic based on pkgconf output 2025-10-10 00:44:13 +02:00
df6ced835e Run obs-git-init . 2025-10-10 00:27:10 +02:00
efd19cb701 On Factory BR lua-interpreter. 2025-08-05 16:05:45 +02:00
91f3720965 Add functional .gitignore. 2025-08-04 15:20:48 +02:00
6 changed files with 73 additions and 32 deletions

4
.gitattributes vendored
View File

@@ -1,4 +1,4 @@
*.changes merge=merge-changes
## Default LFS
*.7z filter=lfs diff=lfs merge=lfs -text
*.bsp filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
@@ -12,7 +12,6 @@
*.pdf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.rpm filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tbz filter=lfs diff=lfs merge=lfs -text
*.tbz2 filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
@@ -22,3 +21,4 @@
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*.changes merge=merge-changes

8
.gitignore vendored
View File

@@ -1 +1,9 @@
.osc
_scmsync.obsinfo
_buildconfig-*
_buildinfo-*.xml
lua-macros-*-build/
*.obscpio
*.osc
_build.*
.pbuild

15
install-lua-rock.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
set -ex
# 1. %{lua_version}
# 2. %{buildroot}%{_prefix}
# 3. %{buildroot}%{luarocks_treedir}/%{mod_name}
SOURCE_DIR="$3"
luarocks --lua-version="$1" --tree="$2" install --deps-mode=none --no-manifest "${*:$#}"
if [ -d "${SOURCE_DIR}" ] && [ "$(find "${SOURCE_DIR}" -type f | wc -l)" -gt 0 ]
then
mkdir -p __rocktree
mv -v "${SOURCE_DIR}"/*/* __rocktree
fi

View File

@@ -1,3 +1,16 @@
-------------------------------------------------------------------
Mon Nov 3 00:20:49 UTC 2025 - Matej Cepl <mcepl@cepl.eu>
- Finally broke %lua_provides to be working. I got stumped by the
craziness of rpm which runs Lua interpreter with locales and
crazy reformatting of integers.
-------------------------------------------------------------------
Mon Oct 20 21:30:36 UTC 2025 - Matej Cepl <mcepl@cepl.eu>
- Rewrite %luarocks_install to use a shell script
install-lua-rock.sh, which is packaged as well.
-------------------------------------------------------------------
Tue Oct 14 23:16:09 UTC 2025 - Matej Cepl <mcepl@cepl.eu>

View File

@@ -27,6 +27,7 @@ License: MIT
Group: Development/Languages/Other
URL: https://www.lua.org
Source0: macros.lua
Source1: install-lua-rock.sh
%if 0%{?suse_version} > 1600
Requires: lua-interpreter
%elif 0%{?suse_version} >= 1500
@@ -34,9 +35,6 @@ Requires: lua-interpreter
Requires: lua
%endif
Requires: pkgconfig
%if "%_vendor" != "debbuild"
ExclusiveArch: do_not_build
%endif
BuildArch: noarch
%description
@@ -49,9 +47,11 @@ cp -p %{SOURCE0} .
:
%install
install -Dm644 macros.lua %{buildroot}%{_rpmmacrodir}/macros.lua
install -Dm644 %{SOURCE0} %{buildroot}%{_rpmmacrodir}/macros.lua
install -Dm755 %{SOURCE1} %{buildroot}%{_rpmconfigdir}/install-lua-rock.sh
%files
%{_rpmmacrodir}/macros.lua
%{_rpmconfigdir}/install-lua-rock.sh
%changelog

View File

@@ -44,14 +44,14 @@ print(rpm.expand("%{_datadir}/lua/%{lua_version}"))
print(result)
}
%lua_version_default %{lua:
local result = 5.4
local result = "5.4"
local ver = rpm.expand("%{?suse_version}")
if #ver > 0 then
ver = tonumber(ver)
if ver < 1500 then
result = 5.1
result = "5.1"
elseif ver < 1600 then
result = 5.3
result = "5.3"
end
end
print(result)
@@ -63,31 +63,39 @@ print(result)
print(nodots)
}
# Lua default version
# This REQUIRES macro %{mod_name} to be defined.
# This REQUIRES macro %%{mod_name} to be defined.
# -e: Exclude lua prefix
# -n: Specify name
%lua_provides(en:) %{lua:
local mod_name = rpm.expand("%{?mod_name}")
if mod_name == "" then
print("-- Error: %{mod_name} is not defined!")
if mod_name == "" or mod_name == "%{?mod_name}" then
print("-- Error: %%{mod_name} is not defined!")
return
end
print([[
%if "%{lua_version_nodots}" == "%{lua_version_default_nodots}"
%if 0%{?-n:1}
Provides: %{-n*} = %{version}-%{release}
Obsoletes: %{-n*} < %{version}-%{release}
%else
%if 0%{?-e:1}
Provides: %{mod_name} = %{version}-%{release}
Obsoletes: %{mod_name} < %{version}-%{release}
%else
Provides: lua-%{mod_name} = %{version}-%{release}
Obsoletes: lua-%{mod_name} < %{version}-%{release}
%endif
%endif
%endif
]])
local lua_ver_nodots = rpm.expand("%{lua_version_nodots}")
local lua_ver_default_nodots = rpm.expand("%{lua_version_default_nodots}")
local flavor = rpm.expand("%{flavor}")
local version = rpm.expand("%{version}")
local release = rpm.expand("%{release}")
local provides_name
if rpm.expand("%{-n*}") ~= "" then
provides_name = rpm.expand("%{-n*}")
elseif rpm.expand("%{-e:1}") == "1" then
provides_name = mod_name
else
provides_name = "lua-" .. mod_name
end
if lua_ver_nodots == lua_ver_default_nodots then
print("Provides: " .. provides_name .. " = " .. version .. "-" .. release .. "\\n")
print("Obsoletes: " .. provides_name .. " < " .. version .. "-" .. release .. "\\n")
end
if flavor == "luajit" then
print("Obsoletes: lua51-" .. mod_name .. " <= " .. version .. "-" .. release .. "\\n")
end
}
# LuaRocks
@@ -97,7 +105,4 @@ luarocks --lua-version "%{lua_version}" make --deps-mode none --pack-binary-rock
%luarocks_treedir %{_prefix}/lib/luarocks/rocks-%{lua_version}
%luarocks_install \
/bin/sh -c 'luarocks --lua-version="%{lua_version}" --tree="%{buildroot}%{_prefix}" install --deps-mode=none --no-manifest "$@" && \
source_dir="%{buildroot}%{luarocks_treedir}/%{mod_name}/%{rock_version}" && \
[ -d "${source_dir}" ] && [ "$(ls -A "${source_dir}" | wc -l)" -gt 0 ] && \
mv -v "${source_dir}" __rocktree' --
%{_rpmconfigdir}/install-lua-rock.sh "%{lua_version}" "%{buildroot}%{_prefix}" "%{buildroot}%{luarocks_treedir}/%{mod_name}"