]> git.e2factory.org Git - e2factory.git/commitdiff
tools: new module, move tool related code from transport to new tools module
authorGordon Hecker <gh@emlix.com>
Tue, 19 Jan 2010 16:59:14 +0000 (17:59 +0100)
committerGordon Hecker <gh@emlix.com>
Fri, 12 Feb 2010 09:51:58 +0000 (10:51 +0100)
Signed-off-by: Gordon Hecker <gh@emlix.com>
12 files changed:
Changelog
generic/Makefile
generic/e2lib.lua
generic/scm.git.lua
generic/tools.lua [new file with mode: 0644]
generic/transport.lua
local/Makefile
local/cvs.lua
local/e2build.lua
local/e2tool.lua
local/git.lua
local/svn.lua

index 5b5dccd1e318648938eb246f8278e956301d4016..f31b6eeef61f0ba69a2d0b72e4de647d83ba98b9 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -18,6 +18,7 @@ NEXT:
  * the local tools check for their own support for the global interface
    version in use.
  * a few minor bugs were fixed
+ * code related to external tools was moved into the new tools module
 
 e2factory-2.3.3
  * use sha1 module instead of calling the sha1sum tool
index ce4072ed5d42e392e1018f8b0d7bde355926271b..0a5cad136d55c14f6715b799ca1b842615529a64 100644 (file)
@@ -78,14 +78,14 @@ clean:
 
 e2generic_global.lc: strict.lua collection.lua e2lib_global_prefix.lua \
                plugin.lua \
-               e2lib.lua e2option.lua hash.lua \
+               e2lib.lua e2option.lua hash.lua tools.lua \
                transport.lua cache.lua url.lua scm.git.lua \
                luafile.lua lua-version-map.lua \
                error.lua lock.lua
        $(BUILD_LUAC) -o $@ $^
 
 e2generic_local.lc: strict.lua collection.lua e2lib_local_prefix.lua \
-               e2lib.lua e2option.lua hash.lua \
+               e2lib.lua e2option.lua hash.lua tools.lua \
                transport.lua cache.lua url.lua scm.git.lua \
                luafile.lua lua-version-map.lua
        $(LUAC) -o $@ $^
index 2ad01af73e4780a91a4caf9a83ca89cfed7cb04a..1608301d7a9a08e80a8387bb89f7e54b2a6ad6a6 100644 (file)
@@ -190,7 +190,7 @@ function e2lib.init2()
   -- honour tool customizations from the config file
   if config.tools then
     for k,v in pairs(config.tools) do
-      transport.set_tool(k, v.name, v.flags)
+      tools.set_tool(k, v.name, v.flags)
     end
   end
 
@@ -200,11 +200,11 @@ function e2lib.init2()
   if ssh then
     e2lib.log(3, string.format(
        "using ssh command from the E2_SSH environment variable: %s", ssh))
-    transport.set_tool("ssh", ssh)
+    tools.set_tool("ssh", ssh)
   end
 
-  -- initialize the transport library after resetting tools
-  local rc, re = transport.init()
+  -- initialize the tools library after resetting tools
+  local rc, re = tools.init()
   if not rc then
     e2lib.abort(e:cat(re))
   end
@@ -1547,11 +1547,11 @@ end
 -- @return bool
 -- @return string: the last line ouf captured output
 function e2lib.call_tool(tool, args)
-       local cmd = transport.get_tool(tool)
+       local cmd = tools.get_tool(tool)
        if not tool then
                e2lib.bomb("trying to call invalid tool: " .. tostring(tool))
        end
-       local flags = transport.get_tool_flags(tool)
+       local flags = tools.get_tool_flags(tool)
        if not flags then
                e2lib.bomb("invalid tool flags for tool: " .. tostring(tool))
        end
@@ -1578,7 +1578,7 @@ function e2lib.git(gitdir, subtool, args)
        if not args then
                args = ""
        end
-       local git, re = transport.get_tool("git")
+       local git, re = tools.get_tool("git")
        if not git then
                return false, e:cat(re)
        end
@@ -1721,11 +1721,11 @@ end
 -- @return bool
 function e2lib.sha1sum(path)
   local args = string.format("'%s'", path)
-  local sha1sum, re = transport.get_tool("sha1sum")
+  local sha1sum, re = tools.get_tool("sha1sum")
   if not sha1sum then
     return nil, re
   end
