]> git.e2factory.org Git - e2factory.git/commitdiff
plugin interface: extensions
authorGordon Hecker <gh@emlix.com>
Wed, 10 Mar 2010 17:56:34 +0000 (18:56 +0100)
committerGordon Hecker <gh@emlix.com>
Mon, 15 Mar 2010 12:37:50 +0000 (13:37 +0100)
 * permit plugins to register commandline options
 * permit tool specific initialization of plugins

Signed-off-by: Gordon Hecker <gh@emlix.com>
12 files changed:
Changelog
local/build-numbers.lua
local/build.lua
local/cf.lua
local/dlist.lua
local/dsort.lua
local/e2build.lua
local/e2tool.lua
local/fetch-sources.lua
local/ls-project.lua
local/new-source.lua
local/playground.lua

index 2b6d3e0a6e11b7e842d2ba15556a9e413d13612c..73aa093fb854d4c7e58bad4938de0bcf8744a835 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,6 @@
 NEXT:
+ * the plugin interface was extended to permit plugins to register
+   commandline options and permit tool specific initialization of plugins
  * a serious bug in the hashcache was fixed. The buildid calculation
    used outdated hash of files from the project tree.
  * the username is included in the chroot environment path again
index 36b07ccc2cbc15f0790ef8521fa7c1c04c2abb31..944b744253088ec75f082d78b4025d4d1e5c309f 100755 (executable)
 require("e2local")
 require("e2tool")
 e2lib.init()
