summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-11-20 22:32:36 +0800
committerruki <[email protected]>2023-11-20 22:32:36 +0800
commit9aad219bee6773423b05361c1b6ed33d1840ebb5 (patch)
treefe0876d85ef2dbe167376a40c9ff632383a78bd0
parent081ab8547ac7faff45ee89cdd9b4fcd6c7d68775 (diff)
improve xpack
-rw-r--r--xmake/plugins/pack/main.lua22
-rw-r--r--xmake/plugins/pack/xpack.lua12
2 files changed, 19 insertions, 15 deletions
diff --git a/xmake/plugins/pack/main.lua b/xmake/plugins/pack/main.lua
index e404aba9b..76cc77912 100644
--- a/xmake/plugins/pack/main.lua
+++ b/xmake/plugins/pack/main.lua
@@ -26,8 +26,7 @@ import("private.service.remote_build.action", {alias = "remote_build_action"})
import("actions.build.main", {rootdir = os.programdir(), alias = "build_action"})
import("xpack")
-function _load_package(package, format)
- package:format_set(format)
+function _load_package(package)
local script = package:script("load")
if script then
script(package)
@@ -54,34 +53,31 @@ function _pack_package(package)
end
-- do pack
- assert(package:formats(), "xpack(%s): formats not found, please use `set_formats()` to set it.", package:name())
local scripts = {
package:script("package_before"),
package:script("package", _on_package),
package:script("package_after")
}
- for _, format in package:formats():keys() do
- if not formats_need or table.contains(formats_need, format) then
- _load_package(package, format)
- for i = 1, 3 do
- local script = scripts[i]
- if script ~= nil then
- script(package)
- end
+ if not formats_need or table.contains(formats_need, package:format()) then
+ _load_package(package)
+ for i = 1, 3 do
+ local script = scripts[i]
+ if script ~= nil then
+ script(package)
end
end
end
end
function _pack_packages()
- for _, package in pairs(xpack.packages()) do
+ for _, package in ipairs(xpack.packages()) do
_pack_package(package)
end
end
function _build_targets()
local targetnames = {}
- for _, package in pairs(xpack.packages()) do
+ for _, package in ipairs(xpack.packages()) do
local targets = package:get("targets")
if targets then
table.join2(targetnames, targets)
diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua
index d0dc56697..0d6dd08f3 100644
--- a/xmake/plugins/pack/xpack.lua
+++ b/xmake/plugins/pack/xpack.lua
@@ -514,8 +514,16 @@ function packages()
need = true
end
if need then
- local instance = _new(name, scope)
- packages[name] = instance
+ local formats = scope:get("formats")
+ if formats then
+ for _, format in ipairs(formats) do
+ local instance = _new(name, scope)
+ instance:format_set(format)
+ table.insert(packages, instance)
+ end
+ else
+ raise("xpack(%s): formats not found, please use `set_formats()` to set it.", scope:get("name"))
+ end
end
end
_g.packages = packages