diff options
| author | Domain <[email protected]> | 2022-06-05 01:31:44 +0800 |
|---|---|---|
| committer | Domain <[email protected]> | 2022-06-05 13:01:29 +0800 |
| commit | 259e08de4b887f91e598f2d62f460c80633f48d9 (patch) | |
| tree | 99ee228f536d77b3e40d8ddf6f8d823a27f8df43 /xmake/plugins/project/vsxmake/render.lua | |
| parent | b19dec5ac1139bcf551165fd1838902bdaa449b8 (diff) | |
Non-default target can be built in vs
Diffstat (limited to 'xmake/plugins/project/vsxmake/render.lua')
| -rw-r--r-- | xmake/plugins/project/vsxmake/render.lua | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/xmake/plugins/project/vsxmake/render.lua b/xmake/plugins/project/vsxmake/render.lua index d599f1dde..6fb1cbc57 100644 --- a/xmake/plugins/project/vsxmake/render.lua +++ b/xmake/plugins/project/vsxmake/render.lua @@ -32,6 +32,33 @@ function _fill(opt, params) end end +function _cfill(opt, params) + return function(match) + local tmp = match:split(";", {strict = 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("=") + 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 + function _expand(params) local r = {""} for _, v in ipairs(params) do @@ -46,7 +73,7 @@ function _expand(params) for i, p in ipairs(r) do rcopy[i] = p .. "\0" .. c end - newr = table.join(newr, rcopy) + newr = table.join(newr, rcopy) end r = newr end @@ -58,17 +85,17 @@ function _expand(params) end function _render(templatepath, opt, args) - local template = io.readfile(templatepath) local params = _expand(opt.paramsprovider(args)) local replaced = "" for _, v in ipairs(params) do - replaced = replaced .. template:gsub(opt.pattern, _fill(opt, v)) + local tmpl = template:gsub(opt.cpattern, _cfill(opt, v)) + replaced = replaced .. tmpl:gsub(opt.pattern, _fill(opt, v)) end return replaced end -function main(templatepath, pattern, paramsprovider) - local opt = { pattern = pattern, paramsprovider = paramsprovider, templatedir = path.directory(templatepath) } +function main(templatepath, pattern, cpattern, paramsprovider) + local opt = { pattern = pattern, cpattern = cpattern, paramsprovider = paramsprovider, templatedir = path.directory(templatepath) } return _render(templatepath, opt, {}) end |
