summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-07-17 00:57:22 +0800
committerruki <[email protected]>2024-07-17 00:57:22 +0800
commitad8a223ce684cd394179aca49fbea9c7b2e0d4c0 (patch)
tree336c5e99524b50b66780eb4da5fcd31b3543c24a
parent10df5c458fcf66832c0ef437157c7397f2283b18 (diff)
add rpath for xpack
-rw-r--r--xmake/modules/private/utils/batchcmds.lua51
-rw-r--r--xmake/modules/target/action/install/main.lua5
-rw-r--r--xmake/modules/utils/binary/rpath.lua4
-rw-r--r--xmake/plugins/pack/batchcmds.lua28
4 files changed, 73 insertions, 15 deletions
diff --git a/xmake/modules/private/utils/batchcmds.lua b/xmake/modules/private/utils/batchcmds.lua
index 6c3742b9f..3ea49ea8d 100644
--- a/xmake/modules/private/utils/batchcmds.lua
+++ b/xmake/modules/private/utils/batchcmds.lua
@@ -29,6 +29,7 @@ import("core.tool.linker")
import("core.tool.compiler")
import("core.language.language")
import("utils.progress", {alias = "progress_utils"})
+import("utils.binary.rpath", {alias = "rpath_utils"})
-- define module
local batchcmds = batchcmds or object { _init = {"_TARGET", "_CMDS", "_DEPINFO", "_tip"}}
@@ -173,6 +174,20 @@ function _runcmd_ln(cmd, opt)
end
end
+-- run command: clean rpath
+function _runcmd_clean_rpath(cmd, opt)
+ if not opt.dryrun then
+ rpath_utils.clean(cmd.filepath, opt.opt)
+ end
+end
+
+-- run command: insert rpath
+function _runcmd_insert_rpath(cmd, opt)
+ if not opt.dryrun then
+ rpath_utils.insert(cmd.filepath, cmd.rpath, opt.opt)
+ end
+end
+
-- run command
function _runcmd(cmd, opt)
local kind = cmd.kind
@@ -180,18 +195,20 @@ function _runcmd(cmd, opt)
if not maps then
maps =
{
- show = _runcmd_show,
- runv = _runcmd_runv,
- vrunv = _runcmd_vrunv,
- execv = _runcmd_execv,
- vexecv = _runcmd_vexecv,
- mkdir = _runcmd_mkdir,
- rmdir = _runcmd_rmdir,
- cd = _runcmd_cd,
- rm = _runcmd_rm,
- cp = _runcmd_cp,
- mv = _runcmd_mv,
- ln = _runcmd_ln
+ show = _runcmd_show,
+ runv = _runcmd_runv,
+ vrunv = _runcmd_vrunv,
+ execv = _runcmd_execv,
+ vexecv = _runcmd_vexecv,
+ mkdir = _runcmd_mkdir,
+ rmdir = _runcmd_rmdir,
+ cd = _runcmd_cd,
+ rm = _runcmd_rm,
+ cp = _runcmd_cp,
+ mv = _runcmd_mv,
+ ln = _runcmd_ln,
+ clean_rpath = _runcmd_clean_rpath,
+ insert_rpath = _runcmd_insert_rpath
}
_g.maps = maps
end
@@ -389,6 +406,16 @@ function batchcmds:show(format, ...)
table.insert(self:cmds(), {kind = "show", showtext = showtext})
end
+-- add command: clean rpath
+function batchcmds:clean_rpath(filepath, opt)
+ table.insert(self:cmds(), {kind = "clean_rpath", filepath = filepath, opt = opt})
+end
+
+-- add command: insert rpath
+function batchcmds:insert_rpath(filepath, rpath, opt)
+ table.insert(self:cmds(), {kind = "insert_rpath", filepath = filepath, rpath = rpath, opt = opt})
+end
+
-- add raw command for the specific generator or xpack format
function batchcmds:rawcmd(kind, rawstr)
table.insert(self:cmds(), {kind = kind, rawstr = rawstr})
diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua
index 6abc513b8..aaa99c4f2 100644
--- a/xmake/modules/target/action/install/main.lua
+++ b/xmake/modules/target/action/install/main.lua
@@ -136,9 +136,12 @@ end
-- update install rpath, we can only get and update rpathdirs with `{installonly = true}`
-- e.g. add_rpathdirs("@loader_path/../lib", {installonly = true})
function _update_install_rpath(target, opt)
+ if target:is_plat("windows", "mingw") then
+ return
+ end
local bindir = target:bindir()
local targetfile = path.join(bindir, target:filename())
- rpath_utils.remove_all(targetfile, {plat = target:plat(), arch = target:arch()})
+ rpath_utils.clean(targetfile, {plat = target:plat(), arch = target:arch()})
if target:policy("install.rpath") then
local result, sources = target:get_from("rpathdirs", "*")
if result and sources then
diff --git a/xmake/modules/utils/binary/rpath.lua b/xmake/modules/utils/binary/rpath.lua
index c47f7c768..016ff5133 100644
--- a/xmake/modules/utils/binary/rpath.lua
+++ b/xmake/modules/utils/binary/rpath.lua
@@ -269,8 +269,8 @@ function remove(binaryfile, rpath, opt)
end
end
--- remove all rpath
-function remove_all(binaryfile, opt)
+-- clean rpath
+function clean(binaryfile, opt)
for _, rpath in ipairs(list(binaryfile, opt)) do
remove(binaryfile, rpath, opt)
end
diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua
index e745cd19d..6245a345c 100644
--- a/xmake/plugins/pack/batchcmds.lua
+++ b/xmake/plugins/pack/batchcmds.lua
@@ -100,6 +100,33 @@ function _copy_file_with_symlinks(batchcmds_, srcfile, outputdir)
end
end
+-- update install rpath, we can only get and update rpathdirs with `{installonly = true}`
+-- e.g. add_rpathdirs("@loader_path/../lib", {installonly = true})
+function _update_target_install_rpath(target, batchcmds_, opt)
+ if target:is_plat("windows", "mingw") then
+ return
+ end
+ local package = opt.package
+ local bindir = _get_target_bindir(package, target)
+ local targetfile = path.join(bindir, target:filename())
+ batchcmds_:clean_rpath(targetfile, {plat = target:plat(), arch = target:arch()})
+ if target:policy("install.rpath") then
+ local result, sources = target:get_from("rpathdirs", "*")
+ if result and sources then
+ for idx, rpathdirs in ipairs(result) do
+ local source = sources[idx]
+ local extraconf = target:extraconf_from("rpathdirs", source)
+ for _, rpathdir in ipairs(rpathdirs) do
+ local extra = extraconf[rpathdir]
+ if extra and extra.installonly then
+ batchcmds_:insert_rpath(targetfile, rpathdir, {plat = target:plat(), arch = target:arch()})
+ end
+ end
+ end
+ end
+ end
+end
+
-- install target files
function _install_target_files(target, batchcmds_, opt)
local package = opt.package
@@ -233,6 +260,7 @@ function _on_target_installcmd_binary(target, batchcmds_, opt)
batchcmds_:cp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile())))
end
_install_target_shared_libraries(target, batchcmds_, opt)
+ _update_target_install_rpath(target, batchcmds_, opt)
end
-- on install shared target command