summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-06-13 22:43:03 +0800
committerruki <[email protected]>2022-06-13 22:43:03 +0800
commit736d72fc583f3a7c5f8f97c6079db2847da7757e (patch)
tree8a33445497209f03a90620f9eb2d9fce9157fa16
parentb871678de09d8185e6e13b05e726e56b72ad696a (diff)
support group for xmake install
-rw-r--r--xmake/actions/install/install.lua5
-rw-r--r--xmake/actions/install/install_admin.lua4
-rw-r--r--xmake/actions/install/main.lua21
-rw-r--r--xmake/actions/install/xmake.lua5
4 files changed, 24 insertions, 11 deletions
diff --git a/xmake/actions/install/install.lua b/xmake/actions/install/install.lua
index b4b0a6628..4b100a8e2 100644
--- a/xmake/actions/install/install.lua
+++ b/xmake/actions/install/install.lua
@@ -106,7 +106,7 @@ function _install_targets(targets)
end
-- install targets
-function main(targetname)
+function main(targetname, group_pattern)
-- install the given target?
if targetname and not targetname:startswith("__") then
@@ -116,7 +116,8 @@ function main(targetname)
else
-- install default or all targets
for _, target in ipairs(project.ordertargets()) do
- if target:is_default() or targetname == "__all" then
+ local group = target:get("group")
+ if (target:is_default() and not group_pattern) or targetname == "__all" or (group_pattern and group and group:match(group_pattern)) then
_install_target(target)
end
end
diff --git a/xmake/actions/install/install_admin.lua b/xmake/actions/install/install_admin.lua
index c2b57f05d..ba5101324 100644
--- a/xmake/actions/install/install_admin.lua
+++ b/xmake/actions/install/install_admin.lua
@@ -26,7 +26,7 @@ import("core.platform.platform")
import("install")
-- install
-function main(targetname, installdir, prefix)
+function main(targetname, group_pattern, installdir, prefix)
local verbose = option.get("verbose")
@@ -56,7 +56,7 @@ function main(targetname, installdir, prefix)
end
-- install target
- install(targetname)
+ install(targetname, group_pattern)
-- restore the previous option context
option.restore()
diff --git a/xmake/actions/install/main.lua b/xmake/actions/install/main.lua
index 2504f3338..7f9a0dd33 100644
--- a/xmake/actions/install/main.lua
+++ b/xmake/actions/install/main.lua
@@ -33,12 +33,13 @@ function _check_targets(targetname)
-- get targets
local targets = {}
- if targetname and not targetname:startswith("__") then
+ if targetname then
table.insert(targets, project.target(targetname))
else
-- install default or all targets
for _, target in pairs(project.targets()) do
- if target:is_default() or targetname == "__all" then
+ local group = target:get("group")
+ if (target:is_default() and not group_pattern) or option.get("all") or (group_pattern and group and group:match(group_pattern)) then
table.insert(targets, target)
end
end
@@ -68,14 +69,20 @@ function main()
config.load()
-- check targets first
- local targetname = option.get("target")
- _check_targets(targetname)
+ local targetname
+ local group_pattern = option.get("group")
+ if group_pattern then
+ group_pattern = "^" .. path.pattern(group_pattern) .. "$"
+ else
+ targetname = option.get("target")
+ end
+ _check_targets(targetname, group_pattern)
-- attempt to install directly
try
{
function ()
- install(targetname or (option.get("all") and "__all" or "__def"))
+ install(targetname or (option.get("all") and "__all" or "__def"), group_pattern)
cprint("${color.success}install ok!")
end,
@@ -89,7 +96,7 @@ function main()
local ok = try
{
function ()
- install(targetname or (option.get("all") and "__all" or "__def"))
+ install(targetname or (option.get("all") and "__all" or "__def"), group_pattern)
cprint("${color.success}install ok!")
return true
end
@@ -105,7 +112,7 @@ function main()
if sudo.has() and option.get("admin") then
-- install target with administrator permission
- sudo.execl(path.join(os.scriptdir(), "install_admin.lua"), {targetname or (option.get("all") and "__all" or "__def"), option.get("installdir"), option.get("prefix")})
+ sudo.execl(path.join(os.scriptdir(), "install_admin.lua"), {targetname or (option.get("all") and "__all" or "__def"), group_pattern, option.get("installdir"), option.get("prefix")})
cprint("${color.success}install ok!")
ok = true
end
diff --git a/xmake/actions/install/xmake.lua b/xmake/actions/install/xmake.lua
index 1bcd90b16..c7079f432 100644
--- a/xmake/actions/install/xmake.lua
+++ b/xmake/actions/install/xmake.lua
@@ -46,6 +46,11 @@ task("install")
" $ xmake install -o /usr/local",
"or $ DESTDIR=/usr/local xmake install",
"or $ INSTALLDIR=/usr/local xmake install" }
+ , {'g', "group", "kv", nil , "Install all targets of the given group. It support path pattern matching.",
+ "e.g.",
+ " xmake install -g test",
+ " xmake install -g test_*",
+ " xmake install --group=benchmark/*" }
, {'a', "all", "k", nil , "Install all targets." }
, {nil, "admin", "k", nil , "Try to request administrator permission to install"}