summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-03-13 00:48:05 +0800
committerruki <[email protected]>2020-03-12 22:48:33 +0800
commitb0fe63f5e878af48e37b99b5067a6fdfbb2c9791 (patch)
treec17c1a1e7e5ef82e0e4b0fc5dfb5feaa43b5c6d0
parentf27cd93d0225ec89370cc5dd1c0051b36518618e (diff)
improve job group and dump
-rw-r--r--xmake/actions/build/kinds/object.lua37
-rw-r--r--xmake/modules/private/async/jobpool.lua107
-rw-r--r--xmake/modules/private/async/runjobs.lua2
3 files changed, 70 insertions, 76 deletions
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua
index 9f19f47b5..df1347686 100644
--- a/xmake/actions/build/kinds/object.lua
+++ b/xmake/actions/build/kinds/object.lua
@@ -91,42 +91,29 @@ end
function add_batchjobs_for_sourcefiles(batchjobs, rootjob, target, sourcebatches)
-- add batch jobs for build_after
- local job_build_after = batchjobs:newgroup(target:name() .. "/after_build_files")
+ batchjobs:group_enter(target:name() .. "/after_build_files")
for _, sourcebatch in pairs(sourcebatches) do
- _add_batchjobs_for_rule(batchjobs, job_build_after, target, sourcebatch, "after")
- _add_batchjobs_for_target(batchjobs, job_build_after, target, sourcebatch, "after")
- end
- if batchjobs:depsize(job_build_after) > 0 then
- batchjobs:add(job_build_after, rootjob)
- else
- job_build_after = rootjob
+ _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, "after")
+ _add_batchjobs_for_target(batchjobs, rootjob, target, sourcebatch, "after")
end
+ local job_build_after = batchjobs:group_leave() or rootjob
-- add source batches
- local job_build = batchjobs:newgroup(target:name() .. "/build_files")
+ batchjobs:group_enter(target:name() .. "/build_files")
for _, sourcebatch in pairs(sourcebatches) do
- if not _add_batchjobs_for_target(target, job_build, target, sourcebatch) then
- _add_batchjobs_for_rule(batchjobs, job_build, target, sourcebatch)
+ if not _add_batchjobs_for_target(target, job_build_after, target, sourcebatch) then
+ _add_batchjobs_for_rule(batchjobs, job_build_after, target, sourcebatch)
end
end
- if batchjobs:depsize(job_build) > 0 then
- batchjobs:add(job_build, job_build_after)
- else
- job_build = job_build_after
- end
+ local job_build = batchjobs:group_leave() or job_build_after
-- add source batches with custom rules before building other sources
- local job_build_before = batchjobs:newgroup(target:name() .. "/before_build_files")
+ batchjobs:group_enter(target:name() .. "/before_build_files")
for _, sourcebatch in pairs(sourcebatches) do
- _add_batchjobs_for_rule(batchjobs, job_build_before, target, sourcebatch, "before")
- _add_batchjobs_for_target(batchjobs, job_build_before, target, sourcebatch, "before")
- end
- if batchjobs:depsize(job_build_before) > 0 then
- batchjobs:add(job_build_before, job_build)
- else
- job_build_before = job_build
+ _add_batchjobs_for_rule(batchjobs, job_build, target, sourcebatch, "before")
+ _add_batchjobs_for_target(batchjobs, job_build, target, sourcebatch, "before")
end
- return job_build_before
+ return batchjobs:group_leave() or job_build
end
-- add batch jobs for building object files
diff --git a/xmake/modules/private/async/jobpool.lua b/xmake/modules/private/async/jobpool.lua
index d2796820c..de8cc7ca5 100644
--- a/xmake/modules/private/async/jobpool.lua
+++ b/xmake/modules/private/async/jobpool.lua
@@ -30,42 +30,11 @@ function jobpool:size()
return self._size
end
--- get dependent jobs size of the given job
-function jobpool:depsize(job)
- return job._deps and job._deps:size() or 0
-end
-
-- get root job
function jobpool:rootjob()
return self._rootjob
end
--- new job
---
--- @param name the job name
--- @param run the run command/script
---
-function jobpool:newjob(name, run)
- return {name = name, run = run}
-end
-
--- new group
---
--- @param name the group name
---
-function jobpool:newgroup(name)
- return self:newjob(name)
-end
-
--- add group to the given job node
---
--- @param name the group name
--- @param rootjob the root job node (optional)
---
-function jobpool:addgroup(name, rootjob)
- return self:addjob(name, nil, rootjob)
-end
-
-- add run job to the given job node
--
-- @param name the job name
@@ -73,30 +42,28 @@ end
-- @param rootjob the root job node (optional)
--
function jobpool:addjob(name, run, rootjob)
+
+ -- add job to the root job
rootjob = rootjob or self:rootjob()
local job = {name = name, run = run, _parent = rootjob}
rootjob._deps = rootjob._deps or dlist:new()
rootjob._deps:push(job)
self._size = self._size + 1
- return job
-end
--- add job to the given job node
---
--- @param job the job or group
--- @param rootjob the root job node (optional)
---
-function jobpool:add(job, rootjob)
- rootjob = rootjob or self:rootjob()
- rootjob._deps = rootjob._deps or dlist:new()
- rootjob._deps:push(job)
- job._parent = rootjob
- self._size = self._size + 1
+ -- in group? attach the group node
+ local group = self._group
+ if group then
+ job._deps = job._deps or dlist:new()
+ job._deps:push(group)
+ group._parent = group._parent or {}
+ table.insert(group._parent, job)
+ self._size = self._size + 1
+ end
return job
end
-- pop job without deps at leaf node
-function jobpool:pop()
+function jobpool:popjob()
-- no jobs?
if self:size() == 0 then
@@ -131,6 +98,27 @@ function jobpool:pop()
end
end
+-- enter group
+--
+-- @param name the group name
+--
+function jobpool:group_enter(name)
+ assert(not self._group, "jobpool: cannot enter group(%s)!", name)
+ self._group = {name = name, group = true}
+end
+
+-- leave group
+--
+-- @return the group node
+--
+function jobpool:group_leave()
+ local group = self._group
+ self._group = nil
+ if group and group._parent then
+ return group
+ end
+end
+
-- generate all leaf jobs from the given job
function jobpool:_genleafjobs(job, leafjobs)
local deps = job._deps
@@ -144,20 +132,39 @@ function jobpool:_genleafjobs(job, leafjobs)
end
-- generate jobs tree for the given job
-function jobpool:_gentree(job)
- local tree = {job.name}
+function jobpool:_gentree(job, groups)
+ local tree = {job.group and ("group(" .. job.name .. ")") or job.name}
local deps = job._deps
if deps and not deps:empty() then
for dep in deps:items() do
- table.insert(tree, self:_gentree(dep))
+ if dep.group then
+ if not groups[dep.name] then
+ groups[dep.name] = true
+ table.insert(tree, self:_gentree(dep, groups))
+ end
+ else
+ table.insert(tree, self:_gentree(dep, groups))
+ end
+ end
+ end
+ -- strip tree
+ local smalltree = {}
+ for _, item in ipairs(tree) do
+ item = table.unwrap(item)
+ if #smalltree < 16 or type(item) == "table" then
+ table.insert(smalltree, item)
+ else
+ table.insert(smalltree, "...")
+ break
end
end
- return tree
+ return smalltree
end
-- tostring
function jobpool:__tostring()
- return string.serialize(self:_gentree(self:rootjob()), {indent = 2})
+ local groups = {}
+ return string.serialize(self:_gentree(self:rootjob(), groups), {indent = 2})
end
-- new a jobpool
diff --git a/xmake/modules/private/async/runjobs.lua b/xmake/modules/private/async/runjobs.lua
index 2b848bde5..6ca176789 100644
--- a/xmake/modules/private/async/runjobs.lua
+++ b/xmake/modules/private/async/runjobs.lua
@@ -157,7 +157,7 @@ function main(name, jobs, opt)
job = job_pending
priority = priority_prev
else
- job, priority = jobs:pop()
+ job, priority = jobs:popjob()
end
if not job then
break