SHA256
10
0
forked from pool/lua-macros
Files
lua-macros/macros.lua
Matěj Cepl 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

91 lines
2.1 KiB
Lua

# RPM macros for Lua
# The major.minor version of Lua
%lua_version %{lua:
local f = io.popen("lua -e 'print(_VERSION)'")
local output = f:read("*a")
f:close()
local ver = output:match("Lua (%d%.%d)")
print(ver)
}
%lua_version_nodots %{lua:
local ver = rpm.expand("%{lua_version}")
local nodots = ver:gsub("%.", "")
print(nodots)
}
# compiled modules should go here
%lua_archdir %(pkgconf --variable=INSTALL_CMOD lua)
# pure Lua modules should go here
%lua_noarchdir %{lua:
local output = ""
local f = io.popen("pkgconf --variable=INSTALL_LMOD lua")
if f ~= nil then
output = f:read("*a"):gsub("^%s*(.-)%s*$", "%1")
f:close()
end
if output:len() > 0 then
print(output)
return
end
print(rpm.expand("%{_datadir}/lua/%{lua_version}"))
}
# lua includes folder
%lua_incdir %(pkgconf --variable=includedir lua)
%lua_version_default %{lua:
local result = 5.4
local ver = rpm.expand("%{?suse_version}")
if #ver > 0 then
ver = tonumber(ver)
if ver < 1500 then
result = 5.1
elseif ver == 1500 then
result = 5.3
end
end
print(result)
}
%lua_version_default_nodots %(lua -e 'print((string.gsub("%{lua_version_default}", "%.", "")))')
%ifluadefault \
%if %{lua_version_nodots} == %{lua_version_default_nodots} \
%{nil}
# Lua default version
# This REQUIRES macro %{mod_name} to be defined.
# -e: Exclude lua prefix
# -n: Specify name
%lua_provides(en:) \
%ifluadefault \
%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 \
%{nil}
# LuaRocks
%luarocks_build \
luarocks --lua-version "%{lua_version}" \\\
make --pack-binary-rock --deps-mode none
%luarocks_install \
luarocks --lua-version="%{lua_version}" --tree="%{buildroot}%{_prefix}" \\\
install --deps-mode=none --no-manifest
%luarocks_treedir %{_prefix}/lib/luarocks/rocks-%{lua_version}