From: Gordon Hecker Date: Thu, 18 Jun 2009 18:36:32 +0000 (+0200) Subject: plugin support: plugin interface X-Git-Tag: e2factory-2.3.4pre1~74 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=3f3af912ab8f47011955a8e5f9f18ec26e1389b3;p=e2factory.git plugin support: plugin interface Signed-off-by: Gordon Hecker --- diff --git a/local/e2tool.lua b/local/e2tool.lua index ff81397..763e421 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -375,6 +375,18 @@ function e2tool.collect_project_info(path) return false, e:cat(re) end + -- table of functions, extensible by plugins + info.ftab = { + collect_project_info = {}, -- f(info) + check_result = {}, -- f(info, resultname) + resultid = {}, -- f(info, resultname) + pbuildid = {}, -- f(info, resultname) + } + rc, re = e2tool.register_check_result(info, e2tool.check_result) + if not rc then + return nil, e:cat(re) + end + -- load local plugins local ctx = { -- plugin context info = info, @@ -803,6 +815,10 @@ The newest configuration syntax supported by the tools is %s. e2lib.abort(e:cat(re)) end end + + for _,f in ipairs(info.ftab.collect_project_info) do + f(info) + end return info, nil end @@ -1705,6 +1721,17 @@ function e2tool.pbuildid(info, resultname) end hc:hash_line(fileid) -- build script hash end + -- call the list of functions in info.ftab.resultid + for _,f in ipairs(info.ftab.resultid) do + local hash, re = f(info, resultname) + -- nil -> error + -- false -> don't modify the hash + if hash == nil then + e2lib.abort(e:cat(re)) + elseif hash ~= false then + hc:hash_line(hash) + end + end e2lib.log(4, string.format("hash data for resultid %s\n%s", resultname, hc.data)) r.resultid = hash.hash_finish(hc) -- result id (without deps) @@ -1729,7 +1756,18 @@ function e2tool.pbuildid(info, resultname) end hash.hash_line(hc, pbid) end - e2lib.log(4, string.format("hash data for resultid %s\n%s", + -- call the list of functions in info.ftab.pbuildid + for _,f in ipairs(info.ftab.pbuildid) do + local hash, re = f(info, resultname) + -- nil -> error + -- false -> don't modify the hash + if hash == nil then + e2lib.abort(e:cat(re)) + elseif hash ~= false then + hc:hash_line(hash) + end + end + e2lib.log(4, string.format("hash data for resultid %s\n%s", resultname, hc.data)) r.pbuildid = hash.hash_finish(hc) -- buildid (with deps) return r.build_mode.buildid(r.pbuildid) @@ -1966,10 +2004,12 @@ end function e2tool.check_results(info) local e = new_error("Error while checking results") local rc, re - for r,_ in pairs(info.results) do - rc, re = e2tool.check_result(info, r) - if not rc then - e:cat(re) + for _,f in ipairs(info.ftab.check_result) do + for r,_ in pairs(info.results) do + rc, re = f(info, r) + if not rc then + return false, e:cat(re) + end end end if e:getcount() > 1 then @@ -2963,3 +3003,27 @@ end function e2tool.sourceconfig(name) return e2tool.sourcedir(name,"config") end + +function e2tool.register_check_result(info, func) + if type(info) ~= "table" or type(func) ~= "function" then + return false, new_error("register_check_result: invalid argument") + end + table.insert(info.ftab.check_result, func) + return true, nil +end + +function e2tool.register_resultid(info, func) + if type(info) ~= "table" or type(func) ~= "function" then + return false, new_error("register_resultid: invalid argument") + end + table.insert(info.ftab.resultid, func) + return true, nil +end + +function e2tool.register_pbuildid(info, func) + if type(info) ~= "table" or type(func) ~= "function" then + return false, new_error("register_pbuildid: invalid argument") + end + table.insert(info.ftab.pbuildid, func) + return true, nil +end