From f40c5053f1d26ebc5f4e6daef3b9bb5ddaba49d2 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Fri, 25 Dec 2015 03:08:25 +0300 Subject: build-pkg: check toposort --- tools/build-pkg.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tools/build-pkg.lua b/tools/build-pkg.lua index c6c0282..627af03 100755 --- a/tools/build-pkg.lua +++ b/tools/build-pkg.lua @@ -261,6 +261,30 @@ local function sortForBuild(items, item2deps) return build_list end +-- return if build_list is ordered topologically +local function isTopoOrdered(build_list, items, item2deps) + if #build_list ~= #items then + return false, 'Length of build_list is wrong' + end + local item2index = {} + for index, item in ipairs(build_list) do + if item2index[item] then + return false, 'Duplicate item: ' .. item + end + item2index[item] = index + end + for item, deps in pairs(item2deps) do + for _, dep in ipairs(deps) do + if item2index[item] < item2index[dep] then + return false, 'Item ' .. item .. + 'is built before its dependency ' .. + dep + end + end + end + return true +end + local function isListed(file, list) for _, pattern in ipairs(list) do if file:match(pattern) then @@ -768,6 +792,7 @@ end gitInit() local items, item2deps, item2ver = getItems() local build_list = sortForBuild(items, item2deps) +assert(isTopoOrdered(build_list, items, item2deps)) build_list = sliceArray(build_list, max_items) local unbroken, item2files = buildPackages(build_list, item2deps) makeDebs(unbroken, item2deps, item2ver, item2files) -- cgit v0.12