Skip to content

Commit

Permalink
improve exclude pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Apr 17, 2024
1 parent 08250fc commit 2346d25
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
9 changes: 6 additions & 3 deletions tests/modules/private/select_script/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ function test_plat_only(t)
t:require_not(_match_patterns("!mac*", {plat = "macosx"}))
t:require(_match_patterns("!macosx", {plat = "linux"}))
t:require(_match_patterns("!macosx,!android", {plat = "linux"}))
t:require_not(_match_patterns("!macosx,!android", {plat = "android"}))
t:require_not(_match_patterns("!macosx,!android", {plat = "macosx"}))
t:require(_match_patterns("!mac*", {plat = "linux"}))
end

Expand All @@ -39,7 +37,6 @@ function test_plat_arch(t)
t:require_not(_match_patterns("!macosx|x86_64", {plat = "macosx", arch = "x86_64"}))
t:require_not(_match_patterns("!mac*|x86_64", {plat = "macosx", arch = "x86_64"}))
t:require(_match_patterns("!macosx|x86_64", {plat = "linux", arch = "x86_64"}))
t:require_not(_match_patterns("!macosx|x86_64,!linux|x86_64", {plat = "linux", arch = "x86_64"}))
t:require(_match_patterns("!mac*|x86_64", {plat = "linux", arch = "x86_64"}))
t:require(_match_patterns("macosx|!i386", {plat = "macosx", arch = "x86_64"}))
t:require(_match_patterns("!macosx|!i386", {plat = "linux", arch = "x86_64"}))
Expand Down Expand Up @@ -119,12 +116,18 @@ function test_plat_arch_subhost_subarch(t)
end

function test_logical_expr(t)
t:require(_match_patterns("!macosx|x86_64,!iphoneos|arm64", {plat = "linux", arch = "x86_64"}))
t:require(_match_patterns("!wasm|!arm* and !cross|!arm*", {plat = "linux", arch = "x86_64"}))
t:require_not(_match_patterns("!wasm|!arm* and !cross|!arm*", {plat = "linux", arch = "arm64"}))
t:require_not(_match_patterns("!wasm|!arm* and !cross|!arm*", {plat = "wasm", arch = "x86_64"}))
t:require(_match_patterns("!macosx|x86_64 or !iphoneos|arm64", {plat = "linux", arch = "x86_64"}))
t:require_not(_match_patterns("!android@macosx or !android@linux", {plat = "android", subhost = "macosx"}))
t:require(_match_patterns("@macosx|x86_64 or @linux|x86_64", {subhost = "macosx", subarch = "x86_64"}))
t:require(_match_patterns("@macosx or @linux", {subhost = "macosx"}))
t:require(_match_patterns("!wasm|!arm* or (!cross|!arm* or linux)", {plat = "linux", arch = "arm64"}))
t:require_not(_match_patterns("!wasm|!arm* or (!cross|!arm* and !linux)", {plat = "linux", arch = "arm64"}))
t:require_not(_match_patterns("!macosx|x86_64 and !linux|x86_64", {plat = "linux", arch = "x86_64"}))
t:require_not(_match_patterns("!macosx and !android", {plat = "android"}))
t:require_not(_match_patterns("!macosx and !android", {plat = "macosx"}))
end

16 changes: 1 addition & 15 deletions xmake/core/base/private/select_script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,11 @@ end

-- match patterns
function _match_patterns(patterns, plat, arch, opt)
local patterns_excluded = {}
for _, pattern in ipairs(patterns) do
if pattern:startswith("!") then
table.insert(patterns_excluded, pattern)
else
if _match_pattern(pattern, plat, arch, opt) then
return true
end
end
end
local matched = 0
for _, pattern in ipairs(patterns_excluded) do
if _match_pattern(pattern, plat, arch, opt) then
matched = matched + 1
return true
end
end
if #patterns_excluded > 0 and #patterns_excluded == matched then
return true
end
end

-- mattch the script pattern
Expand Down

0 comments on commit 2346d25

Please sign in to comment.