diff options
| author | ruki <[email protected]> | 2025-03-27 00:48:17 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-04-08 15:31:55 +0800 |
| commit | 78db72c72e2f2d1c699c7c7010e6bd84cdbf9644 (patch) | |
| tree | 9c29c804b6c9dea5128175dc3e76afde5ce07526 /xmake/modules | |
| parent | 4fee5fe56d3eedb3871ee237b083bb3bcbf6ec5c (diff) | |
add stage jobs for target
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/async/jobgraph.lua | 77 |
1 files changed, 42 insertions, 35 deletions
diff --git a/xmake/modules/async/jobgraph.lua b/xmake/modules/async/jobgraph.lua index d737c7348..3440f606b 100644 --- a/xmake/modules/async/jobgraph.lua +++ b/xmake/modules/async/jobgraph.lua @@ -105,54 +105,61 @@ function jobgraph:remove(name) 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", ...) +-- function jobgraph:add_deps(...) local prev local prev_is_group local dag = self._dag local jobs = self._jobs local groups = self._groups - for _, name in ipairs(table.pack(...)) do - local curr_is_group = false - local curr = jobs[name] - if not curr then - curr = groups[name] - curr_is_group = true - end - assert(curr, "job(%s) not found in jobgraph(%s)", name, self) - if prev then - if prev_is_group and curr_is_group then - -- we use a fake job as a node to bridge the two groups. - local fakejob = {} - for _, job in ipairs(prev) do - if not dag:has_edge(job, fakejob) then - dag:add_edge(job, fakejob) + local deps = table.pack(...) + for i = 1, deps.n do + local name = deps[i] + if name then + local curr_is_group = false + local curr = jobs[name] + if not curr then + curr = groups[name] + curr_is_group = true + end + assert(curr, "job(%s) not found in jobgraph(%s)", name, self) + if prev then + if prev_is_group and curr_is_group then + -- we use a fake job as a node to bridge the two groups. + local fakejob = {} + for _, job in ipairs(prev) do + if not dag:has_edge(job, fakejob) then + dag:add_edge(job, fakejob) + end end - end - for _, job in ipairs(curr) do - if not dag:has_edge(fakejob, job) then - dag:add_edge(fakejob, job) + for _, job in ipairs(curr) do + if not dag:has_edge(fakejob, job) then + dag:add_edge(fakejob, job) + end end - end - elseif curr_is_group then - for _, job in ipairs(curr) do - if not dag:has_edge(prev, job) then - dag:add_edge(prev, job) + elseif curr_is_group then + for _, job in ipairs(curr) do + if not dag:has_edge(prev, job) then + dag:add_edge(prev, job) + end end - end - elseif prev_is_group then - for _, job in ipairs(prev) do - if not dag:has_edge(job, curr) then - dag:add_edge(job, curr) + elseif prev_is_group then + for _, job in ipairs(prev) do + if not dag:has_edge(job, curr) then + dag:add_edge(job, curr) + end + end + else + if not dag:has_edge(prev, curr) then + dag:add_edge(prev, curr) end - end - else - if not dag:has_edge(prev, curr) then - dag:add_edge(prev, curr) end end + prev = curr + prev_is_group = curr_is_group end - prev = curr - prev_is_group = curr_is_group end end |
