]> git.e2factory.org Git - e2factory.git/commitdiff
Move check_project_info into collect_project_info
authorTobias Ulmer <tu@emlix.com>
Thu, 30 Jan 2014 18:41:08 +0000 (19:41 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:17 +0000 (15:41 +0100)
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 <tu@emlix.com>
local/e2-build.lua
local/e2-fetch-sources.lua
local/e2-ls-project.lua
local/e2-playground.lua
local/e2tool.lua

index 7da84adbeea19e55096bc336ba6ed9c00d832a1f..4c65ae0ea0c8a226998bf6bd472551fbbcf90a01 100644 (file)
@@ -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
index 04b2aeb1f54979fc88706b337e9885a825f3c1ea..bd66deadff7476d9fd2758b2b2e1887c76504c96 100644 (file)
@@ -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
index 755451d58006fcb958cca8a9c37c6a7bb6efb0e7..d52b6c8515020eb42f049547d306dc28d2405486 100644 (file)
@@ -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
index 8d5b660fc46b3e98173d46992aabbe4d8660bd06..693470c0996e83b2a3d82ed811a754686cd6f426 100644 (file)
@@ -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)
index 6f23e03c0b02315767d1547e7f1c2dab41b929fc..5ae11a8d5e6cf125871e3ce72ade17196e5b3833 100644 (file)
@@ -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