forked from pool/lua-macros
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`.
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
-------------------------------------------------------------------
|
||||
Sat Oct 11 16:45:06 UTC 2025 - Matej Cepl <mcepl@cepl.eu>
|
||||
|
||||
- Rework Lua version and path macros using RPM Lua blocks.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Fri Oct 10 10:56:01 UTC 2025 - Matej Cepl <mcepl@cepl.eu>
|
||||
|
||||
|
||||
34
macros.lua
34
macros.lua
@@ -1,23 +1,40 @@
|
||||
# RPM macros for Lua
|
||||
|
||||
# The major.minor version of Lua
|
||||
%lua_version %(lua -e 'print(_VERSION)' | cut -d ' ' -f 2)
|
||||
%lua_version_nodots %(lua -e 'print((string.gsub("%{lua_version}", "%.", "")))')
|
||||
%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")
|
||||
local output = f:read("*a")
|
||||
f:close()
|
||||
|
||||
if output:len() == 0 then
|
||||
%lua_noarchdir %{_datadir}/lua/%{lua_version}/luacheck/
|
||||
else
|
||||
%lua_noarchdir %(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)
|
||||
|
||||
@@ -41,6 +58,7 @@ print(result)
|
||||
%{nil}
|
||||
|
||||
# Lua default version
|
||||
# This REQUIRES macro %{mod_name} to be defined.
|
||||
# -e: Exclude lua prefix
|
||||
# -n: Specify name
|
||||
%lua_provides(en:) \
|
||||
|
||||
Reference in New Issue
Block a user