-  local sha1sum_flags, re = transport.get_tool_flags("sha1sum")
+  local sha1sum_flags, re = tools.get_tool_flags("sha1sum")
   if not sha1sum_flags then
     return nil, re
   end
@@ -1768,7 +1768,7 @@ end
 function e2lib.get_sys_arch()
   local rc, re
   local e = new_error("getting host system architecture failed")
-  local uname = transport.get_tool("uname")
+  local uname = tools.get_tool("uname")
   local cmd = string.format("%s -m", uname)
   local p, msg = io.popen(cmd, "r")
   if not p then
index 61a3a5f25a60e1cb73fd2a25b09c1985c8b8ea69..fadd8872000334abc1ea5546dfb04157474d2f44 100644 (file)
@@ -161,7 +161,7 @@ function generic_git.git_init_db1(rurl)
                "mkdir -p \"%s\" && GIT_DIR=\"%s\" git init-db --shared",                                                               gitdir, gitdir)
   if u.transport == "ssh" or u.transport == "scp" or
      u.transport == "rsync+ssh" then
-    local ssh = transport.get_tool("ssh")
+    local ssh = tools.get_tool("ssh")
     cmd = string.format("%s '%s' '%s'", ssh, u.server, gitcmd)
   elseif u.transport == "file" then
     cmd = gitcmd
diff --git a/generic/tools.lua b/generic/tools.lua
new file mode 100644 (file)
index 0000000..b639fc6
--- /dev/null
@@ -0,0 +1,149 @@
+--[[
+   e2factory, the emlix embedded build system
+
+   Copyright (C) 2007-2009 Gordon Hecker <gh@emlix.com>, emlix GmbH
+   Copyright (C) 2007-2009 Oskar Schirmer <os@emlix.com>, emlix GmbH
+   Copyright (C) 2007-2008 Felix Winkelmann, emlix GmbH
+
+   For more information have a look at http://www.e2factory.org
+
+   e2factory is a registered trademark by emlix GmbH.
+
+   This file is part of e2factory, the emlix embedded build system.
+
+   e2factory is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+]]
+
+module("tools", package.seeall)
+require("buildconfig")
+
+local tools = {
+       which = { name = "which", flags = "", optional = false },
+       curl = { name = "curl", flags = "", optional = false },
+       ssh = { name = "ssh", flags = "", optional = false },
+       scp = { name = "scp", flags = "", optional = false },
+       rsync = { name = "rsync", flags = "", optional = false },
+       git = { name = "git", flags = "", optional = false },
+       cvs = { name = "cvs", flags = "", optional = true },
+       svn = { name = "svn", flags = "", optional = true },
+       mktemp = { name = "mktemp", flags = "", optional = false },
+       rm = { name = "rm", flags = "", optional = false },
+       mkdir = { name = "mkdir", flags = "", optional = false },
+       rmdir = { name = "rmdir", flags = "", optional = false },
+       cp = { name = "cp", flags = "", optional = false },
+       ln = { name = "ln", flags = "", optional = false },
+       mv = { name = "mv", flags = "", optional = false },
+       tar = { name = "tar", flags = "", optional = false },
+       sha1sum = { name = "sha1sum", flags = "", optional = false },
+       md5sum = { name = "md5sum", flags = "", optional = false },
+       chmod = { name = "chmod", flags = "", optional = false },
+       test = { name = "test", flags = "", optional = false },
+       cat = { name = "cat", flags = "", optional = false },
+       touch = { name = "touch", flags = "", optional = false },
+       uname = { name = "uname", flags = "", optional = false },
+       patch = { name = "patch", flags = "", optional = false },
+        ["e2-su"] = { name = buildconfig.PREFIX .. "/bin/e2-su", flags = "",
+                                                       optional = false },
+       ["e2-su-2.2"] = { name = buildconfig.PREFIX .. "/bin/e2-su-2.2",
+                                               flags = "", optional = false },
+}
+
+
+--- get a tool command
+-- @param name string: the tool name
+-- @return string: the tool command, nil on error
+function get_tool(name)
+       if not tools[name] then
+               e2lib.bomb("looking up invalid tool: " .. tostring(name))
+       end
+       return tools[name].path
+end
+
+--- get tool flags
+-- @param name string: the tool name
+-- @return string: the tool flags
+function get_tool_flags(name)
+       if not tools[name] then
+               e2lib.bomb("looking up flags for invalid tool: " ..
+                                                       tostring(name))
+       end
+       return tools[name].flags or ""
+end
+
+--- set a tool command and flags
+-- @param name string: the tool name
+-- @param value string: the new tool command
+-- @param flags string: the new tool flags. Optional.
+-- @return bool
+-- @return nil, an error string on error
+function set_tool(name, value, flags)
+       if not tools[name] then
+               return false, "invalid tool setting"
+       end
+       if type(value) == "string" then
+               tools[name].name = value
+       end
+       if type(flags) == "string" then
+               tools[name].flags = flags
+       end
+       e2lib.log(3, string.format("setting tool: %s=%s flags=%s",
+                               name, tools[name].name, tools[name].flags))
+       return true, nil
+end
+
+--- check if a tool is available
+-- @param name string a valid tool name
+-- @return bool
+-- @return nil, an error string on error
+function check_tool(name)
+       local tool = tools[name]
+       if not tool.path then
+               local which = string.format("which \"%s\"", tool.name)
+               local p = io.popen(which, "r")
+               tool.path = p:read()
+               p:close()
+               if not tool.path then
+                       e2lib.log(3, string.format(
+                               "tool not available: %s", tool.name))
+                       return false, "tool not available"
+               end
+       end
+       e2lib.log(4, string.format(
+               "tool available: %s (%s)",
+               tool.name, tool.path))
+       return true
+end
+
+--- initialize the library
+-- @return bool
+function init()
+       local error = false
+       for tool,t in pairs(tools) do
+               local rc = check_tool(tool)
+               if not rc then
+                       local warn = "Warning"
+                       if not t.optional then
+                               error = true
+                               warn = "Error"
+                       end
+                       e2lib.log(1, string.format(
+                                       "%s: tool is not available: %s",
+                                                       warn, tool))
+               end
+       end
+       if error then
+               return false, "missing mandatory tools"
+       end
+       return true, nil
+end
index fa7e8277253e32f753d64ea5737c4d416b6e9c7e..d3229ae1de7d5906f9e6d0bc826e9005bdc576d6 100644 (file)
 ]]
 
 module("transport", package.seeall)
