diff options
| author | ruki <[email protected]> | 2020-03-14 00:14:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-03-13 19:25:35 +0800 |
| commit | 0738f08ef44a4a7c187bbce9049836f9b6f74e7c (patch) | |
| tree | e52af1915309d4bd3957d248dc41a5823df3776b | |
| parent | b0fe63f5e878af48e37b99b5067a6fdfbb2c9791 (diff) | |
fix jobpool
| -rw-r--r-- | xmake/actions/build/build.lua | 1 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/binary.lua | 5 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/shared.lua | 5 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/static.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/private/action/build/object.lua | 22 | ||||
| -rw-r--r-- | xmake/modules/private/async/jobpool.lua | 48 |
6 files changed, 50 insertions, 36 deletions
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua index c4893a9fb..74bc77f26 100644 --- a/xmake/actions/build/build.lua +++ b/xmake/actions/build/build.lua @@ -210,7 +210,6 @@ function main(targetname) -- build all jobs local batchjobs = _get_batchjobs(targetname) - print(batchjobs) if batchjobs and batchjobs:size() > 0 then environment.enter("toolchains") runjobs("build", batchjobs, {comax = option.get("jobs") or 1}) diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua index fd095a7f3..aa9a4df4a 100644 --- a/xmake/actions/build/kinds/binary.lua +++ b/xmake/actions/build/kinds/binary.lua @@ -153,8 +153,11 @@ end -- add batch jobs for building binary target function main(batchjobs, rootjob, target) + -- we need only return and depend the link job for each target, + -- so we can compile the source files for each target in parallel local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total) _link_target(target, {progress = (index * 100) / total}) end, rootjob) - return add_batchjobs_for_object(batchjobs, job_link, target) + add_batchjobs_for_object(batchjobs, job_link, target) + return job_link end diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua index 703393ef4..873e4df0f 100644 --- a/xmake/actions/build/kinds/shared.lua +++ b/xmake/actions/build/kinds/shared.lua @@ -166,8 +166,11 @@ end -- add batch jobs for building shared target function main(batchjobs, rootjob, target) + -- we need only return and depend the link job for each target, + -- so we can compile the source files for each target in parallel local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total) _link_target(target, {progress = (index * 100) / total}) end, rootjob) - return add_batchjobs_for_object(batchjobs, job_link, target) + add_batchjobs_for_object(batchjobs, job_link, target) + return job_link end diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua index 01f3247ea..a4227e013 100644 --- a/xmake/actions/build/kinds/static.lua +++ b/xmake/actions/build/kinds/static.lua @@ -162,8 +162,11 @@ end -- add batch jobs for building static target function main(batchjobs, rootjob, target) + -- we need only return and depend the link job for each target, + -- so we can compile the source files for each target in parallel local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total) _link_target(target, {progress = (index * 100) / total}) end, rootjob) - return add_batchjobs_for_object(batchjobs, job_link, target) + add_batchjobs_for_object(batchjobs, job_link, target) + return job_link end diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua index 2275945e1..423f7fdaa 100644 --- a/xmake/modules/private/action/build/object.lua +++ b/xmake/modules/private/action/build/object.lua @@ -85,25 +85,9 @@ end -- build object function _build_object(target, sourcefile, opt) - - -- do before build - local before_build_file = target:script("build_file_before") - if before_build_file then - before_build_file(target, sourcefile, opt) - end - - -- do build - local on_build_file = target:script("build_file") - if on_build_file then - on_build_file(target, sourcefile, opt) - else - _do_build_file(target, sourcefile, opt) - end - - -- do after build - local after_build_file = target:script("build_file_after") - if after_build_file then - after_build_file(target, sourcefile, opt) + local script = target:script("build_file", _do_build_file) + if script then + script(target, sourcefile, opt) end end diff --git a/xmake/modules/private/async/jobpool.lua b/xmake/modules/private/async/jobpool.lua index de8cc7ca5..9df167598 100644 --- a/xmake/modules/private/async/jobpool.lua +++ b/xmake/modules/private/async/jobpool.lua @@ -57,7 +57,6 @@ function jobpool:addjob(name, run, rootjob) job._deps:push(group) group._parent = group._parent or {} table.insert(group._parent, job) - self._size = self._size + 1 end return job end @@ -73,28 +72,44 @@ function jobpool:popjob() -- init leaf jobs first local leafjobs = self._leafjobs if #leafjobs == 0 then - self:_genleafjobs(self:rootjob(), leafjobs) + local groups = {} + self:_genleafjobs(self:rootjob(), leafjobs, groups) end -- pop a job from the leaf jobs if #leafjobs > 0 then - -- update jobs size - self._size = self._size - 1 - -- get job local job = leafjobs[#leafjobs] table.remove(leafjobs, #leafjobs) - -- remove this job from the parent node + -- get priority and parent node local priority = job._priority or 0 local parent = assert(job._parent, "invalid job without parent node!") - parent._priority = math.max(parent._priority or 0, priority + 1) - parent._deps:remove(job) - if parent._deps:empty() and self._size > 0 then - table.insert(leafjobs, 1, parent) + + -- is group node? remove it from all parent jobs + if job.group then + for _, p in ipairs(parent) do + p._priority = math.max(p._priority or 0, priority + 1) + p._deps:remove(job) + if p._deps:empty() and self._size > 0 then + table.insert(leafjobs, 1, p) + end + end + return self:popjob() + else + + -- update jobs size + self._size = self._size - 1 + + -- remove this job from the parent job + parent._priority = math.max(parent._priority or 0, priority + 1) + parent._deps:remove(job) + if parent._deps:empty() and self._size > 0 then + table.insert(leafjobs, 1, parent) + end + return job, priority end - return job, priority end end @@ -120,11 +135,18 @@ function jobpool:group_leave() end -- generate all leaf jobs from the given job -function jobpool:_genleafjobs(job, leafjobs) +function jobpool:_genleafjobs(job, leafjobs, groups) local deps = job._deps if deps and not deps:empty() then for dep in deps:items() do - self:_genleafjobs(dep, leafjobs) + if dep.group then + if not groups[dep.name] then + groups[dep.name] = true + self:_genleafjobs(dep, leafjobs, groups) + end + else + self:_genleafjobs(dep, leafjobs, groups) + end end else table.insert(leafjobs, job) |
