diff options
| author | ruki <[email protected]> | 2024-03-05 22:50:01 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-03-05 22:50:01 +0800 |
| commit | 53c7d7595a414d2cfa39b01e14dca1d7927635b8 (patch) | |
| tree | 649ef682964e33e12f44c571ff3a5ed04791bb31 | |
| parent | a5e284bd5972a3f85250fa8cd894c4669d086a11 (diff) | |
improve to select script
| -rw-r--r-- | tests/modules/private/select_script/test.lua | 6 | ||||
| -rw-r--r-- | xmake/core/base/private/select_script.lua | 48 |
2 files changed, 35 insertions, 19 deletions
diff --git a/tests/modules/private/select_script/test.lua b/tests/modules/private/select_script/test.lua index e7efcaa84..ab37d732e 100644 --- a/tests/modules/private/select_script/test.lua +++ b/tests/modules/private/select_script/test.lua @@ -34,7 +34,7 @@ function test_plat_arch(t) 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_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"})) @@ -68,7 +68,7 @@ function test_subhost_subarch(t) 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_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"})) @@ -107,5 +107,5 @@ function test_plat_arch_subhost_subarch(t) 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_pattern("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 323944ab4..3fe88163f 100644 --- a/xmake/core/base/private/select_script.lua +++ b/xmake/core/base/private/select_script.lua @@ -28,28 +28,44 @@ function _match_pattern(pattern, plat, arch, opt) local excluded = opt.excluded local subhost = opt.subhost or os.subhost() local subarch = opt.subarch or os.subarch() + local splitinfo = pattern:split("|", {strict = true, plain = true}) + local pattern_plat = splitinfo[1] + local pattern_arch = splitinfo[2] + if pattern_plat and #pattern_plat > 0 then + local matched = false + local is_excluded_pattern = pattern_plat:find('!', 1, true) + if excluded and is_excluded_pattern then + matched = not ('!' .. plat):match('^' .. pattern_plat .. '$') + elseif not is_excluded_pattern then + matched = plat:match('^' .. pattern_plat .. '$') + end + if not matched then + return false + end + end + if pattern_arch and #pattern_arch > 0 then + -- support native arch, e.g. macosx|native + -- @see https://github.com/xmake-io/xmake/issues/4657 + pattern_arch = pattern_arch:gsub("native", subarch) - -- support native arch, e.g. macosx|native - -- @see https://github.com/xmake-io/xmake/issues/4657 - if pattern:find("native", 1, true) then - local splitinfo = pattern:split("|") - local pattern_plat = splitinfo[1] - local pattern_arch = splitinfo[2] - if pattern_arch and pattern_plat:trim("!") == subhost then - pattern_arch = pattern_arch:gsub("native", subarch) - pattern = pattern_plat .. "|" .. pattern_arch + local matched = false + local is_excluded_pattern = pattern_arch:find('!', 1, true) + if excluded and is_excluded_pattern then + matched = not ('!' .. arch):match('^' .. pattern_arch .. '$') + elseif not is_excluded_pattern then + matched = arch:match('^' .. pattern_arch .. '$') + end + if not matched then + return false end end - local is_excluded_pattern = pattern:find('!', 1, true) - if excluded and is_excluded_pattern then - return not ('!' .. plat .. '|' .. arch):match('^' .. pattern .. '$') and - not (plat .. '|!' .. arch):match('^' .. pattern .. '$') and - not ('!' .. plat):match('^' .. pattern .. '$') - elseif not is_excluded_pattern then - return (plat .. '|' .. arch):match('^' .. pattern .. '$') or plat:match('^' .. pattern .. '$') + if not pattern_plat and not pattern_arch then + os.raise("invalid script pattern: %s", pattern) end + return true end + -- match patterns function _match_patterns(patterns, plat, arch, opt) for _, pattern in ipairs(patterns) do |
