diff options
| author | ruki <[email protected]> | 2026-06-18 00:05:26 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-06-18 00:05:26 +0800 |
| commit | b59597d77a411a53ef74d9e384a25dbd9e82a634 (patch) | |
| tree | f395e9c21f91d6eebe01b22b83f6634f5be401e8 /xmake/modules/private/action/utils.lua | |
| parent | eba488dafedd88c1f19e23132276872aac877b73 (diff) | |
improve to get targets
Diffstat (limited to 'xmake/modules/private/action/utils.lua')
| -rw-r--r-- | xmake/modules/private/action/utils.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/xmake/modules/private/action/utils.lua b/xmake/modules/private/action/utils.lua index c31735c54..7878dc916 100644 --- a/xmake/modules/private/action/utils.lua +++ b/xmake/modules/private/action/utils.lua @@ -20,6 +20,8 @@ -- imports import("core.base.option") +import("core.project.project") +import("private.detect.check_targetname") -- get target name and group pattern from option function get_target_and_group() @@ -57,3 +59,36 @@ function get_targets_and_group() end return targetnames, group_pattern end + +-- get the selected target objects from the given target names +-- +-- if explicit target names are given, the matching targets are returned (and checked). +-- otherwise it selects the default/all/group targets, e.g. the actions like +-- build/install/uninstall/package/format share the same selection rule. +-- +-- @param targetnames a list of target names, a single target name, or the magic "__all"/"__def" +-- @param opt the options, e.g. {group_pattern = ..., all = false} +-- +-- @return the selected target objects (list) +-- +function get_targets(targetnames, opt) + opt = opt or {} + 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 + end + end + return targets +end |
