summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-03-29 09:42:11 +0800
committerGitHub <[email protected]>2024-03-29 09:42:11 +0800
commitb5fbc28b673cd901602f54443c4679bc2a064346 (patch)
tree8462ad149ad96cbacb285b3c1f5552c69669a056
parent4b5819f37565750c6b7da673dc7862f21d3db7bd (diff)
parent339c6712f390c511c98159ad7c5c8731734ba0c0 (diff)
Merge pull request #4894 from xmake-io/select
Improve to select scripts
-rw-r--r--tests/modules/private/select_script/test.lua184
-rw-r--r--xmake/core/base/private/select_script.lua19
2 files changed, 115 insertions, 88 deletions
diff --git a/tests/modules/private/select_script/test.lua b/tests/modules/private/select_script/test.lua
index ab37d732e..90258c232 100644
--- a/tests/modules/private/select_script/test.lua
+++ b/tests/modules/private/select_script/test.lua
@@ -1,111 +1,121 @@
import("private.core.base.select_script")
-function _match_pattern(pattern, opt)
- pattern = pattern:gsub("([%+%.%-%^%$%(%)%%])", "%%%1")
- pattern = pattern:gsub("%*", "\001")
- pattern = pattern:gsub("\001", ".*")
- return select_script({[pattern] = true}, opt) == true
+function _match_patterns(patterns, opt)
+ local scripts = {}
+ for _, pattern in ipairs(patterns) do
+ pattern = pattern:gsub("([%+%.%-%^%$%(%)%%])", "%%%1")
+ pattern = pattern:gsub("%*", "\001")
+ pattern = pattern:gsub("\001", ".*")
+ scripts[pattern] = true
+ end
+ return select_script(scripts, opt) == true
end
function test_plat_only(t)
- t:require(_match_pattern("*", {plat = "macosx"}))
- t:require(_match_pattern("macosx", {plat = "macosx"}))
- t:require(_match_pattern("macosx,linux", {plat = "macosx"}))
- t:require(_match_pattern("mac*", {plat = "macosx"}))
- t:require_not(_match_pattern("macosx", {plat = "linux"}))
- t:require_not(_match_pattern("linux", {plat = "macosx"}))
- t:require_not(_match_pattern("!macosx", {plat = "macosx"}))
- t:require_not(_match_pattern("!mac*", {plat = "macosx"}))
- t:require(_match_pattern("!macosx", {plat = "linux"}))
- t:require(_match_pattern("!mac*", {plat = "linux"}))
+ t:require(_match_patterns("*", {plat = "macosx"}))
+ t:require(_match_patterns("macosx", {plat = "macosx"}))
+ t:require(_match_patterns("macosx,linux", {plat = "macosx"}))
+ t:require(_match_patterns("mac*", {plat = "macosx"}))
+ t:require_not(_match_patterns("macosx", {plat = "linux"}))
+ t:require_not(_match_patterns("linux", {plat = "macosx"}))
+ t:require_not(_match_patterns("!macosx", {plat = "macosx"}))
+ 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
function test_plat_arch(t)
- t:require(_match_pattern("*|x86_64", {plat = "macosx", arch = "x86_64"}))
- t:require(_match_pattern("macosx|x86_64", {plat = "macosx", arch = "x86_64"}))
- t:require(_match_pattern("macosx|x86_64,linux|x86_64", {plat = "macosx", arch = "x86_64"}))
- t:require(_match_pattern("macosx|x86_*", {plat = "macosx", arch = "x86_64"}))
- t:require_not(_match_pattern("macosx|x86_64", {plat = "linux", arch = "x86_64"}))
- t:require_not(_match_pattern("macosx|i386", {plat = "macosx", arch = "x86_64"}))
- t:require_not(_match_pattern("!macosx|x86_64", {plat = "macosx", arch = "x86_64"}))
- t:require_not(_match_pattern("!mac*|x86_64", {plat = "macosx", arch = "x86_64"}))
- t:require(_match_pattern("!macosx|x86_64", {plat = "linux", arch = "x86_64"}))
- t:require(_match_pattern("!mac*|x86_64", {plat = "linux", arch = "x86_64"}))
- t:require(_match_pattern("macosx|!i386", {plat = "macosx", arch = "x86_64"}))
- t:require(_match_pattern("!macosx|!i386", {plat = "linux", arch = "x86_64"}))
- t:require(_match_pattern("windows|!x86", {plat = "windows", arch = "x64"}))
- t:require_not(_match_pattern("windows|!x86", {plat = "android", arch = "arm64-v8a"}))
- t:require(_match_pattern("macosx|native", {plat = "macosx", arch = "x86_64", subarch = "x86_64"}))
- t:require(_match_pattern("macosx|!native", {plat = "macosx", arch = "arm64", subarch = "x86_64"}))
- t:require_not(_match_pattern("macosx|!native", {plat = "macosx", arch = "x86_64", subarch = "x86_64"}))
- t:require_not(_match_pattern("windows|native", {plat = "macosx", arch = "x86_64", subarch = "x86_64"}))
+ t:require(_match_patterns("*|x86_64", {plat = "macosx", arch = "x86_64"}))
+ t:require(_match_patterns("macosx|x86_64", {plat = "macosx", arch = "x86_64"}))
+ t:require(_match_patterns("macosx|x86_64,linux|x86_64", {plat = "macosx", arch = "x86_64"}))
+ t:require(_match_patterns("macosx|x86_*", {plat = "macosx", arch = "x86_64"}))
+ t:require_not(_match_patterns("macosx|x86_64", {plat = "linux", arch = "x86_64"}))
+ t:require_not(_match_patterns("macosx|i386", {plat = "macosx", arch = "x86_64"}))
+ 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(_match_patterns("!macosx|x86_64,!iphoneos|arm64", {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"}))
+ t:require(_match_patterns("windows|!x86", {plat = "windows", arch = "x64"}))
+ t:require_not(_match_patterns("windows|!x86", {plat = "android", arch = "arm64-v8a"}))
+ t:require(_match_patterns("macosx|native", {plat = "macosx", arch = "x86_64", subarch = "x86_64"}))
+ t:require(_match_patterns("macosx|!native", {plat = "macosx", arch = "arm64", subarch = "x86_64"}))
+ t:require_not(_match_patterns("macosx|!native", {plat = "macosx", arch = "x86_64", subarch = "x86_64"}))
+ t:require_not(_match_patterns("windows|native", {plat = "macosx", arch = "x86_64", subarch = "x86_64"}))
end
function test_subhost_only(t)
- t:require(_match_pattern("@*", {subhost = "macosx"}))
- t:require(_match_pattern("@macosx", {subhost = "macosx"}))
- t:require(_match_pattern("@macosx,@linux", {subhost = "macosx"}))
- t:require(_match_pattern("@mac*", {subhost = "macosx"}))
- t:require_not(_match_pattern("@macosx", {subhost = "linux"}))
- t:require_not(_match_pattern("@linux", {subhost = "macosx"}))
- t:require_not(_match_pattern("@!macosx", {subhost = "macosx"}))
- t:require_not(_match_pattern("@!mac*", {subhost = "macosx"}))
- t:require(_match_pattern("@!macosx", {subhost = "linux"}))
- t:require(_match_pattern("@!mac*", {subhost = "linux"}))
+ t:require(_match_patterns("@*", {subhost = "macosx"}))
+ t:require(_match_patterns("@macosx", {subhost = "macosx"}))
+ t:require(_match_patterns("@macosx,@linux", {subhost = "macosx"}))
+ t:require(_match_patterns("@mac*", {subhost = "macosx"}))
+ t:require_not(_match_patterns("@macosx", {subhost = "linux"}))
+ t:require_not(_match_patterns("@linux", {subhost = "macosx"}))
+ t:require_not(_match_patterns("@!macosx", {subhost = "macosx"}))
+ t:require_not(_match_patterns("@!mac*", {subhost = "macosx"}))
+ t:require(_match_patterns("@!macosx", {subhost = "linux"}))
+ t:require(_match_patterns("@!mac*", {subhost = "linux"}))
end
function test_subhost_subarch(t)
- t:require(_match_pattern("@*|x86_64", {subhost = "macosx", subarch = "x86_64"}))
- t:require(_match_pattern("@macosx|x86_64", {subhost = "macosx", subarch = "x86_64"}))
- t:require(_match_pattern("@macosx|x86_64,@linux|x86_64", {subhost = "macosx", subarch = "x86_64"}))
- t:require(_match_pattern("@macosx|x86_*", {subhost = "macosx", subarch = "x86_64"}))
- t:require_not(_match_pattern("@macosx|x86_64", {subhost = "linux", subarch = "x86_64"}))
- t:require_not(_match_pattern("@macosx|i386", {subhost = "macosx", subarch = "x86_64"}))
- t:require_not(_match_pattern("@!macosx|x86_64", {subhost = "macosx", subarch = "x86_64"}))
- t:require_not(_match_pattern("@!mac*|x86_64", {subhost = "macosx", subarch = "x86_64"}))
- t:require(_match_pattern("@!macosx|x86_64", {subhost = "linux", subarch = "x86_64"}))
- t:require(_match_pattern("@!mac*|x86_64", {subhost = "linux", subarch = "x86_64"}))
- t:require(_match_pattern("@macosx|!i386", {subhost = "macosx", subarch = "x86_64"}))
- t:require(_match_pattern("@!macosx|!i386", {subhost = "linux", subarch = "x86_64"}))
- t:require(_match_pattern("@windows|!x86", {subhost = "windows", subarch = "x64"}))
- t:require_not(_match_pattern("@windows|!x86", {subhost = "android", subarch = "arm64-v8a"}))
- t:require(_match_pattern("@macosx|native", {subhost = "macosx", subarch = "x86_64"}))
- t:require(_match_pattern("@macosx|native", {subhost = "macosx", subarch = "arm64"}))
- t:require_not(_match_pattern("@macosx|!native", {subhost = "macosx", subarch = "x86_64"}))
- t:require_not(_match_pattern("@windows|native", {subhost = "macosx", subarch = "x86_64"}))
+ t:require(_match_patterns("@*|x86_64", {subhost = "macosx", subarch = "x86_64"}))
+ t:require(_match_patterns("@macosx|x86_64", {subhost = "macosx", subarch = "x86_64"}))
+ t:require(_match_patterns("@macosx|x86_64,@linux|x86_64", {subhost = "macosx", subarch = "x86_64"}))
+ t:require(_match_patterns("@macosx|x86_*", {subhost = "macosx", subarch = "x86_64"}))
+ t:require_not(_match_patterns("@macosx|x86_64", {subhost = "linux", subarch = "x86_64"}))
+ t:require_not(_match_patterns("@macosx|i386", {subhost = "macosx", subarch = "x86_64"}))
+ t:require_not(_match_patterns("@!macosx|x86_64", {subhost = "macosx", subarch = "x86_64"}))
+ t:require_not(_match_patterns("@!mac*|x86_64", {subhost = "macosx", subarch = "x86_64"}))
+ t:require(_match_patterns("@!macosx|x86_64", {subhost = "linux", subarch = "x86_64"}))
+ t:require(_match_patterns("@!mac*|x86_64", {subhost = "linux", subarch = "x86_64"}))
+ t:require(_match_patterns("@macosx|!i386", {subhost = "macosx", subarch = "x86_64"}))
+ t:require(_match_patterns("@!macosx|!i386", {subhost = "linux", subarch = "x86_64"}))
+ t:require(_match_patterns("@windows|!x86", {subhost = "windows", subarch = "x64"}))
+ t:require_not(_match_patterns("@windows|!x86", {subhost = "android", subarch = "arm64-v8a"}))
+ t:require(_match_patterns("@macosx|native", {subhost = "macosx", subarch = "x86_64"}))
+ t:require(_match_patterns("@macosx|native", {subhost = "macosx", subarch = "arm64"}))
+ t:require_not(_match_patterns("@macosx|!native", {subhost = "macosx", subarch = "x86_64"}))
+ t:require_not(_match_patterns("@windows|native", {subhost = "macosx", subarch = "x86_64"}))
end
function test_plat_subhost(t)
- t:require(_match_pattern("*@macosx", {plat = "macosx", subhost = "macosx"}))
- t:require(_match_pattern("android@macosx", {plat = "android", subhost = "macosx"}))
- t:require(_match_pattern("android@macosx,linux", {plat = "android", subhost = "linux"}))
- t:require(_match_pattern("android@mac*", {plat = "android", subhost = "macosx"}))
- t:require(_match_pattern("android@!macosx", {plat = "android", subhost = "linux"}))
- t:require_not(_match_pattern("!android@macosx", {plat = "android", subhost = "macosx"}))
- t:require(_match_pattern("!iphon*@macosx", {plat = "linux", subhost = "macosx"}))
+ t:require(_match_patterns("*@macosx", {plat = "macosx", subhost = "macosx"}))
+ t:require(_match_patterns("android@macosx", {plat = "android", subhost = "macosx"}))
+ t:require_not(_match_patterns("!android@macosx,!android@linux", {plat = "android", subhost = "macosx"}))
+ t:require(_match_patterns("android@macosx,linux", {plat = "android", subhost = "linux"}))
+ t:require(_match_patterns("android@mac*", {plat = "android", subhost = "macosx"}))
+ t:require(_match_patterns("android@!macosx", {plat = "android", subhost = "linux"}))
+ t:require_not(_match_patterns("!android@macosx", {plat = "android", subhost = "macosx"}))
+ t:require(_match_patterns("!iphon*@macosx", {plat = "linux", subhost = "macosx"}))
end
function test_plat_arch_subhost(t)
- t:require(_match_pattern("*|x86_64@macosx", {plat = "macosx", subhost = "macosx", arch = "x86_64"}))
- t:require(_match_pattern("android|arm64-v8a@macosx", {plat = "android", subhost = "macosx", arch = "arm64-v8a"}))
- t:require(_match_pattern("android|x86_64@macosx,linux", {plat = "android", subhost = "linux", arch = "x86_64"}))
- t:require(_match_pattern("android|x86_64@mac*", {plat = "android", subhost = "macosx", arch = "x86_64"}))
- t:require(_match_pattern("android|x86_64@!macosx", {plat = "android", subhost = "linux", arch = "x86_64"}))
- t:require_not(_match_pattern("!android|x86_64@macosx", {plat = "android", subhost = "macosx", arch = "x86_64"}))
- t:require(_match_pattern("!iphon*|x86_64@macosx", {plat = "linux", subhost = "macosx", arch = "x86_64"}))
- t:require(_match_pattern("iphon*|arm64@macosx", {plat = "iphoneos", subhost = "macosx", arch = "arm64"}))
- t:require_not(_match_pattern("iphon*|arm64@macosx", {plat = "iphoneos", subhost = "linux", arch = "arm64"}))
+ t:require(_match_patterns("*|x86_64@macosx", {plat = "macosx", subhost = "macosx", arch = "x86_64"}))
+ t:require(_match_patterns("android|arm64-v8a@macosx", {plat = "android", subhost = "macosx", arch = "arm64-v8a"}))
+ t:require(_match_patterns("android|x86_64@macosx,linux", {plat = "android", subhost = "linux", arch = "x86_64"}))
+ t:require(_match_patterns("android|x86_64@mac*", {plat = "android", subhost = "macosx", arch = "x86_64"}))
+ t:require(_match_patterns("android|x86_64@!macosx", {plat = "android", subhost = "linux", arch = "x86_64"}))
+ t:require_not(_match_patterns("!android|x86_64@macosx", {plat = "android", subhost = "macosx", arch = "x86_64"}))
+ t:require(_match_patterns("!iphon*|x86_64@macosx", {plat = "linux", subhost = "macosx", arch = "x86_64"}))
+ t:require(_match_patterns("iphon*|arm64@macosx", {plat = "iphoneos", subhost = "macosx", arch = "arm64"}))
+ t:require_not(_match_patterns("iphon*|arm64@macosx", {plat = "iphoneos", subhost = "linux", arch = "arm64"}))
end
function test_plat_arch_subhost_subarch(t)
- t:require(_match_pattern("*|x86_64@macosx|x86_64", {plat = "macosx", subhost = "macosx", arch = "x86_64", subarch = "x86_64"}))
- t:require(_match_pattern("android|arm64-v8a@macosx|x86_64", {plat = "android", subhost = "macosx", arch = "arm64-v8a", subarch = "x86_64"}))
- t:require(_match_pattern("android|x86_64@macosx|x86_64,linux|x86_64", {plat = "android", subhost = "linux", arch = "x86_64", subarch = "x86_64"}))
- t:require(_match_pattern("android|x86_64@mac*|x86_64", {plat = "android", subhost = "macosx", arch = "x86_64", subarch = "x86_64"}))
- t:require(_match_pattern("android|x86_64@!macosx|x86_64", {plat = "android", subhost = "linux", arch = "x86_64", subarch = "x86_64"}))
- t:require_not(_match_pattern("!android|x86_64@macosx|x86_64", {plat = "android", subhost = "macosx", arch = "x86_64", subarch = "x86_64"}))
- t:require(_match_pattern("!iphon*|x86_64@macosx|x86_64", {plat = "linux", subhost = "macosx", arch = "x86_64", subarch = "x86_64"}))
- t:require(_match_pattern("iphon*|arm64@macosx|x86_64", {plat = "iphoneos", subhost = "macosx", arch = "arm64", subarch = "x86_64"}))
- t:require_not(_match_pattern("iphon*|arm64@macosx|x86_64", {plat = "iphoneos", subhost = "linux", arch = "arm64", subarch = "x86_64"}))
- t:require(_match_pattern("android|native@macosx|x86_64", {plat = "android", subhost = "macosx", arch = "x86_64", subarch = "x86_64"}))
+ t:require(_match_patterns("*|x86_64@macosx|x86_64", {plat = "macosx", subhost = "macosx", arch = "x86_64", subarch = "x86_64"}))
+ t:require(_match_patterns("android|arm64-v8a@macosx|x86_64", {plat = "android", subhost = "macosx", arch = "arm64-v8a", subarch = "x86_64"}))
+ t:require(_match_patterns("android|x86_64@macosx|x86_64,linux|x86_64", {plat = "android", subhost = "linux", arch = "x86_64", subarch = "x86_64"}))
+ t:require(_match_patterns("android|x86_64@mac*|x86_64", {plat = "android", subhost = "macosx", arch = "x86_64", subarch = "x86_64"}))
+ t:require(_match_patterns("android|x86_64@!macosx|x86_64", {plat = "android", subhost = "linux", arch = "x86_64", subarch = "x86_64"}))
+ t:require_not(_match_patterns("!android|x86_64@macosx|x86_64", {plat = "android", subhost = "macosx", arch = "x86_64", subarch = "x86_64"}))
+ t:require(_match_patterns("!iphon*|x86_64@macosx|x86_64", {plat = "linux", subhost = "macosx", arch = "x86_64", subarch = "x86_64"}))
+ t:require(_match_patterns("iphon*|arm64@macosx|x86_64", {plat = "iphoneos", subhost = "macosx", arch = "arm64", subarch = "x86_64"}))
+ t:require_not(_match_patterns("iphon*|arm64@macosx|x86_64", {plat = "iphoneos", subhost = "linux", arch = "arm64", subarch = "x86_64"}))
+ t:require(_match_patterns("android|native@macosx|x86_64", {plat = "android", subhost = "macosx", arch = "x86_64", subarch = "x86_64"}))
end
diff --git a/xmake/core/base/private/select_script.lua b/xmake/core/base/private/select_script.lua
index 3fe88163f..23c8b55b6 100644
--- a/xmake/core/base/private/select_script.lua
+++ b/xmake/core/base/private/select_script.lua
@@ -36,6 +36,9 @@ function _match_pattern(pattern, plat, arch, opt)
local is_excluded_pattern = pattern_plat:find('!', 1, true)
if excluded and is_excluded_pattern then
matched = not ('!' .. plat):match('^' .. pattern_plat .. '$')
+ if matched then
+ return true
+ end
elseif not is_excluded_pattern then
matched = plat:match('^' .. pattern_plat .. '$')
end
@@ -68,11 +71,25 @@ 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
- return true
+ matched = matched + 1
end
end
+ if #patterns_excluded > 0 and #patterns_excluded == matched then
+ return true
+ end
end
-- mattch the script pattern