From 95e86b5524b4752d9d29e39ff4c17e8f5a3ba844 Mon Sep 17 00:00:00 2001 From: lonless9 Date: Wed, 4 Jun 2025 15:54:13 +0800 Subject: adds target group filtering to `show targets` --- xmake/plugins/show/lists/targets.lua | 28 +++++++++++++++++++++++++--- xmake/plugins/show/xmake.lua | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/xmake/plugins/show/lists/targets.lua b/xmake/plugins/show/lists/targets.lua index 50507aa1b..a5244e9c7 100644 --- a/xmake/plugins/show/lists/targets.lua +++ b/xmake/plugins/show/lists/targets.lua @@ -19,17 +19,39 @@ -- -- imports +import("core.base.option") import("core.project.config") import("core.project.project") import("core.platform.platform") import(".showlist") --- show all platforms +-- show all targets (optionally filtered by group) function main() config.load() + + local group_filter = option.get("group") local targets = {} - for name, _ in pairs(project.targets()) do - table.insert(targets, name) + + if not group_filter then + for name, _ in pairs(project.targets()) do + table.insert(targets, name) + end + else + + local normalized_filter = path.normalize(group_filter) + local filter_prefix = normalized_filter .. "/" + + for name, target in pairs(project.targets()) do + local target_group = target:get("group") + if target_group then + local normalized_target_group = path.normalize(target_group) + if normalized_target_group == normalized_filter or + normalized_target_group:startswith(filter_prefix) then + table.insert(targets, name) + end + end + end end + showlist(targets) end diff --git a/xmake/plugins/show/xmake.lua b/xmake/plugins/show/xmake.lua index bae15471c..33fb51635 100644 --- a/xmake/plugins/show/xmake.lua +++ b/xmake/plugins/show/xmake.lua @@ -29,6 +29,7 @@ task("show") values = function (complete, opt) return import("list").lists() end}, + {'g', "group", "kv", nil, "Filter targets by the given group name."}, {nil, "json", "k", false, "Show information with json format."}, {'t', "target", "kv", nil, "Show the information of the given target.", values = function (complete, opt) -- cgit v1.3.1 From 5c39da6e7dce986e0e2c2d09d2f1ef2fd23ce435 Mon Sep 17 00:00:00 2001 From: lonless9 Date: Thu, 5 Jun 2025 14:43:34 +0800 Subject: fix pattern --- xmake/plugins/show/lists/targets.lua | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/xmake/plugins/show/lists/targets.lua b/xmake/plugins/show/lists/targets.lua index a5244e9c7..ce398fc77 100644 --- a/xmake/plugins/show/lists/targets.lua +++ b/xmake/plugins/show/lists/targets.lua @@ -29,28 +29,21 @@ import(".showlist") function main() config.load() - local group_filter = option.get("group") + local group_pattern = option.get("group") + if group_pattern then + group_pattern = "^" .. path.pattern(group_pattern) .. "$" + end local targets = {} - if not group_filter then - for name, _ in pairs(project.targets()) do + for name, target in pairs(project.targets()) do + local group = target:get("group") + if (target:is_default() and not group_pattern) or + (group_pattern and group and (group:match(group_pattern) or + table.find_first_if(group:split("[/\\]"), function(i, component) + return component:match(group_pattern) + end))) then table.insert(targets, name) end - else - - local normalized_filter = path.normalize(group_filter) - local filter_prefix = normalized_filter .. "/" - - for name, target in pairs(project.targets()) do - local target_group = target:get("group") - if target_group then - local normalized_target_group = path.normalize(target_group) - if normalized_target_group == normalized_filter or - normalized_target_group:startswith(filter_prefix) then - table.insert(targets, name) - end - end - end end showlist(targets) -- cgit v1.3.1 From c57e967a612201bf4edee2bdecfd89e08a2afc19 Mon Sep 17 00:00:00 2001 From: lonless9 Date: Fri, 6 Jun 2025 01:30:03 +0800 Subject: dec pattern --- xmake/plugins/show/lists/targets.lua | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/xmake/plugins/show/lists/targets.lua b/xmake/plugins/show/lists/targets.lua index ce398fc77..57cf78b53 100644 --- a/xmake/plugins/show/lists/targets.lua +++ b/xmake/plugins/show/lists/targets.lua @@ -29,19 +29,17 @@ import(".showlist") function main() config.load() - local group_pattern = option.get("group") - if group_pattern then - group_pattern = "^" .. path.pattern(group_pattern) .. "$" - end + local group_pattern = option.get("group") and ("^" .. path.pattern(option.get("group")) .. "$") local targets = {} for name, target in pairs(project.targets()) do local group = target:get("group") if (target:is_default() and not group_pattern) or - (group_pattern and group and (group:match(group_pattern) or - table.find_first_if(group:split("[/\\]"), function(i, component) - return component:match(group_pattern) - end))) then + (group_pattern and group and (function() + for component in group:gmatch("[^/\\\\]+") do + if component:match(group_pattern) then return true end + end + end)()) then table.insert(targets, name) end end -- cgit v1.3.1 From 4ab3e401f14639f14f590fb091187b674cc90fb5 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 6 Jun 2025 23:51:24 +0800 Subject: Update targets.lua --- xmake/plugins/show/lists/targets.lua | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/xmake/plugins/show/lists/targets.lua b/xmake/plugins/show/lists/targets.lua index 57cf78b53..fa85de628 100644 --- a/xmake/plugins/show/lists/targets.lua +++ b/xmake/plugins/show/lists/targets.lua @@ -28,18 +28,15 @@ import(".showlist") -- show all targets (optionally filtered by group) function main() config.load() - - local group_pattern = option.get("group") and ("^" .. path.pattern(option.get("group")) .. "$") + local targets = {} - + local group_pattern = option.get("group") + if group_pattern then + group_pattern = "^" .. path.pattern(group_pattern) .. "$" + end for name, target in pairs(project.targets()) do local group = target:get("group") - if (target:is_default() and not group_pattern) or - (group_pattern and group and (function() - for component in group:gmatch("[^/\\\\]+") do - if component:match(group_pattern) then return true end - end - end)()) then + if (target:is_default() and not group_pattern) or (group_pattern and group and group:match(group_pattern)) then table.insert(targets, name) end end -- cgit v1.3.1