summaryrefslogtreecommitdiff
path: root/xmake/plugins/pack/xpack_component.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2024-02-15 00:04:49 +0800
committerGitHub <[email protected]>2024-02-15 00:04:49 +0800
commite860f98a8bbc60d296b03a95c374609be86713d8 (patch)
tree49a98ee83d94ea1be8f764cbb260f1f88a298f34 /xmake/plugins/pack/xpack_component.lua
parent2dc22332518a885e565eb17e97f3bafe405748f4 (diff)
parentd069171eaf399228bac1b2e3c2f6c79f06399bbf (diff)
Merge pull request #4729 from xmake-io/script
Improve to select script
Diffstat (limited to 'xmake/plugins/pack/xpack_component.lua')
-rw-r--r--xmake/plugins/pack/xpack_component.lua47
1 files changed, 3 insertions, 44 deletions
diff --git a/xmake/plugins/pack/xpack_component.lua b/xmake/plugins/pack/xpack_component.lua
index dd2c36069..14e19efd5 100644
--- a/xmake/plugins/pack/xpack_component.lua
+++ b/xmake/plugins/pack/xpack_component.lua
@@ -23,6 +23,7 @@ import("core.base.object")
import("core.base.option")
import("core.project.config")
import("core.project.project")
+import("private.core.base.select_script")
-- define module
local xpack_component = xpack_component or object {_init = {"_name", "_info", "_package"}}
@@ -72,51 +73,9 @@ end
-- get xxx_script
function xpack_component:script(name, generic)
-
- -- get script
local script = self:get(name)
- local result = nil
- if type(script) == "function" then
- result = script
- elseif type(script) == "table" then
-
- -- get plat and arch
- local plat = self:plat()
- local arch = self:arch()
-
- -- match pattern
- --
- -- `@linux`
- -- `@linux|x86_64`
- -- `@macosx,linux`
- -- `android@macosx,linux`
- -- `android|armeabi-v7a@macosx,linux`
- -- `android|armeabi-v7a@macosx,linux|x86_64`
- -- `android|armeabi-v7a@linux|x86_64`
- --
- for _pattern, _script in pairs(script) do
- local hosts = {}
- local hosts_spec = false
- _pattern = _pattern:gsub("@(.+)", function (v)
- for _, host in ipairs(v:split(',')) do
- hosts[host] = true
- hosts_spec = true
- end
- return ""
- end)
- if not _pattern:startswith("__") and (not hosts_spec or hosts[os.subhost() .. '|' .. os.subarch()] or hosts[os.subhost()])
- and (_pattern:trim() == "" or (plat .. '|' .. arch):find('^' .. _pattern .. '$') or plat:find('^' .. _pattern .. '$')) then
- result = _script
- break
- end
- end
-
- -- get generic script
- result = result or script["__generic__"] or generic
- end
-
- -- only generic script
- return result or generic
+ local result = select_script(script, {plat = self:plat(), arch = self:arch()}) or generic
+ return result
end
-- get targets