diff options
| author | ruki <[email protected]> | 2024-07-11 22:45:05 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-07-11 22:45:05 +0800 |
| commit | b29871ae1036ac77e35c2eb84d32b5fbda314572 (patch) | |
| tree | 457d6914efae1cdb6d2e3c3b3241bfb7963476c1 /xmake/modules | |
| parent | 737b4fd7cd286d360f155df1ea68324aaa8b7317 (diff) | |
use dumpbin to dump windows bin deps
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/utils/symbols/depend.lua | 34 |
1 files 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 + |
