summaryrefslogtreecommitdiff
path: root/xmake/plugins/pack/runself/main.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2024-07-23 23:44:08 +0800
committerruki <[email protected]>2024-07-23 23:44:08 +0800
commit694c0ac091263a7bfeeda55cfc5a6a816c516a95 (patch)
tree90d1be01bbf3d9eb047f7d3e5d61ec8ff0e188de /xmake/plugins/pack/runself/main.lua
parent9e1643aee954cdadea3eba96f3242b0a55ab6898 (diff)
fix pack io.gsub
Diffstat (limited to 'xmake/plugins/pack/runself/main.lua')
-rw-r--r--xmake/plugins/pack/runself/main.lua31
1 files changed, 21 insertions, 10 deletions
diff --git a/xmake/plugins/pack/runself/main.lua b/xmake/plugins/pack/runself/main.lua
index eb5c01fb1..4343b1a76 100644
--- a/xmake/plugins/pack/runself/main.lua
+++ b/xmake/plugins/pack/runself/main.lua
@@ -117,19 +117,30 @@ function _pack_runself(makeself, package)
-- replace variables in specfile
local specvars = _get_specvars(package)
local pattern = package:extraconf("specfile", "pattern") or "%${([^\n]-)}"
+ local specvars_names = {}
+ local specvars_values = {}
io.gsub(specfile, "(" .. pattern .. ")", function(_, name)
+ table.insert(specvars_names, name)
+ end)
+ for _, name in ipairs(specvars_names) do
name = name:trim()
- local value = specvars[name]
- if type(value) == "function" then
- value = value()
- end
- if value ~= nil then
- dprint(" > replace %s -> %s", name, value)
- end
- if type(value) == "table" then
- dprint("invalid variable value", value)
+ if specvars_values[name] == nil then
+ local value = specvars[name]
+ if type(value) == "function" then
+ value = value()
+ end
+ if value ~= nil then
+ dprint(" > replace %s -> %s", name, value)
+ end
+ if type(value) == "table" then
+ dprint("invalid variable value", value)
+ end
+ specvars_values[name] = value
end
- return value
+ end
+ io.gsub(specfile, "(" .. pattern .. ")", function(_, name)
+ name = name:trim()
+ return specvars_values[name]
end)
-- archive source files