diff options
| author | ruki <[email protected]> | 2024-10-13 21:03:23 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-10-13 21:03:23 +0800 |
| commit | fcc2809210622102cdc0ec64256ff656b51eb509 (patch) | |
| tree | 40e995e08875740f9152767ae22351f691b3d192 /xmake/plugins/pack/batchcmds.lua | |
| parent | ad91dd8db636340a260acea0534fd67e1fb80a6b (diff) | |
| parent | b9daa8d3f4b2601f3e73b31338cb609aa9768a1a (diff) | |
Merge pull request #5706 from xmake-io/install
Improve to Install target libs
Diffstat (limited to 'xmake/plugins/pack/batchcmds.lua')
| -rw-r--r-- | xmake/plugins/pack/batchcmds.lua | 71 |
1 files changed, 40 insertions, 31 deletions
diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua index 4017ed175..bf81ddc43 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,41 @@ 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 + local depfile = dep:targetfile() + if os.isfile(depfile) then + table.insert(libfiles, depfile) + end + _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 +221,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 +268,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 |
