From 02a69e7a3e0442a750c33eae77dc5feb2e5ff655 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 18 Jun 2026 22:09:00 +0800 Subject: improve to clean targets --- xmake/actions/clean/main.lua | 14 +++++++------- xmake/actions/clean/xmake.lua | 5 +++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua index ba30ccb77..6606ddc2f 100644 --- a/xmake/actions/clean/main.lua +++ b/xmake/actions/clean/main.lua @@ -29,7 +29,6 @@ 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_targetnames") import("private.action.utils", {alias = "action_utils"}) -- on clean target @@ -105,10 +104,11 @@ function _clean_targets(targets) end -- clean targets -function _clean(targetnames) - if targetnames and #targetnames > 0 then - _clean_targets(assert(check_targetnames(targetnames))) +function _clean(targetnames, group_pattern) + if (targetnames and #targetnames > 0) or group_pattern then + _clean_targets(action_utils.get_targets(targetnames, {group_pattern = group_pattern})) else + -- clean all targets by default _clean_targets(project.ordertargets()) end end @@ -163,14 +163,14 @@ function main() -- lock the whole project project.lock() - -- get the target names - local targetnames = action_utils.get_targets_and_group() + -- get the target names and group pattern + local targetnames, group_pattern = action_utils.get_targets_and_group() -- enter project directory local oldir = os.cd(project.directory()) -- clean targets - _clean(targetnames) + _clean(targetnames, group_pattern) -- unlock the whole project project.unlock() diff --git a/xmake/actions/clean/xmake.lua b/xmake/actions/clean/xmake.lua index b2968e118..980ee2b28 100644 --- a/xmake/actions/clean/xmake.lua +++ b/xmake/actions/clean/xmake.lua @@ -30,6 +30,11 @@ task("clean") , options = { {'a', "all", "k", nil , "Clean all auto-generated files by xmake." } + , {'g', "group", "kv", nil , "Clean all targets of the given group. It support path pattern matching.", + "e.g.", + " xmake clean -g test", + " xmake clean -g test_*", + " xmake clean --group=benchmark/*" } , {} , {nil, "targets", "vs", nil , "The target names. It will clean all default targets if this parameter is not specified.", -- cgit v1.3.1