From 0f015bca4f0f1faa0b9243feff1467dd099c44a0 Mon Sep 17 00:00:00 2001 From: Gordon Hecker Date: Mon, 18 Jan 2010 14:48:13 +0100 Subject: [PATCH] bugfix: fix error handling when cyclic dependencies are detected in the configuration. Signed-off-by: Gordon Hecker --- local/build.lua | 12 ++++++++++-- local/dlist.lua | 16 ++++++++++------ local/e2build.lua | 5 ++++- local/e2tool.lua | 24 ++++++++++++++++++------ local/ls-project.lua | 10 ++++++++-- 5 files changed, 50 insertions(+), 17 deletions(-) diff --git a/local/build.lua b/local/build.lua index c3febeb..6eb3d62 100755 --- a/local/build.lua +++ b/local/build.lua @@ -121,9 +121,17 @@ end -- a list of results to build, topologically sorted local sel_res = {} if #results > 0 then - sel_res = e2tool.dlist_recursive(info, results) + local re + sel_res, re = e2tool.dlist_recursive(info, results) + if not sel_res then + e2lib.abort(re) + end else - sel_res = e2tool.dsort(info) + local re + sel_res, re = e2tool.dsort(info) + if not sel_res then + e2lib.abort(re) + end end rc, re = e2tool.print_selection(info, sel_res) diff --git a/local/dlist.lua b/local/dlist.lua index d475a32..03011cd 100755 --- a/local/dlist.lua +++ b/local/dlist.lua @@ -55,13 +55,17 @@ if not info.results[ result ] then e2lib.abort("no such result: ", result) end -local dep = opts.recursive - and e2tool.dlist_recursive(info, result) - or e2tool.dlist(info, result) - -if dep then - for i = 1, #dep do print(dep[i]) end +local dep, re +if opts.recursive then + dep, re = e2tool.dlist_recursive(info, result) +else + dep, re = e2tool.dlist(info, result) +end +if not dep then + e2lib.abort(re) end +for i = 1, #dep do print(dep[i]) end + e2lib.finish() diff --git a/local/e2build.lua b/local/e2build.lua index b9e1517..a30b9e6 100644 --- a/local/e2build.lua +++ b/local/e2build.lua @@ -1138,8 +1138,11 @@ function e2build.collect_project(info, r, return_flags) end -- write topologically sorted list of result local destdir = string.format("%s/project", res.build_config.T) - local tsorted_results = e2tool.dlist_recursive(info, + local tsorted_results, re = e2tool.dlist_recursive(info, res.collect_project_results) + if not tsorted_results then + return false, e:cat(re) + end local tsorted_results_string = table.concat(tsorted_results, "\n") local resultlist = string.format("%s/resultlist", destdir) rc, re = e2lib.write_file(resultlist, tsorted_results_string .. "\n") diff --git a/local/e2tool.lua b/local/e2tool.lua index 2e02621..4a97277 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -845,23 +845,31 @@ function e2tool.dlist_recursive(info, result) local t = {} local function visit(res) if had[res] then - e2lib.warn("WOTHER", "cyclic dependency: " .. table.concat(path, " ")) - t = nil + return false, new_error("cyclic dependency: %s", table.concat(path, " ")) elseif t and not col[res] then table.insert(path, res) had[res] = true col[res] = true - for _, d in ipairs(e2tool.dlist(info, res)) do visit(d) end + for _, d in ipairs(e2tool.dlist(info, res)) do + local rc, re = visit(d) + if not rc then + return false, re + end + end if t then table.insert(t, res) end had[res] = nil path[#path] = nil end + return true end for _, r in ipairs( type(result) == "table" and result or e2tool.dlist(info, result)) do - visit(r) + local rc, re = visit(r) + if not rc then + return nil, re + end end - return t + return t, nil end function e2tool.dsort(info) @@ -1885,6 +1893,7 @@ end function e2tool.check_collect_project(info, resultname) local res = info.results[resultname] local e = new_error("in result %s:", resultname) + local rc, re if not res.collect_project then -- insert empty tables, to avoid some conditionals in the code res.collect_project_results = {} @@ -1908,8 +1917,11 @@ function e2tool.check_collect_project(info, resultname) if e:getcount() > 1 then return false, e end - res.collect_project_results = e2tool.dlist_recursive(info, + res.collect_project_results, re = e2tool.dlist_recursive(info, res.collect_project_default_result) + if not res.collect_project_results then + return false, e:cat(re) + end -- store a sorted list of required results table.insert(res.collect_project_results, res.collect_project_default_result) diff --git a/local/ls-project.lua b/local/ls-project.lua index 5baf3cc..6af4287 100755 --- a/local/ls-project.lua +++ b/local/ls-project.lua @@ -66,9 +66,15 @@ elseif #opts.arguments > 0 then end end if #results > 0 then - results = e2tool.dlist_recursive(info, results) + results, re = e2tool.dlist_recursive(info, results) + if not results then + e2lib.abort(re) + end else - results = e2tool.dsort(info) + results, re = e2tool.dsort(info) + if not results then + e2lib.abort(re) + end end table.sort(results) -- 2.39.5