Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows installdir, bindir and libdir to be configured via opt arguments #5634

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions xmake/modules/target/action/install/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ 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:bindir()
end
assert(opt.bindir, "opt.bindir is missing")
return path.join(opt.installdir, opt.bindir)
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)
Expand Down Expand Up @@ -123,7 +139,7 @@ end

-- install shared libraries
function _install_shared_libraries(target, opt)
local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir()
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 = {}
Expand Down Expand Up @@ -158,7 +174,7 @@ function _update_install_rpath(target, opt)
if target:is_plat("windows", "mingw") then
return
end
local bindir = target:bindir()
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", "*")
Expand All @@ -179,7 +195,7 @@ end

-- install binary
function _install_binary(target, opt)
local bindir = target:bindir()
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())))
Expand All @@ -189,15 +205,15 @@ end

-- install shared library
function _install_shared(target, opt)
local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir()
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()

if target:is_plat("windows", "mingw") then
-- 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 = _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)
Expand All @@ -215,7 +231,7 @@ end

-- install static library
function _install_static(target, opt)
local libdir = 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())))
Expand All @@ -233,7 +249,8 @@ function _install_moduleonly(target, opt)
end

function main(target, opt)
local installdir = target:installdir()
opt = opt or {}
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
Expand Down
32 changes: 23 additions & 9 deletions xmake/modules/target/action/uninstall/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ 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:bindir()
end
assert(opt.bindir, "opt.bindir is missing")
return path.join(opt.installdir, opt.bindir)
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)
Expand All @@ -50,7 +66,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
Expand Down Expand Up @@ -114,8 +129,7 @@ end

-- uninstall shared libraries
function _uninstall_shared_libraries(target, opt)
local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir()

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
Expand All @@ -142,20 +156,19 @@ end

-- uninstall binary
function _uninstall_binary(target, opt)
local bindir = target:bindir()
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)
end

-- uninstall shared library
function _uninstall_shared(target, opt)
local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir()

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
local libdir = 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})
Expand All @@ -171,7 +184,7 @@ end

-- uninstall static library
function _uninstall_static(target, opt)
local libdir = 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)
Expand All @@ -188,7 +201,8 @@ function _uninstall_moduleonly(target, opt)
end

function main(target, opt)
local installdir = target:installdir()
opt = opt or {}
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
Expand Down
Loading