diff options
| author | ruki <[email protected]> | 2025-03-27 22:49:41 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-04-08 15:31:55 +0800 |
| commit | 8beb0732ff716cd5b3d7a40744b1d239302fdb4b (patch) | |
| tree | 5baa79a9643e8d937efbb375e8c6005481f7d98a | |
| parent | 881671b9516d2e5b76436db1c9456aa02625ec52 (diff) | |
rename add_deps to add_orders
| -rw-r--r-- | tests/modules/async/run_jobgraph.lua | 4 | ||||
| -rw-r--r-- | xmake/actions/build/target_utils.lua | 15 | ||||
| -rw-r--r-- | xmake/core/base/graph.lua | 18 | ||||
| -rw-r--r-- | xmake/modules/async/jobgraph.lua | 20 |
4 files changed, 32 insertions, 25 deletions
diff --git a/tests/modules/async/run_jobgraph.lua b/tests/modules/async/run_jobgraph.lua index bc1b5500f..9b8f529ed 100644 --- a/tests/modules/async/run_jobgraph.lua +++ b/tests/modules/async/run_jobgraph.lua @@ -18,7 +18,7 @@ function _test_basic() jobs:add("job/" .. i, _jobfunc) for j = 1, 50 do jobs:add("job/" .. i .. "/" .. j, _jobfunc) - jobs:add_deps("job/" .. i .. "/" .. j, "job/" .. i, "job/root") + jobs:add_orders("job/" .. i .. "/" .. j, "job/" .. i, "job/root") end end t = os.mclock() @@ -37,7 +37,7 @@ function _test_group() jobs:add("job/" .. i .. "/" .. j, _jobfunc, {groups = "foo"}) end end - jobs:add_deps("foo", "bar", "job/root") + jobs:add_orders("foo", "bar", "job/root") t = os.mclock() runjobs("test", jobs, {comax = 6, timeout = 1000, timer = function (running_jobs_indices) print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ",")) diff --git a/xmake/actions/build/target_utils.lua b/xmake/actions/build/target_utils.lua index 1fef599ac..b91b436f0 100644 --- a/xmake/actions/build/target_utils.lua +++ b/xmake/actions/build/target_utils.lua @@ -50,7 +50,7 @@ function _add_stage_jobs_for_target(jobgraph, target, stage, opt) end -- call target and rules script - local jobdeps = {} + local joborders = {} for _, instance in ipairs(instances) do local script = instance:script(script_name) if script then @@ -59,7 +59,7 @@ function _add_stage_jobs_for_target(jobgraph, target, stage, opt) -- TODO bind target envs script(target, {progress = progress}) end, {groups = group_name}) - table.insert(jobdeps, jobname) + table.insert(joborders, jobname) else local scriptcmd = instance:script(scriptcmd_name) if scriptcmd then @@ -70,13 +70,16 @@ function _add_stage_jobs_for_target(jobgraph, target, stage, opt) scriptcmd(target, batchcmds_, {progress = progress}) batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")}) end, {groups = group_name}) - table.insert(jobdeps, jobname) + table.insert(joborders, jobname) end end end - -- add job deps - jobgraph:add_deps(jobdeps) + -- add job orders + if #joborders > 0 then + jobgraph:add_orders(joborders) + return group_name + end end -- add jobs for the given target @@ -90,7 +93,7 @@ function _add_jobs_for_target(jobgraph, target, opt) local group = _add_stage_jobs_for_target(jobgraph, target, "", opt) local group_before = _add_stage_jobs_for_target(jobgraph, target, "before", opt) local group_after = _add_stage_jobs_for_target(jobgraph, target, "after", opt) - jobgraph:add_deps(group_after, group, group_before) + jobgraph:add_orders(group_before, group, group_after) end -- add jobs for the given target and deps diff --git a/xmake/core/base/graph.lua b/xmake/core/base/graph.lua index 43b43ce3c..db8682b21 100644 --- a/xmake/core/base/graph.lua +++ b/xmake/core/base/graph.lua @@ -173,12 +173,14 @@ end -- -- e.g. -- --- add_edge(a, b) -- a depend on b --- add_edge(b, c) -- b depend on c +-- edges: a (indegree: 0) -> b -> c -- --- local node1, has_cycle = g:partial_topo_sort_next() -- return c +-- add_edge(a, b) +-- add_edge(b, c) +-- +-- local node1, has_cycle = g:partial_topo_sort_next() -- return a -- local node2, has_cycle = g:partial_topo_sort_next() -- return b --- local node3, has_cycle = g:partial_topo_sort_next() -- return a +-- local node3, has_cycle = g:partial_topo_sort_next() -- return c -- local node4, has_cycle = g:partial_topo_sort_next() -- return nil (empty, all done) -- function graph:partial_topo_sort_next() @@ -250,10 +252,12 @@ end -- -- e.g. -- --- add_edge(a, b) -- a depend on b --- add_edge(b, c) -- b depend on c +-- edges: a (indegree: 0) -> b -> c +-- +-- add_edge(a, b) +-- add_edge(b, c) -- --- it will return {c, b, a} +-- it will return {a, b, c} function graph:topo_sort() if not self:is_directed() then return diff --git a/xmake/modules/async/jobgraph.lua b/xmake/modules/async/jobgraph.lua index b72fb5b16..fe42f6647 100644 --- a/xmake/modules/async/jobgraph.lua +++ b/xmake/modules/async/jobgraph.lua @@ -104,25 +104,25 @@ function jobgraph:remove(name) end end --- add job deps, e.g. add_deps(a, b, c, ...): a -> b -> c, ... +-- add job orders, e.g. add_orders(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) +-- and it supports nil, e.g add_orders("foo", nil, "bar", ...) +-- and it also supports to add orders list, e.g. add_orders(orders) -- -function jobgraph:add_deps(...) +function jobgraph:add_orders(...) local prev local prev_is_group local dag = self._dag local jobs = self._jobs local groups = self._groups - local deps = table.pack(...) - local count = deps.n - if count == 1 and type(deps[1]) == "table" then - deps = deps[1] - count = #deps + local orders = table.pack(...) + local count = orders.n + if count == 1 and type(orders[1]) == "table" then + orders = orders[1] + count = #orders end for i = 1, count do - local name = deps[i] + local name = orders[i] if name then local curr_is_group = false local curr = jobs[name] |
