diff options
| author | ruki <[email protected]> | 2024-03-05 00:52:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-03-05 00:52:03 +0800 |
| commit | 69d11ecb1f292694bec66c061ad4c92584e9f7d5 (patch) | |
| tree | 728939f063f0c11e35b132940383eae0657a3e65 | |
| parent | 4ff48f7a7027ab9c403f2448c918d2d1ded118fa (diff) | |
improve to select script
| -rw-r--r-- | tests/modules/private/select_script/test.lua | 17 | ||||
| -rw-r--r-- | xmake/core/base/private/select_script.lua | 19 |
2 files changed, 29 insertions, 7 deletions
diff --git a/tests/modules/private/select_script/test.lua b/tests/modules/private/select_script/test.lua index 193da790a..f1e950dd1 100644 --- a/tests/modules/private/select_script/test.lua +++ b/tests/modules/private/select_script/test.lua @@ -1,6 +1,23 @@ 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 +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"})) end function test_arch_only(t) diff --git a/xmake/core/base/private/select_script.lua b/xmake/core/base/private/select_script.lua index 1fe8a77fd..b9cb7ad12 100644 --- a/xmake/core/base/private/select_script.lua +++ b/xmake/core/base/private/select_script.lua @@ -86,7 +86,8 @@ end -- `!android|armeabi-v7a@!linux|!x86_64` -- `!linux|*` -- -function _match_script(pattern, plat, arch, excluded) +function _match_script(pattern, opt) + opt = opt or {} local splitinfo = pattern:split("@", {strict = true, plain = true}) local plat_part = splitinfo[1] local host_part = splitinfo[2] @@ -98,17 +99,22 @@ function _match_script(pattern, plat, arch, excluded) if host_part and #host_part > 0 then host_patterns = host_part:split(",", {plain = true}) end + local plat = opt.plat or "" + local arch = opt.arch or "" + local subhost = opt.subhost or os.subhost() + local subarch = opt.subarch or os.subarch() + local excluded = opt.excluded if plat_patterns and #plat_patterns > 0 then if _match_patterns(plat_patterns, plat, arch, excluded) then if host_patterns and #host_patterns > 0 and - not _match_patterns(host_patterns, os.subhost(), os.subarch(), excluded) then + not _match_patterns(host_patterns, subhost, subarch, excluded) then return false end return true end else if host_patterns and #host_patterns > 0 then - return _match_patterns(host_patterns, os.subhost(), os.subarch(), excluded) + return _match_patterns(host_patterns, subhost, subarch, excluded) end end end @@ -120,11 +126,9 @@ function select_script(scripts, opt) if type(scripts) == "function" then result = scripts elseif type(scripts) == "table" then - local plat = opt.plat or "" - local arch = opt.arch or "" local script_matched for pattern, script in pairs(scripts) do - if not pattern:startswith("__") and _match_script(pattern, plat, arch) then + if not pattern:startswith("__") and _match_script(pattern, opt) then script_matched = script break end @@ -132,8 +136,9 @@ function select_script(scripts, opt) if not script_matched then local scripts_fallback = {} local patterns_fallback = {} + local excluded_opt = table.join(opt, {excluded = true}) for pattern, script in pairs(scripts) do - if not pattern:startswith("__") and _match_script(pattern, plat, arch, true) then + if not pattern:startswith("__") and _match_script(pattern, excluded_opt) then table.insert(scripts_fallback, script) table.insert(patterns_fallback, pattern) end |
