Skip to content

Commit

Permalink
Merge pull request #5588 from xmake-io/vsxmake
Browse files Browse the repository at this point in the history
optimize vsxmake render #5573
  • Loading branch information
waruqi committed Sep 9, 2024
2 parents 8f0151d + a883d8f commit 1dfec90
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions xmake/plugins/project/vsxmake/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
-- @file render.lua
--

-- imports
import("lib.detect.find_file")

function _fill(opt, params)
return function(match)
local imp = match:match("^Import%((.+)%)$")
if imp then
local funcs = os.files(path.join(opt.templatedir, imp .. "(*)"))
assert(#funcs == 1)
local func = funcs[1]
local args = path.filename(func):match("%((.+)%)$"):split(",")
local func = find_file(imp .. "(*)", opt.templatedir)
assert(func)
local args = path.filename(func):match("%((.+)%)$"):split(",", {plain = true})
return _render(func, opt, args)
end
return opt.paramsprovider(match, params) or "<Not Provided>"
Expand All @@ -34,27 +36,24 @@ end

function _cfill(opt, params)
return function(match)
local tmp = match:split(";", {strict = true})
local tmp = match:split(";", {strict = true, plain = true})
assert(#tmp == 2 or #tmp == 3)

local cond = tmp[1]
local value1 = tmp[2]
local value2 = ""

if #tmp == 3 then
value2 = tmp[3]
end

tmp = cond:split("=")
tmp = cond:split("=", {plain = true})
assert(#tmp == 2)

local k = tmp[1]:trim()
local v = tmp[2]:trim()

if opt.paramsprovider(k, params) == v then
return value1
end

return value2
end
end
Expand All @@ -69,11 +68,9 @@ function _expand(params)
else
local newr = {}
for _, c in ipairs(v) do
local rcopy = {}
for i, p in ipairs(r) do
rcopy[i] = p .. "\0" .. c
for _, p in ipairs(r) do
table.insert(newr, p .. "\0" .. c)
end
newr = table.join(newr, rcopy)
end
r = newr
end
Expand All @@ -96,6 +93,12 @@ function _render(templatepath, opt, args)
end

function main(templatepath, pattern, cpattern, paramsprovider)
local opt = { pattern = pattern, cpattern = cpattern, paramsprovider = paramsprovider, templatedir = path.directory(templatepath) }
local opt = {
pattern = pattern,
cpattern = cpattern,
paramsprovider = paramsprovider,
templatedir = path.directory(templatepath)
}
return _render(templatepath, opt, {})
end

0 comments on commit 1dfec90

Please sign in to comment.