summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-05-11 00:51:25 +0800
committerruki <[email protected]>2021-05-11 10:28:37 +0800
commitcec2f889c5e9fa644b0b93c584b577b503b7bb2e (patch)
tree5b4a55d701e438605951b2bab6ecb3685fb51cca
parent0b9b15fb9cd681831d3964474f5935e4e38e0e60 (diff)
improve jobpool:addjob
-rw-r--r--tests/modules/scheduler/runjobs.lua4
-rw-r--r--xmake/actions/build/build.lua13
-rw-r--r--xmake/actions/build/kinds/binary.lua2
-rw-r--r--xmake/actions/build/kinds/object.lua12
-rw-r--r--xmake/actions/build/kinds/shared.lua2
-rw-r--r--xmake/actions/build/kinds/static.lua2
-rw-r--r--xmake/modules/private/async/jobpool.lua7
-rw-r--r--xmake/modules/private/async/runjobs.lua2
8 files changed, 21 insertions, 23 deletions
diff --git a/tests/modules/scheduler/runjobs.lua b/tests/modules/scheduler/runjobs.lua
index 8659ef6ef..aea365241 100644
--- a/tests/modules/scheduler/runjobs.lua
+++ b/tests/modules/scheduler/runjobs.lua
@@ -28,11 +28,11 @@ function main()
for i = 1, 3 do
local job = jobs:addjob("job/" .. i, function (idx, total)
_jobfunc(idx, total)
- end, root)
+ end, {rootjob = root})
for j = 1, 50 do
jobs:addjob("job/" .. i .. "/" .. j, function (idx, total)
_jobfunc(idx, total)
- end, job)
+ end, {rootjob = job})
end
end
t = os.mclock()
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua
index aa8805c62..6448fd03d 100644
--- a/xmake/actions/build/build.lua
+++ b/xmake/actions/build/build.lua
@@ -48,7 +48,7 @@ function _add_batchjobs_builtin(batchjobs, rootjob, target)
else
job = batchjobs:addjob("rule/" .. r:name() .. "/build", function (index, total)
script(target, {progress = (index * 100) / total})
- end, job or rootjob)
+ end, {rootjob = job or rootjob, envs = target:pkgenvs()})
end
end
end
@@ -76,7 +76,7 @@ function _add_batchjobs(batchjobs, rootjob, target)
-- on_build(function (target, batchjobs, opt)
-- return batchjobs:addjob("test", function (idx, total)
-- print("build it")
- -- end, opt.rootjob)
+ -- end, {rootjob = opt.rootjob})
-- end, {batch = true})
--
job, job_leaf = assert(script(target, batchjobs, {rootjob = rootjob}), "target(%s):on_build(): no returned job!", target:name())
@@ -91,7 +91,7 @@ function _add_batchjobs(batchjobs, rootjob, target)
--
job = batchjobs:addjob(target:name() .. "/build", function (index, total)
script(target, {progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob, envs = target:pkgenvs()})
end
return job, job_leaf or job
end
@@ -119,7 +119,7 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target)
after_build(target, {progress = progress})
end
end
- end, rootjob)
+ end, {rootjob = rootjob, envs = target:pkgenvs()})
-- add batch jobs for target, @note only on_build script support batch jobs
local job_build, job_build_leaf = _add_batchjobs(batchjobs, job_after_build, target)
@@ -127,9 +127,6 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target)
-- add before_build job for target
local job_build_before = batchjobs:addjob(target:name() .. "/before_build", function (index, total)
- -- enter the environments of the target packages
- os.addenvs(target:pkgenvs())
-
-- clean target if rebuild
if option.get("rebuild") and not option.get("dry-run") then
_clean_target(target)
@@ -147,7 +144,7 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target)
before_build(target, {progress = progress})
end
end
- end, job_build_leaf)
+ end, {rootjob = job_build_leaf, envs = target:pkgenvs()})
-- we need do build_before after all dependent targets if across_targets_in_parallel is disabled
return target:policy("build.across_targets_in_parallel") == false and job_build_before or job_build, job_after_build
diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua
index bc4763fd6..0f2f8f96a 100644
--- a/xmake/actions/build/kinds/binary.lua
+++ b/xmake/actions/build/kinds/binary.lua
@@ -135,7 +135,7 @@ function main(batchjobs, rootjob, target)
-- add link job
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total)
_link_target(target, {progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob, envs = target:pkgenvs()})
-- we need only return and depend the link job for each target,
-- so we can compile the source files for each target in parallel
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua
index 866c9680c..5d4e4e47d 100644
--- a/xmake/actions/build/kinds/object.lua
+++ b/xmake/actions/build/kinds/object.lua
@@ -42,7 +42,7 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
else
batchjobs:addjob("rule/" .. rulename .. "/" .. scriptname, function (index, total)
script(target, sourcebatch, {progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob, envs = target:pkgenvs()})
end
end
@@ -55,7 +55,7 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
batchjobs:addjob(sourcefile, function (index, total)
script(target, sourcefile, {sourcekind = sourcekind, progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob, envs = target:pkgenvs()})
end
end
end
@@ -69,7 +69,7 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
local batchcmds_ = batchcmds.new({target = target})
script(target, batchcmds_, sourcebatch, {progress = (index * 100) / total})
batchcmds_:runcmds({dryrun = option.get("dry-run")})
- end, rootjob)
+ end, {rootjob = rootjob, envs = target:pkgenvs()})
end
end
@@ -84,7 +84,7 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
local batchcmds_ = batchcmds.new({target = target})
script(target, batchcmds_, sourcefile, {sourcekind = sourcekind, progress = (index * 100) / total})
batchcmds_:runcmds({dryrun = option.get("dry-run")})
- end, rootjob)
+ end, {rootjob = rootjob, envs = target:pkgenvs()})
end
end
end
@@ -102,7 +102,7 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target, sourcebatch, suff
else
batchjobs:addjob(target:name() .. "/" .. scriptname, function (index, total)
script(target, sourcebatch, {progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob, envs = target:pkgenvs()})
end
return true
else
@@ -113,7 +113,7 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target, sourcebatch, suff
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
batchjobs:addjob(sourcefile, function (index, total)
script(target, sourcefile, {sourcekind = sourcekind, progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob, envs = target:pkgenvs()})
end
return true
end
diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua
index 2c95bd95b..c7c4d2a37 100644
--- a/xmake/actions/build/kinds/shared.lua
+++ b/xmake/actions/build/kinds/shared.lua
@@ -150,7 +150,7 @@ function main(batchjobs, rootjob, target)
-- add link job
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total)
_link_target(target, {progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob, envs = target:pkgenvs()})
-- we need only return and depend the link job for each target,
-- so we can compile the source files for each target in parallel
diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua
index 63bc50304..3983adef0 100644
--- a/xmake/actions/build/kinds/static.lua
+++ b/xmake/actions/build/kinds/static.lua
@@ -150,7 +150,7 @@ function main(batchjobs, rootjob, target)
-- add link job
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total)
_link_target(target, {progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob, envs = target:pkgenvs()})
-- we need only return and depend the link job for each target,
-- so we can compile the source files for each target in parallel
diff --git a/xmake/modules/private/async/jobpool.lua b/xmake/modules/private/async/jobpool.lua
index eb7d5ffc1..2709db341 100644
--- a/xmake/modules/private/async/jobpool.lua
+++ b/xmake/modules/private/async/jobpool.lua
@@ -39,10 +39,11 @@ end
--
-- @param name the job name
-- @param run the run command/script
--- @param rootjob the root job node (optional)
+-- @param opt the options (rootjob, envs)
--
-function jobpool:addjob(name, run, rootjob)
- return self:add({name = name, run = run}, rootjob)
+function jobpool:addjob(name, run, opt)
+ opt = opt or {}
+ return self:add({name = name, run = run, envs = opt.envs}, opt.rootjob)
end
-- add job to the given job node
diff --git a/xmake/modules/private/async/runjobs.lua b/xmake/modules/private/async/runjobs.lua
index 307adfa55..d1d1739b5 100644
--- a/xmake/modules/private/async/runjobs.lua
+++ b/xmake/modules/private/async/runjobs.lua
@@ -46,7 +46,7 @@ end
-- for i = 1, 3 do
-- local job = jobs:addjob("job/" .. i, function (idx, total)
-- print(idx, total)
--- end, root)
+-- end, {rootjob = root})
-- end
-- runjobs("test", jobs, {comax = 6, timeout = 1000, on_timer = function (running_jobs_indices) end})
--