summaryrefslogtreecommitdiff
path: root/xmake/plugins/pack/batchcmds.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2024-07-17 22:56:58 +0800
committerruki <[email protected]>2024-07-17 22:56:58 +0800
commitf1b9376d8dcdddee617bff0b6a245f106238f813 (patch)
treec63718a873a610647316f0dce5114cfeeb8eba47 /xmake/plugins/pack/batchcmds.lua
parent7f3f3a626757f7b9eb0f2334de2ae3ad43d16b99 (diff)
improve install prefix for xpack
Diffstat (limited to 'xmake/plugins/pack/batchcmds.lua')
-rw-r--r--xmake/plugins/pack/batchcmds.lua32
1 files changed, 23 insertions, 9 deletions
diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua
index c41efb89d..f810b934c 100644
--- a/xmake/plugins/pack/batchcmds.lua
+++ b/xmake/plugins/pack/batchcmds.lua
@@ -61,14 +61,15 @@ function _get_target_installdir(package, target)
return path.normalize(installdir)
end
-function _get_target_package_libfiles(target, opt)
+function _get_target_package_libfiles(package, target, opt)
local libfiles = {}
+ local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(package, target) or _get_target_libdir(package, target)
for _, pkg in ipairs(target:orderpkgs(opt)) do
if pkg:enabled() and pkg:get("libfiles") then
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, libfile)
+ table.insert(libfiles, path.joinenv({libfile, bindir}))
end
end
end
@@ -81,7 +82,10 @@ function _get_target_package_libfiles(target, opt)
for _, libfile in ipairs(depend_libraries) do
depends:insert(path.filename(libfile))
end
- table.remove_if(libfiles, function (_, libfile) return not depends:has(path.filename(libfile)) end)
+ table.remove_if(libfiles, function (_, libfile)
+ libfile = path.splitenv(libfile)[1]
+ return not depends:has(path.filename(libfile))
+ end)
end
return libfiles
end
@@ -170,26 +174,31 @@ end
-- install target shared libraries
function _install_target_shared_libraries(target, batchcmds_, opt)
local package = opt.package
- local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(package, target) or _get_target_libdir(package, target)
-- get all dependent shared libraries
local libfiles = {}
for _, dep in ipairs(target:orderdeps()) do
+ local bindir = dep:is_plat("windows", "mingw") and _get_target_bindir(package, dep) or _get_target_libdir(package, dep)
if dep:kind() == "shared" then
local depfile = dep:targetfile()
if os.isfile(depfile) then
- table.insert(libfiles, depfile)
+ table.insert(libfiles, path.joinenv({depfile, bindir}))
end
end
- table.join2(libfiles, _get_target_package_libfiles(dep, {interface = true}))
+ table.join2(libfiles, _get_target_package_libfiles(package, dep, {interface = true}))
end
- table.join2(libfiles, _get_target_package_libfiles(target))
+ table.join2(libfiles, _get_target_package_libfiles(package, target))
-- deduplicate libfiles, prevent packages using the same libfiles from overwriting each other
libfiles = table.unique(libfiles)
-- do install
for _, libfile in ipairs(libfiles) do
+ local splitinfo = path.splitenv(libfile)
+ libfile = splitinfo[1]
+ local bindir = splitinfo[2]
+ assert(libfile and bindir)
+
local filename = path.filename(libfile)
_copy_file_with_symlinks(batchcmds_, libfile, bindir)
end
@@ -228,15 +237,15 @@ end
-- uninstall target shared libraries
function _uninstall_target_shared_libraries(target, batchcmds_, opt)
local package = opt.package
- local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(package, target) or _get_target_libdir(package, target)
-- get all dependent shared libraries
local libfiles = {}
for _, dep in ipairs(target:orderdeps()) do
+ local bindir = dep:is_plat("windows", "mingw") and _get_target_bindir(package, dep) or _get_target_libdir(package, dep)
if dep:kind() == "shared" then
local depfile = dep:targetfile()
if os.isfile(depfile) then
- table.insert(libfiles, depfile)
+ table.insert(libfiles, path.joinenv({depfile, bindir}))
end
end
table.join2(libfiles, _get_target_package_libfiles(dep, {interface = true}))
@@ -248,6 +257,11 @@ function _uninstall_target_shared_libraries(target, batchcmds_, opt)
-- do uninstall
for _, libfile in ipairs(libfiles) do
+ local splitinfo = path.splitenv(libfile)
+ libfile = splitinfo[1]
+ local bindir = splitinfo[2]
+ assert(libfile and bindir)
+
local filename = path.filename(libfile)
batchcmds_:rm(libfile, path.join(bindir, filename), {emptydirs = true})
end