+local info, re = e2tool.local_init(nil, "build-numbers")
+if not info then
+  e2lib.abort(re)
+end
 
 e2option.documentation = [[
 usage:
@@ -45,7 +49,7 @@ local build_mode = policy.handle_commandline_options(opts, true)
 if not build_mode then
        e2lib.abort("no build mode given")
 end
-local info, re = e2tool.collect_project_info()
+info, re = e2tool.collect_project_info(info)
 if not info then
   e2lib.abort(re)
 end
index 6f41cc98b245b3159b1f2210fd39dc78da118316..1eb1e8985745178060b863fdd72dc46561588a2f 100755 (executable)
@@ -31,6 +31,10 @@ require("e2local")
 require("e2tool")
 require("e2build")
 e2lib.init()
+local info, re = e2tool.local_init(nil, "build")
+if not info then
+  e2lib.abort(re)
+end
 
 e2option.documentation = [[
 usage: e2-build [<option> | <result> ...]
@@ -56,7 +60,7 @@ if not build_mode then
        e2lib.abort("no build mode given")
 end
 
-local info, re = e2tool.collect_project_info()
+info, re = e2tool.collect_project_info(info)
 if not info then
   e2lib.abort(re)
 end
index 04bacfa9690b4bb29680a2870eedf9b2d3caa3c2..1fbefc96ee6194dafe1ab5dab2c1eb9dbb47a8ce 100755 (executable)
 require("e2local")
 require("e2tool")
 e2lib.init()
+local info, re = e2tool.local_init(nil, "cf")
+if not info then
+  e2lib.abort(re)
+end
 
 e2option.documentation = [[
 usage: e2 cf <command> ...
@@ -54,7 +58,7 @@ local opts = e2option.parse(arg)
 
 -- initialize some basics in the info structure without actually loading
 -- the project configuration.
-local info, re = e2tool.collect_project_info(nil, true)
+info, re = e2tool.collect_project_info(info, true)
 if not info then
   e2lib.abort(re)
 end
index 431b06478cf0549f8b99d8b493aa630c7c4f4eb2..8f19919a611befb451145e25ab474ec3580708e0 100755 (executable)
@@ -31,6 +31,10 @@ require("e2local")
 require("e2tool")
 require("e2build")
 e2lib.init()
+local info, re = e2tool.local_init(nil, "dlist")
+if not info then
+  e2lib.abort(re)
+end
 
 e2option.documentation = [[
 usage: e2-dlist [<option> | <result> ...]
@@ -46,7 +50,7 @@ if #opts.arguments == 0 then
 elseif #opts.arguments ~= 1 then e2option.usage(1) end
 
 local result = opts.arguments[1]
-local info, re = e2tool.collect_project_info()
+info, re = e2tool.collect_project_info(info)
 if not info then
   e2lib.abort(re)
 end
index 4dc7eacb6963ed3420106868d9d0003f461b194d..1bb4d5b1ddc536b792e4641fc42ad57f0b2a0a15 100755 (executable)
@@ -31,6 +31,10 @@ require("e2local")
 require("e2tool")
 require("e2build")
 e2lib.init()
+local info, re = e2tool.local_init(nil, "dsort")
+if not info then
+  e2lib.abort(re)
+end
 
 e2option.documentation = [[
 usage: e2-dsort
@@ -40,7 +44,7 @@ lists all results sorted by dependency
 
 e2option.parse(arg)
 
-local info, re = e2tool.collect_project_info()
+info, re = e2tool.collect_project_info(info)
 if not info then
   e2lib.abort(re)
 end
index 979858d0b4f56f7b8433c56c80c1f2e5ad350557..d00266ccb20159a2194e39ed3ed66ac97c444e90 100644 (file)
@@ -803,7 +803,7 @@ end
 -- @param results table: list of results, sorted by dependencies
 -- @return bool
 -- @return an error object on failure
-function build_results(info, results)
+function build_results_default(info, results)
   e2lib.logf(3, "building results")
   for _, r in ipairs(results) do
     local e = new_error("building result failed: %s", r)
@@ -824,6 +824,35 @@ function build_results(info, results)
   return true, nil
 end
 
+function build_results(info, results)
+  for i,f in ipairs(build_results_ftab) do
+    rc, re = f(info, results)
+    if not rc then
+      return rc, re
+    end
+  end
+  return true, nil
+end
+
+build_results_ftab = {
+       build_results_default,
+}
+
+function register_build_results(func, position, post)
+  for i,f in ipairs(build_results_ftab) do
+    if f == position then
+      if post then
+        table.insert(build_results_ftab, i + 1 ,func)
+       return true, nil
+      else
+       table.insert(build_results_ftab, i, func)
+       return true, nil
+      end
+    end
+  end
+  return false, new_error("registering build_results function failed")
+end
+
 --- build a result
 -- @param info
 -- @param result string: result name
index e28b413fe9e16b0663bc4e95649eddd504123352..5f413e399a23ce9dee10b0533195e7b4cc34d3af 100644 (file)
@@ -376,12 +376,20 @@ function load_user_config2(info, path, types)
   return list, nil
 end
 
-function collect_project_info(path, skip_load_config)
+--- initialize the local library, load and initialize local plugins
+-- @param path string: path to project tree
+-- @param tool string: tool name (without the 'e2-' prefix)
+-- @return table: the info table, or false on failure
+-- @return an error object on failure
+function local_init(path, tool)
   local rc, re
-  local e = new_error("reading project configuration")
-
+  local e = new_error("initializing")
   local info = {}
 
+  -- provide the current tool name to allow conditionals in plugin
+  -- initialization
+  info.current_tool = tool
+
   -- set the umask value to be used in chroot
   info.chroot_umask = 18   -- 0022 octal
   init_umask(info)
@@ -426,6 +434,13 @@ function collect_project_info(path, skip_load_config)
     return false, e:cat(re)
   end
 
+  return info
+end
+
+function collect_project_info(info, skip_load_config)
+  local rc, re
+  local e = new_error("reading project configuration")
+
   -- check for configuration compatibility
   info.config_syntax_compat = buildconfig.SYNTAX
   info.config_syntax_file = ".e2/syntax"
index e4e83fad5f26e5331e3e68b7ee74e4afc78cf6a4..f2ba774de3e06675e329ae21e9ee0123923a20b0 100755 (executable)
@@ -31,6 +31,10 @@ require("e2local")
 require("e2tool")
 require("e2build")
 e2lib.init()
+local info, re = e2tool.local_init(nil, "fetch-sources")
+if not info then
+  e2lib.abort(re)
+end
 
 e2option.documentation = [[
 usage: e2-fetch-sources <source> ...
@@ -67,7 +71,7 @@ e2option.flag("source", "select sources by source names (default)")
 e2option.flag("result", "select sources by result names")
 
 local opts = e2option.parse(arg)
-local info, re = e2tool.collect_project_info()
+info, re = e2tool.collect_project_info(info)
 if not info then
   e2lib.abort(re)
 end
index 3e639c51759542248a66f712032fc22d09e88acb..6a1bca20eac6ba7d9784916640b5a21660b7a78f 100755 (executable)
 require("e2local")
 require("e2tool")
 e2lib.init()
+local info, re = e2tool.local_init(nil, "ls-project")
+if not info then
+  e2lib.abort(re)
+end
 
 e2option.documentation = [[
 usage: e2-ls-project [<result> ...]
@@ -45,7 +49,7 @@ e2option.flag("all", "show unused results and sources, too")
 
 local opts = e2option.parse(arg)
 
-local info, re = e2tool.collect_project_info()
+info, re = e2tool.collect_project_info(info)
 if not info then
   e2lib.abort(re)
 end
index c962285bf10dbdecb8a929d3dd6fde63f6761c49..12db7e70391bf72590eb6e2f74349a004073a70c 100644 (file)
 require("e2local")
 require("e2tool")
 e2lib.init()
+local info, re = e2tool.local_init(nil, "new-source")
+if not info then
+  e2lib.abort(re)
+end
 
 e2option.documentation = [[
 usage: e2-new-source --git [--server <server>] <name>
@@ -238,7 +242,7 @@ function new_files_source(c, server, location, source_file, checksum_file,
        return true, nil
 end
 
-local info, re = e2tool.collect_project_info()
+info, re = e2tool.collect_project_info(info)
 if not info then
   e2lib.abort(re)
 end
index 8a43a11f3b5494ef4ab4eda1aa9ab02ab1d3e807..51c274c3679ab8524dd81e15c24b7cc1301686e1 100644 (file)
@@ -31,6 +31,10 @@ require("e2local")
 require("e2tool")
 require("e2build")
 e2lib.init()
+local info, re = e2tool.local_init(nil, "playground")
+if not info then
+  e2lib.abort(re)
+end
 
 local e = new_error("entering playground failed")
 local rc, re
@@ -50,7 +54,7 @@ local build_mode = policy.handle_commandline_options(opts, true)
 if not build_mode then
        e2lib.abort("no build mode given")
 end
-local info, re = e2tool.collect_project_info()
+info, re = e2tool.collect_project_info(info)
 if not info then
   e2lib.abort(re)
 end