summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-03-08 18:06:23 +0800
committerruki <[email protected]>2020-03-08 18:06:23 +0800
commit07cb69433cdc6a8d60504ae88cc6251f9c69201a (patch)
tree1e4554c8f1941a620c0240d5d2c8e43e2d7789e5
parent3f5723c632d0734ce3ea93e174cdf099eeefb543 (diff)
fix jobpool
-rw-r--r--tests/modules/scheduler/runjobs.lua6
-rw-r--r--xmake/actions/build/build.lua52
-rw-r--r--xmake/core/base/interpreter.lua7
-rw-r--r--xmake/core/project/target.lua4
-rw-r--r--xmake/modules/private/async/jobpool.lua30
-rw-r--r--xmake/modules/private/async/runjobs.lua14
6 files changed, 87 insertions, 26 deletions
diff --git a/tests/modules/scheduler/runjobs.lua b/tests/modules/scheduler/runjobs.lua
index 489e221ee..29befa5d0 100644
--- a/tests/modules/scheduler/runjobs.lua
+++ b/tests/modules/scheduler/runjobs.lua
@@ -22,15 +22,15 @@ function main()
-- test jobs
print("==================================== test jobs ====================================")
local jobs = jobpool.new()
- local root = jobs:addjob("job/root", function (idx, total, job)
+ local root = jobs:addjob("job/root", function (idx, total)
_jobfunc(idx, total)
end)
for i = 1, 3 do
- local job = jobs:addjob("job/" .. i, function (idx, total, job)
+ local job = jobs:addjob("job/" .. i, function (idx, total)
_jobfunc(idx, total)
end, root)
for j = 1, 50 do
- jobs:addjob("job/" .. i .. "/" .. j, function (idx, total, job)
+ jobs:addjob("job/" .. i .. "/" .. j, function (idx, total)
_jobfunc(idx, total)
end, job)
end
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua
index d01890c0f..b7fbd4e49 100644
--- a/xmake/actions/build/build.lua
+++ b/xmake/actions/build/build.lua
@@ -62,7 +62,43 @@ function _on_build_target(target, opt)
_do_build_target(target, opt)
end
--- build the given target
+-- add build jobs for script
+function _add_buildjob_for_script(buildjobs, rootjob, target, script_name, originjob)
+
+ local job
+ local script = target:script(script_name)
+ if not script then
+ -- do builtin original batch job
+ assert(originjob, "target(%s):%s(): not found!", target:name(), script_name)
+ job = buildjobs:addjob(originjob, rootjob)
+ elseif target:extraconf(script_name, "batch") then
+ -- do custom batch script
+ -- e.g.
+ -- target("test")
+ -- on_build(function (target, batchjobs, opt)
+ -- return batchjobs:addjob("test", function (idx, total)
+ -- print("build it")
+ -- end, opt.rootjob)
+ -- end, {batch = true})
+ --
+ job = assert(script(target, buildjobs, {rootjob = rootjob}), "target(%s):%s(): no returned job!", target:name(), script_name)
+ else
+ -- do custom script directly
+ -- e.g.
+ --
+ -- target("test")
+ -- on_build(function (target, opt)
+ -- print("build it")
+ -- end)
+ --
+ job = buildjobs:addjob(target:name() .. "/" .. script_name, function (index, total)
+ script(target, {progress = (index * 100) / total})
+ end, rootjob)
+ end
+ return job
+end
+
+-- add build jobs for the given target
function _add_buildjob_for_target(buildjobs, rootjob, target)
-- has been disabled?
@@ -72,7 +108,7 @@ function _add_buildjob_for_target(buildjobs, rootjob, target)
-- add after_build job for target
local oldenvs = {}
- local job_after_build = buildjobs:addjob(target:name() .. "/after_build", function (index, total, job)
+ local job_after_build = buildjobs:addjob(target:name() .. "/after_build", function (index, total)
-- do after_build
local progress = (index * 100) / total
@@ -94,16 +130,10 @@ function _add_buildjob_for_target(buildjobs, rootjob, target)
end, rootjob)
-- add build job for target
- local job_build = buildjobs:addjob(target:name() .. "/build", function (index, total, job)
- local progress = (index * 100) / total
- local on_build = target:script("build", _on_build_target)
- if on_build then
- on_build(target, {origin = _do_build_target, progress = progress})
- end
- end, job_after_build)
+ local job_build = _add_buildjob_for_script(buildjobs, job_after_build, target, "build")
-- add before_build job for target
- local job_before_build = buildjobs:addjob(target:name() .. "/before_build", function (index, total, job)
+ local job_before_build = buildjobs:addjob(target:name() .. "/before_build", function (index, total)
-- enter the environments of the target packages
for name, values in pairs(target:pkgenvs()) do
@@ -132,7 +162,7 @@ function _add_buildjob_for_target(buildjobs, rootjob, target)
return job_before_build
end
--- build the given target and deps
+-- add build jobs for the given target and deps
function _add_buildjob_for_target_and_deps(buildjobs, rootjob, inserted, target)
if not inserted[target:name()] then
rootjob = _add_buildjob_for_target(buildjobs, rootjob, target)
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 579ffec46..9e9583d32 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -286,6 +286,13 @@ function interpreter:_api_register_xxx_script(scope_kind, action, ...)
-- get arguments, pattern1, pattern2, ..., script function or name
local args = {...}
+ -- get and save extra config
+ local extra_config = args[#args]
+ if table.is_dictionary(extra_config) then
+ table.remove(args)
+ scope["__extra_" .. name] = extra_config
+ end
+
-- get patterns
local patterns = {}
if #args > 1 then
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index cdcb65f0c..cb486a025 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -276,7 +276,7 @@ function _instance:get(name, opt)
end
-- get the extra configuration
- local extraconf = self._INFO:extraconf(name)
+ local extraconf = self:extraconf(name)
if extraconf then
-- filter values for public, private or interface if be not dictionary
if not table.is_dictionary(values) then
@@ -1456,8 +1456,6 @@ function _instance:script(name, generic)
end
end
end
-
- -- ok
return result
end
diff --git a/xmake/modules/private/async/jobpool.lua b/xmake/modules/private/async/jobpool.lua
index 07f651d11..956ee9300 100644
--- a/xmake/modules/private/async/jobpool.lua
+++ b/xmake/modules/private/async/jobpool.lua
@@ -35,17 +35,41 @@ 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
+
-- add job to the given job node
--
--- @param rootjob the root job node
+-- @param job the job
+-- @param rootjob the root job node (optional)
+--
+-- or
+--
-- @param name the job name
-- @param run the run command/script
+-- @param rootjob the root job node (optional)
--
-function jobpool:addjob(name, run, rootjob)
+function jobpool:addjob(job_or_name, ...)
+ local args = table.pack(...)
+ local job
+ local rootjob
+ if type(job_or_name) == "table" then
+ job = job_or_name
+ rootjob = args[1]
+ else
+ rootjob = args[2]
+ job = {name = job_or_name, run = args[1]}
+ end
rootjob = rootjob or self:rootjob()
- local job = {name = name, run = run, _parent = rootjob}
rootjob._deps = rootjob._deps or dlist:new()
rootjob._deps:push(job)
+ job._parent = rootjob
self._count = self._count + 1
return job
end
diff --git a/xmake/modules/private/async/runjobs.lua b/xmake/modules/private/async/runjobs.lua
index ce899bc2e..00b8b5f55 100644
--- a/xmake/modules/private/async/runjobs.lua
+++ b/xmake/modules/private/async/runjobs.lua
@@ -46,12 +46,14 @@ end
-- runjobs("test", function (index) print("hello") end, {total = 100, comax = 6, timeout = 1000, timer = function (running_jobs_indices) end})
-- runjobs("test", function () os.sleep(10000) end, {showtips = true})
--
--- local jobs = {}
+-- local jobs = jobpool.new()
+-- local root = jobs:addjob("job/root", function (idx, total)
+-- print(idx, total)
+-- end)
-- for i = 1, 3 do
--- for j = 1, 50 do
--- table.insert(jobs, {priority = i, run = function (idx, job)
--- end})
--- end
+-- local job = jobs:addjob("job/" .. i, function (idx, total)
+-- print(idx, total)
+-- end, root)
-- end
-- runjobs("test", jobs, {comax = 6, timeout = 1000, timer = function (running_jobs_indices) end})
--
@@ -178,7 +180,7 @@ function main(name, jobs, opt)
try
{
function()
- jobfunc(i, total, job)
+ jobfunc(i, total)
end,
catch
{