Skip to content

Commit b84cea0

Browse files
committed
remove deduplicated targets
1 parent 43a4e2c commit b84cea0

5 files changed

Lines changed: 26 additions & 19 deletions

File tree

xmake/actions/install/install.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@ end
118118
function main(targetnames, group_pattern)
119119
local targets = action_utils.get_targets(targetnames, {group_pattern = group_pattern})
120120
if #targets > 0 then
121-
_install_targets(table.unique(targets))
121+
_install_targets(targets)
122122
end
123123
end

xmake/actions/uninstall/main.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ function main()
3232
-- load config first
3333
task.run("config", {require = false}, {disable_dump = true})
3434

35-
-- attempt to uninstall directly, TODO group_pattern
35+
-- attempt to uninstall directly
3636
local targetnames, group_pattern = action_utils.get_targets_and_group()
3737
try
3838
{
3939
function ()
40-
uninstall(targetnames)
40+
uninstall(targetnames, group_pattern)
4141
cprint("${color.success}uninstall ok!")
4242
end,
4343

@@ -51,7 +51,7 @@ function main()
5151
local ok = try
5252
{
5353
function ()
54-
uninstall(targetnames)
54+
uninstall(targetnames, group_pattern)
5555
cprint("${color.success}uninstall ok!")
5656
return true
5757
end
@@ -71,6 +71,7 @@ function main()
7171
-- uninstall target with administrator permission
7272
sudo.execl(path.join(os.scriptdir(), "uninstall_admin.lua"), {
7373
targetnames and table.concat(targetnames, path.envsep()) or "__all",
74+
group_pattern or "",
7475
option.get("installdir") or "",
7576
option.get("bindir"),
7677
option.get("libdir"),

xmake/actions/uninstall/uninstall.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,6 @@ end
113113
function main(targetnames, group_pattern)
114114
local targets = action_utils.get_targets(targetnames, {group_pattern = group_pattern})
115115
if #targets > 0 then
116-
_uninstall_targets(table.unique(targets))
116+
_uninstall_targets(targets)
117117
end
118118
end

xmake/actions/uninstall/uninstall_admin.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ import("core.project.project")
2525
import("core.platform.platform")
2626
import("uninstall")
2727

28-
function main(targetname, installdir, bindir, libdir, includedir)
28+
function main(targetname, group_pattern, installdir, bindir, libdir, includedir)
2929
local verbose = option.get("verbose")
3030

3131
-- the targetname may be a list of target names joined with the path separator
3232
if targetname and targetname:find(path.envsep(), 1, true) then
3333
targetname = path.splitenv(targetname)
3434
end
35+
if group_pattern and #group_pattern == 0 then
36+
group_pattern = nil
37+
end
3538
if installdir and #installdir == 0 then
3639
installdir = nil
3740
end
@@ -65,6 +68,6 @@ function main(targetname, installdir, bindir, libdir, includedir)
6568
option.set("includedir", includedir)
6669
end
6770
-- uninstall target
68-
uninstall(targetname ~= "__all" and targetname or nil)
71+
uninstall(targetname ~= "__all" and targetname or nil, group_pattern)
6972
option.restore()
7073
end

xmake/modules/private/action/utils.lua

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,22 @@ function get_targets(targetnames, opt)
7575
opt = opt or {}
7676

7777
-- select the explicitly given targets (table.wrap to always get a list back)
78+
local targets
7879
if type(targetnames) == "table" or (type(targetnames) == "string" and not targetnames:startswith("__")) then
79-
return assert(check_targetnames(table.wrap(targetnames)))
80-
end
81-
82-
-- otherwise select the default/all/group targets
83-
local targets = {}
84-
local all = opt.all or targetnames == "__all" or option.get("all")
85-
local group_pattern = opt.group_pattern
86-
for _, target in ipairs(project.ordertargets()) do
87-
local group = target:get("group")
88-
if (target:is_default() and not group_pattern) or all or (group_pattern and group and group:match(group_pattern)) then
89-
table.insert(targets, target)
80+
targets = assert(check_targetnames(table.wrap(targetnames)))
81+
else
82+
-- otherwise select the default/all/group targets
83+
targets = {}
84+
local all = opt.all or targetnames == "__all" or option.get("all")
85+
local group_pattern = opt.group_pattern
86+
for _, target in ipairs(project.ordertargets()) do
87+
local group = target:get("group")
88+
if (target:is_default() and not group_pattern) or all or (group_pattern and group and group:match(group_pattern)) then
89+
table.insert(targets, target)
90+
end
9091
end
9192
end
92-
return targets
93+
94+
-- remove duplicates, e.g. the same target name may be given more than once
95+
return table.unique(targets)
9396
end

0 commit comments

Comments
 (0)