From b4fd8763e8cd72e521b668bf75a0f37061f5762d Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Sun, 18 Aug 2019 10:49:22 +0800 Subject: fix #533 --- xmake/core/base/table.lua | 30 ++++++++++++++++++++++++++++++ xmake/plugins/project/vsxmake/getinfo.lua | 10 +++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index 1f3e79add..1917d827a 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -309,5 +309,35 @@ function table.values(tab) return valueset, n end +-- map values to a new table +function table.map(tab, mapper) + + assert(tab) + if mapper == nil then + return table.copy(tab) + end + + local newtab = {} + for k, v in pairs(tab) do + newtab[k] = mapper(k, v) + end + return newtab +end + +-- map values to a new array +function table.imap(arr, mapper) + + assert(arr) + if mapper == nil then + return table.copy(arr) + end + + local newarr = {} + for k, v in ipairs(arr) do + table.insert(newarr, mapper(k, v)) + end + return newarr +end + -- return module: table return table diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 0ee2605c3..240d93881 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -176,10 +176,7 @@ function _make_targetinfo(mode, arch, target) -- save runenvs local runenvs = {} for k, v in pairs(target:get("runenvs")) do - local defs = {} - for _, d in ipairs(v) do - table.insert(defs, vformat(d)) - end + local defs = table.imap(v, function(_, v) return vformat(v) end) table.insert(runenvs, format("%s=%s", k, path.joinenv(defs))) end targetinfo.runenvs = table.concat(runenvs, "\n") @@ -345,7 +342,10 @@ function main(outputdir, vsinfo) for _,target in pairs(targets) do target._sub2 = {} local dirs = {} - for _,f in ipairs(table.join(target.sourcefiles, target.headerfiles)) do + local root = project.directory() + target.sourcefiles = table.map(target.sourcefiles, function(_, v) return path.relative(v, root) end) + target.headerfiles = table.map(target.headerfiles, function(_, v) return path.relative(v, root) end) + for _, f in ipairs(table.join(target.sourcefiles, target.headerfiles)) do local dir = path.directory(f) target._sub2[f] = { -- cgit v1.3.1 From f23e65985ef61f264df15ff40277d16f35789b4d Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Sun, 18 Aug 2019 10:54:35 +0800 Subject: imap --- xmake/plugins/project/vsxmake/getinfo.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 240d93881..d029a8a4b 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -343,8 +343,8 @@ function main(outputdir, vsinfo) target._sub2 = {} local dirs = {} local root = project.directory() - target.sourcefiles = table.map(target.sourcefiles, function(_, v) return path.relative(v, root) end) - target.headerfiles = table.map(target.headerfiles, function(_, v) return path.relative(v, root) end) + target.sourcefiles = table.imap(target.sourcefiles, function(_, v) return path.relative(v, root) end) + target.headerfiles = table.imap(target.headerfiles, function(_, v) return path.relative(v, root) end) for _, f in ipairs(table.join(target.sourcefiles, target.headerfiles)) do local dir = path.directory(f) target._sub2[f] = -- cgit v1.3.1 From bd4181e0321ec9db4dd6b304db51f5cf6566a484 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Sun, 18 Aug 2019 11:01:11 +0800 Subject: fix map --- xmake/core/base/table.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index 1917d827a..c08526c34 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -313,9 +313,7 @@ end function table.map(tab, mapper) assert(tab) - if mapper == nil then - return table.copy(tab) - end + assert(mapper) local newtab = {} for k, v in pairs(tab) do @@ -328,9 +326,7 @@ end function table.imap(arr, mapper) assert(arr) - if mapper == nil then - return table.copy(arr) - end + assert(mapper) local newarr = {} for k, v in ipairs(arr) do -- cgit v1.3.1