diff options
| author | ruki <[email protected]> | 2025-03-19 23:35:27 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-04-08 15:31:54 +0800 |
| commit | bc4f14679956d6eac336cb23d72e5e91c189a5bf (patch) | |
| tree | 6d08e7865066546e06abf1171318470494770be1 /xmake/modules/async/jobgraph.lua | |
| parent | a588ee1c3f407cdfcbe5bc9753a5be1b7ca72e7e (diff) | |
add deps for jobgraph
Diffstat (limited to 'xmake/modules/async/jobgraph.lua')
| -rw-r--r-- | xmake/modules/async/jobgraph.lua | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/xmake/modules/async/jobgraph.lua b/xmake/modules/async/jobgraph.lua index 612e56dee..684b7d7d8 100644 --- a/xmake/modules/async/jobgraph.lua +++ b/xmake/modules/async/jobgraph.lua @@ -25,7 +25,7 @@ import("core.base.graph") -- define module local jobqueue = jobqueue or object {_init = {"_jobgraph"}} -local jobgraph = jobgraph or object {_init = {"_jobs", "_size", "_deps", "_dirty"}} +local jobgraph = jobgraph or object {_init = {"_name", "_jobs", "_size", "_deps", "_dirty"}} -- build the job queue function jobqueue:_build() @@ -87,9 +87,21 @@ end -- add job deps, e.g. add_deps(a, b, c, ...): a -> b -> c, ... function jobgraph:add_deps(...) - -- TODO - local deps = table.pack(...) - self._dirty = true + local prev + local dirty + local jobs = self._jobs + local deps = self._deps + for _, name in ipairs(table.pack(...)) do + local curr = assert(jobs[name], "job(%s) not found in jobgraph(%s)", name, self) + if prev then + deps:add_edge(prev, curr) + dirty = true + end + prev = curr + end + if dirty then + self._dirty = true + end end -- add jog group @@ -108,6 +120,11 @@ function jobgraph:jobs() return self._jobs end +-- get jobgraph name +function jobgraph:name() + return self._name +end + -- get job size function jobgraph:size() return self._size @@ -115,10 +132,10 @@ end -- tostring function jobgraph:__tostring() - return string.format("<jobgraph:%s>", self:size()) + return string.format("<jobgraph:%s/%d>", self:name() or "anonymous", self:size()) end -- new a jobgraph -function new() - return jobgraph {{}, 0, graph.new(true), false} +function new(name) + return jobgraph {name, {}, 0, graph.new(true), false} end |
