diff options
| author | ruki <[email protected]> | 2020-03-08 18:45:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-03-08 18:45:38 +0800 |
| commit | afc3cc3fd10f5b5622ff9c431162000720cb05de (patch) | |
| tree | 66134f8918a99b65852c14edf829b284cf60ae7c | |
| parent | c0de5b765909ae429173935110702d0bb221bec5 (diff) | |
revert jobpool
| -rw-r--r-- | xmake/actions/build/build.lua | 35 | ||||
| -rw-r--r-- | xmake/modules/private/async/jobpool.lua | 19 |
2 files changed, 19 insertions, 35 deletions
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua index b7fbd4e49..563f98db8 100644 --- a/xmake/actions/build/build.lua +++ b/xmake/actions/build/build.lua @@ -44,8 +44,8 @@ function _do_build_target(target, opt) end end --- on build the given target -function _on_build_target(target, opt) +-- add builtin build jobs +function _add_buildjobs_builtin(buildjobs, rootjob, target) -- build target with rules local done = false @@ -62,16 +62,15 @@ function _on_build_target(target, opt) _do_build_target(target, opt) end --- add build jobs for script -function _add_buildjob_for_script(buildjobs, rootjob, target, script_name, originjob) +-- add build jobs +function _add_buildjobs(buildjobs, rootjob, target) local job - local script = target:script(script_name) + local script = target:script("build") 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 builtin build jobs + job = _add_buildjobs_builtin(buildjobs, rootjob, target) + elseif target:extraconf("build", "batch") then -- do custom batch script -- e.g. -- target("test") @@ -81,7 +80,7 @@ function _add_buildjob_for_script(buildjobs, rootjob, target, script_name, origi -- end, opt.rootjob) -- end, {batch = true}) -- - job = assert(script(target, buildjobs, {rootjob = rootjob}), "target(%s):%s(): no returned job!", target:name(), script_name) + job = assert(script(target, buildjobs, {rootjob = rootjob}), "target(%s):on_build(): no returned job!", target:name()) else -- do custom script directly -- e.g. @@ -91,7 +90,7 @@ function _add_buildjob_for_script(buildjobs, rootjob, target, script_name, origi -- print("build it") -- end) -- - job = buildjobs:addjob(target:name() .. "/" .. script_name, function (index, total) + job = buildjobs:addjob(target:name() .. "/build", function (index, total) script(target, {progress = (index * 100) / total}) end, rootjob) end @@ -99,7 +98,7 @@ function _add_buildjob_for_script(buildjobs, rootjob, target, script_name, origi end -- add build jobs for the given target -function _add_buildjob_for_target(buildjobs, rootjob, target) +function _add_buildjobs_for_target(buildjobs, rootjob, target) -- has been disabled? if target:get("enabled") == false then @@ -129,8 +128,8 @@ function _add_buildjob_for_target(buildjobs, rootjob, target) end end, rootjob) - -- add build job for target - local job_build = _add_buildjob_for_script(buildjobs, job_after_build, target, "build") + -- add build jobs for target, @note only on_build script support batch jobs + local job_build = _add_buildjobs(buildjobs, job_after_build, target) -- add before_build job for target local job_before_build = buildjobs:addjob(target:name() .. "/before_build", function (index, total) @@ -163,11 +162,11 @@ function _add_buildjob_for_target(buildjobs, rootjob, target) end -- add build jobs for the given target and deps -function _add_buildjob_for_target_and_deps(buildjobs, rootjob, inserted, target) +function _add_buildjobs_for_target_and_deps(buildjobs, rootjob, inserted, target) if not inserted[target:name()] then - rootjob = _add_buildjob_for_target(buildjobs, rootjob, target) + rootjob = _add_buildjobs_for_target(buildjobs, rootjob, target) for _, depname in ipairs(target:get("deps")) do - _add_buildjob_for_target_and_deps(buildjobs, rootjob, inserted, project.target(depname)) + _add_buildjobs_for_target_and_deps(buildjobs, rootjob, inserted, project.target(depname)) end inserted[target:name()] = true end @@ -203,7 +202,7 @@ function _get_buildjobs(targetname) local inserted = {} local buildjobs = jobpool.new() for _, target in pairs(targets_root) do - _add_buildjob_for_target_and_deps(buildjobs, buildjobs:rootjob(), inserted, target) + _add_buildjobs_for_target_and_deps(buildjobs, buildjobs:rootjob(), inserted, target) end return buildjobs end diff --git a/xmake/modules/private/async/jobpool.lua b/xmake/modules/private/async/jobpool.lua index 956ee9300..94b1e6a56 100644 --- a/xmake/modules/private/async/jobpool.lua +++ b/xmake/modules/private/async/jobpool.lua @@ -46,30 +46,15 @@ end -- add job to the given 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(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 +function jobpool:addjob(name, run, rootjob) 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 |
