summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-07-11 22:54:13 +0800
committerruki <[email protected]>2024-07-11 22:54:13 +0800
commit425be3c4ca8ccb3cd68692fcce0150f06bfa2ce3 (patch)
tree46f525e339ad7098a642c61339dde174373a99d4
parentb908a2200db75057f59a047a4d60d2c49e70a63d (diff)
dump deps by otool
-rw-r--r--xmake/modules/utils/symbols/depend.lua61
1 files changed, 54 insertions, 7 deletions
diff --git a/xmake/modules/utils/symbols/depend.lua b/xmake/modules/utils/symbols/depend.lua
index a2e44817e..7c63aa957 100644
--- a/xmake/modules/utils/symbols/depend.lua
+++ b/xmake/modules/utils/symbols/depend.lua
@@ -27,9 +27,10 @@ function _get_all_depends_by_dumpbin(binaryfile, opt)
local depends
local plat = opt.plat or os.host()
local arch = opt.arch or os.arch()
+ local cachekey = "utils.symbols.depend"
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()})
+ local dumpbin = find_tool("dumpbin", {cachekey = cachekey, envs = msvc:runenvs()})
if dumpbin then
local binarydir = path.directory(binaryfile)
local result = try { function () return os.iorunv(dumpbin.program, {"/dependents", "/nologo", binaryfile}) end }
@@ -64,7 +65,7 @@ function _get_all_depends_by_objdump(binaryfile, opt)
if objdump then
local binarydir = path.directory(binaryfile)
local argv = {"-p", binaryfile}
- if plat == "macosx" then
+ if plat == "macosx" or plat == "iphoneos" or plat == "appletvos" or plat == "watchos" then
argv = {"--macho", "--dylibs-used", binaryfile}
end
local result = try { function () return os.iorunv(objdump.program, argv) end }
@@ -87,17 +88,17 @@ function _get_all_depends_by_objdump(binaryfile, opt)
end
end
end
- elseif plat == "macosx" then
- local filename = line:match(".-%.dylib")
+ elseif plat == "macosx" or plat == "iphoneos" or plat == "appletvos" or plat == "watchos" then
+ local filename = line:match(".-%.dylib") or line:match(".-%.framework")
if filename then
local dependfile
- if os.isfile(filename) then
+ if os.exists(filename) then
dependfile = filename
- elseif os.isfile(path.join(binarydir, filename)) then
+ elseif os.exists(path.join(binarydir, filename)) then
dependfile = path.join(binarydir, filename)
elseif filename:startswith("@rpath/") then -- TODO
filename = filename:sub(8)
- if os.isfile(path.join(binarydir, filename)) then
+ if os.exists(path.join(binarydir, filename)) then
dependfile = path.join(binarydir, filename)
end
end
@@ -129,6 +130,48 @@ function _get_all_depends_by_objdump(binaryfile, opt)
return depends
end
+function _get_all_depends_by_ldd(binaryfile, opt)
+end
+
+function _get_all_depends_by_otool(binaryfile, opt)
+ local plat = opt.plat or os.host()
+ local arch = opt.arch or os.arch()
+ if plat ~= "macosx" and plat ~= "iphoneos" and plat ~= "appletvos" and plat ~= "watchos" then
+ return
+ end
+ local depends
+ local cachekey = "utils.symbols.depend"
+ local otool = find_tool("otool", {cachekey = cachekey})
+ if otool then
+ local binarydir = path.directory(binaryfile)
+ local result = try { function () return os.iorunv(otool.program, {"-L", binaryfile}) end }
+ if result then
+ for _, line in ipairs(result:split("\n")) do
+ line = line:trim()
+ local filename = line:match(".-%.dylib") or line:match(".-%.framework")
+ if filename then
+ local dependfile
+ if os.exists(filename) then
+ dependfile = filename
+ elseif os.exists(path.join(binarydir, filename)) then
+ dependfile = path.join(binarydir, filename)
+ elseif filename:startswith("@rpath/") then -- TODO
+ filename = filename:sub(8)
+ if os.exists(path.join(binarydir, filename)) then
+ dependfile = path.join(binarydir, filename)
+ end
+ end
+ if dependfile then
+ depends = depends or {}
+ table.insert(depends, path.absolute(dependfile))
+ end
+ end
+ end
+ end
+ end
+ return depends
+end
+
function main(binaryfile, opt)
opt = opt or {}
local dumpers = {
@@ -136,6 +179,10 @@ function main(binaryfile, opt)
}
if is_host("windows") then
table.insert(dumpers, _get_all_depends_by_dumpbin)
+ elseif is_host("ldd") then
+ table.insert(dumpers, _get_all_depends_by_ldd)
+ elseif is_host("macosx") then
+ table.insert(dumpers, _get_all_depends_by_otool)
end
for _, dump in ipairs(dumpers) do
local depends = dump(binaryfile, opt)