summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmake/actions/build/main.lua6
-rw-r--r--xmake/actions/clean/main.lua7
-rw-r--r--xmake/modules/private/action/utils.lua29
-rw-r--r--xmake/modules/private/detect/check_targetnames.lua47
4 files changed, 65 insertions, 24 deletions
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index 9b0fcc1e2..2bc298cd1 100644
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -38,7 +38,7 @@ 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"})
-import("private.detect.check_targetname")
+import("private.detect.check_targetnames")
-- try building it
function _do_try_build(configfile, tool, trybuild, trybuild_detected, targetnames)
@@ -201,9 +201,7 @@ function main(opt)
-- check target names
if targetnames then
- for _, targetname in ipairs(targetnames) do
- assert(check_targetname(targetname))
- end
+ assert(check_targetnames(targetnames))
end
-- enter project directory
diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua
index a85fca742..ba30ccb77 100644
--- a/xmake/actions/clean/main.lua
+++ b/xmake/actions/clean/main.lua
@@ -29,7 +29,7 @@ import("core.platform.platform")
import("private.action.clean.remove_files")
import("target.action.clean", {alias = "_do_clean_target"})
import("private.service.remote_build.action", {alias = "remote_build_action"})
-import("private.detect.check_targetname")
+import("private.detect.check_targetnames")
import("private.action.utils", {alias = "action_utils"})
-- on clean target
@@ -107,10 +107,7 @@ end
-- clean targets
function _clean(targetnames)
if targetnames and #targetnames > 0 then
- for _, targetname in ipairs(targetnames) do
- local target = assert(check_targetname(targetname))
- _clean_target(target)
- end
+ _clean_targets(assert(check_targetnames(targetnames)))
else
_clean_targets(project.ordertargets())
end
diff --git a/xmake/modules/private/action/utils.lua b/xmake/modules/private/action/utils.lua
index 7878dc916..24a5e3a46 100644
--- a/xmake/modules/private/action/utils.lua
+++ b/xmake/modules/private/action/utils.lua
@@ -21,7 +21,7 @@
-- imports
import("core.base.option")
import("core.project.project")
-import("private.detect.check_targetname")
+import("private.detect.check_targetnames")
-- get target name and group pattern from option
function get_target_and_group()
@@ -73,21 +73,20 @@ end
--
function get_targets(targetnames, opt)
opt = opt or {}
+
+ -- select the explicitly given targets
+ if type(targetnames) == "table" or (type(targetnames) == "string" and not targetnames:startswith("__")) then
+ return assert(check_targetnames(targetnames))
+ end
+
+ -- otherwise select the default/all/group targets
local targets = {}
- if type(targetnames) == "table" then
- for _, targetname in ipairs(targetnames) do
- table.insert(targets, assert(check_targetname(targetname)))
- end
- elseif type(targetnames) == "string" and not targetnames:startswith("__") then
- table.insert(targets, assert(check_targetname(targetnames)))
- else
- local all = opt.all or targetnames == "__all" or option.get("all")
- local group_pattern = opt.group_pattern
- for _, target in ipairs(project.ordertargets()) do
- local group = target:get("group")
- if (target:is_default() and not group_pattern) or all or (group_pattern and group and group:match(group_pattern)) then
- table.insert(targets, target)
- end
+ local all = opt.all or targetnames == "__all" or option.get("all")
+ local group_pattern = opt.group_pattern
+ for _, target in ipairs(project.ordertargets()) do
+ local group = target:get("group")
+ if (target:is_default() and not group_pattern) or all or (group_pattern and group and group:match(group_pattern)) then
+ table.insert(targets, target)
end
end
return targets
diff --git a/xmake/modules/private/detect/check_targetnames.lua b/xmake/modules/private/detect/check_targetnames.lua
new file mode 100644
index 000000000..7c7f1b56a
--- /dev/null
+++ b/xmake/modules/private/detect/check_targetnames.lua
@@ -0,0 +1,47 @@
+--!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 check_targetnames.lua
+--
+
+-- imports
+import("private.detect.check_targetname")
+
+-- check if the given target names are valid
+--
+-- @param targetnames a single target name or a list of target names to check for
+-- @param opt the argument options, e.g. {find_similar = false, max_similar = 5}
+-- @return targets or nil, errors
+--
+-- @code
+--
+-- local targets, errors = check_targetnames("mytarget")
+-- local targets, errors = check_targetnames({"target1", "target2"})
+--
+-- @endcode
+--
+function main(targetnames, opt)
+ local targets = {}
+ for _, targetname in ipairs(table.wrap(targetnames)) do
+ local target, errors = check_targetname(targetname, opt)
+ if not target then
+ return nil, errors
+ end
+ table.insert(targets, target)
+ end
+ return targets
+end