-require("buildconfig")
-
-local tools = {
-       which = { name = "which", flags = "", optional = false },
-       curl = { name = "curl", flags = "", optional = false },
-       ssh = { name = "ssh", flags = "", optional = false },
-       scp = { name = "scp", flags = "", optional = false },
-       rsync = { name = "rsync", flags = "", optional = false },
-       git = { name = "git", flags = "", optional = false },
-       cvs = { name = "cvs", flags = "", optional = true },
-       svn = { name = "svn", flags = "", optional = true },
-       mktemp = { name = "mktemp", flags = "", optional = false },
-       rm = { name = "rm", flags = "", optional = false },
-       mkdir = { name = "mkdir", flags = "", optional = false },
-       rmdir = { name = "rmdir", flags = "", optional = false },
-       cp = { name = "cp", flags = "", optional = false },
-       ln = { name = "ln", flags = "", optional = false },
-       mv = { name = "mv", flags = "", optional = false },
-       tar = { name = "tar", flags = "", optional = false },
-       sha1sum = { name = "sha1sum", flags = "", optional = false },
-       md5sum = { name = "md5sum", flags = "", optional = false },
-       chmod = { name = "chmod", flags = "", optional = false },
-       test = { name = "test", flags = "", optional = false },
-       cat = { name = "cat", flags = "", optional = false },
-       touch = { name = "touch", flags = "", optional = false },
-       uname = { name = "uname", flags = "", optional = false },
-       patch = { name = "patch", flags = "", optional = false },
-        ["e2-su"] = { name = buildconfig.PREFIX .. "/bin/e2-su", flags = "",
-                                                       optional = false },
-       ["e2-su-2.2"] = { name = buildconfig.PREFIX .. "/bin/e2-su-2.2",
-                                               flags = "", optional = false },
-}
-
-
---- get a tool command
--- @param name string: the tool name
--- @return string: the tool command, nil on error
-function get_tool(name)
-       if not tools[name] then
-               e2lib.bomb("looking up invalid tool: " .. tostring(name))
-       end
-       return tools[name].path
-end
-
---- get tool flags
--- @param name string: the tool name
--- @return string: the tool flags
-function get_tool_flags(name)
-       if not tools[name] then
-               e2lib.bomb("looking up flags for invalid tool: " .. 
-                                                       tostring(name))
-       end
-       return tools[name].flags or ""
-end
-
---- set a tool command and flags
--- @param name string: the tool name
--- @param value string: the new tool command
--- @param flags string: the new tool flags. Optional.
--- @return bool
--- @return nil, an error string on error
-function set_tool(name, value, flags)
-       if not tools[name] then
-               return false, "invalid tool setting"
-       end
-       if type(value) == "string" then
-               tools[name].name = value
-       end
-       if type(flags) == "string" then
-               tools[name].flags = flags
-       end
-       e2lib.log(3, string.format("setting tool: %s=%s flags=%s",
-                               name, tools[name].name, tools[name].flags))
-       return true, nil
-end
 
 --- fetch a file from a server
 -- @param surl url to the server
