summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2026-03-10 00:52:32 +0800
committerruki <[email protected]>2026-03-10 00:52:32 +0800
commitdbd3e1a81718585105ed342ecc128df149590f70 (patch)
treeea03f47a403a0e51d60539017b311bd7adacc5fb /xmake/modules
parent1ec51411988ae0ca5adcaeeb383a107d305f9907 (diff)
show target name in progress
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/async/runjobs.lua21
-rw-r--r--xmake/modules/private/action/build/link_objects.lua1
-rw-r--r--xmake/modules/private/action/build/object.lua2
-rw-r--r--xmake/modules/private/action/build/target.lua11
-rw-r--r--xmake/modules/utils/progress.lua41
5 files changed, 76 insertions, 0 deletions
diff --git a/xmake/modules/async/runjobs.lua b/xmake/modules/async/runjobs.lua
index 20e8890a1..224841c12 100644
--- a/xmake/modules/async/runjobs.lua
+++ b/xmake/modules/async/runjobs.lua
@@ -66,6 +66,7 @@ function _init_progress(state, opt)
state.progress_finished_count = 0
state.progress_factor = opt.progress_factor or 1.0
local progress_wrapper = {}
+ local progress_wrapper_data = {}
progress_wrapper.current = function ()
return state.progress_finished_count
end
@@ -80,6 +81,26 @@ function _init_progress(state, opt)
return 0
end
end
+ progress_wrapper.set = function (_, key, value)
+ local running = scheduler.co_running()
+ if running then
+ local co_data = progress_wrapper_data[running]
+ if not co_data then
+ co_data = {}
+ progress_wrapper_data[running] = co_data
+ end
+ co_data[key] = value
+ end
+ end
+ progress_wrapper.get = function (_, key)
+ local running = scheduler.co_running()
+ if running then
+ local co_data = progress_wrapper_data[running]
+ if co_data then
+ return co_data[key]
+ end
+ end
+ end
debug.setmetatable(progress_wrapper, {
__tostring = function ()
return string.format("%d%%", progress_wrapper.percent())
diff --git a/xmake/modules/private/action/build/link_objects.lua b/xmake/modules/private/action/build/link_objects.lua
index c2056e836..864ba395e 100644
--- a/xmake/modules/private/action/build/link_objects.lua
+++ b/xmake/modules/private/action/build/link_objects.lua
@@ -69,6 +69,7 @@ function main(jobgraph, target, opt)
local buildcmds = opt.buildcmds
local linkjob = target:fullname() .. "/link_objects"
jobgraph:add(linkjob, function (index, total, opt)
+ progress.set_target(opt.progress, target)
if not buildcmds then
_do_link_target(target, opt)
end
diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua
index ef9697ee9..e4c5b49e2 100644
--- a/xmake/modules/private/action/build/object.lua
+++ b/xmake/modules/private/action/build/object.lua
@@ -152,6 +152,7 @@ function _add_batchjobs(target, batchjobs, sourcebatch, opt)
local dependfile = sourcebatch.dependfiles[i]
local sourcekind = assert(sourcebatch.sourcekind, "%s: sourcekind not found!", sourcefile)
batchjobs:addjob(sourcefile, function (index, total, jobopt)
+ progress.set_target(jobopt.progress, target)
local build_opt = table.join({objectfile = objectfile, dependfile = dependfile, sourcekind = sourcekind, progress = jobopt.progress}, opt)
build_object(target, sourcefile, build_opt)
end, {rootjob = rootjob, distcc = opt.distcc})
@@ -167,6 +168,7 @@ function _add_jobgraph(target, jobgraph, sourcebatch, opt)
local sourcekind = assert(sourcebatch.sourcekind, "%s: sourcekind not found!", sourcefile)
local jobname = target:fullname() .. "/obj/" .. sourcefile
jobgraph:add(jobname, function (index, total, jobopt)
+ progress.set_target(jobopt.progress, target)
local build_opt = table.join({objectfile = objectfile, dependfile = dependfile, sourcekind = sourcekind, progress = jobopt.progress}, opt)
build_object(target, sourcefile, build_opt)
end, {distcc = opt.distcc})
diff --git a/xmake/modules/private/action/build/target.lua b/xmake/modules/private/action/build/target.lua
index 1a100f1c2..ad50390ae 100644
--- a/xmake/modules/private/action/build/target.lua
+++ b/xmake/modules/private/action/build/target.lua
@@ -188,6 +188,7 @@ function add_targetjobs_for_script(jobgraph, target, instance, opt)
-- end)
local jobname = string.format("%s/%s", job_prefix, script_name)
jobgraph:add(jobname, function (index, total, opt)
+ progress_utils.set_target(opt.progress, target)
script(target, table.join({progress = opt.progress}, job_opt))
end)
end
@@ -207,6 +208,7 @@ function add_targetjobs_for_script(jobgraph, target, instance, opt)
if scriptcmd then
local jobname = string.format("%s/%s", job_prefix, scriptcmd_name)
jobgraph:add(jobname, function (index, total, opt)
+ progress_utils.set_target(opt.progress, target)
if buildcmds then
-- only generate cmds and do not run them, use cases: e.g. project generator
scriptcmd(target, buildcmds, {progress = opt.progress})
@@ -440,6 +442,7 @@ function add_filejobs_for_script(jobgraph, target, instance, sourcebatch, opt)
-- end)
local jobname = string.format("%s/%s", job_prefix, script_files_name)
jobgraph:add(jobname, function (index, total, opt)
+ progress_utils.set_target(opt.progress, target)
script_files(target, sourcebatch, {progress = opt.progress, distcc = distcc})
end)
end
@@ -477,6 +480,9 @@ function add_filejobs_for_script(jobgraph, target, instance, sourcebatch, opt)
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
local jobname = string.format("%s/%s/%s", job_prefix, script_file_name, sourcefile)
jobgraph:add(jobname, function (index, total, opt)
+ if opt.progress and opt.progress.set then
+ opt.progress:set("target_name", target:fullname())
+ end
script_file(target, sourcefile, {progress = opt.progress, sourcekind = sourcekind, distcc = distcc})
end)
end
@@ -498,6 +504,7 @@ function add_filejobs_for_script(jobgraph, target, instance, sourcebatch, opt)
local distcc = instance:extraconf(scriptcmd_files_name, "distcc")
local jobname = string.format("%s/%s", job_prefix, scriptcmd_files_name)
jobgraph:add(jobname, function (index, total, opt)
+ progress_utils.set_target(opt.progress, target)
-- only generate cmds and do not run them, use cases: e.g. project generator
if buildcmds then
scriptcmd_files(target, buildcmds, sourcebatch, {progress = opt.progress})
@@ -527,6 +534,7 @@ function add_filejobs_for_script(jobgraph, target, instance, sourcebatch, opt)
-- only generate cmds and do not run them, use cases: e.g. project generator
local jobname = string.format("%s/%s", job_prefix, scriptcmd_file_name)
jobgraph:add(jobname, function (index, total, opt)
+ progress_utils.set_target(opt.progress, target)
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
scriptcmd_file(target, buildcmds, sourcefile, {progress = opt.progress, sourcekind = sourcekind})
end
@@ -536,6 +544,9 @@ function add_filejobs_for_script(jobgraph, target, instance, sourcebatch, opt)
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
local jobname = string.format("%s/%s/%s", job_prefix, scriptcmd_file_name, sourcefile)
jobgraph:add(jobname, function (index, total, opt)
+ if opt.progress and opt.progress.set then
+ opt.progress:set("target_name", target:fullname())
+ end
local batchcmds_ = batchcmds.new({target = target})
scriptcmd_file(target, batchcmds_, sourcefile, {progress = opt.progress, sourcekind = sourcekind, distcc = distcc})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
diff --git a/xmake/modules/utils/progress.lua b/xmake/modules/utils/progress.lua
index b6201d5cc..40cab5ec3 100644
--- a/xmake/modules/utils/progress.lua
+++ b/xmake/modules/utils/progress.lua
@@ -350,8 +350,45 @@ function _show_current_coroutine_progress(maxwidth)
end
end
+-- is show target enabled?
+function _is_show_target_enabled()
+ local show_target = _g.show_target
+ if show_target == nil then
+ local policy_value = project.policy("build.progress_show_target")
+ if policy_value == nil then
+ show_target = true
+ else
+ show_target = policy_value
+ end
+ _g.show_target = show_target
+ end
+ return show_target
+end
+
+-- get target name prefix from progress object
+function _get_target_name_prefix(progress)
+ if type(progress) == "table" and progress.get then
+ local target_name = progress:get("target_name")
+ if target_name and _is_show_target_enabled() then
+ return "${color.build.target}<" .. target_name .. ">${clear} "
+ end
+ end
+end
+
+-- set the associated target name for the progress object (coroutine-local)
+-- it's safe to call with non-table progress (e.g. number), it will be ignored
+function set_target(progress, target)
+ if type(progress) == "table" and progress.set then
+ progress:set("target_name", target:fullname())
+ end
+end
+
-- show the message with progress
function show(progress, format, ...)
+ local target_prefix = _get_target_name_prefix(progress)
+ if target_prefix then
+ format = target_prefix .. format
+ end
progress = type(progress) == "table" and progress:percent() or math.floor(progress)
if option.get("verbose") then
_show_progress_with_verbose(progress, format, ...)
@@ -467,6 +504,10 @@ end
-- get the message text with progress
function text(progress, format, ...)
+ local target_prefix = _get_target_name_prefix(progress)
+ if target_prefix then
+ format = target_prefix .. format
+ end
progress = type(progress) == "table" and progress:percent() or math.floor(progress)
local progress_prefix = _get_progress_prefix()
if option.get("verbose") then