* 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
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 $@ $^
-- 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
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
-- @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
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
-- @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
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
"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
--- /dev/null
+--[[
+ 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
]]
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
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
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 \
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
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)
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\" && " ..
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\" " ..
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)
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)
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
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,
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