@@ -363,49 +288,3 @@ function file_path(surl, location)
        local path = string.format("/%s/%s", u.path, location)
        return path
 end
-
---- check if a tool is available
--- @param name string a valid tool name
--- @return bool
--- @return nil, an error string on error
-function check_tool(name)
-       local tool = tools[name]
-       if not tool.path then
-               local which = string.format("which \"%s\"", tool.name)
-               local p = io.popen(which, "r")
-               tool.path = p:read()
-               p:close()
-               if not tool.path then
-                       e2lib.log(3, string.format(
-                               "tool not available: %s", tool.name))
-                       return false, "tool not available"
-               end
-       end
-       e2lib.log(4, string.format(
-               "tool available: %s (%s)", 
-               tool.name, tool.path))
-       return true
-end
-
---- initialize the library
--- @return bool
-function init()
-       local error = false
-       for tool,t in pairs(tools) do
-               local rc = check_tool(tool)
-               if not rc then
-                       local warn = "Warning"
-                       if not t.optional then
-                               error = true
-                               warn = "Error"
-                       end
-                       e2lib.log(1, string.format(
-                                       "%s: tool is not available: %s",
-                                                       warn, tool))
-               end
-       end
-       if error then
-               return false, "missing mandatory tools"
-       end
-       return true, nil
-end
index 2a65f3ece8c5f29e2c54d5387dc32e1a3b9319a9..243b1854c35e288b7d2e94d9f86f667c3b28224f 100644 (file)
@@ -113,6 +113,7 @@ e2local.lc: $(TOPLEVEL)/generic/strict.lua \
                environment.lua \
                $(TOPLEVEL)/generic/plugin.lua \
                $(TOPLEVEL)/generic/scm.git.lua \
+               $(TOPLEVEL)/generic/tools.lua \
                $(TOPLEVEL)/generic/transport.lua \
                $(TOPLEVEL)/generic/cache.lua \
                $(TOPLEVEL)/generic/error.lua \
index 3b852c6efe6f65ca5c3a4da830429175cf0b29ec..629be7e00d79921f2ce668c4b92a202f1724180d 100644 (file)
@@ -95,7 +95,7 @@ function cvs.validate_source(info, sourcename)
   if not src.working then
     e:append("source has no `working' attribute")
   end
-  local rc, re = transport.check_tool("cvs")
+  local rc, re = tools.check_tool("cvs")
   if not rc then
     e:cat(re)
   end
@@ -168,9 +168,9 @@ function cvs.fetch_source(info, sourcename)
   end
   -- always fetch the configured branch, as we don't know the build mode here.
   local rev = src.branch
-  local rsh = transport.get_tool("ssh")
-  local cvstool = transport.get_tool("cvs")
-  local cvsflags = transport.get_tool_flags("cvs")
+  local rsh = tools.get_tool("ssh")
+  local cvstool = tools.get_tool("cvs")
+  local cvsflags = tools.get_tool_flags("cvs")
   -- split the working directory into dirname and basename as some cvs clients
   -- don't like slashes (e.g. in/foo) in their checkout -d<path> argument
   local dir = e2lib.dirname(src.working)
@@ -220,9 +220,9 @@ function cvs.prepare_source(info, sourcename, source_set, buildpath)
   local cmd = nil
   if source_set == "tag" or source_set == "branch" then
     local rev = mkrev(src, source_set)
