improve to select script

pull/3299/head
ruki 9 months ago
parent 8c6dd6604a
commit 0f239d0ba8
  1. 46
      scripts/packages.lua

@ -1,59 +1,19 @@
-- imports
import("core.package.package")
import("core.platform.platform")
import("private.core.base.select_script")
-- is supported platform and architecture?
function is_supported(instance, plat, arch, opt)
-- ignore template package
if instance.is_template and instance:is_template() then
if instance:is_template() then
return false
end
-- get script
local script = instance:get("install")
local result = nil
if type(script) == "function" then
result = script
elseif type(script) == "table" then
-- get plat and arch
local plat = plat or ""
local arch = arch or ""
-- 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 _pattern:trim() == "" and opt and opt.onlyhost then
_pattern = os.subhost()
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__"]
end
local result = select_script(script, {plat = plat, arch = arch})
return result
end

Loading…
Cancel
Save