diff options
| author | ruki <[email protected]> | 2024-10-12 00:56:49 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-10-12 00:56:49 +0800 |
| commit | d8dc18b5edec681d8860b12b6e7d2d89c297037f (patch) | |
| tree | 1bf83b97a4a001be2d7e49f19934b88953729b05 /xmake/plugins/pack/batchcmds.lua | |
| parent | ad91dd8db636340a260acea0534fd67e1fb80a6b (diff) | |
improve to install target libs
Diffstat (limited to 'xmake/plugins/pack/batchcmds.lua')
| -rw-r--r-- | xmake/plugins/pack/batchcmds.lua | 67 |
1 files changed, 36 insertions, 31 deletions
diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua index 4017ed175..a881cfb18 100644 --- a/xmake/plugins/pack/batchcmds.lua +++ b/xmake/plugins/pack/batchcmds.lua @@ -63,8 +63,8 @@ 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()}) +function _get_target_package_deplibs(binaryfile, depends, libfiles, opt) + local deplibs = get_depend_libraries(binaryfile, {plat = opt.plat, arch = opt.arch}) local depends_new = hashset.new() for _, deplib in ipairs(deplibs) do local libname = path.filename(deplib) @@ -76,12 +76,16 @@ function _get_target_package_deplibs(target, depends, libfiles, binaryfile) 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) + _get_target_package_deplibs(libfile, depends, libfiles, opt) end end end function _get_target_package_libfiles(target, opt) + if option.get("nopkgs") then + return {} + end + opt = opt or {} local libfiles = {} for _, pkg in ipairs(target:orderpkgs(opt)) do if pkg:enabled() and pkg:get("libfiles") then @@ -94,14 +98,37 @@ function _get_target_package_libfiles(target, opt) end end -- we can only reserve used libraries - if target:is_binary() or target:is_shared() then - local depends = hashset.new() - _get_target_package_deplibs(target, depends, libfiles, target:targetfile()) - table.remove_if(libfiles, function (_, libfile) return not depends:has(path.filename(libfile)) end) + if project.policy("install.strip_packagelibs") then + if target:is_binary() or target:is_shared() or opt.binaryfile then + local depends = hashset.new() + _get_target_package_deplibs(opt.binaryfile or target:targetfile(), depends, libfiles, {plat = target:plat(), arch = target:arch()}) + table.remove_if(libfiles, function (_, libfile) return not depends:has(path.filename(libfile)) end) + end end return libfiles end +-- get target libraries +function _get_target_libfiles(target, libfiles, binaryfile, refs) + if not refs[target] then + local plaindeps = target:get("deps") + if plaindeps then + for _, depname in ipairs(plaindeps) do + local dep = target:dep(depname) + if dep then + if dep:is_shared() then + _get_target_libfiles(dep, libfiles, dep:targetfile(), refs) + elseif dep:is_library() then + _get_target_libfiles(dep, libfiles, binaryfile, refs) + end + end + end + end + table.join2(libfiles, _get_target_package_libfiles(target, {binaryfile = binaryfile})) + refs[target] = true + end +end + -- copy file with symlinks function _copy_file_with_symlinks(batchcmds_, srcfile, outputdir) if os.islink(srcfile) then @@ -190,18 +217,7 @@ function _install_target_shared_libraries(target, batchcmds_, opt) -- get all dependent shared libraries local libfiles = {} - for _, dep in ipairs(target:orderdeps()) do - if dep:kind() == "shared" then - local depfile = dep:targetfile() - if os.isfile(depfile) then - table.insert(libfiles, depfile) - end - end - table.join2(libfiles, _get_target_package_libfiles(dep, {interface = true})) - end - table.join2(libfiles, _get_target_package_libfiles(target)) - - -- deduplicate libfiles, prevent packages using the same libfiles from overwriting each other + _get_target_libfiles(target, libfiles, target:targetfile(), {}) libfiles = table.unique(libfiles) -- do install @@ -248,18 +264,7 @@ function _uninstall_target_shared_libraries(target, batchcmds_, opt) -- get all dependent shared libraries local libfiles = {} - for _, dep in ipairs(target:orderdeps()) do - if dep:kind() == "shared" then - local depfile = dep:targetfile() - if os.isfile(depfile) then - table.insert(libfiles, depfile) - end - end - table.join2(libfiles, _get_target_package_libfiles(dep, {interface = true})) - end - table.join2(libfiles, _get_target_package_libfiles(target)) - - -- deduplicate libfiles, prevent packages using the same libfiles from overwriting each other + _get_target_libfiles(target, libfiles, target:targetfile(), {}) libfiles = table.unique(libfiles) -- do uninstall |
