diff options
| author | ruki <[email protected]> | 2026-03-10 00:52:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-03-10 00:52:32 +0800 |
| commit | dbd3e1a81718585105ed342ecc128df149590f70 (patch) | |
| tree | ea03f47a403a0e51d60539017b311bd7adacc5fb | |
| parent | 1ec51411988ae0ca5adcaeeb383a107d305f9907 (diff) | |
show target name in progress
| -rw-r--r-- | xmake/core/project/policy.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/async/runjobs.lua | 21 | ||||
| -rw-r--r-- | xmake/modules/private/action/build/link_objects.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/private/action/build/object.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/private/action/build/target.lua | 11 | ||||
| -rw-r--r-- | xmake/modules/utils/progress.lua | 41 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/builder.lua | 14 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/clang/scanner.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/gcc/scanner.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/msvc/scanner.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/scanner.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/swift/xmake.lua | 2 |
12 files changed, 93 insertions, 9 deletions
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 38eaa3fa2..0cf184d91 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -123,6 +123,8 @@ function policy.policies() ["build.distcc.remote_only"] = {description = "Enable build on only remote machines.", default = false, type = "boolean"}, -- Set the build progress output style, e.g. scroll (default), singlerow, multirow ["build.progress_style"] = {description = "Set the build progress output style.", type = "string", values = {"scroll", "singlerow", "multirow"}}, + -- Show target name in build progress output + ["build.progress_show_target"] = {description = "Show target name in build progress output.", default = true, type = "boolean"}, -- Enable windows UAC and set level, e.g. invoker, admin, highest ["windows.manifest.uac"] = {description = "Enable windows manifest UAC.", type = "string"}, -- Enable ui access for windows UAC 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 diff --git a/xmake/rules/c++/modules/builder.lua b/xmake/rules/c++/modules/builder.lua index ae25d3063..761b2cf6c 100644 --- a/xmake/rules/c++/modules/builder.lua +++ b/xmake/rules/c++/modules/builder.lua @@ -254,6 +254,7 @@ function build_modules_for_jobgraph(target, jobgraph, built_modules) local buildfilejob = _get_module_buildfilejob_for(target, sourcefile, moduletype) table.insert(buildfilejobs, buildfilejob) jobgraph:add(buildfilejob, function(_, _, jobopt) + progress.set_target(jobopt.progress, target) -- build bmi if named job jobopt.bmi = module.name -- build objectfile here if two phase compilation is not supported @@ -308,6 +309,7 @@ function build_objectfiles_for_jobgraph(target, jobgraph, built_modules) local module = mapper.get(target, sourcefile) local buildfilejob = _get_module_buildfilejob_for(target, sourcefile, "objectfile") jobgraph:add(buildfilejob, function(_, _, jobopt) + progress.set_target(jobopt.progress, target) jobopt.bmi = false jobopt.objectfile = true builder.make_module_job(target, module, jobopt) @@ -498,6 +500,7 @@ function build_headerunits_for_jobgraph(target, jobgraph, built_stlheaderunits, local buildfilejob = _get_headerunit_buildfilejob_for(_target, headerunit.sourcefile .. headerunit.key) if not jobgraph:has(buildfilejob) then jobgraph:add(buildfilejob, function(_, _, jobopt) + progress.set_target(jobopt.progress, _target) builder.make_headerunit_job(_target, headerunit, table.join(jobopt, opt)) end) end @@ -606,9 +609,10 @@ function generate_metadata(target, modules) local jobs = option.get("jobs") or os.default_njob() runjobs(target:fullname() .. "_install_modules", function(index, _, jobopt) + progress.set_target(jobopt.progress, target) local module = public_modules[index] local metafilepath = support.get_metafile(target, module) - progress.show(jobopt.progress, "${color.build.target}<%s> generating.module.metadata %s", target:fullname(), module.name) + progress.show(jobopt.progress, "${color.build.target}generating.module.metadata %s", module.name) local metadata = _generate_meta_module_info(target, module) json.savefile(metafilepath, metadata) end, {comax = jobs, total = #public_modules}) @@ -653,15 +657,15 @@ function show_progress(target, module, opt) if option.get("verbose") then dim = "${dim}" end - local header = "${clear}${color.build.target}<%s>${clear}" .. dim + local header = "${clear}" .. dim if opt.headerunit then local name = module.method == "include-angle" and ("<" .. path.filename(module.name) .. ">") or module.name - show(header .. " compiling.headerunit.$(mode) %s${clear}%s" .. suffix, target:fullname(), name, cmd) + show(header .. "compiling.headerunit.$(mode) %s${clear}%s" .. suffix, name, cmd) elseif opt.bmi then if opt.objectfile then - show(header .. " compiling.module.$(mode) %s${clear}%s" .. suffix, target:fullname(), module.name, cmd) + show(header .. "compiling.module.$(mode) %s${clear}%s" .. suffix, module.name, cmd) else - show(header .. " compiling.module.bmi.$(mode) %s${clear}%s" .. suffix, target:fullname(), module.name, cmd) + show(header .. "compiling.module.bmi.$(mode) %s${clear}%s" .. suffix, module.name, cmd) end else show("compiling.$(mode) %s${clear}%s" .. suffix, module.sourcefile, cmd) diff --git a/xmake/rules/c++/modules/clang/scanner.lua b/xmake/rules/c++/modules/clang/scanner.lua index 96aa6a7e2..d73c40621 100644 --- a/xmake/rules/c++/modules/clang/scanner.lua +++ b/xmake/rules/c++/modules/clang/scanner.lua @@ -37,7 +37,7 @@ function scan_dependency_for(target, sourcefile, rescan, opt) depend.on_changed(function() if opt.progress and not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") then - progress.show(opt.progress, "${clear}${color.build.target}<%s> generating.module.deps %s", target:fullname(), sourcefile) + progress.show(opt.progress, "${clear}generating.module.deps %s", sourcefile) end local outputdir = support.get_outputdir(target, sourcefile, {scan = true}) diff --git a/xmake/rules/c++/modules/gcc/scanner.lua b/xmake/rules/c++/modules/gcc/scanner.lua index b0cdda7af..fea1cec99 100644 --- a/xmake/rules/c++/modules/gcc/scanner.lua +++ b/xmake/rules/c++/modules/gcc/scanner.lua @@ -44,7 +44,7 @@ function scan_dependency_for(target, sourcefile, rescan, opt) depend.on_changed(function() if opt.progress and not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") then - progress.show(opt.progress, "${clear}${color.build.target}<%s> scanning.module.deps %s", target:fullname(), sourcefile) + progress.show(opt.progress, "${clear}scanning.module.deps %s", sourcefile) end local outputdir = support.get_outputdir(target, sourcefile, {scan = true}) diff --git a/xmake/rules/c++/modules/msvc/scanner.lua b/xmake/rules/c++/modules/msvc/scanner.lua index 07f7de41e..bc7d7b1da 100644 --- a/xmake/rules/c++/modules/msvc/scanner.lua +++ b/xmake/rules/c++/modules/msvc/scanner.lua @@ -45,7 +45,7 @@ function scan_dependency_for(target, sourcefile, rescan, opt) depend.on_changed(function () if opt.progress and not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") then - progress.show(opt.progress, "${clear}${color.build.target}<%s> generating.module.deps %s", target:fullname(), sourcefile) + progress.show(opt.progress, "${clear}generating.module.deps %s", sourcefile) end local outputdir = support.get_outputdir(target, sourcefile, {scan = true}) diff --git a/xmake/rules/c++/modules/scanner.lua b/xmake/rules/c++/modules/scanner.lua index 8d5fd057d..2bcee1f12 100644 --- a/xmake/rules/c++/modules/scanner.lua +++ b/xmake/rules/c++/modules/scanner.lua @@ -27,6 +27,7 @@ import("core.base.profiler") import("core.base.bytes") import("async.jobgraph") import("async.runjobs") +import("utils.progress") import("support") import("mapper") import("stlheaders") @@ -538,6 +539,7 @@ function _schedule_module_dependencies_scan(target, jobgraph, sourcebatch) if not jobgraph:has(scanfilejob) then has_scanjob = true jobgraph:add(scanfilejob, function(_, _, opt) + progress.set_target(opt.progress, target) _do_scan(target, sourcefile, opt) end) end diff --git a/xmake/rules/swift/xmake.lua b/xmake/rules/swift/xmake.lua index 63ad1384e..e124865f2 100644 --- a/xmake/rules/swift/xmake.lua +++ b/xmake/rules/swift/xmake.lua @@ -130,7 +130,7 @@ rule("swift.interop") end if opt.progress then - progress.show(opt.progress, "${clear}${color.build.target}<%s> generating.swift.header %s", target:fullname(), headername) + progress.show(opt.progress, "${clear}generating.swift.header %s", headername) end local _scflags = sc:compflags({target = target, sourcekind = "sc"}) |