-    local rsh = transport.get_tool("ssh")
-    local cvstool = transport.get_tool("cvs")
-    local cvsflags = transport.get_tool_flags("cvs")
+    local rsh = tools.get_tool("ssh")
+    local cvstool = tools.get_tool("cvs")
+    local cvsflags = tools.get_tool_flags("cvs")
     -- cd buildpath && cvs -d cvsroot export -R -r rev module
     cmd = string.format(
        "cd \"%s\" && " ..
@@ -253,9 +253,9 @@ function cvs.update(info, sourcename)
   local e = new_error("updating cvs source failed")
   local src = info.sources[ sourcename ]
   local working = string.format("%s/%s", info.root, src.working)
-  local rsh = transport.get_tool("ssh")
-  local cvstool = transport.get_tool("cvs")
-  local cvsflags = transport.get_tool_flags("cvs")
+  local rsh = tools.get_tool("ssh")
+  local cvstool = tools.get_tool("cvs")
+  local cvsflags = tools.get_tool_flags("cvs")
   local cmd = string.format(
        "cd \"%s\" && " ..
        "CVS_RSH=\"%s\" " ..
index a30b9e6f2ef4d3af126c764edcbfa99962139ced..418784f814e81d3589b2b2ea1c96bf6f9b08af95 100644 (file)
@@ -299,7 +299,7 @@ function e2build.enter_playground(info, r, chroot_command)
   local e = new_error("entering playground")
   e2lib.log(4, "entering playground for " .. r .. " ...")
   local term = e2lib.terminal
-  local e2_su = transport.get_tool("e2-su-2.2")
+  local e2_su = tools.get_tool("e2-su-2.2")
   local cmd = string.format("%s %s chroot_2_3 '%s' %s",
                                res.build_config.chroot_call_prefix, e2_su, 
                                res.build_config.base, chroot_command)
@@ -353,7 +353,7 @@ function e2build.runbuild(info, r, return_flags)
   local runbuild = string.format("/bin/bash -e -x '%s/%s/%s'",
                        res.build_config.Tc, res.build_config.scriptdir,
                                        res.build_config.build_driver_file)
-  local e2_su = transport.get_tool("e2-su-2.2")
+  local e2_su = tools.get_tool("e2-su-2.2")
   local cmd = string.format("%s %s chroot_2_3 '%s' %s", 
                                res.build_config.chroot_call_prefix, e2_su, 
                                res.build_config.base, runbuild)
index aeb4e71b2c193137ee084476f077d17a39618515..24e0ae952169aaa57bc614d53a897879f1e03746 100644 (file)
@@ -1311,7 +1311,7 @@ function e2tool.verify_remote_fileid(info, file, fileid)
        local retcmd
        if u.transport == "ssh" or u.transport == "scp" or
                u.transport == "rsync+ssh" then
-               local ssh = transport.get_tool("ssh")
+               local ssh = tools.get_tool("ssh")
                retcmd = string.format("%s '%s' %s /%s", ssh, u.server,
                                                                cmd, u.path)
        elseif u.transport == "file" then
index 2af4086d469c7dbb92055a14d88b8f5f7dbe84d4..2470f6f16eb1b9823f77311a69b7f792a15f32ea 100644 (file)
@@ -445,8 +445,8 @@ function git.prepare_source(info, sourcename, sourceset, buildpath)
     if not rc then
       return false, re
     end
-    local tar = transport.get_tool("tar")
-    local tarflags = transport.get_tool_flags("tar")
+    local tar = tools.get_tool("tar")
+    local tarflags = tools.get_tool_flags("tar")
     local cmd1 = string.format("%s %s -c -C '%s/%s' --exclude '.git' .", tar,
                                        tarflags, info.root, src.working)
     local cmd2 = string.format("%s %s -x -C '%s/%s'", tar, tarflags, buildpath,
index 993c20507ea265656b8ee535e5dc8e9a1fbc9ba6..b9bcf56fc1bf5378308c5fb704e1b9c22dd41b74 100644 (file)
@@ -367,7 +367,7 @@ function svn.validate_source(info, sourcename) --OK
   if not src.working then
     e:append("source has no `working' attribute")
   end
-  local rc, re = transport.check_tool("svn")
+  local rc, re = tools.check_tool("svn")
   if not rc then
     e:cat(re)
   end