diff options
| author | ruki <[email protected]> | 2025-03-26 23:40:41 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-04-08 15:31:55 +0800 |
| commit | ac5adead4c78cd74f9e3127e423fefaad700a1d8 (patch) | |
| tree | b7ae913c20eccdc359f63620384878d6617daaaf | |
| parent | 05605de8581d8f4f343b8e297b4e828b0b03c445 (diff) | |
add runjobs for target utils
| -rw-r--r-- | xmake/actions/build/prepare.lua | 50 | ||||
| -rw-r--r-- | xmake/actions/build/target_utils.lua | 48 |
2 files changed, 52 insertions, 46 deletions
diff --git a/xmake/actions/build/prepare.lua b/xmake/actions/build/prepare.lua index 2b2f605b2..55e97afe1 100644 --- a/xmake/actions/build/prepare.lua +++ b/xmake/actions/build/prepare.lua @@ -19,52 +19,10 @@ -- -- imports -import("core.base.option") -import("core.project.project") -import("async.runjobs") -import("async.jobgraph", {alias = "async_jobgraph"}) - --- add prepare jobs for the given target -function _add_prepare_jobs_for_target(jobgraph, target) - if not target:is_enabled() then - return - end - -end - --- add prepare jobs for the given target and deps -function _add_preprare_jobs_for_target_and_deps(jobgraph, target, targetrefs) - local targetname = target:fullname() - if not targetrefs[targetname] then - targetrefs[targetname] = target - _add_prepare_jobs_for_target(jobgraph, target) - for _, depname in ipairs(target:get("deps")) do - local dep = project.target(depname, {namespace = target:namespace()}) - _add_preprare_jobs_for_target_and_deps(jobgraph, dep, targetrefs) - end - end -end - --- get prepare jobs -function _get_prepare_jobs(targets_root, opt) - local jobgraph = async_jobgraph.new() - local targetrefs = {} - for _, target in ipairs(targets_root) do - _add_preprare_jobs_for_target_and_deps(jobgraph, target, targetrefs) - end - return jobgraph -end +import("target_utils") function main(targets_root, opt) - local jobgraph = _get_prepare_jobs(targets_root, opt) - if jobgraph and not jobgraph:empty() then - local curdir = os.curdir() - runjobs("prepare", jobgraph, {on_exit = function (errors) - import("utils.progress") - if errors and progress.showing_without_scroll() then - print("") - end - end, comax = option.get("jobs") or 1, curdir = curdir}) - os.cd(curdir) - end + opt = opt or {} + opt.jobkind = "prepare" + target_utils.runjobs(targets_root, opt) end diff --git a/xmake/actions/build/target_utils.lua b/xmake/actions/build/target_utils.lua index 2c098400d..baa63d5b2 100644 --- a/xmake/actions/build/target_utils.lua +++ b/xmake/actions/build/target_utils.lua @@ -23,6 +23,38 @@ import("core.base.option") import("core.base.hashset") import("core.project.config") import("core.project.project") +import("async.runjobs") +import("async.jobgraph", {alias = "async_jobgraph"}) + +-- add jobs for the given target +function _add_jobs_for_target(jobgraph, target) + if not target:is_enabled() then + return + end +end + +-- add jobs for the given target and deps +function _add_jobs_for_target_and_deps(jobgraph, target, targetrefs) + local targetname = target:fullname() + if not targetrefs[targetname] then + targetrefs[targetname] = target + _add_jobs_for_target(jobgraph, target) + for _, depname in ipairs(target:get("deps")) do + local dep = project.target(depname, {namespace = target:namespace()}) + _add_jobs_for_target_and_deps(jobgraph, dep, targetrefs) + end + end +end + +-- get jobs +function _get_jobs(targets_root, opt) + local jobgraph = async_jobgraph.new() + local targetrefs = {} + for _, target in ipairs(targets_root) do + _add_jobs_for_target_and_deps(jobgraph, target, targetrefs) + end + return jobgraph +end -- get all root targets function get_root_targets(targetnames, opt) @@ -71,3 +103,19 @@ function get_root_targets(targetnames, opt) end return targets_root end + +function runjobs(targets_root, opt) + opt = opt or {} + local jobkind = opt.jobkind + local jobgraph = _get_jobs(targets_root, opt) + if jobgraph and not jobgraph:empty() then + local curdir = os.curdir() + runjobs(jobkind, jobgraph, {on_exit = function (errors) + import("utils.progress") + if errors and progress.showing_without_scroll() then + print("") + end + end, comax = option.get("jobs") or 1, curdir = curdir}) + os.cd(curdir) + end +end |
