diff options
| author | ruki <[email protected]> | 2025-08-11 14:34:42 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-11 14:34:42 +0800 |
| commit | c39e51cd62cd158827df495eef79276c43cd4dfc (patch) | |
| tree | 462c51fe1451cc3e28b253296ba50329ef491a7a | |
| parent | a9732fa5cb1b0447740b3e50cbd972627f96e505 (diff) | |
| parent | 5d22e5c5919dddcf298af07d5bfe98f0dd8790a3 (diff) | |
Merge pull request #6688 from xmake-io/install
improve to install targets
| -rw-r--r-- | xmake/actions/install/install.lua | 7 | ||||
| -rw-r--r-- | xmake/actions/install/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/package/tools/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/target/action/install/main.lua | 107 | ||||
| -rw-r--r-- | xmake/modules/target/action/uninstall/main.lua | 3 | ||||
| -rw-r--r-- | xmake/plugins/pack/batchcmds.lua | 3 |
6 files changed, 79 insertions, 49 deletions
diff --git a/xmake/actions/install/install.lua b/xmake/actions/install/install.lua index 973b7496f..232f4f9c0 100644 --- a/xmake/actions/install/install.lua +++ b/xmake/actions/install/install.lua @@ -20,6 +20,7 @@ -- imports import("core.base.task") +import("core.base.option") import("core.project.rule") import("core.project.project") import("target.action.install", {alias = "_do_install_target"}) @@ -42,7 +43,11 @@ function _on_install_target(target) if done then return end -- do install - _do_install_target(target) + _do_install_target(target, { + headers = option.get("headers"), + binaries = option.get("binaries"), + libraries = option.get("libraries"), + packages = option.get("packages")}) end -- install the given target diff --git a/xmake/actions/install/xmake.lua b/xmake/actions/install/xmake.lua index 3fa870061..a18b11214 100644 --- a/xmake/actions/install/xmake.lua +++ b/xmake/actions/install/xmake.lua @@ -37,7 +37,11 @@ task("install") " xmake install -g test_*", " xmake install --group=benchmark/*" }, {'a', "all", "k", nil , "Install all targets." }, - {nil, "nopkgs", "k", nil , "Only install targets without packages." }, + {nil, "binaries", "kv", true , "Enable or disable install binary files." }, + {nil, "headers", "kv", true , "Enable or disable install header files." }, + {nil, "libraries", "kv", true , "Enable or disable install library files." }, + {nil, "packages", "kv", true , "Enable or disable install package files." }, + {}, {nil, "admin", "k", nil , "Try to request administrator permission to install"}, {}, {nil, "target", "v", nil , "The target name. It will install all default targets if this parameter is not specified.", diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index 17cf48a2e..b572c2fec 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -543,7 +543,7 @@ function install(package, configs, opt) os.vrunv(os.programfile(), argv, {envs = envs, curdir = opt.curdir}) -- do install - argv = {"install", "-y", "--nopkgs", "-o", package:installdir()} + argv = {"install", "-y", "--packages=n", "-o", package:installdir()} _set_builtin_argv(package, argv) local targets = table.wrap(opt.targets or opt.target) if #targets ~= 0 then diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua index d9faa80ad..e4f48ddfa 100644 --- a/xmake/modules/target/action/install/main.lua +++ b/xmake/modules/target/action/install/main.lua @@ -19,7 +19,6 @@ -- -- imports -import("core.base.option") import("core.base.hashset") import("core.project.project") import("utils.binary.deplibs", {alias = "get_depend_libraries"}) @@ -50,10 +49,10 @@ function _get_target_includedir(target, opt) end function _get_target_package_libfiles(target, opt) - if option.get("nopkgs") then + opt = opt or {} + if not opt.packages then return {} end - opt = opt or {} local libfiles = {} for _, pkg in ipairs(target:orderpkgs(opt)) do if pkg:enabled() and pkg:get("libfiles") then @@ -83,7 +82,7 @@ function _get_target_package_libfiles(target, opt) end -- get target libraries -function _get_target_libfiles(target, libfiles, binaryfile, refs) +function _get_target_libfiles(target, libfiles, binaryfile, refs, opt) if not refs[target] then local plaindeps = target:get("deps") if plaindeps then @@ -95,14 +94,14 @@ function _get_target_libfiles(target, libfiles, binaryfile, refs) if os.isfile(depfile) then table.insert(libfiles, depfile) end - _get_target_libfiles(dep, libfiles, dep:targetfile(), refs) + _get_target_libfiles(dep, libfiles, dep:targetfile(), refs, opt) elseif dep:is_library() then - _get_target_libfiles(dep, libfiles, binaryfile, refs) + _get_target_libfiles(dep, libfiles, binaryfile, refs, opt) end end end end - table.join2(libfiles, _get_target_package_libfiles(target, {binaryfile = binaryfile})) + table.join2(libfiles, _get_target_package_libfiles(target, table.join({binaryfile = binaryfile}, opt))) refs[target] = true end end @@ -163,7 +162,7 @@ function _install_shared_libraries(target, opt) -- get all dependent shared libraries local libfiles = {} - _get_target_libfiles(target, libfiles, target:targetfile(), {}) + _get_target_libfiles(target, libfiles, target:targetfile(), {}, opt) libfiles = table.unique(libfiles) -- do install @@ -204,61 +203,89 @@ end -- install binary function _install_binary(target, opt) - 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()))) - _install_shared_libraries(target, opt) - _update_install_rpath(target, opt) + if opt.libraries then + _install_shared_libraries(target, opt) + end + if opt.binaries then + 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()))) + _update_install_rpath(target, opt) + end end -- install shared library function _install_shared(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() + if opt.libraries then + 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 = _get_target_libdir(target, opt) - local implibfile = target:artifactfile("implib") - if os.isfile(implibfile) then - os.mkdir(libdir) - os.vcp(implibfile, libdir) + 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 = _get_target_libdir(target, opt) + local implibfile = target:artifactfile("implib") + if os.isfile(implibfile) then + os.mkdir(libdir) + os.vcp(implibfile, libdir) + end + else + -- install target with soname and symlink + _copy_file_with_symlinks(targetfile, bindir) end - else - -- install target with soname and symlink - _copy_file_with_symlinks(targetfile, bindir) + os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile()))) + _install_shared_libraries(target, opt) + end + if opt.headers then + _install_headers(target, opt) end - os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile()))) - - _install_headers(target, opt) - _install_shared_libraries(target, opt) end -- install static library function _install_static(target, opt) - 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()))) - _install_headers(target, opt) + if opt.libraries then + 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()))) + end + if opt.headers then + _install_headers(target, opt) + end end -- install headeronly library function _install_headeronly(target, opt) - _install_headers(target, opt) + if opt.headers then + _install_headers(target, opt) + end end -- install moduleonly library function _install_moduleonly(target, opt) - _install_headers(target, opt) + if opt.headers then + _install_headers(target, opt) + end end function main(target, opt) opt = opt or {} + if opt.headers == nil then + opt.headers = true + end + if opt.binaries == nil then + opt.binaries = true + end + if opt.libraries == nil then + opt.libraries = true + end + if opt.packages == nil then + opt.packages = true + end + 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.") diff --git a/xmake/modules/target/action/uninstall/main.lua b/xmake/modules/target/action/uninstall/main.lua index 2273ff76d..26ea33530 100644 --- a/xmake/modules/target/action/uninstall/main.lua +++ b/xmake/modules/target/action/uninstall/main.lua @@ -50,9 +50,6 @@ function _get_target_includedir(target, opt) 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 diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua index 2418f39ac..b67d66b5b 100644 --- a/xmake/plugins/pack/batchcmds.lua +++ b/xmake/plugins/pack/batchcmds.lua @@ -63,9 +63,6 @@ function _get_target_installdir(package, target) 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 |
