Skip to content

Commit

Permalink
use new progress
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Mar 18, 2024
1 parent ca16db3 commit 8f40dc6
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 61 deletions.
20 changes: 10 additions & 10 deletions xmake/actions/build/build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ function _add_batchjobs_builtin(batchjobs, rootjob, target)
if r:extraconf("build", "batch") then
job, job_leaf = assert(script(target, batchjobs, {rootjob = job or rootjob}), "rule(%s):on_build(): no returned job!", r:name())
else
job = batchjobs:addjob("rule/" .. r:name() .. "/build", function (index, total)
script(target, {progress = (index * 100) / total})
job = batchjobs:addjob("rule/" .. r:name() .. "/build", function (index, total, opt)
script(target, {progress = opt.progress})
end, {rootjob = job or rootjob})
end
else
local buildcmd = r:script("buildcmd")
if buildcmd then
job = batchjobs:addjob("rule/" .. r:name() .. "/build", function (index, total)
job = batchjobs:addjob("rule/" .. r:name() .. "/build", function (index, total, opt)
local batchcmds_ = batchcmds.new({target = target})
buildcmd(target, batchcmds_, {progress = (index * 100) / total})
buildcmd(target, batchcmds_, {progress = opt.progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
end, {rootjob = job or rootjob})
end
Expand Down Expand Up @@ -100,8 +100,8 @@ function _add_batchjobs(batchjobs, rootjob, target)
-- print("build it")
-- end)
--
job = batchjobs:addjob(target:name() .. "/build", function (index, total)
script(target, {progress = (index * 100) / total})
job = batchjobs:addjob(target:name() .. "/build", function (index, total, opt)
script(target, {progress = opt.progress})
end, {rootjob = rootjob})
end
return job, job_leaf or job
Expand All @@ -118,10 +118,10 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target)
-- add after_build job for target
local pkgenvs = _g.pkgenvs or {}
_g.pkgenvs = pkgenvs
local job_build_after = batchjobs:addjob(target:name() .. "/after_build", function (index, total)
local job_build_after = batchjobs:addjob(target:name() .. "/after_build", function (index, total, opt)

-- do after_build
local progress = (index * 100) / total
local progress = opt.progress
local after_build = target:script("build_after")
if after_build then
after_build(target, {progress = progress})
Expand Down Expand Up @@ -158,7 +158,7 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target)
local job_build, job_build_leaf = _add_batchjobs(batchjobs, job_build_after, target)

-- add before_build job for target
local job_build_before = batchjobs:addjob(target:name() .. "/before_build", function (index, total)
local job_build_before = batchjobs:addjob(target:name() .. "/before_build", function (index, total, opt)

-- enter package environments
-- https://github.com/xmake-io/xmake/issues/4033
Expand All @@ -184,7 +184,7 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target)

-- do before_build
-- we cannot add batchjobs for this rule scripts, @see https://github.com/xmake-io/xmake/issues/2684
local progress = (index * 100) / total
local progress = opt.progress
local before_build = target:script("build_before")
if before_build then
before_build(target, {progress = progress})
Expand Down
4 changes: 2 additions & 2 deletions xmake/actions/build/kinds/binary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ end
function main(batchjobs, rootjob, target)

-- add link job
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total)
_link_target(target, {progress = (index * 100) / total})
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total, opt)
_link_target(target, {progress = opt.progress})
end, {rootjob = rootjob})

-- we only need to return and depend the link job for each target,
Expand Down
24 changes: 12 additions & 12 deletions xmake/actions/build/kinds/object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
if ruleinst:extraconf(scriptname, "batch") then
script(target, batchjobs, sourcebatch, {rootjob = rootjob, distcc = ruleinst:extraconf(scriptname, "distcc")})
else
batchjobs:addjob("rule/" .. rulename .. "/" .. scriptname, function (index, total)
script(target, sourcebatch, {progress = (index * 100) / total})
batchjobs:addjob("rule/" .. rulename .. "/" .. scriptname, function (index, total, opt)
script(target, sourcebatch, {progress = opt.progress})
end, {rootjob = rootjob})
end
end
Expand All @@ -113,8 +113,8 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
if script then
local sourcekind = sourcebatch.sourcekind
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
batchjobs:addjob(sourcefile, function (index, total)
script(target, sourcefile, {sourcekind = sourcekind, progress = (index * 100) / total})
batchjobs:addjob(sourcefile, function (index, total, opt)
script(target, sourcefile, {sourcekind = sourcekind, progress = opt.progress})
end, {rootjob = rootjob, distcc = ruleinst:extraconf(scriptname, "distcc")})
end
end
Expand All @@ -125,10 +125,10 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
scriptname = "buildcmd_files" .. (suffix and ("_" .. suffix) or "")
script = ruleinst:script(scriptname)
if script then
batchjobs:addjob("rule/" .. rulename .. "/" .. scriptname, function (index, total)
batchjobs:addjob("rule/" .. rulename .. "/" .. scriptname, function (index, total, opt)
local batchcmds_ = batchcmds.new({target = target})
local distcc = ruleinst:extraconf(scriptname, "distcc")
script(target, batchcmds_, sourcebatch, {progress = (index * 100) / total, distcc = distcc})
script(target, batchcmds_, sourcebatch, {progress = opt.progress, distcc = distcc})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
end, {rootjob = rootjob})
end
Expand All @@ -141,9 +141,9 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
if script then
local sourcekind = sourcebatch.sourcekind
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
batchjobs:addjob(sourcefile, function (index, total)
batchjobs:addjob(sourcefile, function (index, total, opt)
local batchcmds_ = batchcmds.new({target = target})
script(target, batchcmds_, sourcefile, {sourcekind = sourcekind, progress = (index * 100) / total})
script(target, batchcmds_, sourcefile, {sourcekind = sourcekind, progress = opt.progress})
batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")})
end, {rootjob = rootjob, distcc = ruleinst:extraconf(scriptname, "distcc")})
end
Expand Down Expand Up @@ -177,8 +177,8 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target, sourcebatch, suff
if target:extraconf(scriptname, "batch") then
script(target, batchjobs, sourcebatch, {rootjob = rootjob, distcc = target:extraconf(scriptname, "distcc")})
else
batchjobs:addjob(target:name() .. "/" .. scriptname, function (index, total)
script(target, sourcebatch, {progress = (index * 100) / total})
batchjobs:addjob(target:name() .. "/" .. scriptname, function (index, total, opt)
script(target, sourcebatch, {progress = opt.progress})
end, {rootjob = rootjob})
end
return true
Expand All @@ -188,8 +188,8 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target, sourcebatch, suff
if script then
local sourcekind = sourcebatch.sourcekind
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
batchjobs:addjob(sourcefile, function (index, total)
script(target, sourcefile, {sourcekind = sourcekind, progress = (index * 100) / total})
batchjobs:addjob(sourcefile, function (index, total, opt)
script(target, sourcefile, {sourcekind = sourcekind, progress = opt.progress})
end, {rootjob = rootjob, distcc = target:extraconf(scriptname, "distcc")})
end
return true
Expand Down
4 changes: 2 additions & 2 deletions xmake/actions/build/kinds/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ end
function main(batchjobs, rootjob, target)

-- add link job
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total)
_link_target(target, {progress = (index * 100) / total})
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total, opt)
_link_target(target, {progress = opt.progress})
end, {rootjob = rootjob})

-- we only need to return and depend the link job for each target,
Expand Down
4 changes: 2 additions & 2 deletions xmake/actions/build/kinds/static.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ end
function main(batchjobs, rootjob, target)

-- add link job
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total)
_link_target(target, {progress = (index * 100) / total})
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total, opt)
_link_target(target, {progress = opt.progress})
end, {rootjob = rootjob})

-- we only need to return and depend the link job for each target,
Expand Down
10 changes: 5 additions & 5 deletions xmake/modules/async/runjobs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ end
-- runjobs("test", function () os.sleep(10000) end, { progress = { chars = {'/','\'} } }) -- see module utils.progress
--
-- local jobs = jobpool.new()
-- local root = jobs:addjob("job/root", function (index, total)
-- print(index, total)
-- local root = jobs:addjob("job/root", function (index, total, opt)
-- print(index, total, opt.progress)
-- end)
-- for i = 1, 3 do
-- local job = jobs:addjob("job/" .. i, function (index, total)
-- print(index, total)
-- local job = jobs:addjob("job/" .. i, function (index, total, opt)
-- print(index, total, opt.progress)
-- end, {rootjob = root})
-- end
-- runjobs("test", jobs, {comax = 6, timeout = 1000, on_timer = function (running_jobs_indices) end})
Expand Down Expand Up @@ -252,8 +252,8 @@ function main(name, jobs, opt)
if opt.curdir then
os.cd(opt.curdir)
end
jobfunc(i, total, {progress = progress_wrapper})
count = count + 1
jobfunc(i, total, {progress = progress_wrapper})
end
running_jobs_indices[i] = nil
end,
Expand Down
4 changes: 2 additions & 2 deletions xmake/modules/private/action/build/object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ function main(target, batchjobs, sourcebatch, opt)
local objectfile = sourcebatch.objectfiles[i]
local dependfile = sourcebatch.dependfiles[i]
local sourcekind = assert(sourcebatch.sourcekind, "%s: sourcekind not found!", sourcefile)
batchjobs:addjob(sourcefile, function (index, total)
local build_opt = table.join({objectfile = objectfile, dependfile = dependfile, sourcekind = sourcekind, progress = (index * 100) / total}, opt)
batchjobs:addjob(sourcefile, function (index, total, jobopt)
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})
end
Expand Down
2 changes: 1 addition & 1 deletion xmake/modules/private/async/buildjobs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ end
nodes["node1"] = {
name = "node1",
deps = {"node2", "node3"},
job = batchjobs:newjob("/job/node1", function(index, total)
job = batchjobs:newjob("/job/node1", function(index, total, opt)
end)
}
--]]
Expand Down
4 changes: 2 additions & 2 deletions xmake/modules/utils/progress.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ end

-- show the message with progress
function show(progress, format, ...)
progress = math.floor(progress)
progress = type(progress) == "table" and progress:percent() or math.floor(progress)
local progress_prefix = "${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} "
if option.get("verbose") then
cprint(progress_prefix .. "${dim}" .. format, progress, ...)
Expand Down Expand Up @@ -114,7 +114,7 @@ end

-- get the message text with progress
function text(progress, format, ...)
progress = math.floor(progress)
progress = type(progress) == "table" and progress:percent() or math.floor(progress)
local progress_prefix = "${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} "
if option.get("verbose") then
return string.format(progress_prefix .. "${dim}" .. format, progress, ...)
Expand Down
14 changes: 7 additions & 7 deletions xmake/rules/c++/modules/modules_support/clang/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt)
name = job_name,
deps = table.join(target:name() .. "_populate_module_map", deps),
sourcefile = opt.cppfile,
job = batchjobs:newjob(name or opt.cppfile, function(index, total)
job = batchjobs:newjob(name or opt.cppfile, function(index, total, jobopt)
local mapped_bmi
if provide and compiler_support.memcache():get2(target:name() .. name, "reuse") then
if not target:is_binary() then
Expand Down Expand Up @@ -252,18 +252,18 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt)
local bmifile = mapped_bmi or bmifile
if target:is_binary() then
if mapped_bmi then
progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.objectfile.$(mode) %s", target:name(), name or opt.cppfile)
progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.objectfile.$(mode) %s", target:name(), name or opt.cppfile)
_compile_objectfile_step(target, bmifile, opt.cppfile, opt.objectfile)
else
progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile)
progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile)
_compile_one_step(target, bmifile, opt.cppfile, opt.objectfile, {std = (name == "std" or name == "std.compat")})
end
else
if (not public and not external) or (external and private_dep) then
progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile)
progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile)
_compile_one_step(target, bmifile, opt.cppfile, opt.objectfile, {std = (name == "std" or name == "std.compat")})
else
progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.bmi.$(mode) %s", target:name(), name or opt.cppfile)
progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.bmi.$(mode) %s", target:name(), name or opt.cppfile)
_compile_bmi_step(target, bmifile, opt.cppfile, {std = (name == "std" or name == "std.compat")})
end
end
Expand Down Expand Up @@ -352,7 +352,7 @@ function make_headerunit_buildjobs(target, job_name, batchjobs, headerunit, bmif
return {
name = job_name,
sourcefile = headerunit.path,
job = batchjobs:newjob(job_name, function(index, total)
job = batchjobs:newjob(job_name, function(index, total, jobopt)
if not os.isdir(outputdir) then
os.mkdir(outputdir)
end
Expand All @@ -366,7 +366,7 @@ function make_headerunit_buildjobs(target, job_name, batchjobs, headerunit, bmif
local depvalues = {compinst:program(), compflags}

if opt.build then
progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:name(), headerunit.name)
progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:name(), headerunit.name)
_compile(target, _make_headerunitflags(target, headerunit, bmifile), headerunit.path, bmifile)
end

Expand Down
Loading

0 comments on commit 8f40dc6

Please sign in to comment.