diff options
| author | ruki <[email protected]> | 2024-02-12 21:02:25 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-02-12 21:02:25 +0800 |
| commit | 5c51e97c3c35d21f8b463ed3377e113b55c4af22 (patch) | |
| tree | abfe6c18929a8de3af3c6d93bab81cb559623606 /xmake/plugins | |
| parent | a208ed59d8068fbb34a0baae4e01a5276021ac94 (diff) | |
improve xpack script
Diffstat (limited to 'xmake/plugins')
| -rw-r--r-- | xmake/plugins/pack/xpack.lua | 47 | ||||
| -rw-r--r-- | xmake/plugins/pack/xpack_component.lua | 47 |
2 files changed, 6 insertions, 88 deletions
diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua index 0eae84a7a..1868252d7 100644 --- a/xmake/plugins/pack/xpack.lua +++ b/xmake/plugins/pack/xpack.lua @@ -25,6 +25,7 @@ import("core.base.semver") import("core.base.hashset") import("core.project.config") import("core.project.project") +import("private.core.base.select_script") import("lib.detect.find_tool") import("filter") import("xpack_component") @@ -116,51 +117,9 @@ end -- get xxx_script function xpack: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 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 |
