From 2d8a23e465979092f209860287dee4d227254f14 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Thu, 30 Jan 2014 19:41:08 +0100 Subject: [PATCH] Move check_project_info into collect_project_info The distinction makes little sense now, since collect_project_info also does a lot of checking. One less step for local tools required Signed-off-by: Tobias Ulmer --- local/e2-build.lua | 5 +- local/e2-fetch-sources.lua | 4 - local/e2-ls-project.lua | 4 - local/e2-playground.lua | 4 - local/e2tool.lua | 420 +++++++++++++++++++------------------ 5 files changed, 214 insertions(+), 223 deletions(-) diff --git a/local/e2-build.lua b/local/e2-build.lua index 7da84ad..4c65ae0 100644 --- a/local/e2-build.lua +++ b/local/e2-build.lua @@ -110,11 +110,8 @@ local function e2_build(arg) if not info then return false, re end + perform_writeback_settings(writeback) - local rc, re = e2tool.check_project_info(info) - if not rc then - return false, re - end -- apply the standard build mode to all results for _,res in pairs(info.results) do diff --git a/local/e2-fetch-sources.lua b/local/e2-fetch-sources.lua index 04b2aeb..bd66dea 100644 --- a/local/e2-fetch-sources.lua +++ b/local/e2-fetch-sources.lua @@ -71,10 +71,6 @@ local function e2_fetch_source(arg) if not info then return false, info end - local rc, re = e2tool.check_project_info(info) - if not rc then - return false, e:cat(re) - end if not (opts.fetch or opts.update) then opts.fetch = true diff --git a/local/e2-ls-project.lua b/local/e2-ls-project.lua index 755451d..d52b6c8 100644 --- a/local/e2-ls-project.lua +++ b/local/e2-ls-project.lua @@ -65,10 +65,6 @@ local function e2_ls_project(arg) if not info then return false, re end - local rc, re = e2tool.check_project_info(info) - if not rc then - return false, re - end local results = {} if opts.all then diff --git a/local/e2-playground.lua b/local/e2-playground.lua index 8d5b660..693470c 100644 --- a/local/e2-playground.lua +++ b/local/e2-playground.lua @@ -71,10 +71,6 @@ local function e2_playground(arg) if not info then return false, re end - local rc, re = e2tool.check_project_info(info) - if not rc then - return false, re - end if #arguments ~= 1 then e2option.usage(1) diff --git a/local/e2tool.lua b/local/e2tool.lua index 6f23e03..5ae11a8 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -1126,6 +1126,217 @@ local function read_project_config(info) return true end +--- check chroot config +-- @param chroot +-- @return bool +-- @return an error object on failure +local function check_chroot_config(info) + local e = err.new("error validating chroot configuration") + for g,grp in pairs(info.chroot.groups) do + if not grp.server then + e:append("in group: %s", grp.name) + e:append(" `server' attribute missing") + elseif not cache.valid_server(info.cache, grp.server) then + e:append("in group: %s", grp.name) + e:append(" no such server: %s", grp.server) + end + if (not grp.files) or (#grp.files) == 0 then + e:append("in group: %s", grp.name) + e:append(" list of files is empty") + else + for _,f in ipairs(grp.files) do + local inherit = { + server = grp.server, + } + local keys = { + server = { + mandatory = true, + type = "string", + inherit = true, + }, + location = { + mandatory = true, + type = "string", + inherit = false, + }, + sha1 = { + mandatory = false, + type = "string", + inherit = false, + }, + } + local rc, re = check_tab(f, keys, inherit) + if not rc then + e:append("in group: %s", grp.name) + e:cat(re) + end + if f.server ~= info.root_server_name and not f.sha1 then + e:append("in group: %s", grp.name) + e:append("file entry for remote file without `sha1` attribute") + end + end + end + end + if (not info.chroot.default_groups) or #info.chroot.default_groups == 0 then + e:append(" `default_groups' attribute is missing or empty list") + else + for _,g in ipairs(info.chroot.default_groups) do + if not info.chroot.groups_byname[g] then + e:append(" unknown group in default groups list: %s", g) + end + end + end + if e:getcount() > 1 then + return false, e + end + return true +end + +--- check source. +local function check_source(info, sourcename) + local src = info.sources[sourcename] + local rc, e, re + if not src then + e = err.new("no source by that name: %s", sourcename) + return false, e + end + local e = err.new("in source: %s", sourcename) + if not src.type then + e2lib.warnf("WDEFAULT", "in source %s", sourcename) + e2lib.warnf("WDEFAULT", " type attribute defaults to `files'") + src.type = "files" + end + rc, re = scm.validate_source(info, sourcename) + if not rc then + return false, re + end + return true +end + +--- check sources. +local function check_sources(info) + local e = err.new("Error while checking sources") + local rc, re + for n,s in pairs(info.sources) do + rc, re = check_source(info, n) + if not rc then + e:cat(re) + end + end + if e:getcount() > 1 then + return false, e + end + return true +end + +--- check licence. +local function check_licence(info, l) + local e = err.new("in licence: %s", l) + local lic = info.licences[l] + if not lic.server then + e:append("no server attribute") + end + if not lic.files then + e:append("no files attribute") + elseif type(lic.files) ~= "table" then + e:append("files attribute is not a table") + else + for _,f in ipairs(lic.files) do + local inherit = { + server = lic.server, + } + local keys = { + server = { + mandatory = true, + type = "string", + inherit = true, + }, + location = { + mandatory = true, + type = "string", + inherit = false, + }, + sha1 = { + mandatory = false, + type = "string", + inherit = false, + }, + } + local rc, re = check_tab(f, keys, inherit) + if not rc then + e:cat(re) + elseif f.server ~= info.root_server_name and + not f.sha1 then + e:append("file entry for remote file without".. + " `sha1` attribute") + end + end + end + if e:getcount() > 1 then + return false, e + end + return true +end + +--- check licences. +local function check_licences(info) + local e = err.new("Error while checking licences") + local rc, re + for l, lic in pairs(info.licences) do + rc, re = check_licence(info, l) + if not rc then + e:cat(re) + end + end + if e:getcount() > 1 then + return false, e + end + return true +end + +--- Checks project information for consistancy. +-- @param info Info table. +-- @return True on success, false on error. +-- @return Error object on failure. +local function check_project_info(info) + local rc, re + local e = err.new("error in project configuration") + rc, re = check_chroot_config(info) + if not rc then + return false, e:cat(re) + end + local rc, re = check_sources(info) + if not rc then + return false, e:cat(re) + end + local rc, re = check_results(info) + if not rc then + return false, e:cat(re) + end + local rc, re = check_licences(info) + if not rc then + return false, e:cat(re) + end + for _, r in ipairs(info.project.default_results) do + if not info.results[r] then + e:append("default_results: No such result: %s", r) + end + end + for _, r in ipairs(info.project.deploy_results) do + if not info.results[r] then + e:append("deploy_results: No such result: %s", r) + end + end + if e:getcount() > 1 then + return false, e + end + local rc = e2tool.dsort(info) + if not rc then + return false, e:cat("cyclic dependencies") + end + return true +end + --- collect project info. function e2tool.collect_project_info(info, skip_load_config) local rc, re @@ -1391,218 +1602,13 @@ function e2tool.collect_project_info(info, skip_load_config) return false, e:cat(re) end end - return info -end - ---- check chroot config --- @param chroot --- @return bool --- @return an error object on failure -local function check_chroot_config(info) - local e = err.new("error validating chroot configuration") - for g,grp in pairs(info.chroot.groups) do - if not grp.server then - e:append("in group: %s", grp.name) - e:append(" `server' attribute missing") - elseif not cache.valid_server(info.cache, grp.server) then - e:append("in group: %s", grp.name) - e:append(" no such server: %s", grp.server) - end - if (not grp.files) or (#grp.files) == 0 then - e:append("in group: %s", grp.name) - e:append(" list of files is empty") - else - for _,f in ipairs(grp.files) do - local inherit = { - server = grp.server, - } - local keys = { - server = { - mandatory = true, - type = "string", - inherit = true, - }, - location = { - mandatory = true, - type = "string", - inherit = false, - }, - sha1 = { - mandatory = false, - type = "string", - inherit = false, - }, - } - local rc, re = check_tab(f, keys, inherit) - if not rc then - e:append("in group: %s", grp.name) - e:cat(re) - end - if f.server ~= info.root_server_name and not f.sha1 then - e:append("in group: %s", grp.name) - e:append("file entry for remote file without `sha1` attribute") - end - end - end - end - if (not info.chroot.default_groups) or #info.chroot.default_groups == 0 then - e:append(" `default_groups' attribute is missing or empty list") - else - for _,g in ipairs(info.chroot.default_groups) do - if not info.chroot.groups_byname[g] then - e:append(" unknown group in default groups list: %s", g) - end - end - end - if e:getcount() > 1 then - return false, e - end - return true -end ---- check source. -local function check_source(info, sourcename) - local src = info.sources[sourcename] - local rc, e, re - if not src then - e = err.new("no source by that name: %s", sourcename) - return false, e - end - local e = err.new("in source: %s", sourcename) - if not src.type then - e2lib.warnf("WDEFAULT", "in source %s", sourcename) - e2lib.warnf("WDEFAULT", " type attribute defaults to `files'") - src.type = "files" - end - rc, re = scm.validate_source(info, sourcename) + rc, re = check_project_info(info) if not rc then return false, re end - return true -end - ---- check sources. -local function check_sources(info) - local e = err.new("Error while checking sources") - local rc, re - for n,s in pairs(info.sources) do - rc, re = check_source(info, n) - if not rc then - e:cat(re) - end - end - if e:getcount() > 1 then - return false, e - end - return true -end - ---- check licence. -local function check_licence(info, l) - local e = err.new("in licence: %s", l) - local lic = info.licences[l] - if not lic.server then - e:append("no server attribute") - end - if not lic.files then - e:append("no files attribute") - elseif type(lic.files) ~= "table" then - e:append("files attribute is not a table") - else - for _,f in ipairs(lic.files) do - local inherit = { - server = lic.server, - } - local keys = { - server = { - mandatory = true, - type = "string", - inherit = true, - }, - location = { - mandatory = true, - type = "string", - inherit = false, - }, - sha1 = { - mandatory = false, - type = "string", - inherit = false, - }, - } - local rc, re = check_tab(f, keys, inherit) - if not rc then - e:cat(re) - elseif f.server ~= info.root_server_name and - not f.sha1 then - e:append("file entry for remote file without".. - " `sha1` attribute") - end - end - end - if e:getcount() > 1 then - return false, e - end - return true -end - ---- check licences. -local function check_licences(info) - local e = err.new("Error while checking licences") - local rc, re - for l, lic in pairs(info.licences) do - rc, re = check_licence(info, l) - if not rc then - e:cat(re) - end - end - if e:getcount() > 1 then - return false, e - end - return true -end ---- Checks project information for consistancy. --- @param info Info table. --- @return True on success, false on error. --- @return Error object on failure. -function e2tool.check_project_info(info) - local rc, re - local e = err.new("error in project configuration") - rc, re = check_chroot_config(info) - if not rc then - return false, e:cat(re) - end - local rc, re = check_sources(info) - if not rc then - return false, e:cat(re) - end - local rc, re = check_results(info) - if not rc then - return false, e:cat(re) - end - local rc, re = check_licences(info) - if not rc then - return false, e:cat(re) - end - for _, r in ipairs(info.project.default_results) do - if not info.results[r] then - e:append("default_results: No such result: %s", r) - end - end - for _, r in ipairs(info.project.deploy_results) do - if not info.results[r] then - e:append("deploy_results: No such result: %s", r) - end - end - if e:getcount() > 1 then - return false, e - end - local rc = e2tool.dsort(info) - if not rc then - return false, e:cat("cyclic dependencies") - end - return true + return info end --- Returns a sorted vector with all dependencies for the given result -- 2.39.5