diff options
| author | ruki <[email protected]> | 2024-07-23 00:41:48 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-07-23 00:41:48 +0800 |
| commit | 56ca5adad669d45f400198b0c99a1d20f546970c (patch) | |
| tree | 4b51a8f0b6fde1388d5a0306c0d91551c60d37df | |
| parent | 7aaf46f34749b39067bf9c70ba08138ec2708497 (diff) | |
improve to get deplibs
| -rw-r--r-- | xmake/modules/target/action/install/main.lua | 26 | ||||
| -rw-r--r-- | xmake/modules/target/action/uninstall/main.lua | 33 | ||||
| -rw-r--r-- | xmake/plugins/pack/batchcmds.lua | 26 |
3 files changed, 65 insertions, 20 deletions
diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua index 0b5ac126e..6eecfaba4 100644 --- a/xmake/modules/target/action/install/main.lua +++ b/xmake/modules/target/action/install/main.lua @@ -24,6 +24,26 @@ import("core.base.hashset") import("utils.binary.deplibs", {alias = "get_depend_libraries"}) import("utils.binary.rpath", {alias = "rpath_utils"}) +-- we need to get all deplibs, e.g. app -> libfoo.so -> libbar.so ... +-- @see https://github.com/xmake-io/xmake/issues/5325#issuecomment-2242597732 +function _get_target_package_deplibs(target, depends, libfiles, binaryfile) + local deplibs = get_depend_libraries(binaryfile, {plat = target:plat(), arch = target:arch()}) + local depends_new = hashset.new() + for _, deplib in ipairs(deplibs) do + local libname = path.filename(deplib) + if not depends:has(libname) then + depends:insert(libname) + depends_new:insert(libname) + end + end + for _, libfile in ipairs(libfiles) do + local libname = path.filename(libfile) + if depends_new:has(libname) then + _get_target_package_deplibs(target, depends, libfiles, libfile) + end + end +end + function _get_target_package_libfiles(target, opt) if option.get("nopkgs") then return {} @@ -42,11 +62,7 @@ function _get_target_package_libfiles(target, opt) -- we can only reserve used libraries if target:is_binary() or target:is_shared() then local depends = hashset.new() - local targetfile = target:targetfile() - local depend_libraries = get_depend_libraries(targetfile, {plat = target:plat(), arch = target:arch()}) - for _, libfile in ipairs(depend_libraries) do - depends:insert(path.filename(libfile)) - end + _get_target_package_deplibs(target, depends, libfiles, target:targetfile()) table.remove_if(libfiles, function (_, libfile) return not depends:has(path.filename(libfile)) end) end return libfiles diff --git a/xmake/modules/target/action/uninstall/main.lua b/xmake/modules/target/action/uninstall/main.lua index 2b082d3cb..ab2333207 100644 --- a/xmake/modules/target/action/uninstall/main.lua +++ b/xmake/modules/target/action/uninstall/main.lua @@ -24,6 +24,26 @@ import("core.base.hashset") import("utils.binary.deplibs", {alias = "get_depend_libraries"}) import("private.action.clean.remove_files") +-- we need to get all deplibs, e.g. app -> libfoo.so -> libbar.so ... +-- @see https://github.com/xmake-io/xmake/issues/5325#issuecomment-2242597732 +function _get_target_package_deplibs(target, depends, libfiles, binaryfile) + local deplibs = get_depend_libraries(binaryfile, {plat = target:plat(), arch = target:arch()}) + local depends_new = hashset.new() + for _, deplib in ipairs(deplibs) do + local libname = path.filename(deplib) + if not depends:has(libname) then + depends:insert(libname) + depends_new:insert(libname) + end + end + for _, libfile in ipairs(libfiles) do + local libname = path.filename(libfile) + if depends_new:has(libname) then + _get_target_package_deplibs(target, depends, libfiles, libfile) + end + end +end + function _get_target_package_libfiles(target, opt) if option.get("nopkgs") then return {} @@ -35,7 +55,7 @@ function _get_target_package_libfiles(target, opt) for _, libfile in ipairs(table.wrap(pkg:get("libfiles"))) do local filename = path.filename(libfile) if filename:endswith(".dll") or filename:endswith(".so") or filename:find("%.so%.%d+$") or filename:endswith(".dylib") then - table.insert(libfiles, path.joinenv({libfile, bindir})) + table.insert(libfiles, libfile) end end end @@ -43,15 +63,8 @@ function _get_target_package_libfiles(target, opt) -- we can only reserve used libraries if target:is_binary() or target:is_shared() then local depends = hashset.new() - local targetfile = target:targetfile() - local depend_libraries = get_depend_libraries(targetfile, {plat = target:plat(), arch = target:arch()}) - for _, libfile in ipairs(depend_libraries) do - depends:insert(path.filename(libfile)) - end - table.remove_if(libfiles, function (_, libfile) - libfile = path.splitenv(libfile)[1] - return not depends:has(path.filename(libfile)) - end) + _get_target_package_deplibs(target, depends, libfiles, target:targetfile()) + table.remove_if(libfiles, function (_, libfile) return not depends:has(path.filename(libfile)) end) end return libfiles end diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua index c41efb89d..4017ed175 100644 --- a/xmake/plugins/pack/batchcmds.lua +++ b/xmake/plugins/pack/batchcmds.lua @@ -61,6 +61,26 @@ function _get_target_installdir(package, target) return path.normalize(installdir) end +-- we need to get all deplibs, e.g. app -> libfoo.so -> libbar.so ... +-- @see https://github.com/xmake-io/xmake/issues/5325#issuecomment-2242597732 +function _get_target_package_deplibs(target, depends, libfiles, binaryfile) + local deplibs = get_depend_libraries(binaryfile, {plat = target:plat(), arch = target:arch()}) + local depends_new = hashset.new() + for _, deplib in ipairs(deplibs) do + local libname = path.filename(deplib) + if not depends:has(libname) then + depends:insert(libname) + depends_new:insert(libname) + end + end + for _, libfile in ipairs(libfiles) do + local libname = path.filename(libfile) + if depends_new:has(libname) then + _get_target_package_deplibs(target, depends, libfiles, libfile) + end + end +end + function _get_target_package_libfiles(target, opt) local libfiles = {} for _, pkg in ipairs(target:orderpkgs(opt)) do @@ -76,11 +96,7 @@ function _get_target_package_libfiles(target, opt) -- we can only reserve used libraries if target:is_binary() or target:is_shared() then local depends = hashset.new() - local targetfile = target:targetfile() - local depend_libraries = get_depend_libraries(targetfile, {plat = target:plat(), arch = target:arch()}) - for _, libfile in ipairs(depend_libraries) do - depends:insert(path.filename(libfile)) - end + _get_target_package_deplibs(target, depends, libfiles, target:targetfile()) table.remove_if(libfiles, function (_, libfile) return not depends:has(path.filename(libfile)) end) end return libfiles |
