From 6f6fa84e93428ad6695fcdedb3aef7b60383bf19 Mon Sep 17 00:00:00 2001 From: A2va <49582555+A2va@users.noreply.github.com> Date: Wed, 18 Sep 2024 15:41:23 +0200 Subject: [PATCH 1/3] Allows installdir, bindir and libdir to be configured via opt arguments --- xmake/modules/target/action/install/main.lua | 21 ++++++++++++++----- .../modules/target/action/uninstall/main.lua | 20 +++++++++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua index b1ae56a4da..04f85e905c 100644 --- a/xmake/modules/target/action/install/main.lua +++ b/xmake/modules/target/action/install/main.lua @@ -124,6 +124,11 @@ end -- install shared libraries function _install_shared_libraries(target, opt) local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir() + if target:is_plat("windows", "mingw") and opt.bindir then + bindir = target:installdir(opt.bindir) + elseif opt.libdir then + bindir = target:installdir(opt.libdir) + end -- get all dependent shared libraries local libfiles = {} @@ -158,7 +163,7 @@ function _update_install_rpath(target, opt) if target:is_plat("windows", "mingw") then return end - local bindir = target:bindir() + local bindir = opt.bindir and target:installdir(opt.bindir) or target:bindir() local targetfile = path.join(bindir, target:filename()) if target:policy("install.rpath") then local result, sources = target:get_from("rpathdirs", "*") @@ -179,7 +184,7 @@ end -- install binary function _install_binary(target, opt) - local bindir = target:bindir() + local bindir = opt.bindir and target:installdir(opt.bindir) or target:bindir() os.mkdir(bindir) os.vcp(target:targetfile(), bindir) os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile()))) @@ -190,6 +195,11 @@ end -- install shared library function _install_shared(target, opt) local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir() + if target:is_plat("windows", "mingw") and opt.bindir then + bindir = target:installdir(opt.bindir) + elseif opt.libdir then + bindir = target:installdir(opt.libdir) + end os.mkdir(bindir) local targetfile = target:targetfile() @@ -197,7 +207,7 @@ function _install_shared(target, opt) -- install *.lib for shared/windows (*.dll) target -- @see https://github.com/xmake-io/xmake/issues/714 os.vcp(target:targetfile(), bindir) - local libdir = target:libdir() + local libdir = opt.libdir and target:installdir(opt.libdir) or target:libdir() local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. (target:is_plat("mingw") and ".dll.a" or ".lib")) if os.isfile(targetfile_lib) then os.mkdir(libdir) @@ -215,7 +225,7 @@ end -- install static library function _install_static(target, opt) - local libdir = target:libdir() + local libdir = opt.libdir and target:installdir(opt.libdir) or target:libdir() os.mkdir(libdir) os.vcp(target:targetfile(), libdir) os.trycp(target:symbolfile(), path.join(libdir, path.filename(target:symbolfile()))) @@ -233,7 +243,8 @@ function _install_moduleonly(target, opt) end function main(target, opt) - local installdir = target:installdir() + opt = opt or {} + local installdir = opt.installdir and target:set("installdir", opt.installdir) or target:installdir() if not installdir then wprint("please use `xmake install -o installdir` or `set_installdir` to set install directory.") return diff --git a/xmake/modules/target/action/uninstall/main.lua b/xmake/modules/target/action/uninstall/main.lua index 912e5140f6..5d4ea943fd 100644 --- a/xmake/modules/target/action/uninstall/main.lua +++ b/xmake/modules/target/action/uninstall/main.lua @@ -50,7 +50,6 @@ function _get_target_package_libfiles(target, opt) return {} end local libfiles = {} - local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir() 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 @@ -115,6 +114,11 @@ end -- uninstall shared libraries function _uninstall_shared_libraries(target, opt) local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir() + if target:is_plat("windows", "mingw") and opt.bindir then + bindir = target:installdir(opt.bindir) + elseif opt.libdir then + bindir = target:installdir(opt.libdir) + end -- get all dependent shared libraries local libfiles = {} @@ -142,7 +146,7 @@ end -- uninstall binary function _uninstall_binary(target, opt) - local bindir = target:bindir() + local bindir = opt.bindir and target:installdir(opt.bindir) or target:bindir() remove_files(path.join(bindir, path.filename(target:targetfile())), {emptydir = true}) remove_files(path.join(bindir, path.filename(target:symbolfile())), {emptydir = true}) _uninstall_shared_libraries(target, opt) @@ -151,11 +155,16 @@ end -- uninstall shared library function _uninstall_shared(target, opt) local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir() + if target:is_plat("windows", "mingw") and opt.bindir then + bindir = target:installdir(opt.bindir) + elseif opt.libdir then + bindir = target:installdir(opt.libdir) + end if target:is_plat("windows", "mingw") then -- uninstall *.lib for shared/windows (*.dll) target -- @see https://github.com/xmake-io/xmake/issues/714 - local libdir = target:libdir() + local libdir = opt.libdir and target:installdir(opt.libdir) or target:libdir() local targetfile = target:targetfile() remove_files(path.join(bindir, path.filename(targetfile)), {emptydir = true}) remove_files(path.join(libdir, path.basename(targetfile) .. (target:is_plat("mingw") and ".dll.a" or ".lib")), {emptydir = true}) @@ -171,7 +180,7 @@ end -- uninstall static library function _uninstall_static(target, opt) - local libdir = target:libdir() + local libdir = opt.libdir and target:installdir(opt.libdir) or target:libdir() remove_files(path.join(libdir, path.filename(target:targetfile())), {emptydir = true}) remove_files(path.join(libdir, path.filename(target:symbolfile())), {emptydir = true}) _uninstall_headers(target, opt) @@ -188,7 +197,8 @@ function _uninstall_moduleonly(target, opt) end function main(target, opt) - local installdir = target:installdir() + opt = opt or {} + local installdir = opt.installdir and target:set("installdir", opt.installdir) or target:installdir() if not installdir then wprint("please use `xmake install -o installdir` or `set_installdir` to set install directory.") return From 60df5b236a5ea26a1c0acab29a9b627e1cef12ad Mon Sep 17 00:00:00 2001 From: A2va <49582555+A2va@users.noreply.github.com> Date: Fri, 20 Sep 2024 09:57:23 +0200 Subject: [PATCH 2/3] Avoid calling set installdir --- xmake/modules/target/action/install/main.lua | 44 ++++++++++++------- .../modules/target/action/uninstall/main.lua | 44 +++++++++++-------- 2 files changed, 53 insertions(+), 35 deletions(-) diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua index 04f85e905c..0e1c9eda3d 100644 --- a/xmake/modules/target/action/install/main.lua +++ b/xmake/modules/target/action/install/main.lua @@ -25,6 +25,26 @@ import("core.project.project") import("utils.binary.deplibs", {alias = "get_depend_libraries"}) import("utils.binary.rpath", {alias = "rpath_utils"}) +function _get_target_libdir(target, opt) + if not opt.installdir then + return target:libdir() + end + assert(opt.libdir, "opt.libdir is missing") + return path.join(opt.installdir, opt.libdir) +end + +function _get_target_bindir(target, opt) + if not opt.installdir then + return (target:is_plat("windows", "mingw") or opt.true_bindir) and target:bindir() or target:libdir() + end + assert(opt.libdir, "opt.libdir is missing") + assert(opt.bindir, "opt.bindir is missing") + + local bindir = path.join(opt.installdir, opt.bindir) + local libdir = path.join(opt.installdir, opt.libdir) + return (target:is_plat("windows", "mingw") or opt.true_bindir) and bindir or libdir +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) @@ -123,12 +143,7 @@ end -- install shared libraries function _install_shared_libraries(target, opt) - local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir() - if target:is_plat("windows", "mingw") and opt.bindir then - bindir = target:installdir(opt.bindir) - elseif opt.libdir then - bindir = target:installdir(opt.libdir) - end + local bindir = _get_target_bindir(target, opt) -- get all dependent shared libraries local libfiles = {} @@ -163,7 +178,7 @@ function _update_install_rpath(target, opt) if target:is_plat("windows", "mingw") then return end - local bindir = opt.bindir and target:installdir(opt.bindir) or target:bindir() + local bindir = _get_target_bindir(target, table.join(opt, {true_bindir = true})) local targetfile = path.join(bindir, target:filename()) if target:policy("install.rpath") then local result, sources = target:get_from("rpathdirs", "*") @@ -184,7 +199,7 @@ end -- install binary function _install_binary(target, opt) - local bindir = opt.bindir and target:installdir(opt.bindir) or target:bindir() + local bindir = _get_target_bindir(target, table.join(opt, {true_bindir = true})) os.mkdir(bindir) os.vcp(target:targetfile(), bindir) os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile()))) @@ -194,12 +209,7 @@ end -- install shared library function _install_shared(target, opt) - local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir() - if target:is_plat("windows", "mingw") and opt.bindir then - bindir = target:installdir(opt.bindir) - elseif opt.libdir then - bindir = target:installdir(opt.libdir) - end + local bindir = _get_target_bindir(target, opt) os.mkdir(bindir) local targetfile = target:targetfile() @@ -207,7 +217,7 @@ function _install_shared(target, opt) -- install *.lib for shared/windows (*.dll) target -- @see https://github.com/xmake-io/xmake/issues/714 os.vcp(target:targetfile(), bindir) - local libdir = opt.libdir and target:installdir(opt.libdir) or target:libdir() + local libdir = _get_target_libdir(target, opt) local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. (target:is_plat("mingw") and ".dll.a" or ".lib")) if os.isfile(targetfile_lib) then os.mkdir(libdir) @@ -225,7 +235,7 @@ end -- install static library function _install_static(target, opt) - local libdir = opt.libdir and target:installdir(opt.libdir) or target:libdir() + local libdir = _get_target_libdir(target, opt) os.mkdir(libdir) os.vcp(target:targetfile(), libdir) os.trycp(target:symbolfile(), path.join(libdir, path.filename(target:symbolfile()))) @@ -244,7 +254,7 @@ end function main(target, opt) opt = opt or {} - local installdir = opt.installdir and target:set("installdir", opt.installdir) or target:installdir() + local installdir = opt.installdir or target:installdir() if not installdir then wprint("please use `xmake install -o installdir` or `set_installdir` to set install directory.") return diff --git a/xmake/modules/target/action/uninstall/main.lua b/xmake/modules/target/action/uninstall/main.lua index 5d4ea943fd..81b4103b25 100644 --- a/xmake/modules/target/action/uninstall/main.lua +++ b/xmake/modules/target/action/uninstall/main.lua @@ -25,6 +25,26 @@ import("core.project.project") import("utils.binary.deplibs", {alias = "get_depend_libraries"}) import("private.action.clean.remove_files") +function _get_target_libdir(target, opt) + if not opt.installdir then + return target:libdir() + end + assert(opt.libdir, "opt.libdir is missing") + return path.join(opt.installdir, opt.libdir) +end + +function _get_target_bindir(target, opt) + if not opt.installdir then + return (target:is_plat("windows", "mingw") or opt.true_bindir) and target:bindir() or target:libdir() + end + assert(opt.libdir, "opt.libdir is missing") + assert(opt.bindir, "opt.bindir is missing") + + local bindir = path.join(opt.installdir, opt.bindir) + local libdir = path.join(opt.installdir, opt.libdir) + return (target:is_plat("windows", "mingw") or opt.true_bindir) and bindir or libdir +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) @@ -113,13 +133,7 @@ end -- uninstall shared libraries function _uninstall_shared_libraries(target, opt) - local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir() - if target:is_plat("windows", "mingw") and opt.bindir then - bindir = target:installdir(opt.bindir) - elseif opt.libdir then - bindir = target:installdir(opt.libdir) - end - + local bindir = _get_target_bindir(target, opt) -- get all dependent shared libraries local libfiles = {} for _, dep in ipairs(target:orderdeps()) do @@ -146,7 +160,7 @@ end -- uninstall binary function _uninstall_binary(target, opt) - local bindir = opt.bindir and target:installdir(opt.bindir) or target:bindir() + local bindir = _get_target_bindir(target, table.join(opt, {true_bindir = true})) remove_files(path.join(bindir, path.filename(target:targetfile())), {emptydir = true}) remove_files(path.join(bindir, path.filename(target:symbolfile())), {emptydir = true}) _uninstall_shared_libraries(target, opt) @@ -154,17 +168,11 @@ end -- uninstall shared library function _uninstall_shared(target, opt) - local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir() - if target:is_plat("windows", "mingw") and opt.bindir then - bindir = target:installdir(opt.bindir) - elseif opt.libdir then - bindir = target:installdir(opt.libdir) - end - + local bindir = _get_target_bindir(target, opt) if target:is_plat("windows", "mingw") then -- uninstall *.lib for shared/windows (*.dll) target -- @see https://github.com/xmake-io/xmake/issues/714 - local libdir = opt.libdir and target:installdir(opt.libdir) or target:libdir() + local libdir = _get_target_libdir(target, opt) local targetfile = target:targetfile() remove_files(path.join(bindir, path.filename(targetfile)), {emptydir = true}) remove_files(path.join(libdir, path.basename(targetfile) .. (target:is_plat("mingw") and ".dll.a" or ".lib")), {emptydir = true}) @@ -180,7 +188,7 @@ end -- uninstall static library function _uninstall_static(target, opt) - local libdir = opt.libdir and target:installdir(opt.libdir) or target:libdir() + local libdir = _get_target_libdir(target, opt) remove_files(path.join(libdir, path.filename(target:targetfile())), {emptydir = true}) remove_files(path.join(libdir, path.filename(target:symbolfile())), {emptydir = true}) _uninstall_headers(target, opt) @@ -198,7 +206,7 @@ end function main(target, opt) opt = opt or {} - local installdir = opt.installdir and target:set("installdir", opt.installdir) or target:installdir() + local installdir = opt.installdir or target:installdir() if not installdir then wprint("please use `xmake install -o installdir` or `set_installdir` to set install directory.") return From f92bdc11978e585ae349432e3c519861b803f604 Mon Sep 17 00:00:00 2001 From: A2va <49582555+A2va@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:47:00 +0200 Subject: [PATCH 3/3] Remove true_bindir argument --- xmake/modules/target/action/install/main.lua | 16 ++++++---------- xmake/modules/target/action/uninstall/main.lua | 14 +++++--------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua index 0e1c9eda3d..9b70a9096a 100644 --- a/xmake/modules/target/action/install/main.lua +++ b/xmake/modules/target/action/install/main.lua @@ -35,14 +35,10 @@ end function _get_target_bindir(target, opt) if not opt.installdir then - return (target:is_plat("windows", "mingw") or opt.true_bindir) and target:bindir() or target:libdir() + return target:bindir() end - assert(opt.libdir, "opt.libdir is missing") assert(opt.bindir, "opt.bindir is missing") - - local bindir = path.join(opt.installdir, opt.bindir) - local libdir = path.join(opt.installdir, opt.libdir) - return (target:is_plat("windows", "mingw") or opt.true_bindir) and bindir or libdir + return path.join(opt.installdir, opt.bindir) end -- we need to get all deplibs, e.g. app -> libfoo.so -> libbar.so ... @@ -143,7 +139,7 @@ end -- install shared libraries function _install_shared_libraries(target, opt) - local bindir = _get_target_bindir(target, opt) + local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(target, opt) or _get_target_libdir(target, opt) -- get all dependent shared libraries local libfiles = {} @@ -178,7 +174,7 @@ function _update_install_rpath(target, opt) if target:is_plat("windows", "mingw") then return end - local bindir = _get_target_bindir(target, table.join(opt, {true_bindir = true})) + local bindir = _get_target_bindir(target, opt) local targetfile = path.join(bindir, target:filename()) if target:policy("install.rpath") then local result, sources = target:get_from("rpathdirs", "*") @@ -199,7 +195,7 @@ end -- install binary function _install_binary(target, opt) - local bindir = _get_target_bindir(target, table.join(opt, {true_bindir = true})) + local bindir = _get_target_bindir(target, opt) os.mkdir(bindir) os.vcp(target:targetfile(), bindir) os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile()))) @@ -209,7 +205,7 @@ end -- install shared library function _install_shared(target, opt) - local bindir = _get_target_bindir(target, opt) + local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(target, opt) or _get_target_libdir(target, opt) os.mkdir(bindir) local targetfile = target:targetfile() diff --git a/xmake/modules/target/action/uninstall/main.lua b/xmake/modules/target/action/uninstall/main.lua index 81b4103b25..e36d5617ab 100644 --- a/xmake/modules/target/action/uninstall/main.lua +++ b/xmake/modules/target/action/uninstall/main.lua @@ -35,14 +35,10 @@ end function _get_target_bindir(target, opt) if not opt.installdir then - return (target:is_plat("windows", "mingw") or opt.true_bindir) and target:bindir() or target:libdir() + return target:bindir() end - assert(opt.libdir, "opt.libdir is missing") assert(opt.bindir, "opt.bindir is missing") - - local bindir = path.join(opt.installdir, opt.bindir) - local libdir = path.join(opt.installdir, opt.libdir) - return (target:is_plat("windows", "mingw") or opt.true_bindir) and bindir or libdir + return path.join(opt.installdir, opt.bindir) end -- we need to get all deplibs, e.g. app -> libfoo.so -> libbar.so ... @@ -133,7 +129,7 @@ end -- uninstall shared libraries function _uninstall_shared_libraries(target, opt) - local bindir = _get_target_bindir(target, opt) + local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(target, opt) or _get_target_libdir(target, opt) -- get all dependent shared libraries local libfiles = {} for _, dep in ipairs(target:orderdeps()) do @@ -160,7 +156,7 @@ end -- uninstall binary function _uninstall_binary(target, opt) - local bindir = _get_target_bindir(target, table.join(opt, {true_bindir = true})) + local bindir = _get_target_bindir(target, opt) remove_files(path.join(bindir, path.filename(target:targetfile())), {emptydir = true}) remove_files(path.join(bindir, path.filename(target:symbolfile())), {emptydir = true}) _uninstall_shared_libraries(target, opt) @@ -168,7 +164,7 @@ end -- uninstall shared library function _uninstall_shared(target, opt) - local bindir = _get_target_bindir(target, opt) + local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(target, opt) or _get_target_libdir(target, opt) if target:is_plat("windows", "mingw") then -- uninstall *.lib for shared/windows (*.dll) target -- @see https://github.com/xmake-io/xmake/issues/714