summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-03-27 00:54:11 +0800
committerruki <[email protected]>2025-04-08 15:31:55 +0800
commit37c593a71339240ea880ab5478f2f5120af992cc (patch)
treef06f593474127d9c0b50a51c64813fbe0145c381
parent78db72c72e2f2d1c699c7c7010e6bd84cdbf9644 (diff)
improve jobs
-rw-r--r--xmake/actions/build/target_utils.lua62
-rw-r--r--xmake/modules/async/jobgraph.lua8
2 files changed, 37 insertions, 33 deletions
diff --git a/xmake/actions/build/target_utils.lua b/xmake/actions/build/target_utils.lua
index aa6f06aa9..aa5413995 100644
--- a/xmake/actions/build/target_utils.lua
+++ b/xmake/actions/build/target_utils.lua
@@ -32,47 +32,45 @@ import("private.utils.batchcmds")
function _add_stage_jobs_for_target(jobgraph, target, stage, opt)
opt = opt or {}
local job_kind = opt.job_kind
+ local progress = opt.progress
- -- the stage group, e.g. foo/after_prepare, bar/before_build
+ -- the group name, e.g. foo/after_prepare, bar/before_build
local group_name = string.format("%s/%s_%s", target:fullname(), stage, job_kind)
- -- call target script first, e.g. before/after_prepare, before/after_build
- local progress = opt.progress
- local script_name = job_kind .. "_" .. stage
- local script = target:script(script_name)
- if script then
- local jobname = target:fullname() .. "/" .. script_name
- jobgraph:add(jobname, function (index, total, opt)
- -- TODO bind target envs
- script(target, {progress = progress})
- end, {groups = group_name})
- end
+ -- the script name, e.g. before/after_prepare, before/after_build
+ local script_name = stage ~= "" and (job_kind .. "_" .. stage) or job_kind
+ -- the command script name, e.g. before/after_preparecmd, before/after_buildcmd
+ local scriptcmd_name = stage ~= "" and (job_kind .. "cmd_" .. stage) or (job_kind .. "cmd")
- -- TODO we should remove root job, use group instead of it
- --[[
- jobgraph:add(job_after, function (index, total, opt)
- local progress = opt.progress
- local script_aftername = job_kind .. "_after"
- local script_after = target:script(script_aftername)
- if script_after then
- script_after(target, {progress = progress})
- end
- for _, r in ipairs(target:orderules()) do
- local script_after = r:script(script_aftername)
- if script_after then
- script_after(target, {progress = progress})
- else
- local scriptcmd_aftername = job_kind .. "cmd_after"
- local scriptcmd_after = r:script(scriptcmd_aftername)
- if scriptcmd_after then
+ -- call target and rules script
+ local jobdeps = {}
+ local instances = table.join(target, target:orderules()) -- TODO sort them
+ for _, instance in ipairs(instances) do
+ local script = instance:script(script_name)
+ if script then
+ local jobname = string.format("%s/%s/%s", instance == target and "target" or "rule", instance:fullname(), script_name)
+ jobgraph:add(jobname, function (index, total, opt)
+ -- TODO bind target envs
+ script(target, {progress = progress})
+ end, {groups = group_name})
+ table.insert(jobdeps, jobname)
+ else
+ local scriptcmd = instance:script(scriptcmd_name)
+ if scriptcmd then
+ local jobname = string.format("%s/%s/%s", instance == target and "target" or "rule", instance:fullname(), scriptcmd_name)
+ jobgraph:add(jobname, function (index, total, opt)
local batchcmds_ = batchcmds.new({target = target})
- scriptcmd_after(target, batchcmds_, {progress = progress})
+ scriptcmd(target, batchcmds_, {progress = progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
- end
+ end, {groups = group_name})
+ table.insert(jobdeps, jobname)
end
end
- end)]]
+ end
+
+ -- add job deps
+ jobgraph:add_deps(jobdeps)
end
-- add jobs for the given target
diff --git a/xmake/modules/async/jobgraph.lua b/xmake/modules/async/jobgraph.lua
index 3440f606b..b72fb5b16 100644
--- a/xmake/modules/async/jobgraph.lua
+++ b/xmake/modules/async/jobgraph.lua
@@ -107,6 +107,7 @@ end
-- add job deps, e.g. add_deps(a, b, c, ...): a -> b -> c, ...
--
-- and it supports nil, e.g add_deps("foo", nil, "bar", ...)
+-- and it also supports to add deps list, e.g. add_deps(deps)
--
function jobgraph:add_deps(...)
local prev
@@ -115,7 +116,12 @@ function jobgraph:add_deps(...)
local jobs = self._jobs
local groups = self._groups
local deps = table.pack(...)
- for i = 1, deps.n do
+ local count = deps.n
+ if count == 1 and type(deps[1]) == "table" then
+ deps = deps[1]
+ count = #deps
+ end
+ for i = 1, count do
local name = deps[i]
if name then
local curr_is_group = false