Skip to content

Commit b3fa6a3

Browse files
committed
optimize get sourcefile for export all
1 parent e22e69c commit b3fa6a3

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

xmake/rules/utils/symbols/export_all/export_all.lua

+23-24
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,27 @@ import("utils.progress")
2929
-- It is not very accurate because some rules automatically
3030
-- generate objectfiles and do not save the corresponding sourcefiles.
3131
-- @see https://github.com/xmake-io/xmake/issues/5601
32-
function _get_sourcefile_from_objectfile(target, objectfile)
33-
local sourcefile
32+
function _get_sourcefiles_map(target, sourcefiles_map)
3433
for _, sourcebatch in pairs(target:sourcebatches()) do
35-
local sourcefiles = sourcebatch.sourcefiles
36-
if sourcefiles then
37-
for idx, obj in ipairs(sourcebatch.objectfiles) do
38-
if obj == objectfile then
39-
sourcefile = sourcefiles[idx]
40-
break
34+
for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do
35+
local objectfiles = sourcebatch.objectfiles
36+
if objectfiles then
37+
local objectfile = objectfiles[idx]
38+
if objectfile then
39+
sourcefiles_map[objectfile] = sourcefile
4140
end
4241
end
4342
end
4443
end
45-
if not sourcefile then
46-
for _, dep in ipairs(target:orderdeps()) do
47-
if dep:is_object() then
48-
sourcefile = _get_sourcefile_from_objectfile(dep, objectfile)
49-
if sourcefile then
50-
break
51-
end
44+
local plaindeps = target:get("deps")
45+
if plaindeps then
46+
for _, depname in ipairs(plaindeps) do
47+
local dep = target:dep(depname)
48+
if dep and dep:is_object() then
49+
_get_sourcefiles_map(dep, sourcefiles_map)
5250
end
5351
end
5452
end
55-
return sourcefile
5653
end
5754

5855
-- use dumpbin to get all symbols from object files
@@ -61,13 +58,14 @@ function _get_allsymbols_by_dumpbin(target, dumpbin, opt)
6158
local allsymbols = hashset.new()
6259
local export_classes = opt.export_classes
6360
local export_filter = opt.export_filter
61+
local sourcefiles_map = {}
62+
if export_filter then
63+
_get_sourcefiles_map(target, sourcefiles_map)
64+
end
6465
for _, objectfile in ipairs(target:objectfiles()) do
6566
local objectsymbols = try { function () return os.iorunv(dumpbin, {"/symbols", "/nologo", objectfile}) end }
6667
if objectsymbols then
67-
local sourcefile
68-
if export_filter then
69-
sourcefile = _get_sourcefile_from_objectfile(target, objectfile)
70-
end
68+
local sourcefile = sourcefiles_map[objectfile]
7169
for _, line in ipairs(objectsymbols:split('\n', {plain = true})) do
7270
-- https://docs.microsoft.com/en-us/cpp/build/reference/symbols
7371
-- 008 00000000 SECT3 notype () External | add
@@ -108,13 +106,14 @@ function _get_allsymbols_by_objdump(target, objdump, opt)
108106
local allsymbols = hashset.new()
109107
local export_classes = opt.export_classes
110108
local export_filter = opt.export_filter
109+
local sourcefiles_map = {}
110+
if export_filter then
111+
_get_sourcefiles_map(target, sourcefiles_map)
112+
end
111113
for _, objectfile in ipairs(target:objectfiles()) do
112114
local objectsymbols = try { function () return os.iorunv(objdump, {"--syms", objectfile}) end }
113115
if objectsymbols then
114-
local sourcefile
115-
if export_filter then
116-
sourcefile = _get_sourcefile_from_objectfile(target, objectfile)
117-
end
116+
local sourcefile = sourcefiles_map[objectfile]
118117
for _, line in ipairs(objectsymbols:split('\n', {plain = true})) do
119118
if line:find("(scl 2)", 1, true) then
120119
local splitinfo = line:split("%s")

0 commit comments

Comments
 (0)