summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-09-12 22:42:20 +0800
committerruki <[email protected]>2024-09-12 22:42:20 +0800
commitb3fa6a33fec098c147e3d978f010f12df5e994f6 (patch)
treea1f33970972a0c779fdb27e4ab7f9e0f56a4a0a9
parente22e69c851c611e5ab42d36e592534dc2e02ea92 (diff)
optimize get sourcefile for export all
-rw-r--r--xmake/rules/utils/symbols/export_all/export_all.lua47
1 files changed, 23 insertions, 24 deletions
diff --git a/xmake/rules/utils/symbols/export_all/export_all.lua b/xmake/rules/utils/symbols/export_all/export_all.lua
index 50d8a8ace..b3a569d97 100644
--- a/xmake/rules/utils/symbols/export_all/export_all.lua
+++ b/xmake/rules/utils/symbols/export_all/export_all.lua
@@ -29,30 +29,27 @@ import("utils.progress")
-- It is not very accurate because some rules automatically
-- generate objectfiles and do not save the corresponding sourcefiles.
-- @see https://github.com/xmake-io/xmake/issues/5601
-function _get_sourcefile_from_objectfile(target, objectfile)
- local sourcefile
+function _get_sourcefiles_map(target, sourcefiles_map)
for _, sourcebatch in pairs(target:sourcebatches()) do
- local sourcefiles = sourcebatch.sourcefiles
- if sourcefiles then
- for idx, obj in ipairs(sourcebatch.objectfiles) do
- if obj == objectfile then
- sourcefile = sourcefiles[idx]
- break
+ for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ local objectfiles = sourcebatch.objectfiles
+ if objectfiles then
+ local objectfile = objectfiles[idx]
+ if objectfile then
+ sourcefiles_map[objectfile] = sourcefile
end
end
end
end
- if not sourcefile then
- for _, dep in ipairs(target:orderdeps()) do
- if dep:is_object() then
- sourcefile = _get_sourcefile_from_objectfile(dep, objectfile)
- if sourcefile then
- break
- end
+ local plaindeps = target:get("deps")
+ if plaindeps then
+ for _, depname in ipairs(plaindeps) do
+ local dep = target:dep(depname)
+ if dep and dep:is_object() then
+ _get_sourcefiles_map(dep, sourcefiles_map)
end
end
end
- return sourcefile
end
-- use dumpbin to get all symbols from object files
@@ -61,13 +58,14 @@ function _get_allsymbols_by_dumpbin(target, dumpbin, opt)
local allsymbols = hashset.new()
local export_classes = opt.export_classes
local export_filter = opt.export_filter
+ local sourcefiles_map = {}
+ if export_filter then
+ _get_sourcefiles_map(target, sourcefiles_map)
+ end
for _, objectfile in ipairs(target:objectfiles()) do
local objectsymbols = try { function () return os.iorunv(dumpbin, {"/symbols", "/nologo", objectfile}) end }
if objectsymbols then
- local sourcefile
- if export_filter then
- sourcefile = _get_sourcefile_from_objectfile(target, objectfile)
- end
+ local sourcefile = sourcefiles_map[objectfile]
for _, line in ipairs(objectsymbols:split('\n', {plain = true})) do
-- https://docs.microsoft.com/en-us/cpp/build/reference/symbols
-- 008 00000000 SECT3 notype () External | add
@@ -108,13 +106,14 @@ function _get_allsymbols_by_objdump(target, objdump, opt)
local allsymbols = hashset.new()
local export_classes = opt.export_classes
local export_filter = opt.export_filter
+ local sourcefiles_map = {}
+ if export_filter then
+ _get_sourcefiles_map(target, sourcefiles_map)
+ end
for _, objectfile in ipairs(target:objectfiles()) do
local objectsymbols = try { function () return os.iorunv(objdump, {"--syms", objectfile}) end }
if objectsymbols then
- local sourcefile
- if export_filter then
- sourcefile = _get_sourcefile_from_objectfile(target, objectfile)
- end
+ local sourcefile = sourcefiles_map[objectfile]
for _, line in ipairs(objectsymbols:split('\n', {plain = true})) do
if line:find("(scl 2)", 1, true) then
local splitinfo = line:split("%s")