From b29871ae1036ac77e35c2eb84d32b5fbda314572 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 11 Jul 2024 22:45:05 +0800 Subject: use dumpbin to dump windows bin deps --- xmake/modules/utils/symbols/depend.lua | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/xmake/modules/utils/symbols/depend.lua b/xmake/modules/utils/symbols/depend.lua index 33cc821e5..08381c419 100644 --- a/xmake/modules/utils/symbols/depend.lua +++ b/xmake/modules/utils/symbols/depend.lua @@ -20,19 +20,47 @@ -- imports import("core.base.option") +import("core.tool.toolchain") import("lib.detect.find_tool") function _get_all_depends_by_dumpbin(binaryfile, opt) - local dumpbin = find_tool("dumpbin") - if dumpbin then - local depends = try { function () return os.iorunv(dumpbin.program, {"/dependent", "/nologo", objectfile}) end } + local depends + local plat = opt.plat or os.host() + local arch = opt.arch or os.arch() + local msvc = toolchain.load("msvc", {plat = plat, arch = arch}) + if msvc:check() then + local dumpbin = find_tool("dumpbin", {cachekey = "utils.symbols.depend", envs = msvc:runenvs()}) + if dumpbin then + local binarydir = path.directory(binaryfile) + local result = try { function () return os.iorunv(dumpbin.program, {"/dependents", "/nologo", binaryfile}) end } + if result then + for _, line in ipairs(result:split("\n")) do + line = line:trim() + if line:endswith(".dll") then + local dependfile + if os.isfile(line) then + dependfile = line + elseif os.isfile(path.join(binarydir, line)) then + dependfile = path.join(binarydir, line) + end + if dependfile then + depends = depends or {} + table.insert(depends, path.absolute(dependfile)) + end + end + end + end + end end + return depends end function main(binaryfile, opt) + opt = opt or {} local depends if is_host("windows") then depends = _get_all_depends_by_dumpbin(binaryfile, opt) end return depends end + -- cgit v1.3.1