Merge pull request #963 from LuaAndC/build-pkg-print-progress

build-pkg: print progress
This commit is contained in:
Tony Theodore 2015-11-10 10:59:29 +11:00
commit c47f22edff
1 changed files with 63 additions and 2 deletions

View File

@ -59,8 +59,12 @@ local TARGETS = {
'x86_64-w64-mingw32.shared',
}
local function echo(fmt, ...)
print(fmt:format(...))
end
local function log(fmt, ...)
print('[build-pkg]', fmt:format(...))
echo('[build-pkg]\t' .. fmt, ...)
end
-- based on http://lua-users.org/wiki/SplitJoin
@ -490,6 +494,60 @@ local function isBuilt(item, files)
return false
end
-- script building HUGE_TIMES from MXE main log
-- https://gist.github.com/starius/3ea9d953b0c30df88aa7
local HUGE_TIMES = {
[7] = {"ocaml-native", "ffmpeg", "boost"},
[9] = {"openssl", "qtdeclarative", "ossim", "wxwidgets"},
[12] = {"ocaml-core", "itk", "wt"},
[19] = {"gcc", "qtbase", "llvm"},
[24] = {"vtk", "vtk6", "openscenegraph"},
[36] = {"openblas", "pcl", "oce"},
[51] = {"qt"},
}
local PROGRESS = "[%3d/%d] " ..
"The build is expected to complete in %0.1f hours, " ..
"on %s"
local function progressPrinter(items)
local pkg2time = {}
for time, pkgs in pairs(HUGE_TIMES) do
for _, pkg in ipairs(pkgs) do
pkg2time[pkg] = time
end
end
--
local started_at = os.time()
local sums = {}
for i, item in ipairs(items) do
local target, pkg = parseItem(item)
local expected_time = pkg2time[pkg] or 1
sums[i] = (sums[i - 1] or 0) + expected_time
end
local total_time = sums[#sums]
local time_done = 0
local pkgs_done = 0
local printer = {}
--
function printer:advance(i)
pkgs_done = i
time_done = sums[i]
end
function printer:status()
local now = os.time()
local spent = now - started_at
local predicted_duration = spent * total_time / time_done
local predicted_end = started_at + predicted_duration
local predicted_end_str = os.date("%c", predicted_end)
local predicted_wait = predicted_end - now
local predicted_wait_hours = predicted_wait / 3600.0
return PROGRESS:format(pkgs_done, #items,
predicted_wait_hours, predicted_end_str)
end
return printer
end
-- build all packages, save filelist to list file
local function buildPackages(items, item2deps)
local broken = {}
@ -504,7 +562,8 @@ local function buildPackages(items, item2deps)
end
return false
end
for _, item in ipairs(items) do
local progress_printer = progressPrinter(items)
for i, item in ipairs(items) do
if not brokenDep(item) then
local files = buildItem(item, item2deps, file2item)
if isBuilt(item, files) then
@ -520,6 +579,8 @@ local function buildPackages(items, item2deps)
log('Item %s depends on broken item %s',
item, brokenDep(item))
end
progress_printer:advance(i)
echo(progress_printer:status())
end
return unbroken, item2files
end