diff options
| author | ruki <[email protected]> | 2025-03-27 23:05:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-04-08 15:31:55 +0800 |
| commit | f55ca39e18390317210ac7d660cbfaa517c1e691 (patch) | |
| tree | a18b2ac8f62e18e49d5bd5c467c810f25bdb98b3 | |
| parent | e12ddee3cc3d237b6f01f03c71f18763781eb1eb (diff) | |
add jobgraph:group
| -rw-r--r-- | tests/modules/async/run_jobgraph.lua | 8 | ||||
| -rw-r--r-- | xmake/actions/build/target_utils.lua | 21 | ||||
| -rw-r--r-- | xmake/modules/async/jobgraph.lua | 27 |
3 files changed, 42 insertions, 14 deletions
diff --git a/tests/modules/async/run_jobgraph.lua b/tests/modules/async/run_jobgraph.lua index 9b8f529ed..4463038b7 100644 --- a/tests/modules/async/run_jobgraph.lua +++ b/tests/modules/async/run_jobgraph.lua @@ -33,9 +33,11 @@ function _test_group() jobs:add("job/root", _jobfunc) for i = 1, 3 do jobs:add("job/" .. i, _jobfunc, {groups = "bar"}) - for j = 1, 50 do - jobs:add("job/" .. i .. "/" .. j, _jobfunc, {groups = "foo"}) - end + jobgraph:group("foo", function () + for j = 1, 50 do + jobs:add("job/" .. i .. "/" .. j, _jobfunc) + end + end) end jobs:add_orders("foo", "bar", "job/root") t = os.mclock() diff --git a/xmake/actions/build/target_utils.lua b/xmake/actions/build/target_utils.lua index 41c979b85..13cf54ad9 100644 --- a/xmake/actions/build/target_utils.lua +++ b/xmake/actions/build/target_utils.lua @@ -39,7 +39,6 @@ end function _add_script_job(jobgraph, instance, script_name, scriptcmd_name, opt) opt = opt or {} local joborders = opt.joborders - local group_name = opt.group_name local script = instance:script(script_name) if script then -- call custom script with jobgraph @@ -49,6 +48,7 @@ function _add_script_job(jobgraph, instance, script_name, scriptcmd_name, opt) -- on_build(function (target, jobgraph, opt) -- end, {jobgraph = true}) if instance:extraconf(script_name, "jobgraph") then + -- TODO group and joborders script(target, jobgraph) elseif instance:extraconf(script_name, "batch") then wprint("%s.%s: the batch mode is deprecated, please use jobgraph mode instead of it.", instance:fullname(), script_name) @@ -62,9 +62,11 @@ function _add_script_job(jobgraph, instance, script_name, scriptcmd_name, opt) local jobname = string.format("%s/%s/%s", instance == target and "target" or "rule", instance:fullname(), script_name) jobgraph:add(jobname, function (index, total, opt) script(target, {progress = opt.progress}) - end, {groups = group_name}) + end) table.insert(joborders, jobname) end + elseif false then + -- TODO call builtin script else -- call command script -- e.g. @@ -79,7 +81,7 @@ function _add_script_job(jobgraph, instance, script_name, scriptcmd_name, opt) local batchcmds_ = batchcmds.new({target = target}) scriptcmd(target, batchcmds_, {progress = opt.progress}) batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")}) - end, {groups = group_name}) + end) table.insert(joborders, jobname) end end @@ -108,12 +110,13 @@ function _add_stage_jobs_for_target(jobgraph, target, stage, opt) -- call target and rules script local joborders = {} - for _, instance in ipairs(instances) do - _add_script_job(jobgraph, instance, script_name, scriptcmd_name, { - group_name = group_name, - joborders = joborders - }) - end + jobgraph:group(group_name, function () + for _, instance in ipairs(instances) do + _add_script_job(jobgraph, instance, script_name, scriptcmd_name, { + joborders = joborders + }) + end + end) -- add job orders if #joborders > 0 then diff --git a/xmake/modules/async/jobgraph.lua b/xmake/modules/async/jobgraph.lua index fe42f6647..b9e9a46da 100644 --- a/xmake/modules/async/jobgraph.lua +++ b/xmake/modules/async/jobgraph.lua @@ -78,8 +78,9 @@ function jobgraph:add(name, run, opt) dag:add_vertex(job) self._size = self._size + 1 - if opt.groups then - for _, group_name in ipairs(opt.groups) do + if self._current_groups or opt.groups then + local job_groups = table.join(self._current_groups or {}, opt.groups) + for _, group_name in ipairs(job_groups) do local groups = self._groups[group_name] if not groups then groups = {} @@ -104,6 +105,28 @@ function jobgraph:remove(name) end end +-- enter group to add jobs +-- +-- e.g. +-- jobgraph:group("foo", function () +-- jobgraph:add("job1", function (index, total, opt) +-- TODO +-- end) +-- jobgraph:add("job2", function (index, total, opt) +-- TODO +-- end) +-- end) +function jobgraph:group(name, callback) + local current_groups = self._current_groups + if current_groups == nil then + current_groups = {} + self._current_groups = current_groups + end + table.insert(current_groups, name) + callback() + table.remove(current_groups) +end + -- add job orders, e.g. add_orders(a, b, c, ...): a -> b -> c, ... -- -- and it supports nil, e.g add_orders("foo", nil, "bar", ...) |
