diff options
| author | ruki <[email protected]> | 2024-03-29 21:01:47 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-03-29 21:01:47 +0800 |
| commit | 339c6712f390c511c98159ad7c5c8731734ba0c0 (patch) | |
| tree | 8462ad149ad96cbacb285b3c1f5552c69669a056 | |
| parent | 0ed3ddc176a7e97f9dfe6fcb76c241cc0eafdbff (diff) | |
improve select pattern
| -rw-r--r-- | tests/modules/private/select_script/test.lua | 8 | ||||
| -rw-r--r-- | xmake/core/base/private/select_script.lua | 19 |
2 files changed, 24 insertions, 3 deletions
diff --git a/tests/modules/private/select_script/test.lua b/tests/modules/private/select_script/test.lua index 1ba820b63..90258c232 100644 --- a/tests/modules/private/select_script/test.lua +++ b/tests/modules/private/select_script/test.lua @@ -21,8 +21,9 @@ function test_plat_only(t) 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(_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 @@ -36,6 +37,8 @@ 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(_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"})) @@ -84,6 +87,7 @@ end function test_plat_subhost(t) 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"})) 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 |
