summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-10-19 22:34:20 +0800
committerruki <[email protected]>2025-10-19 22:34:35 +0800
commit9fba3e92a48958cbba78bee3a6500455248800f6 (patch)
tree59736a98468a7a70ea0d917366a6102357e1663d
parentb703ec328f42d6f5c4ed5e7185b35bc13730b7b0 (diff)
add action utils to get target and group
-rw-r--r--xmake/actions/build/main.lua9
-rw-r--r--xmake/actions/install/main.lua9
-rw-r--r--xmake/actions/run/main.lua9
-rw-r--r--xmake/actions/test/xmake.lua2
-rw-r--r--xmake/actions/uninstall/main.lua5
-rw-r--r--xmake/modules/private/action/utils.lua34
-rw-r--r--xmake/plugins/format/main.lua10
-rw-r--r--xmake/plugins/show/lists/targets.lua2
8 files changed, 47 insertions, 33 deletions
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index c0d3761df..02138ef89 100644
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -37,6 +37,7 @@ import("check", {alias = "check_targets"})
import("private.cache.build_cache")
import("private.service.remote_build.action", {alias = "remote_build_action"})
import("private.utils.statistics")
+import("private.action.utils", {alias = "action_utils"})
-- try building it
function _do_try_build(configfile, tool, trybuild, trybuild_detected, targetname)
@@ -194,13 +195,7 @@ function main(opt)
project.lock()
-- config it first
- local targetname
- local group_pattern = option.get("group")
- if group_pattern then
- group_pattern = "^" .. path.pattern(group_pattern) .. "$"
- else
- targetname = option.get("target")
- end
+ local targetname, group_pattern = action_utils.get_target_and_group()
task.run("config", {}, {disable_dump = true})
-- enter project directory
diff --git a/xmake/actions/install/main.lua b/xmake/actions/install/main.lua
index 731871552..70a716c6c 100644
--- a/xmake/actions/install/main.lua
+++ b/xmake/actions/install/main.lua
@@ -27,6 +27,7 @@ import("core.platform.platform")
import("core.base.privilege")
import("privilege.sudo")
import("install")
+import("private.action.utils", {alias = "action_utils"})
-- check targets
function _check_targets(targetname, group_pattern)
@@ -68,13 +69,7 @@ function main()
task.run("config", {require = false}, {disable_dump = true})
-- check targets first
- local targetname
- local group_pattern = option.get("group")
- if group_pattern then
- group_pattern = "^" .. path.pattern(group_pattern) .. "$"
- else
- targetname = option.get("target")
- end
+ local targetname, group_pattern = action_utils.get_target_and_group()
_check_targets(targetname, group_pattern)
-- attempt to install directly
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua
index 6b8f90a8a..94c7d7d6b 100644
--- a/xmake/actions/run/main.lua
+++ b/xmake/actions/run/main.lua
@@ -31,6 +31,7 @@ import("private.action.run.runenvs")
import("private.service.remote_build.action", {alias = "remote_build_action"})
import("private.detect.check_targetname")
import("lib.detect.find_tool")
+import("private.action.utils", {alias = "action_utils"})
-- run target
function _do_run_target(target)
@@ -203,13 +204,7 @@ function main()
end
-- check targets first
- local targetname
- local group_pattern = option.get("group")
- if group_pattern then
- group_pattern = "^" .. path.pattern(group_pattern) .. "$"
- else
- targetname = option.get("target")
- end
+ local targetname, group_pattern = action_utils.get_target_and_group()
_check_targets(targetname, group_pattern)
-- enter project directory
diff --git a/xmake/actions/test/xmake.lua b/xmake/actions/test/xmake.lua
index fed09bcdd..1e04ab5f2 100644
--- a/xmake/actions/test/xmake.lua
+++ b/xmake/actions/test/xmake.lua
@@ -22,7 +22,7 @@ task("test")
set_category("action")
on_run("main")
set_menu {
- usage = "xmake test [options] [target] [arguments]",
+ usage = "xmake test [options] [tests]",
description = "Run the project tests.",
options = {
{'g', "group", "kv", nil , "Run all tests of the given group. It support path pattern matching.",
diff --git a/xmake/actions/uninstall/main.lua b/xmake/actions/uninstall/main.lua
index 0924ccf0e..fa8d58f3d 100644
--- a/xmake/actions/uninstall/main.lua
+++ b/xmake/actions/uninstall/main.lua
@@ -25,14 +25,15 @@ import("core.platform.platform")
import("core.base.privilege")
import("privilege.sudo")
import("uninstall")
+import("private.action.utils", {alias = "action_utils"})
function main()
-- load config first
task.run("config", {require = false}, {disable_dump = true})
- -- attempt to uninstall directly
- local targetname = option.get("target")
+ -- attempt to uninstall directly, TODO group_pattern
+ local targetname, group_pattern = action_utils.get_target_and_group()
try
{
function ()
diff --git a/xmake/modules/private/action/utils.lua b/xmake/modules/private/action/utils.lua
new file mode 100644
index 000000000..9b83b59ab
--- /dev/null
+++ b/xmake/modules/private/action/utils.lua
@@ -0,0 +1,34 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file utils.lua
+--
+
+-- imports
+import("core.base.option")
+
+-- get target name and group pattern from option
+function get_target_and_group()
+ local targetname
+ local group_pattern = option.get("group")
+ if group_pattern then
+ group_pattern = "^" .. path.pattern(group_pattern) .. "$"
+ else
+ targetname = option.get("target")
+ end
+ return targetname, group_pattern
+end
diff --git a/xmake/plugins/format/main.lua b/xmake/plugins/format/main.lua
index efc825c2a..87744ad12 100644
--- a/xmake/plugins/format/main.lua
+++ b/xmake/plugins/format/main.lua
@@ -26,6 +26,7 @@ import("core.project.project")
import("lib.detect.find_tool")
import("private.action.require.impl.packagenv")
import("private.action.require.impl.install_packages")
+import("private.action.utils", {alias = "action_utils"})
-- match source files
function _match_sourcefiles(sourcefile, filepatterns)
@@ -173,14 +174,7 @@ function main()
table.insert(argv, "--verbose")
end
- local targetname
- local group_pattern = option.get("group")
- if group_pattern then
- group_pattern = "^" .. path.pattern(group_pattern) .. "$"
- else
- targetname = option.get("target")
- end
-
+ local targetname, group_pattern = action_utils.get_target_and_group()
local targets = _get_targets(targetname, group_pattern)
if option.get("files") then
local filepatterns = _get_file_patterns(option.get("files"))
diff --git a/xmake/plugins/show/lists/targets.lua b/xmake/plugins/show/lists/targets.lua
index 7ac81619d..fb004b67e 100644
--- a/xmake/plugins/show/lists/targets.lua
+++ b/xmake/plugins/show/lists/targets.lua
@@ -28,7 +28,7 @@ import(".showlist")
-- show all targets (optionally filtered by group)
function main()
config.load()
-
+
local targets = {}
local group_pattern = option.get("group")
if group_pattern then