From 7b5d5ba2a7f62d840e68aa9bdb048a0b2943ff3d Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Thu, 23 Aug 2012 12:57:43 +0200 Subject: [PATCH] Fix indentation Signed-off-by: Tobias Ulmer --- local/cvs.lua | 676 +++++++++++++++++----------------- local/files.lua | 730 ++++++++++++++++++------------------- local/git.lua | 948 ++++++++++++++++++++++++------------------------ local/svn.lua | 584 ++++++++++++++--------------- 4 files changed, 1473 insertions(+), 1465 deletions(-) diff --git a/local/cvs.lua b/local/cvs.lua index 6dd6eae..005c7c6 100644 --- a/local/cvs.lua +++ b/local/cvs.lua @@ -34,9 +34,9 @@ local err = require("err") local e2lib = require("e2lib") plugin_descriptor = { - description = "CVS SCM Plugin", - init = function (ctx) scm.register("cvs", cvs) return true end, - exit = function (ctx) return true end, + description = "CVS SCM Plugin", + init = function (ctx) scm.register("cvs", cvs) return true end, + exit = function (ctx) return true end, } --- validate source configuration, log errors to the debug log @@ -44,60 +44,60 @@ plugin_descriptor = { -- @param sourcename the source name -- @return bool function cvs.validate_source(info, sourcename) - local rc, re = scm.generic_source_validate(info, sourcename) - if not rc then - -- error in generic configuration. Don't try to go on. - return false, re - end - local src = info.sources[ sourcename ] - if not src.sourceid then - src.sourceid = {} - end - local e = err.new("in source %s:", sourcename) - rc, re = scm.generic_source_default_working(info, sourcename) - if not rc then - return false, e:cat(re) - end - e:setcount(0) - -- XXX should move the default value out of the validate function - if not src.server then - e:append("source has no `server' attribute") - end - if not src.licences then - e:append("source has no `licences' attribute") - end - if not src.cvsroot then - e2lib.warnf("WDEFAULT", "in source %s:", sourcename) - e2lib.warnf("WDEFAULT", - " source has no `cvsroot' attribute, defaulting to the server path") - src.cvsroot = "." - end - if not src.cvsroot then - e:append("source has no `cvsroot' attribute") - end - if src.remote then - e:append("source has `remote' attribute, not allowed for cvs sources") - end - if not src.branch then - e:append("source has no `branch' attribute") - end - if not type(src.tag) == "string" then - e:append("source has no `tag' attribute or tag attribute has wrong type") - end - if not src.module then - e:append("source has no `module' attribute") - end - if not src.working then - e:append("source has no `working' attribute") - end - local rc, re = tools.check_tool("cvs") - if not rc then - e:cat(re) - end - if e:getcount() > 0 then - return false, e - end - return true, nil + local rc, re = scm.generic_source_validate(info, sourcename) + if not rc then + -- error in generic configuration. Don't try to go on. + return false, re + end + local src = info.sources[ sourcename ] + if not src.sourceid then + src.sourceid = {} + end + local e = err.new("in source %s:", sourcename) + rc, re = scm.generic_source_default_working(info, sourcename) + if not rc then + return false, e:cat(re) + end + e:setcount(0) + -- XXX should move the default value out of the validate function + if not src.server then + e:append("source has no `server' attribute") + end + if not src.licences then + e:append("source has no `licences' attribute") + end + if not src.cvsroot then + e2lib.warnf("WDEFAULT", "in source %s:", sourcename) + e2lib.warnf("WDEFAULT", + " source has no `cvsroot' attribute, defaulting to the server path") + src.cvsroot = "." + end + if not src.cvsroot then + e:append("source has no `cvsroot' attribute") + end + if src.remote then + e:append("source has `remote' attribute, not allowed for cvs sources") + end + if not src.branch then + e:append("source has no `branch' attribute") + end + if not type(src.tag) == "string" then + e:append("source has no `tag' attribute or tag attribute has wrong type") + end + if not src.module then + e:append("source has no `module' attribute") + end + if not src.working then + e:append("source has no `working' attribute") + end + local rc, re = tools.check_tool("cvs") + if not rc then + e:cat(re) + end + if e:getcount() > 0 then + return false, e + end + return true, nil end --- build the cvsroot string @@ -105,18 +105,18 @@ end -- @return string: cvsroot, nil on error -- @return an error object on failure local function mkcvsroot(u) - local cvsroot = nil - if u.transport == "file" then - cvsroot = string.format("/%s", u.path) - elseif (u.transport == "ssh") or - (u.transport == "rsync+ssh") then - cvsroot = string.format("%s:/%s", u.server, u.path) - elseif u.transport == "cvspserver" then - cvsroot = string.format(":pserver:%s:/%s", u.server, u.path) - else - return nil, err.new("cvs: transport not supported") - end - return cvsroot, nil + local cvsroot = nil + if u.transport == "file" then + cvsroot = string.format("/%s", u.path) + elseif (u.transport == "ssh") or + (u.transport == "rsync+ssh") then + cvsroot = string.format("%s:/%s", u.server, u.path) + elseif u.transport == "cvspserver" then + cvsroot = string.format(":pserver:%s:/%s", u.server, u.path) + else + return nil, err.new("cvs: transport not supported") + end + return cvsroot, nil end --- build the revision string containing branch or tag name @@ -125,153 +125,153 @@ end -- @return string: cvsroot, nil on error -- @return an error object on failure local function mkrev(src, source_set) - local rev = nil - if source_set == "branch" or - (source_set == "lazytag" and src.tag == "^") then - rev = src.branch - elseif (source_set == "tag" or source_set == "lazytag") and - src.tag ~= "^" then - rev = src.tag - end - if not rev then - return nil, err.new("source set not allowed") - end - return rev, nil + local rev = nil + if source_set == "branch" or + (source_set == "lazytag" and src.tag == "^") then + rev = src.branch + elseif (source_set == "tag" or source_set == "lazytag") and + src.tag ~= "^" then + rev = src.tag + end + if not rev then + return nil, err.new("source set not allowed") + end + return rev, nil end function cvs.fetch_source(info, sourcename) - local rc, re = cvs.validate_source(info, sourcename) - if not rc then - return false, re - end - local e = err.new("fetching source failed: %s", sourcename) - local src = info.sources[ sourcename ] - local location = src.cvsroot - local server = src.server - local surl, re = info.cache:remote_url(server, location) - if not surl then - return false, e:cat(re) - end - local u, re = url.parse(surl) - if not u then - return false, e:cat(re) - end - local cmd = nil - local cvsroot, re = mkcvsroot(u) - if not cvsroot then - return false, e:cat(re) - end - -- always fetch the configured branch, as we don't know the build mode here. - local rev = src.branch - 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 argument - local dir = e2lib.dirname(src.working) - local base = e2lib.basename(src.working) - -- cd info.root && cvs -d cvsroot checkout -R [-r rev] -d working module - if rev == "HEAD" then - -- HEAD is a special case in cvs: do not pass -r 'HEAD' to cvs checkout - rev = "" - else - rev = string.format("-r '%s'", rev) - end - cmd = string.format("cd %s/%s && CVS_RSH=%s " .. + local rc, re = cvs.validate_source(info, sourcename) + if not rc then + return false, re + end + local e = err.new("fetching source failed: %s", sourcename) + local src = info.sources[ sourcename ] + local location = src.cvsroot + local server = src.server + local surl, re = info.cache:remote_url(server, location) + if not surl then + return false, e:cat(re) + end + local u, re = url.parse(surl) + if not u then + return false, e:cat(re) + end + local cmd = nil + local cvsroot, re = mkcvsroot(u) + if not cvsroot then + return false, e:cat(re) + end + -- always fetch the configured branch, as we don't know the build mode here. + local rev = src.branch + 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 argument + local dir = e2lib.dirname(src.working) + local base = e2lib.basename(src.working) + -- cd info.root && cvs -d cvsroot checkout -R [-r rev] -d working module + if rev == "HEAD" then + -- HEAD is a special case in cvs: do not pass -r 'HEAD' to cvs checkout + rev = "" + else + rev = string.format("-r '%s'", rev) + end + cmd = string.format("cd %s/%s && CVS_RSH=%s " .. "%s %s -d %s checkout -R %s -d %s %s", e2lib.shquote(info.root), e2lib.shquote(dir), e2lib.shquote(rsh), e2lib.shquote(cvstool), cvsflags, e2lib.shquote(cvsroot), e2lib.shquote(rev), e2lib.shquote(base), e2lib.shquote(src.module)) - local rc, re = e2lib.callcmd_log(cmd) - if rc ~= 0 then - return false, e:cat(re) - end - return true, nil + local rc, re = e2lib.callcmd_log(cmd) + if rc ~= 0 then + return false, e:cat(re) + end + return true, nil end function cvs.prepare_source(info, sourcename, source_set, buildpath) - local rc, re = cvs.validate_source(info, sourcename) - if not rc then - return false, re - end - local e = err.new("cvs.prepare_source failed") - local src = info.sources[ sourcename ] - local location = src.cvsroot - local server = src.server - local surl, re = info.cache:remote_url(server, location) - if not surl then - return false, e:cat(re) - end - local u, re = url.parse(surl) - if not u then - return false, e:cat(re) - end - local cvsroot, re = mkcvsroot(u) -- XXX error checking - if not cvsroot then - return false, re - end - local cmd = nil - if source_set == "tag" or source_set == "branch" then - local rev = mkrev(src, source_set) - 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 && CVS_RSH=%s " .. - "%s %s -d %s export -R -r %s -d %s %s", - e2lib.shquote(buildpath), e2lib.shquote(rsh), e2lib.shquote(cvstool), - cvsflags, e2lib.shquote(cvsroot), e2lib.shquote(rev), - e2lib.shquote(src.name), e2lib.shquote(src.module)) - elseif source_set == "working-copy" then - -- cp -R info.root/src.working buildpath - cmd = string.format("cp -R %s/%s %s/%s", - e2lib.shquote(info.root), e2lib.shquote(src.working), - e2lib.shquote(buildpath), e2lib.shquote(src.name)) - else - e2lib.abort("invalid build mode") - end - local rc, re = e2lib.callcmd_log(cmd) - if rc ~= 0 then - return false, e:cat(re) - end - return true, nil + local rc, re = cvs.validate_source(info, sourcename) + if not rc then + return false, re + end + local e = err.new("cvs.prepare_source failed") + local src = info.sources[ sourcename ] + local location = src.cvsroot + local server = src.server + local surl, re = info.cache:remote_url(server, location) + if not surl then + return false, e:cat(re) + end + local u, re = url.parse(surl) + if not u then + return false, e:cat(re) + end + local cvsroot, re = mkcvsroot(u) -- XXX error checking + if not cvsroot then + return false, re + end + local cmd = nil + if source_set == "tag" or source_set == "branch" then + local rev = mkrev(src, source_set) + 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 && CVS_RSH=%s " .. + "%s %s -d %s export -R -r %s -d %s %s", + e2lib.shquote(buildpath), e2lib.shquote(rsh), e2lib.shquote(cvstool), + cvsflags, e2lib.shquote(cvsroot), e2lib.shquote(rev), + e2lib.shquote(src.name), e2lib.shquote(src.module)) + elseif source_set == "working-copy" then + -- cp -R info.root/src.working buildpath + cmd = string.format("cp -R %s/%s %s/%s", + e2lib.shquote(info.root), e2lib.shquote(src.working), + e2lib.shquote(buildpath), e2lib.shquote(src.name)) + else + e2lib.abort("invalid build mode") + end + local rc, re = e2lib.callcmd_log(cmd) + if rc ~= 0 then + return false, e:cat(re) + end + return true, nil end function cvs.update(info, sourcename) - local rc, re = cvs.validate_source(info, sourcename) - if not rc then - e2lib.abort(re) - end - local e = err.new("updating cvs source failed") - local src = info.sources[ sourcename ] - local working = string.format("%s/%s", info.root, src.working) - 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 %s %s update -R", + local rc, re = cvs.validate_source(info, sourcename) + if not rc then + e2lib.abort(re) + end + local e = err.new("updating cvs source failed") + local src = info.sources[ sourcename ] + local working = string.format("%s/%s", info.root, src.working) + 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 %s %s update -R", e2lib.shquote(working), e2lib.shquote(rsh), e2lib.shquote(cvstool), cvsflags) - local rc, re = e2lib.callcmd_log(cmd) - if rc ~= 0 then - e:cat(re) - return false, e - end - return true, nil + local rc, re = e2lib.callcmd_log(cmd) + if rc ~= 0 then + e:cat(re) + return false, e + end + return true, nil end function cvs.working_copy_available(info, sourcename) - local rc, e - rc, e = cvs.validate_source(info, sourcename) - if not rc then - return false, e - end - local src = info.sources[sourcename] - local dir = string.format("%s/%s", info.root, src.working) - return e2lib.isdir(dir) + local rc, e + rc, e = cvs.validate_source(info, sourcename) + if not rc then + return false, e + end + local src = info.sources[sourcename] + local dir = string.format("%s/%s", info.root, src.working) + return e2lib.isdir(dir) end function cvs.has_working_copy(info, sourcename) - return true + return true end --- create a table of lines for display @@ -280,155 +280,157 @@ end -- @return a table, nil on error -- @return an error object on failure function cvs.display(info, sourcename) - local src = info.sources[sourcename] - local rc, re - rc, re = cvs.validate_source(info, sourcename) - if not rc then - return false, re - end - local display = {} - display[1] = string.format("type = %s", src.type) - display[2] = string.format("branch = %s", src.branch) - display[3] = string.format("tag = %s", src.tag) - display[4] = string.format("server = %s", src.server) - display[5] = string.format("cvsroot = %s", src.cvsroot) - display[6] = string.format("module = %s", src.module) - display[7] = string.format("working = %s", src.working) - local i = 8 - for _,l in ipairs(src.licences) do - display[i] = string.format("licence = %s", l) - i = i + 1 - end - for k,v in pairs(src.sourceid) do - if v then - display[i] = string.format("sourceid [%s] = %s", k, v) - i = i + 1 - end - end - return display, nil + local src = info.sources[sourcename] + local rc, re + rc, re = cvs.validate_source(info, sourcename) + if not rc then + return false, re + end + local display = {} + display[1] = string.format("type = %s", src.type) + display[2] = string.format("branch = %s", src.branch) + display[3] = string.format("tag = %s", src.tag) + display[4] = string.format("server = %s", src.server) + display[5] = string.format("cvsroot = %s", src.cvsroot) + display[6] = string.format("module = %s", src.module) + display[7] = string.format("working = %s", src.working) + local i = 8 + for _,l in ipairs(src.licences) do + display[i] = string.format("licence = %s", l) + i = i + 1 + end + for k,v in pairs(src.sourceid) do + if v then + display[i] = string.format("sourceid [%s] = %s", k, v) + i = i + 1 + end + end + return display, nil end function cvs.sourceid(info, sourcename, source_set) - local src = info.sources[sourcename] - local rc, re - rc, re = cvs.validate_source(info, sourcename) - if not rc then - return false, re - end - if source_set == "working-copy" then - src.sourceid[source_set] = "working-copy" - end - if src.sourceid[source_set] then - return true, nil, src.sourceid[source_set] - end - local e = err.new("calculating sourceid failed for source %s", - sourcename) - local hc = hash.hash_start() - hash.hash_line(hc, src.name) - hash.hash_line(hc, src.type) - hash.hash_line(hc, src._env:id()) - for _,l in ipairs(src.licences) do - hash.hash_line(hc, l) - local licenceid, re = e2tool.licenceid(info, l) - if not licenceid then - return false, re - end - hash.hash_line(hc, licenceid) - end - -- cvs specific - if source_set == "tag" and src.tag ~= "^" then - -- we rely on tags being unique with cvs - hc:hash_line(src.tag) - else - -- the old function took a hash of the CVS/Entries file, but - -- forgot the subdirecties' CVS/Entries files. We might - -- reimplement that once... - e:append("cannot calculate sourceid for source set %s", - source_set) - return false, e - end - hash.hash_line(hc, src.server) - hash.hash_line(hc, src.cvsroot) - hash.hash_line(hc, src.module) - -- skip src.working - e2lib.logf(4, "hash data for source %s\n%s", src.name, hc.data) - src.sourceid[source_set] = hash.hash_finish(hc) - return true, nil, src.sourceid[source_set] + local src = info.sources[sourcename] + local rc, re + rc, re = cvs.validate_source(info, sourcename) + if not rc then + return false, re + end + if source_set == "working-copy" then + src.sourceid[source_set] = "working-copy" + end + if src.sourceid[source_set] then + return true, nil, src.sourceid[source_set] + end + local e = err.new("calculating sourceid failed for source %s", + sourcename) + local hc = hash.hash_start() + hash.hash_line(hc, src.name) + hash.hash_line(hc, src.type) + hash.hash_line(hc, src._env:id()) + for _,l in ipairs(src.licences) do + hash.hash_line(hc, l) + local licenceid, re = e2tool.licenceid(info, l) + if not licenceid then + return false, re + end + hash.hash_line(hc, licenceid) + end + -- cvs specific + if source_set == "tag" and src.tag ~= "^" then + -- we rely on tags being unique with cvs + hc:hash_line(src.tag) + else + -- the old function took a hash of the CVS/Entries file, but + -- forgot the subdirecties' CVS/Entries files. We might + -- reimplement that once... + e:append("cannot calculate sourceid for source set %s", + source_set) + return false, e + end + hash.hash_line(hc, src.server) + hash.hash_line(hc, src.cvsroot) + hash.hash_line(hc, src.module) + -- skip src.working + e2lib.logf(4, "hash data for source %s\n%s", src.name, hc.data) + src.sourceid[source_set] = hash.hash_finish(hc) + return true, nil, src.sourceid[source_set] end function cvs.toresult(info, sourcename, sourceset, directory) - -- /source/.tar.gz - -- /makefile - -- /licences - local rc, re - local e = err.new("converting result") - rc, re = scm.generic_source_check(info, sourcename, true) - if not rc then - return false, e:cat(re) - end - local src = info.sources[sourcename] - -- write makefile - local makefile = "makefile" - local source = "source" - local sourcedir = string.format("%s/%s", directory, source) - local archive = string.format("%s.tar.gz", sourcename) - local fname = string.format("%s/%s", directory, makefile) - rc, re = e2lib.mkdir(sourcedir, "-p") - if not rc then - return false, e:cat(re) - end - local f, msg = io.open(fname, "w") - if not f then - return false, e:cat(msg) - end - f:write(string.format( - ".PHONY:\tplace\n\n".. - "place:\n".. - "\ttar xzf \"%s/%s\" -C \"$(BUILD)\"\n", - source, archive)) - f:close() - -- export the source tree to a temporary directory - local tmpdir = e2lib.mktempdir() - rc, re = cvs.prepare_source(info, sourcename, sourceset, tmpdir) - if not rc then - return false, e:cat(re) - end - -- create a tarball in the final location - local archive = string.format("%s.tar.gz", src.name) - local tar_args = string.format("-C '%s' -czf '%s/%s' '%s'", - tmpdir, sourcedir, archive, sourcename) - rc, re = e2lib.tar(tar_args) - if not rc then - return false, e:cat(re) - end - -- write licences - local destdir = string.format("%s/licences", directory) - local fname = string.format("%s/%s.licences", destdir, archive) - local licence_list = table.concat(src.licences, "\n") .. "\n" - rc, re = e2lib.mkdir(destdir, "-p") - if not rc then - return false, e:cat(re) - end - rc, re = e2lib.write_file(fname, licence_list) - if not rc then - return false, e:cat(re) - end - e2lib.rmtempdir(tmpdir) - return true, nil + -- /source/.tar.gz + -- /makefile + -- /licences + local rc, re + local e = err.new("converting result") + rc, re = scm.generic_source_check(info, sourcename, true) + if not rc then + return false, e:cat(re) + end + local src = info.sources[sourcename] + -- write makefile + local makefile = "makefile" + local source = "source" + local sourcedir = string.format("%s/%s", directory, source) + local archive = string.format("%s.tar.gz", sourcename) + local fname = string.format("%s/%s", directory, makefile) + rc, re = e2lib.mkdir(sourcedir, "-p") + if not rc then + return false, e:cat(re) + end + local f, msg = io.open(fname, "w") + if not f then + return false, e:cat(msg) + end + f:write(string.format( + ".PHONY:\tplace\n\n".. + "place:\n".. + "\ttar xzf \"%s/%s\" -C \"$(BUILD)\"\n", + source, archive)) + f:close() + -- export the source tree to a temporary directory + local tmpdir = e2lib.mktempdir() + rc, re = cvs.prepare_source(info, sourcename, sourceset, tmpdir) + if not rc then + return false, e:cat(re) + end + -- create a tarball in the final location + local archive = string.format("%s.tar.gz", src.name) + local tar_args = string.format("-C '%s' -czf '%s/%s' '%s'", + tmpdir, sourcedir, archive, sourcename) + rc, re = e2lib.tar(tar_args) + if not rc then + return false, e:cat(re) + end + -- write licences + local destdir = string.format("%s/licences", directory) + local fname = string.format("%s/%s.licences", destdir, archive) + local licence_list = table.concat(src.licences, "\n") .. "\n" + rc, re = e2lib.mkdir(destdir, "-p") + if not rc then + return false, e:cat(re) + end + rc, re = e2lib.write_file(fname, licence_list) + if not rc then + return false, e:cat(re) + end + e2lib.rmtempdir(tmpdir) + return true, nil end function cvs.check_workingcopy(info, sourcename) - local rc, re - local e = err.new("checking working copy failed") - e:append("in source %s (cvs configuration):", sourcename) - e:setcount(0) - rc, re = cvs.validate_source(info, sourcename) - if not rc then - return false, re - end - local src = info.sources[sourcename] - if e:getcount() > 0 then - return false, e - end - return true, nil + local rc, re + local e = err.new("checking working copy failed") + e:append("in source %s (cvs configuration):", sourcename) + e:setcount(0) + rc, re = cvs.validate_source(info, sourcename) + if not rc then + return false, re + end + local src = info.sources[sourcename] + if e:getcount() > 0 then + return false, e + end + return true, nil end + +-- vim:sw=4:sts=4:et: diff --git a/local/files.lua b/local/files.lua index cb2f02a..ee07a78 100644 --- a/local/files.lua +++ b/local/files.lua @@ -32,9 +32,9 @@ local err = require("err") local e2lib = require("e2lib") plugin_descriptor = { - description = "Files SCM Plugin", - init = function (ctx) scm.register("files", files) return true end, - exit = function (ctx) return true end, + description = "Files SCM Plugin", + init = function (ctx) scm.register("files", files) return true end, + exit = function (ctx) return true end, } --- validate source configuration, log errors to the debug log @@ -42,71 +42,71 @@ plugin_descriptor = { -- @param sourcename the source name -- @return bool function files.validate_source(info, sourcename) - local rc1 = true -- the return value - local rc, e = scm.generic_source_validate(info, sourcename) - if not rc then - return false, e - end - e = err.new("in source %s:", sourcename) - e:setcount(0) - local src = info.sources[ sourcename ] - if not src.file then - e:append("%s: source has no `file' attribute", sourcename) - end - if src.file then - for _,f in pairs(src.file) do - if type(f) ~= "table" then - e:append("%s: source has invalid file entry in `file' attribute", - sourcename) - break - end - -- catch deprecated configuration - if f.name then - e:append("source has file entry with `name' attribute") - end - if (not f.licences) and src.licences then - f.licences = src.licences - end - if (not f.server) and src.server then - f.server = src.server - end - if not f.licences then - e:append("source has file entry without `licences' attribute") - end - for _,l in ipairs(f.licences) do - if not info.licences[l] then - e:append("invalid licence assigned to file: %s", l) - end - end - if not f.server then - e:append("source has file entry without `server' attribute") - end - if f.server and (not info.cache:valid_server(f.server)) then - e:append("invalid server: %s", f.server) - end - if not f.location then - e:append("source has file entry without `location' attribute") - end - if f.server ~= info.root_server_name and not f.sha1 then - e:append("source has file entry for remote file without `sha1` ".. - "attribute") - end - if not (f.unpack or f.copy or f.patch) then - e:append("source has file entry without `unpack, copy or patch' " .. - "attribute") - end - if f.checksum_file then - e2lib.warnf("WDEPRECATED", "in source %s:", sourcename) - e2lib.warnf("WDEPRECATED", - " checksum_file attribute is deprecated and no longer used") - f.checksum_file = nil - end + local rc1 = true -- the return value + local rc, e = scm.generic_source_validate(info, sourcename) + if not rc then + return false, e + end + e = err.new("in source %s:", sourcename) + e:setcount(0) + local src = info.sources[ sourcename ] + if not src.file then + e:append("%s: source has no `file' attribute", sourcename) + end + if src.file then + for _,f in pairs(src.file) do + if type(f) ~= "table" then + e:append("%s: source has invalid file entry in `file' attribute", + sourcename) + break + end + -- catch deprecated configuration + if f.name then + e:append("source has file entry with `name' attribute") + end + if (not f.licences) and src.licences then + f.licences = src.licences + end + if (not f.server) and src.server then + f.server = src.server + end + if not f.licences then + e:append("source has file entry without `licences' attribute") + end + for _,l in ipairs(f.licences) do + if not info.licences[l] then + e:append("invalid licence assigned to file: %s", l) + end + end + if not f.server then + e:append("source has file entry without `server' attribute") + end + if f.server and (not info.cache:valid_server(f.server)) then + e:append("invalid server: %s", f.server) + end + if not f.location then + e:append("source has file entry without `location' attribute") + end + if f.server ~= info.root_server_name and not f.sha1 then + e:append("source has file entry for remote file without `sha1` ".. + "attribute") + end + if not (f.unpack or f.copy or f.patch) then + e:append("source has file entry without `unpack, copy or patch' " .. + "attribute") + end + if f.checksum_file then + e2lib.warnf("WDEPRECATED", "in source %s:", sourcename) + e2lib.warnf("WDEPRECATED", + " checksum_file attribute is deprecated and no longer used") + f.checksum_file = nil + end + end end - end - if e:getcount() > 0 then - return false, e - end - return true, nil + if e:getcount() > 0 then + return false, e + end + return true, nil end --- cache files for a source @@ -115,166 +115,166 @@ end -- @return bool -- @return nil, an error string on error function files.cache_source(info, sourcename) - local rc, e - rc, e = files.validate_source(info, sourcename) - if not rc then - return false, e - end - local s = info.sources[sourcename] - -- cache all files for this source - for i,f in pairs(s.file) do - e2lib.log(4, string.format("files.cache_source: caching file %s:%s", - f.server, f.location)) - local flags = { cache = true } - if f.server ~= info.root_server_name then - local rc, e = info.cache:cache_file(f.server, f.location, flags) - if not rc then + local rc, e + rc, e = files.validate_source(info, sourcename) + if not rc then return false, e - end - else - e2lib.log(4, string.format("not caching %s:%s (stored locally)", - f.server, f.location)) end - end - return true, nil + local s = info.sources[sourcename] + -- cache all files for this source + for i,f in pairs(s.file) do + e2lib.log(4, string.format("files.cache_source: caching file %s:%s", + f.server, f.location)) + local flags = { cache = true } + if f.server ~= info.root_server_name then + local rc, e = info.cache:cache_file(f.server, f.location, flags) + if not rc then + return false, e + end + else + e2lib.log(4, string.format("not caching %s:%s (stored locally)", + f.server, f.location)) + end + end + return true, nil end function files.fetch_source(info, sourcename) - local rc, re - local e = err.new("fetching source failed: %s", sourcename) - rc, re = files.validate_source(info, sourcename) - if not rc then - return false, e:cat(re) - end - local rc, re = files.cache_source(info, sourcename) - if not rc then - return false, e:cat(re) - end - return true, nil + local rc, re + local e = err.new("fetching source failed: %s", sourcename) + rc, re = files.validate_source(info, sourcename) + if not rc then + return false, e:cat(re) + end + local rc, re = files.cache_source(info, sourcename) + if not rc then + return false, e:cat(re) + end + return true, nil end function files.working_copy_available(info, sourcename) - local rc, e - rc, e = files.validate_source(info, sourcename) - if not rc then - return false, e - end - return false + local rc, e + rc, e = files.validate_source(info, sourcename) + if not rc then + return false, e + end + return false end function files.has_working_copy(info, sourcename) - local rc, e - rc, e = files.validate_source(info, sourcename) - if not rc then - return false, e - end - return false + local rc, e + rc, e = files.validate_source(info, sourcename) + if not rc then + return false, e + end + return false end --- prepare a files source -- @return bool -- @return nil, maybe an error string on error function files.prepare_source(info, sourcename, sourceset, buildpath) - local rc, re - local e = err.new("error preparing source: %s", sourcename) - rc, re = files.validate_source(info, sourcename) - if not rc then - return false, e:cat(re) - end - local symlink = nil - e2lib.log(4, string.format("prepare source: %s", sourcename)) - local s = info.sources[sourcename] - for _,file in ipairs(info.sources[sourcename].file) do - if file.sha1 then - rc, re = e2tool.verify_hash(info, file.server, file.location, file.sha1) - if not rc then - return false, e:cat(re) - end + local rc, re + local e = err.new("error preparing source: %s", sourcename) + rc, re = files.validate_source(info, sourcename) + if not rc then + return false, e:cat(re) end - if file.unpack then - local cache_flags = { cache = true } - local rc, re = info.cache:cache_file(file.server, file.location, - cache_flags) - if not rc then - return false, e:cat(re) - end - local path, re = info.cache:file_path(file.server, file.location, - cache_flags) - if not path then - return false, e:cat(re) - end - local y = e2lib.howtounpack(path, path, buildpath) - if not y or e2lib.callcmd_capture(y) ~= 0 then - return false, e:append("failed to unpack: %s", path) - end - if not symlink then - symlink = buildpath .. "/" .. sourcename - if file.unpack ~= sourcename then - if not e2util.symlink(file.unpack, symlink) then - return false, e:append("cannot create symlink: %s -> %s", symlink, - file.unpack) - end - end - end - else - if not symlink then - symlink = buildpath .. "/" .. sourcename - local rc, re = e2lib.mkdir(symlink, "-p") - if not rc then - return false, e:cat(re) - end - end - if file.patch then - local cache_flags = { cache = true } - local rc, re = info.cache:cache_file(file.server, file.location, - cache_flags) - if not rc then - return false, e:cat(re) - end - local path, re = info.cache:file_path(file.server, - file.location, cache_flags) - if not path then - return false, e:append(re) - end - local args = string.format("-p '%s' -d '%s' -i '%s'", file.patch, - symlink, path) - rc, re = e2lib.patch(args) - if not rc then - e:append("applying patch: \"%s:%s\"", file.server, file.location) - return false, e:cat(re) - end - elseif file.copy then - local fcdirname = e2lib.dirname(file.copy) - local fcbasename = e2lib.basename(file.copy) - local destination = string.format("%s/%s/%s", buildpath, sourcename, - file.copy) - local destdir, destname - -- emulate the cp behaviour to feed the cache.fetch_file interface - -- correctly, that does not allow ambiguities - if e2lib.isdir(destination) then - destdir = destination - destname = nil - else - destdir = string.format("%s/%s/%s", buildpath, sourcename, - fcdirname) - destname = fcbasename - if not e2lib.mkdir(destdir, "-p") then - e2lib.abort(string.format( - "can't create destination directory: %s", destdir)) - end - end - local rc, re = info.cache:fetch_file(file.server, file.location, - destdir, destname, {}) - if not rc then - return false, e:cat(re) - end - else - e2lib.abort(string.format("missing destiny for file %s (%s)", - file.location, file.server)) - end + local symlink = nil + e2lib.log(4, string.format("prepare source: %s", sourcename)) + local s = info.sources[sourcename] + for _,file in ipairs(info.sources[sourcename].file) do + if file.sha1 then + rc, re = e2tool.verify_hash(info, file.server, file.location, file.sha1) + if not rc then + return false, e:cat(re) + end + end + if file.unpack then + local cache_flags = { cache = true } + local rc, re = info.cache:cache_file(file.server, file.location, + cache_flags) + if not rc then + return false, e:cat(re) + end + local path, re = info.cache:file_path(file.server, file.location, + cache_flags) + if not path then + return false, e:cat(re) + end + local y = e2lib.howtounpack(path, path, buildpath) + if not y or e2lib.callcmd_capture(y) ~= 0 then + return false, e:append("failed to unpack: %s", path) + end + if not symlink then + symlink = buildpath .. "/" .. sourcename + if file.unpack ~= sourcename then + if not e2util.symlink(file.unpack, symlink) then + return false, e:append("cannot create symlink: %s -> %s", symlink, + file.unpack) + end + end + end + else + if not symlink then + symlink = buildpath .. "/" .. sourcename + local rc, re = e2lib.mkdir(symlink, "-p") + if not rc then + return false, e:cat(re) + end + end + if file.patch then + local cache_flags = { cache = true } + local rc, re = info.cache:cache_file(file.server, file.location, + cache_flags) + if not rc then + return false, e:cat(re) + end + local path, re = info.cache:file_path(file.server, + file.location, cache_flags) + if not path then + return false, e:append(re) + end + local args = string.format("-p '%s' -d '%s' -i '%s'", file.patch, + symlink, path) + rc, re = e2lib.patch(args) + if not rc then + e:append("applying patch: \"%s:%s\"", file.server, file.location) + return false, e:cat(re) + end + elseif file.copy then + local fcdirname = e2lib.dirname(file.copy) + local fcbasename = e2lib.basename(file.copy) + local destination = string.format("%s/%s/%s", buildpath, sourcename, + file.copy) + local destdir, destname + -- emulate the cp behaviour to feed the cache.fetch_file interface + -- correctly, that does not allow ambiguities + if e2lib.isdir(destination) then + destdir = destination + destname = nil + else + destdir = string.format("%s/%s/%s", buildpath, sourcename, + fcdirname) + destname = fcbasename + if not e2lib.mkdir(destdir, "-p") then + e2lib.abort(string.format( + "can't create destination directory: %s", destdir)) + end + end + local rc, re = info.cache:fetch_file(file.server, file.location, + destdir, destname, {}) + if not rc then + return false, e:cat(re) + end + else + e2lib.abort(string.format("missing destiny for file %s (%s)", + file.location, file.server)) + end + end end - end - return true, nil + return true, nil end --- create a table of lines for display @@ -283,28 +283,28 @@ end -- @return a table, nil on error -- @return an error string on failure function files.display(info, sourcename) - local rc, e - rc, e = files.validate_source(info, sourcename) - if not rc then - return false, e - end - local src = info.sources[sourcename] - local display = {} - display[1] = string.format("type = %s", src.type) - local i = 2 - for _,f in pairs(src.file) do - display[i] = string.format("file = %s:%s", f.server, f.location) - i = i + 1 - end - for _,l in ipairs(src.licences) do - display[i] = string.format("licence = %s", l) - i = i + 1 - end - if src.sourceid then - display[i] = string.format("sourceid = %s", src.sourceid) - i = i + 1 - end - return display + local rc, e + rc, e = files.validate_source(info, sourcename) + if not rc then + return false, e + end + local src = info.sources[sourcename] + local display = {} + display[1] = string.format("type = %s", src.type) + local i = 2 + for _,f in pairs(src.file) do + display[i] = string.format("file = %s:%s", f.server, f.location) + i = i + 1 + end + for _,l in ipairs(src.licences) do + display[i] = string.format("licence = %s", l) + i = i + 1 + end + if src.sourceid then + display[i] = string.format("sourceid = %s", src.sourceid) + i = i + 1 + end + return display end --- calculate an id for a source @@ -314,148 +314,150 @@ end -- @return string: the source id, nil on error -- @return an error string on error function files.sourceid(info, sourcename, sourceset) - local rc, re - local e = err.new("error calculating sourceid for source: %s", - sourcename) - rc, re = files.validate_source(info, sourcename) - if not rc then - return false, re - end - local src = info.sources[sourcename] - if src.sourceid then - return true, nil, src.sourceid - end - -- sourceset is ignored for files sources - local hc = hash.hash_start() - hash.hash_line(hc, src.name) - hash.hash_line(hc, src.type) - hash.hash_line(hc, src._env:id()) - for _,l in ipairs(src.licences) do - hash.hash_line(hc, l) - local licenceid, re = e2tool.licenceid(info, l) - if not licenceid then - return false, re - end - hash.hash_line(hc, licenceid) - end - for _,f in ipairs(src.file) do - local fileid, re = e2tool.fileid(info, f) - if not fileid then - return false, e:cat(re) - end - hash.hash_line(hc, fileid) - hash.hash_line(hc, f.location) - hash.hash_line(hc, f.server) - hash.hash_line(hc, tostring(f.unpack)) - hash.hash_line(hc, tostring(f.patch)) - hash.hash_line(hc, tostring(f.copy)) - end - e2lib.log(4, string.format("hash data for source %s\n%s", src.name, - hc.data)) - src.sourceid = hash.hash_finish(hc) - return true, nil, src.sourceid + local rc, re + local e = err.new("error calculating sourceid for source: %s", + sourcename) + rc, re = files.validate_source(info, sourcename) + if not rc then + return false, re + end + local src = info.sources[sourcename] + if src.sourceid then + return true, nil, src.sourceid + end + -- sourceset is ignored for files sources + local hc = hash.hash_start() + hash.hash_line(hc, src.name) + hash.hash_line(hc, src.type) + hash.hash_line(hc, src._env:id()) + for _,l in ipairs(src.licences) do + hash.hash_line(hc, l) + local licenceid, re = e2tool.licenceid(info, l) + if not licenceid then + return false, re + end + hash.hash_line(hc, licenceid) + end + for _,f in ipairs(src.file) do + local fileid, re = e2tool.fileid(info, f) + if not fileid then + return false, e:cat(re) + end + hash.hash_line(hc, fileid) + hash.hash_line(hc, f.location) + hash.hash_line(hc, f.server) + hash.hash_line(hc, tostring(f.unpack)) + hash.hash_line(hc, tostring(f.patch)) + hash.hash_line(hc, tostring(f.copy)) + end + e2lib.log(4, string.format("hash data for source %s\n%s", src.name, + hc.data)) + src.sourceid = hash.hash_finish(hc) + return true, nil, src.sourceid end -- export the source to a result structure function files.toresult(info, sourcename, sourceset, directory) - local rc, re - local e = err.new("converting result failed") - rc, re = files.validate_source(info, sourcename) - if not rc then - return false, e:cat(re) - end - local s = info.sources[sourcename] - local makefile = "makefile" -- name of the makefile - local source = "source" -- directory to store source files in - local fname = string.format("%s/%s", directory, makefile) - local f, msg = io.open(fname, "w") - if not f then - return false, e:cat(msg) - end - f:write(string.format( - ".PHONY:\tplace\n\n".. - "place:\n")) - for _,file in ipairs(s.file) do - e2lib.log(4, string.format("export file: %s", file.location)) - local destdir = string.format("%s/%s", directory, source) - local destname = nil - e2lib.mkdir(destdir, "-p") - local rc, re = info.cache:fetch_file(file.server, - file.location, destdir, destname, {}) - if not rc then - return false, e:cat(re) - end - if file.sha1 then - local filename = e2lib.basename(file.location) - local checksum_file = string.format("%s/%s.sha1", - destdir, filename) - rc, re = e2lib.write_file(checksum_file, - string.format("%s %s", file.sha1, filename)) - if not rc then - return false, e:cat(re) - end - f:write(string.format( - "\tcd source && sha1sum -c '%s'\n", - e2lib.basename(checksum_file))) - end - if file.unpack then - local c = e2lib.howtounpack( - string.format("%s/%s", destdir, - e2lib.basename(file.location)), - string.format("%s/%s", source, - e2lib.basename(file.location)), - string.format("$(BUILD)")) - if not c then - return false, e:cat("%s:%s: ".. - "can't generate command to unpack", - file.server, file.location) - end - f:write(string.format("\t%s\n", c)) - if file.unpack ~= sourcename then - f:write(string.format( - "\tln -s %s $(BUILD)/%s\n", file.unpack, - sourcename)) - end - end - if file.copy then - f:write(string.format( - "\tmkdir -p \"$(BUILD)/%s\"\n".. - "\tcp \"%s/%s\" \"$(BUILD)/%s/%s\"\n", - sourcename, - source, e2lib.basename(file.location), sourcename, - file.copy)) - end - if file.patch then - f:write(string.format( - "\tpatch -p%s -d \"$(BUILD)/%s\" ".. - "-i \"$(shell pwd)/%s/%s\"\n", - file.patch, sourcename, source, - e2lib.basename(file.location))) - end - -- write licences - local destdir = string.format("%s/licences", directory) - local fname = string.format("%s/%s.licences", destdir, - e2lib.basename(file.location)) - local licence_list = table.concat(file.licences, "\n") .. "\n" - rc, re = e2lib.mkdir(destdir, "-p") - if not rc then - return false, e:cat(re) - end - rc, re = e2lib.write_file(fname, licence_list) - if not rc then - return false, e:cat(re) - end - e2lib.log(4, string.format("export file: %s done", - file.location)) - end - f:close() - return true, nil + local rc, re + local e = err.new("converting result failed") + rc, re = files.validate_source(info, sourcename) + if not rc then + return false, e:cat(re) + end + local s = info.sources[sourcename] + local makefile = "makefile" -- name of the makefile + local source = "source" -- directory to store source files in + local fname = string.format("%s/%s", directory, makefile) + local f, msg = io.open(fname, "w") + if not f then + return false, e:cat(msg) + end + f:write(string.format( + ".PHONY:\tplace\n\n".. + "place:\n")) + for _,file in ipairs(s.file) do + e2lib.log(4, string.format("export file: %s", file.location)) + local destdir = string.format("%s/%s", directory, source) + local destname = nil + e2lib.mkdir(destdir, "-p") + local rc, re = info.cache:fetch_file(file.server, + file.location, destdir, destname, {}) + if not rc then + return false, e:cat(re) + end + if file.sha1 then + local filename = e2lib.basename(file.location) + local checksum_file = string.format("%s/%s.sha1", + destdir, filename) + rc, re = e2lib.write_file(checksum_file, + string.format("%s %s", file.sha1, filename)) + if not rc then + return false, e:cat(re) + end + f:write(string.format( + "\tcd source && sha1sum -c '%s'\n", + e2lib.basename(checksum_file))) + end + if file.unpack then + local c = e2lib.howtounpack( + string.format("%s/%s", destdir, + e2lib.basename(file.location)), + string.format("%s/%s", source, + e2lib.basename(file.location)), + string.format("$(BUILD)")) + if not c then + return false, e:cat("%s:%s: ".. + "can't generate command to unpack", + file.server, file.location) + end + f:write(string.format("\t%s\n", c)) + if file.unpack ~= sourcename then + f:write(string.format( + "\tln -s %s $(BUILD)/%s\n", file.unpack, + sourcename)) + end + end + if file.copy then + f:write(string.format( + "\tmkdir -p \"$(BUILD)/%s\"\n".. + "\tcp \"%s/%s\" \"$(BUILD)/%s/%s\"\n", + sourcename, + source, e2lib.basename(file.location), sourcename, + file.copy)) + end + if file.patch then + f:write(string.format( + "\tpatch -p%s -d \"$(BUILD)/%s\" ".. + "-i \"$(shell pwd)/%s/%s\"\n", + file.patch, sourcename, source, + e2lib.basename(file.location))) + end + -- write licences + local destdir = string.format("%s/licences", directory) + local fname = string.format("%s/%s.licences", destdir, + e2lib.basename(file.location)) + local licence_list = table.concat(file.licences, "\n") .. "\n" + rc, re = e2lib.mkdir(destdir, "-p") + if not rc then + return false, e:cat(re) + end + rc, re = e2lib.write_file(fname, licence_list) + if not rc then + return false, e:cat(re) + end + e2lib.log(4, string.format("export file: %s done", + file.location)) + end + f:close() + return true, nil end function files.check_workingcopy(info, sourcename) - return true, nil + return true, nil end function files.update(info, sourcename) - return true, nil + return true, nil end + +-- vim:sw=4:sts=4:et: diff --git a/local/git.lua b/local/git.lua index 7c9e038..dea93fe 100644 --- a/local/git.lua +++ b/local/git.lua @@ -36,9 +36,9 @@ local e2option = require("e2option") local e2lib = require("e2lib") plugin_descriptor = { - description = "Git SCM Plugin", - init = function (ctx) scm.register("git", git) return true end, - exit = function (ctx) return true end, + description = "Git SCM Plugin", + init = function (ctx) scm.register("git", git) return true end, + exit = function (ctx) return true end, } --- git branch wrapper @@ -47,27 +47,27 @@ plugin_descriptor = { -- @return string: the branch name, nil on error -- @return string: nil, or an error string on error local function git_branch_get(gitdir) - -- git branch - local cmd = string.format("GIT_DIR=\"%s\" git branch", gitdir) - local p = io.popen(cmd, "r") - local branch = nil - while true do - local line = p:read() - if not line then - break - end - local x - -- search for a line matching '* ' - x, branch = line:match("^(\* )(%S*)$") - if x and branch then - break - end - end - p:close() - if not branch then - return branch, nil, "git branch: can't get current branch" - end - return branch, nil + -- git branch + local cmd = string.format("GIT_DIR=\"%s\" git branch", gitdir) + local p = io.popen(cmd, "r") + local branch = nil + while true do + local line = p:read() + if not line then + break + end + local x + -- search for a line matching '* ' + x, branch = line:match("^(\* )(%S*)$") + if x and branch then + break + end + end + p:close() + if not branch then + return branch, nil, "git branch: can't get current branch" + end + return branch, nil end --- return a value suitable for buildid computation, i.e. the commit-id @@ -78,52 +78,52 @@ end -- @return string: the commit id, nil on error -- @return nil on success, an error string on error local function get_revision_id(info, source, sourceset, check_remote) - local sourcename = source - local rc, re - local e = err.new("getting revision id failed for source: %s", source) - local s = info.sources[source] - rc, re = git.validate_source(info, sourcename) - if not rc then - return false, e:cat(re) - end - rc, re = scm.working_copy_available(info, sourcename) - if not rc then - return false, e:append("working copy is not available") - end - rc, re = scm.check_workingcopy(info, sourcename) - if not rc then - return false, e:cat(re) - end - local p = info.root .. "/" .. s.working .. "/.git/refs/" - local id, fr, gitdir, ref - gitdir = string.format("%s/%s/.git", info.root, s.working) - if sourceset == "branch" or - (sourceset == "lazytag" and s.tag == "^") then - ref = string.format("refs/heads/%s", s.branch) - id, re = generic_git.git_rev_list1(gitdir, ref) - -- error checking delayed to end of function - elseif sourceset == "tag" or - (sourceset == "lazytag" and s.tag ~= "^") then - gitdir = string.format("%s/%s/.git", info.root, s.working) - ref = string.format("refs/tags/%s", s.tag) - id, re = generic_git.git_rev_list1(gitdir, ref) - -- error checking delayed to end of function - if id and check_remote then - e2lib.logf(4, "%s: check for remote tag", s.name) - rc, re = generic_git.verify_remote_tag(gitdir, s.tag) - if not rc then + local sourcename = source + local rc, re + local e = err.new("getting revision id failed for source: %s", source) + local s = info.sources[source] + rc, re = git.validate_source(info, sourcename) + if not rc then return false, e:cat(re) - end - e2lib.logf(4, "%s: check for remote tag: match", s.name) - end - else - e2lib.abort("not an scm sourceset: " .. sourceset) - end - if not id then - fr = string.format("can't get commit id for ref %s from repository %s", - ref, s.working) - end - return id, not id and fr + end + rc, re = scm.working_copy_available(info, sourcename) + if not rc then + return false, e:append("working copy is not available") + end + rc, re = scm.check_workingcopy(info, sourcename) + if not rc then + return false, e:cat(re) + end + local p = info.root .. "/" .. s.working .. "/.git/refs/" + local id, fr, gitdir, ref + gitdir = string.format("%s/%s/.git", info.root, s.working) + if sourceset == "branch" or + (sourceset == "lazytag" and s.tag == "^") then + ref = string.format("refs/heads/%s", s.branch) + id, re = generic_git.git_rev_list1(gitdir, ref) + -- error checking delayed to end of function + elseif sourceset == "tag" or + (sourceset == "lazytag" and s.tag ~= "^") then + gitdir = string.format("%s/%s/.git", info.root, s.working) + ref = string.format("refs/tags/%s", s.tag) + id, re = generic_git.git_rev_list1(gitdir, ref) + -- error checking delayed to end of function + if id and check_remote then + e2lib.logf(4, "%s: check for remote tag", s.name) + rc, re = generic_git.verify_remote_tag(gitdir, s.tag) + if not rc then + return false, e:cat(re) + end + e2lib.logf(4, "%s: check for remote tag: match", s.name) + end + else + e2lib.abort("not an scm sourceset: " .. sourceset) + end + if not id then + fr = string.format("can't get commit id for ref %s from repository %s", + ref, s.working) + end + return id, not id and fr end --- validate source configuration, log errors to the debug log @@ -132,47 +132,47 @@ end -- @return bool -- @return an error object on error function git.validate_source(info, sourcename) - local rc, re = scm.generic_source_validate(info, sourcename) - if not rc then - -- error in generic configuration. Don't try to go on. - return false, re - end - local src = info.sources[ sourcename ] - local e = err.new("in source %s:", sourcename) - rc, re = scm.generic_source_default_working(info, sourcename) - if not rc then - return false, e:cat(re) - end - e:setcount(0) - -- catch deprecated attributes - if src.remote then - e:append("source has deprecated `remote' attribute") - end - if not src.server then - e:append("source has no `server' attribute") - end - if src.server and (not info.cache:valid_server(src.server)) then - e:append("invalid server: %s", src.server) - end - if not src.licences then - e:append("source has no `licences' attribute") - end - if not src.branch then - e:append("source has no `branch' attribute") - end - if type(src.tag) ~= "string" then - e:append("source has no `tag' attribute or tag attribute has wrong type") - end - if not src.location then - e:append("source has no `location' attribute") - end - if not src.working then - e:append("source has no `working' attribute") - end - if e:getcount() > 0 then - return false, e - end - return true, nil + local rc, re = scm.generic_source_validate(info, sourcename) + if not rc then + -- error in generic configuration. Don't try to go on. + return false, re + end + local src = info.sources[ sourcename ] + local e = err.new("in source %s:", sourcename) + rc, re = scm.generic_source_default_working(info, sourcename) + if not rc then + return false, e:cat(re) + end + e:setcount(0) + -- catch deprecated attributes + if src.remote then + e:append("source has deprecated `remote' attribute") + end + if not src.server then + e:append("source has no `server' attribute") + end + if src.server and (not info.cache:valid_server(src.server)) then + e:append("invalid server: %s", src.server) + end + if not src.licences then + e:append("source has no `licences' attribute") + end + if not src.branch then + e:append("source has no `branch' attribute") + end + if type(src.tag) ~= "string" then + e:append("source has no `tag' attribute or tag attribute has wrong type") + end + if not src.location then + e:append("source has no `location' attribute") + end + if not src.working then + e:append("source has no `working' attribute") + end + if e:getcount() > 0 then + return false, e + end + return true, nil end --- update a working copy @@ -181,51 +181,51 @@ end -- @return bool -- @return an error object function git.update(info, sourcename) - local src = info.sources[ sourcename ] - local rc, re - local e = err.new("updating source failed") - rc, re = scm.working_copy_available(info, sourcename) - if not rc then - return false, e:cat(re) - end - local gitwc = string.format("%s/%s", info.root, src.working) - local gitdir = string.format("%s/%s/.git", info.root, src.working) - e2lib.logf(2, "updating %s [%s]", src.working, src.branch) - rc, re = e2tool.lcd(info, src.working) - if not rc then - return false, e:append("working copy not available") - end - rc, re = e2lib.git(nil, "fetch") -- git fetch is safe - if not rc then - return false, e:cat(re) - end - e:append("fetch succeeded") + local src = info.sources[ sourcename ] + local rc, re + local e = err.new("updating source failed") + rc, re = scm.working_copy_available(info, sourcename) + if not rc then + return false, e:cat(re) + end + local gitwc = string.format("%s/%s", info.root, src.working) + local gitdir = string.format("%s/%s/.git", info.root, src.working) + e2lib.logf(2, "updating %s [%s]", src.working, src.branch) + rc, re = e2tool.lcd(info, src.working) + if not rc then + return false, e:append("working copy not available") + end + rc, re = e2lib.git(nil, "fetch") -- git fetch is safe + if not rc then + return false, e:cat(re) + end + e:append("fetch succeeded") - -- setup the branch tracking its remote. This fails if the branch exists, - -- but that's fine. - local args - args = string.format("--track '%s' 'origin/%s'", src.branch, src.branch) - rc, re = e2lib.git(nil, "branch", args) + -- setup the branch tracking its remote. This fails if the branch exists, + -- but that's fine. + local args + args = string.format("--track '%s' 'origin/%s'", src.branch, src.branch) + rc, re = e2lib.git(nil, "branch", args) - -- sanity checks: - -- must be on configured branch - local branch, re = git_branch_get(gitdir) - if not branch then - return false, e:cat(re) - end - if branch ~= src.branch then - e2lib.warnf("WOTHER", "not on configured branch. Skipping 'git pull'") + -- sanity checks: + -- must be on configured branch + local branch, re = git_branch_get(gitdir) + if not branch then + return false, e:cat(re) + end + if branch ~= src.branch then + e2lib.warnf("WOTHER", "not on configured branch. Skipping 'git pull'") + return true, nil + end + rc, re = e2tool.lcd(info, src.working) + if not rc then + return false, e:append("working copy not available") + end + rc, re = e2lib.git(nil, "pull") + if not rc then + return false, e:cat(re) + end return true, nil - end - rc, re = e2tool.lcd(info, src.working) - if not rc then - return false, e:append("working copy not available") - end - rc, re = e2lib.git(nil, "pull") - if not rc then - return false, e:cat(re) - end - return true, nil end --- fetch a git source @@ -234,40 +234,40 @@ end -- @return bool -- @return nil on success, an error string on error function git.fetch_source(info, sourcename) - local src = info.sources[ sourcename ] - local rc, re - local e = err.new("fetching source failed: %s", sourcename) - rc, re = git.validate_source(info, sourcename) - if not rc then - return false, e:cat(re) - end - local wrk = info.root .. "/" .. src.working - e2lib.log(2, string.format("cloning %s:%s [%s]", - src.server, src.location, src.branch)) - local skip_checkout = e2lib.globals.git_skip_checkout - rc, re = generic_git.git_clone_from_server(info.cache, src.server, - src.location, wrk, skip_checkout) - if not rc then - return false, e:cat(re) - end - -- check for the branch, and checkout if it's not yet there after cloning. - local ref = string.format("refs/heads/%s", src.branch) - local gitdir = string.format("%s/.git", wrk) - local rc, re = generic_git.git_rev_list1(gitdir, ref) - if not rc then - local track = true - local start_point = string.format("origin/%s", src.branch) - local rc, re = generic_git.git_branch_new1(wrk, track, src.branch, - start_point) + local src = info.sources[ sourcename ] + local rc, re + local e = err.new("fetching source failed: %s", sourcename) + rc, re = git.validate_source(info, sourcename) if not rc then - return false, e:cat(re) + return false, e:cat(re) end - local rc, re = generic_git.git_checkout1(wrk, src.branch) + local wrk = info.root .. "/" .. src.working + e2lib.log(2, string.format("cloning %s:%s [%s]", + src.server, src.location, src.branch)) + local skip_checkout = e2lib.globals.git_skip_checkout + rc, re = generic_git.git_clone_from_server(info.cache, src.server, + src.location, wrk, skip_checkout) if not rc then - return false, e:cat(re) + return false, e:cat(re) end - end - return true, nil + -- check for the branch, and checkout if it's not yet there after cloning. + local ref = string.format("refs/heads/%s", src.branch) + local gitdir = string.format("%s/.git", wrk) + local rc, re = generic_git.git_rev_list1(gitdir, ref) + if not rc then + local track = true + local start_point = string.format("origin/%s", src.branch) + local rc, re = generic_git.git_branch_new1(wrk, track, src.branch, + start_point) + if not rc then + return false, e:cat(re) + end + local rc, re = generic_git.git_checkout1(wrk, src.branch) + if not rc then + return false, e:cat(re) + end + end + return true, nil end --- prepare a git source @@ -276,70 +276,70 @@ end -- @return bool -- @return nil on success, an error string on error function git.prepare_source(info, sourcename, sourceset, buildpath) - local src = info.sources[ sourcename ] - local rc, re, e - local e = err.new("preparing git sources failed") - rc, re = scm.generic_source_check(info, sourcename, true) - if not rc then - return false, e:cat(re) - end - local gitdir = info.root .. "/" .. src.working .. "/.git/" - if sourceset == "branch" or - (sourceset == "lazytag" and src.tag == "^") then - local rev, re = get_revision_id(info, sourcename, sourceset) - if not rev then - return false, e:cat(re) - end - gitdir = string.format("%s/%s/.git", info.root, src.working) - local git = string.format("GIT_DIR=%s ".. - "git archive --format=tar --prefix=%s/ refs/heads/%s", - e2lib.shquote(gitdir), e2lib.shquote(sourcename), - e2lib.shquote(src.branch)) - local tar = string.format("tar -C %s -xf -", e2lib.shquote(buildpath)) - local re = e2lib.callcmd_pipe({git, tar}) - if re then - return false, e:cat(re) - end - elseif sourceset == "tag" or - (sourceset == "lazytag" and src.tag ~= "^") then - local rev, re = get_revision_id(info, sourcename, sourceset) - if not rev then - return false, e:cat(re) - end - gitdir = string.format("%s/%s/.git", info.root, src.working) - local git = string.format("GIT_DIR=%s ".. - "git archive --format=tar --prefix=%s/ refs/tags/%s", - e2lib.shquote(gitdir), e2lib.shquote(sourcename), e2lib.shquote(src.tag)) - local tar = string.format("tar -C %s -xf -", e2lib.shquote(buildpath)) - local re = e2lib.callcmd_pipe({git, tar}) - if re then - return false, e:cat(re) - end - elseif sourceset == "working-copy" then - -- warn for empty working-copy - local working = string.format("%s/%s", info.root, src.working) - local d = e2util.directory(working, false) - if #d == 0 then - e2lib.warnf("WOTHER", "in result: %s", src.name) - e2lib.warnf("WOTHER", "working copy seems empty") - end - local dir = string.format("%s/%s", buildpath, sourcename) - local rc, re = e2lib.mkdir(dir, "-p") + local src = info.sources[ sourcename ] + local rc, re, e + local e = err.new("preparing git sources failed") + rc, re = scm.generic_source_check(info, sourcename, true) if not rc then - return false, re - end - 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' .", - e2lib.shquote(tar), tarflags, e2lib.shquote(info.root), - e2lib.shquote(src.working)) - local cmd2 = string.format("%s %s -x -C %s/%s", e2lib.shquote(tar), - tarflags, e2lib.shquote(buildpath), e2lib.shquote(sourcename)) - local r = e2lib.callcmd_pipe({ cmd1, cmd2 }) - if r then e2lib.abort(r) end - else e2lib.abort("invalid sourceset: ", sourceset) - end - return true, nil + return false, e:cat(re) + end + local gitdir = info.root .. "/" .. src.working .. "/.git/" + if sourceset == "branch" or + (sourceset == "lazytag" and src.tag == "^") then + local rev, re = get_revision_id(info, sourcename, sourceset) + if not rev then + return false, e:cat(re) + end + gitdir = string.format("%s/%s/.git", info.root, src.working) + local git = string.format("GIT_DIR=%s ".. + "git archive --format=tar --prefix=%s/ refs/heads/%s", + e2lib.shquote(gitdir), e2lib.shquote(sourcename), + e2lib.shquote(src.branch)) + local tar = string.format("tar -C %s -xf -", e2lib.shquote(buildpath)) + local re = e2lib.callcmd_pipe({git, tar}) + if re then + return false, e:cat(re) + end + elseif sourceset == "tag" or + (sourceset == "lazytag" and src.tag ~= "^") then + local rev, re = get_revision_id(info, sourcename, sourceset) + if not rev then + return false, e:cat(re) + end + gitdir = string.format("%s/%s/.git", info.root, src.working) + local git = string.format("GIT_DIR=%s ".. + "git archive --format=tar --prefix=%s/ refs/tags/%s", + e2lib.shquote(gitdir), e2lib.shquote(sourcename), e2lib.shquote(src.tag)) + local tar = string.format("tar -C %s -xf -", e2lib.shquote(buildpath)) + local re = e2lib.callcmd_pipe({git, tar}) + if re then + return false, e:cat(re) + end + elseif sourceset == "working-copy" then + -- warn for empty working-copy + local working = string.format("%s/%s", info.root, src.working) + local d = e2util.directory(working, false) + if #d == 0 then + e2lib.warnf("WOTHER", "in result: %s", src.name) + e2lib.warnf("WOTHER", "working copy seems empty") + end + local dir = string.format("%s/%s", buildpath, sourcename) + local rc, re = e2lib.mkdir(dir, "-p") + if not rc then + return false, re + end + 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' .", + e2lib.shquote(tar), tarflags, e2lib.shquote(info.root), + e2lib.shquote(src.working)) + local cmd2 = string.format("%s %s -x -C %s/%s", e2lib.shquote(tar), + tarflags, e2lib.shquote(buildpath), e2lib.shquote(sourcename)) + local r = e2lib.callcmd_pipe({ cmd1, cmd2 }) + if r then e2lib.abort(r) end + else e2lib.abort("invalid sourceset: ", sourceset) + end + return true, nil end --- check if a working copy for a git repository is available @@ -348,21 +348,21 @@ end -- @return bool -- @return sometimes an error string, when ret. false. XXX interface cleanup. function git.working_copy_available(info, sourcename) - local src = info.sources[sourcename] - local rc, re - local e = err.new("checking if working copy is available for source %s", - sourcename) - rc, re = git.validate_source(info, sourcename) - if not rc then - return false, e:cat(re) - end - local gitwc = info.root .. "/" .. src.working - local rc = e2lib.isdir(gitwc) - return rc, nil + local src = info.sources[sourcename] + local rc, re + local e = err.new("checking if working copy is available for source %s", + sourcename) + rc, re = git.validate_source(info, sourcename) + if not rc then + return false, e:cat(re) + end + local gitwc = info.root .. "/" .. src.working + local rc = e2lib.isdir(gitwc) + return rc, nil end function git.has_working_copy(info, sname) - return true + return true end --- turn server:location into a git-style url @@ -372,20 +372,20 @@ end -- @return string: the git url, or nil -- @return an error object on failure local function git_url(c, server, location) - local e = err.new("translating server:location to git url") - local rurl, re = cache.remote_url(c, server, location) - if not rurl then - return nil, e:cat(re) - end - local u, re = url.parse(rurl) - if not u then - return nil, e:cat(re) - end - local g, re = generic_git.git_url1(u) - if not g then - return nil, e:cat(re) - end - return g, nil + local e = err.new("translating server:location to git url") + local rurl, re = cache.remote_url(c, server, location) + if not rurl then + return nil, e:cat(re) + end + local u, re = url.parse(rurl) + if not u then + return nil, e:cat(re) + end + local g, re = generic_git.git_url1(u) + if not g then + return nil, e:cat(re) + end + return g, nil end --- create a table of lines for display @@ -394,47 +394,47 @@ end -- @return a table, nil on error -- @return an error string on failure function git.display(info, sourcename) - local src = info.sources[sourcename] - local rc, re - local e = err.new("display source information failed") - rc, re = git.validate_source(info, sourcename) - if not rc then - return nil, e:cat(re) - end - -- try to calculte the sourceid, but do not care if it fails. - -- working copy might be unavailable - scm.sourceid(info, sourcename, "tag") - scm.sourceid(info, sourcename, "branch") - local rev_tag = "" - local rev_branch = "" - if src.commitid["tag"] then - rev_tag = string.format("[%s...]", src.commitid["tag"]:sub(1,8)) - end - if src.commitid["branch"] then - rev_branch = string.format("[%s...]", src.commitid["branch"]:sub(1,8)) - end - local display = {} - display[1] = string.format("type = %s", src.type) - display[2] = string.format("branch = %-15s %s", src.branch, rev_branch) - display[3] = string.format("tag = %-15s %s", src.tag, rev_tag) - display[4] = string.format("server = %s", src.server) - display[5] = string.format("location = %s", src.location) - display[6] = string.format("working = %s", src.working) - local i = 8 - for _,l in ipairs(src.licences) do - display[i] = string.format("licence = %s", l) + local src = info.sources[sourcename] + local rc, re + local e = err.new("display source information failed") + rc, re = git.validate_source(info, sourcename) + if not rc then + return nil, e:cat(re) + end + -- try to calculte the sourceid, but do not care if it fails. + -- working copy might be unavailable + scm.sourceid(info, sourcename, "tag") + scm.sourceid(info, sourcename, "branch") + local rev_tag = "" + local rev_branch = "" + if src.commitid["tag"] then + rev_tag = string.format("[%s...]", src.commitid["tag"]:sub(1,8)) + end + if src.commitid["branch"] then + rev_branch = string.format("[%s...]", src.commitid["branch"]:sub(1,8)) + end + local display = {} + display[1] = string.format("type = %s", src.type) + display[2] = string.format("branch = %-15s %s", src.branch, rev_branch) + display[3] = string.format("tag = %-15s %s", src.tag, rev_tag) + display[4] = string.format("server = %s", src.server) + display[5] = string.format("location = %s", src.location) + display[6] = string.format("working = %s", src.working) + local i = 8 + for _,l in ipairs(src.licences) do + display[i] = string.format("licence = %s", l) + i = i + 1 + end + for _,sourceset in pairs({"tag", "branch"}) do + if src.sourceid and src.sourceid[sourceset] then + local id = src.sourceid[sourceset] + local s = string.format("sourceid[%s]", sourceset) + display[i] = string.format("%-11s= %s", s, id) + i = i + 1 + end + end i = i + 1 - end - for _,sourceset in pairs({"tag", "branch"}) do - if src.sourceid and src.sourceid[sourceset] then - local id = src.sourceid[sourceset] - local s = string.format("sourceid[%s]", sourceset) - display[i] = string.format("%-11s= %s", s, id) - i = i + 1 - end - end - i = i + 1 - return display + return display end --- calculate an id for a source @@ -443,172 +443,174 @@ end -- @return string: the sourceid, or nil -- @return an error string function git.sourceid(info, sourcename, sourceset) - local src = info.sources[sourcename] - local e - if not src.sourceid then - src.sourceid = {} - src.sourceid["working-copy"] = "working-copy" - src.commitid = {} - end - if src.sourceid[sourceset] then - return true, nil, src.sourceid[sourceset] - end - src.commitid[sourceset], e = get_revision_id(info, sourcename, - sourceset, e2option.opts["check-remote"]) - if not src.commitid[sourceset] then - return false, e - end - local hc = hash.hash_start() - hash.hash_line(hc, src.name) - hash.hash_line(hc, src.type) - hash.hash_line(hc, src._env:id()) - for _,l in ipairs(src.licences) do - hash.hash_line(hc, l) - local licenceid, re = e2tool.licenceid(info, l) - if not licenceid then - return false, re - end - hash.hash_line(hc, licenceid) - end - -- git specific - --hash.hash_line(hc, src.branch) - --hash.hash_line(hc, src.tag) - hash.hash_line(hc, src.server) - hash.hash_line(hc, src.location) - hash.hash_line(hc, src.working) - hash.hash_line(hc, src.commitid[sourceset]) - e2lib.log(4, string.format("hash data for source %s\n%s", src.name, - hc.data)) - src.sourceid[sourceset] = hash.hash_finish(hc) - return true, nil, src.sourceid[sourceset] + local src = info.sources[sourcename] + local e + if not src.sourceid then + src.sourceid = {} + src.sourceid["working-copy"] = "working-copy" + src.commitid = {} + end + if src.sourceid[sourceset] then + return true, nil, src.sourceid[sourceset] + end + src.commitid[sourceset], e = get_revision_id(info, sourcename, + sourceset, e2option.opts["check-remote"]) + if not src.commitid[sourceset] then + return false, e + end + local hc = hash.hash_start() + hash.hash_line(hc, src.name) + hash.hash_line(hc, src.type) + hash.hash_line(hc, src._env:id()) + for _,l in ipairs(src.licences) do + hash.hash_line(hc, l) + local licenceid, re = e2tool.licenceid(info, l) + if not licenceid then + return false, re + end + hash.hash_line(hc, licenceid) + end + -- git specific + --hash.hash_line(hc, src.branch) + --hash.hash_line(hc, src.tag) + hash.hash_line(hc, src.server) + hash.hash_line(hc, src.location) + hash.hash_line(hc, src.working) + hash.hash_line(hc, src.commitid[sourceset]) + e2lib.log(4, string.format("hash data for source %s\n%s", src.name, + hc.data)) + src.sourceid[sourceset] = hash.hash_finish(hc) + return true, nil, src.sourceid[sourceset] end function git.toresult(info, sourcename, sourceset, directory) - local rc, re - local e = err.new("converting result") - rc, re = scm.generic_source_check(info, sourcename, true) - if not rc then - return false, e:cat(re) - end - local src = info.sources[sourcename] - local makefile = "makefile" - local source = "source" - local sourcedir = string.format("%s/%s", directory, source) - e2lib.mkdir(sourcedir, "-p") - local archive = string.format("%s.tar.gz", src.name) - local cmd = nil - if sourceset == "tag" or sourceset == "branch" then - local ref = generic_git.sourceset2ref(sourceset, src.branch, src.tag) - -- git archive --format=tar | gzip > - cmd = string.format( - "cd %s/%s && git archive --format=tar --prefix=%s/ %s".. - " | gzip > %s/%s", - e2lib.shquote(info.root), e2lib.shquote(src.working), - e2lib.shquote(sourcename), e2lib.shquote(ref), - e2lib.shquote(sourcedir), e2lib.shquote(archive)) - elseif sourceset == "working-copy" or sourceset == "mmm" then - cmd = string.format("tar -C %s/%s " .. - "--transform=s,^./,./%s/, ".. - "--exclude=.git ".. - "-czf %s/%s .", - e2lib.shquote(info.root), e2lib.shquote(src.working), - e2lib.shquote(sourcename), e2lib.shquote(sourcedir), - e2lib.shquote(archive)) - else - return false, e:append("sourceset not supported: %s", - sourceset) - end - local rc, re = e2lib.callcmd_log(cmd) - if rc ~= 0 then - return false, e:cat(re) - end - local fname = string.format("%s/%s", directory, makefile) - local f, msg = io.open(fname, "w") - if not f then - return false, e:cat(msg) - end - f:write(string.format( - ".PHONY:\tplace\n\n".. - "place:\n".. - "\ttar xzf \"%s/%s\" -C \"$(BUILD)\"\n", - source, archive)) - f:close() - -- write licences - local destdir = string.format("%s/licences", directory) - local fname = string.format("%s/%s.licences", destdir, archive) - local licence_list = table.concat(src.licences, "\n") .. "\n" - rc, re = e2lib.mkdir(destdir, "-p") - if not rc then - return false, e:cat(re) - end - rc, re = e2lib.write_file(fname, licence_list) - if not rc then - return false, e:cat(re) - end - return true, nil + local rc, re + local e = err.new("converting result") + rc, re = scm.generic_source_check(info, sourcename, true) + if not rc then + return false, e:cat(re) + end + local src = info.sources[sourcename] + local makefile = "makefile" + local source = "source" + local sourcedir = string.format("%s/%s", directory, source) + e2lib.mkdir(sourcedir, "-p") + local archive = string.format("%s.tar.gz", src.name) + local cmd = nil + if sourceset == "tag" or sourceset == "branch" then + local ref = generic_git.sourceset2ref(sourceset, src.branch, src.tag) + -- git archive --format=tar | gzip > + cmd = string.format( + "cd %s/%s && git archive --format=tar --prefix=%s/ %s".. + " | gzip > %s/%s", + e2lib.shquote(info.root), e2lib.shquote(src.working), + e2lib.shquote(sourcename), e2lib.shquote(ref), + e2lib.shquote(sourcedir), e2lib.shquote(archive)) + elseif sourceset == "working-copy" or sourceset == "mmm" then + cmd = string.format("tar -C %s/%s " .. + "--transform=s,^./,./%s/, ".. + "--exclude=.git ".. + "-czf %s/%s .", + e2lib.shquote(info.root), e2lib.shquote(src.working), + e2lib.shquote(sourcename), e2lib.shquote(sourcedir), + e2lib.shquote(archive)) + else + return false, e:append("sourceset not supported: %s", + sourceset) + end + local rc, re = e2lib.callcmd_log(cmd) + if rc ~= 0 then + return false, e:cat(re) + end + local fname = string.format("%s/%s", directory, makefile) + local f, msg = io.open(fname, "w") + if not f then + return false, e:cat(msg) + end + f:write(string.format( + ".PHONY:\tplace\n\n".. + "place:\n".. + "\ttar xzf \"%s/%s\" -C \"$(BUILD)\"\n", + source, archive)) + f:close() + -- write licences + local destdir = string.format("%s/licences", directory) + local fname = string.format("%s/%s.licences", destdir, archive) + local licence_list = table.concat(src.licences, "\n") .. "\n" + rc, re = e2lib.mkdir(destdir, "-p") + if not rc then + return false, e:cat(re) + end + rc, re = e2lib.write_file(fname, licence_list) + if not rc then + return false, e:cat(re) + end + return true, nil end function git.check_workingcopy(info, sourcename) - local rc, re - local e = err.new("checking working copy failed") - e:append("in source %s (git configuration):", sourcename) - e:setcount(0) - rc, re = git.validate_source(info, sourcename) - if not rc then - return nil, re - end - local src = info.sources[sourcename] - local query, expect, res - local rc, re = scm.working_copy_available(info, sourcename) - if not rc then - e2lib.warnf("WOTHER", "in source %s: ", sourcename) - e2lib.warnf("WOTHER", " working copy is not available") - return true, nil - end - local gitdir = string.format("%s/%s/.git", info.root, src.working) - -- check if branch exists - rc, re = e2tool.lcd(info, src.working) - if not rc then - return false, e:cat(re) - end - local ref = string.format("refs/heads/%s", src.branch) - rc, re = generic_git.git_rev_list1(nil, ref) - if not rc then - e:append("branch not available: %s", src.branch) - return false, e:cat(re) - end - -- git config branch..remote == "origin" - query = string.format("branch.%s.remote", src.branch) - expect = string.format("origin") - res, re = generic_git.git_config(gitdir, query) - if not res then - e:append("remote is not configured for branch %s", src.branch) - elseif res ~= expect then - e:append("%s is not \"origin\"", query) - end - -- git config remote.origin.url == server:location - query = string.format("remote.origin.url") - expect, re = git_url(info.cache, src.server, src.location) - if not expect then - return false, e:cat(re) - end - res, re = generic_git.git_config(gitdir, query) - if not res then - return false, e:cat(re) - end - local function remove_trailing_slashes(s) - while s:sub(#s) == "/" do - s = s:sub(1, #s-1) - end - return s - end - res = remove_trailing_slashes(res) - expect = remove_trailing_slashes(expect) - if res ~= expect then - e:append("%s does not match the configuration", query) - end - if e:getcount() > 0 then - return false, e - end - return true, nil + local rc, re + local e = err.new("checking working copy failed") + e:append("in source %s (git configuration):", sourcename) + e:setcount(0) + rc, re = git.validate_source(info, sourcename) + if not rc then + return nil, re + end + local src = info.sources[sourcename] + local query, expect, res + local rc, re = scm.working_copy_available(info, sourcename) + if not rc then + e2lib.warnf("WOTHER", "in source %s: ", sourcename) + e2lib.warnf("WOTHER", " working copy is not available") + return true, nil + end + local gitdir = string.format("%s/%s/.git", info.root, src.working) + -- check if branch exists + rc, re = e2tool.lcd(info, src.working) + if not rc then + return false, e:cat(re) + end + local ref = string.format("refs/heads/%s", src.branch) + rc, re = generic_git.git_rev_list1(nil, ref) + if not rc then + e:append("branch not available: %s", src.branch) + return false, e:cat(re) + end + -- git config branch..remote == "origin" + query = string.format("branch.%s.remote", src.branch) + expect = string.format("origin") + res, re = generic_git.git_config(gitdir, query) + if not res then + e:append("remote is not configured for branch %s", src.branch) + elseif res ~= expect then + e:append("%s is not \"origin\"", query) + end + -- git config remote.origin.url == server:location + query = string.format("remote.origin.url") + expect, re = git_url(info.cache, src.server, src.location) + if not expect then + return false, e:cat(re) + end + res, re = generic_git.git_config(gitdir, query) + if not res then + return false, e:cat(re) + end + local function remove_trailing_slashes(s) + while s:sub(#s) == "/" do + s = s:sub(1, #s-1) + end + return s + end + res = remove_trailing_slashes(res) + expect = remove_trailing_slashes(expect) + if res ~= expect then + e:append("%s does not match the configuration", query) + end + if e:getcount() > 0 then + return false, e + end + return true, nil end + +-- vim:sw=4:sts=4:et: diff --git a/local/svn.lua b/local/svn.lua index 24e673c..c1f3220 100644 --- a/local/svn.lua +++ b/local/svn.lua @@ -34,9 +34,9 @@ local err = require("err") local e2lib = require("e2lib") plugin_descriptor = { - description = "SVN SCM Plugin", - init = function (ctx) scm.register("svn", svn) return true end, - exit = function (ctx) return true end, + description = "SVN SCM Plugin", + init = function (ctx) scm.register("svn", svn) return true end, + exit = function (ctx) return true end, } --- translate url into subversion url @@ -44,141 +44,141 @@ plugin_descriptor = { -- @return string: subversion style url -- @return an error object on failure local function mksvnurl(surl) - local rc, re - local e = err.new("cannot translate url into subversion url:") - e:append("%s", surl) - local u, re = url.parse(surl) - if not u then - return nil, e:cat(re) - end - local transport - -- TODO: http, https and svn are valid transports that should be added - if u.transport == "ssh" or u.transport == "scp" or - u.transport == "rsync+ssh" then - transport = "svn+ssh" - elseif u.transport == "file" then - transport = "file" - else - return nil, e:append(string.format("unsupported subversion transport: %s", - u.transport)) - end - return string.format("%s://%s/%s", transport, u.server, u.path) + local rc, re + local e = err.new("cannot translate url into subversion url:") + e:append("%s", surl) + local u, re = url.parse(surl) + if not u then + return nil, e:cat(re) + end + local transport + -- TODO: http, https and svn are valid transports that should be added + if u.transport == "ssh" or u.transport == "scp" or + u.transport == "rsync+ssh" then + transport = "svn+ssh" + elseif u.transport == "file" then + transport = "file" + else + return nil, e:append(string.format("unsupported subversion transport: %s", + u.transport)) + end + return string.format("%s://%s/%s", transport, u.server, u.path) end function svn.fetch_source(info, sourcename) - local rc, re = svn.validate_source(info, sourcename) - if not rc then - return false, re - end - local e = err.new("fetching source failed: %s", sourcename) - local src = info.sources[sourcename] - local location = src.location - local server = src.server - local surl, re = info.cache:remote_url(server, location) - if not surl then - return false, e:cat(re) - end - local svnurl, re = mksvnurl(surl) - if not svnurl then - return false, e:cat(re) - end + local rc, re = svn.validate_source(info, sourcename) + if not rc then + return false, re + end + local e = err.new("fetching source failed: %s", sourcename) + local src = info.sources[sourcename] + local location = src.location + local server = src.server + local surl, re = info.cache:remote_url(server, location) + if not surl then + return false, e:cat(re) + end + local svnurl, re = mksvnurl(surl) + if not svnurl then + return false, e:cat(re) + end - local argv = { "checkout", svnurl, info.root .. "/" .. src.working } + local argv = { "checkout", svnurl, info.root .. "/" .. src.working } - rc, re = e2lib.svn(argv) - if not rc then - return false, e:cat(re) - end - return true, nil + rc, re = e2lib.svn(argv) + if not rc then + return false, e:cat(re) + end + return true, nil end function svn.prepare_source(info, sourcename, source_set, build_path) --OK - local rc, re = svn.validate_source(info, sourcename) - if not rc then - return false, re - end - local e = err.new("svn.prepare_source failed") - local src = info.sources[ sourcename ] - local location = src.location - local server = src.server - local surl, re = info.cache:remote_url(server, location) - if not surl then - return false, e:cat(re) - end - local svnurl, re = mksvnurl(surl) - if not svnurl then - return false, e:cat(re) - end - if source_set == "tag" or source_set == "branch" then - local rev - if source_set == "tag" then - rev = src.tag - else -- source_set == "branch" - rev = src.branch - end - local argv = { "export", svnurl .. "/" .. rev, - build_path .. "/" .. sourcename } - rc, re = e2lib.svn(argv) - if not rc then - return false, e:cat(re) - end - elseif source_set == "working-copy" then - -- cp -R info.root/src.working/src.workingcopy_subdir build_path - local s = string.format("%s/%s/%s", info.root, src.working, - src.workingcopy_subdir) - local d = string.format("%s/%s", build_path, src.name) - rc, re = e2lib.cp(s, d, "-R") + local rc, re = svn.validate_source(info, sourcename) if not rc then - return false, e:cat(re) + return false, re + end + local e = err.new("svn.prepare_source failed") + local src = info.sources[ sourcename ] + local location = src.location + local server = src.server + local surl, re = info.cache:remote_url(server, location) + if not surl then + return false, e:cat(re) + end + local svnurl, re = mksvnurl(surl) + if not svnurl then + return false, e:cat(re) end - else - return false, e:cat("invalid source set") - end - return true, nil + if source_set == "tag" or source_set == "branch" then + local rev + if source_set == "tag" then + rev = src.tag + else -- source_set == "branch" + rev = src.branch + end + local argv = { "export", svnurl .. "/" .. rev, + build_path .. "/" .. sourcename } + rc, re = e2lib.svn(argv) + if not rc then + return false, e:cat(re) + end + elseif source_set == "working-copy" then + -- cp -R info.root/src.working/src.workingcopy_subdir build_path + local s = string.format("%s/%s/%s", info.root, src.working, + src.workingcopy_subdir) + local d = string.format("%s/%s", build_path, src.name) + rc, re = e2lib.cp(s, d, "-R") + if not rc then + return false, e:cat(re) + end + else + return false, e:cat("invalid source set") + end + return true, nil end function svn.working_copy_available(info, sourcename) --OK - local rc, re - rc, re = svn.validate_source(info, sourcename) - if not rc then - return false, re - end - local src = info.sources[sourcename] - local dir = string.format("%s/%s", info.root, src.working) - return e2lib.isdir(dir) + local rc, re + rc, re = svn.validate_source(info, sourcename) + if not rc then + return false, re + end + local src = info.sources[sourcename] + local dir = string.format("%s/%s", info.root, src.working) + return e2lib.isdir(dir) end function svn.check_workingcopy(info, sourcename) --OK - local rc, re - local e = err.new("checking working copy failed") - e:append("in source %s (svn configuration):", sourcename) - e:setcount(0) - rc, re = svn.validate_source(info, sourcename) - if not rc then - return false, re - end - local src = info.sources[sourcename] - if e:getcount() > 0 then - return false, e - end - -- check if the configured branch and tag exist - local d - d = string.format("%s/%s/%s", info.root, src.working, src.branch) - if not e2lib.isdir(d) then - e:append("branch does not exist: %s", src.branch) - end - d = string.format("%s/%s/%s", info.root, src.working, src.tag) - if not e2lib.isdir(d) then - e:append("tag does not exist: %s", src.tag) - end - if e:getcount() > 0 then - return false, e - end - return true, nil + local rc, re + local e = err.new("checking working copy failed") + e:append("in source %s (svn configuration):", sourcename) + e:setcount(0) + rc, re = svn.validate_source(info, sourcename) + if not rc then + return false, re + end + local src = info.sources[sourcename] + if e:getcount() > 0 then + return false, e + end + -- check if the configured branch and tag exist + local d + d = string.format("%s/%s/%s", info.root, src.working, src.branch) + if not e2lib.isdir(d) then + e:append("branch does not exist: %s", src.branch) + end + d = string.format("%s/%s/%s", info.root, src.working, src.tag) + if not e2lib.isdir(d) then + e:append("tag does not exist: %s", src.tag) + end + if e:getcount() > 0 then + return false, e + end + return true, nil end function svn.has_working_copy(info, sname) --OK - return true + return true end --- create a table of lines for display @@ -187,140 +187,140 @@ end -- @return a table, nil on error -- @return an error string on failure function svn.display(info, sourcename) --OK - local src = info.sources[sourcename] - local rc, e - rc, e = svn.validate_source(info, sourcename) - if not rc then - return false, e - end - local display = {} - display[1] = string.format("type = %s", src.type) - display[2] = string.format("server = %s", src.server) - display[3] = string.format("remote = %s", src.location) - display[4] = string.format("branch = %s", src.branch) - display[5] = string.format("tag = %s", src.tag) - display[6] = string.format("working = %s", src.working) - local i = 7 - for _,l in pairs(src.licences) do - display[i] = string.format("licence = %s", l) - i = i + 1 - end - return display + local src = info.sources[sourcename] + local rc, e + rc, e = svn.validate_source(info, sourcename) + if not rc then + return false, e + end + local display = {} + display[1] = string.format("type = %s", src.type) + display[2] = string.format("server = %s", src.server) + display[3] = string.format("remote = %s", src.location) + display[4] = string.format("branch = %s", src.branch) + display[5] = string.format("tag = %s", src.tag) + display[6] = string.format("working = %s", src.working) + local i = 7 + for _,l in pairs(src.licences) do + display[i] = string.format("licence = %s", l) + i = i + 1 + end + return display end --- calculate an id for a source -- @param info -- @param sourcename function svn.sourceid(info, sourcename, source_set) --OK - local src = info.sources[sourcename] - local rc, e - rc, e = svn.validate_source(info, sourcename) - if not rc then - return false, e - end - if not src.sourceid then - src.sourceid = {} - end - src.sourceid["working-copy"] = "working-copy" - if src.sourceid[source_set] then - return true, nil, src.sourceid[source_set] - end - local hc = hash.hash_start() - hash.hash_line(hc, src.name) - hash.hash_line(hc, src.type) - hash.hash_line(hc, src._env:id()) - for _,l in pairs(src.licences) do - hash.hash_line(hc, l) - end - -- svn specific - hash.hash_line(hc, src.branch) - hash.hash_line(hc, src.tag) - hash.hash_line(hc, src.server) - hash.hash_line(hc, src.location) - e2lib.log(4, string.format("hash data for source %s\n%s", src.name, - hc.data)) - src.sourceid[source_set] = hash.hash_finish(hc) - return true, nil, src.sourceid[source_set] + local src = info.sources[sourcename] + local rc, e + rc, e = svn.validate_source(info, sourcename) + if not rc then + return false, e + end + if not src.sourceid then + src.sourceid = {} + end + src.sourceid["working-copy"] = "working-copy" + if src.sourceid[source_set] then + return true, nil, src.sourceid[source_set] + end + local hc = hash.hash_start() + hash.hash_line(hc, src.name) + hash.hash_line(hc, src.type) + hash.hash_line(hc, src._env:id()) + for _,l in pairs(src.licences) do + hash.hash_line(hc, l) + end + -- svn specific + hash.hash_line(hc, src.branch) + hash.hash_line(hc, src.tag) + hash.hash_line(hc, src.server) + hash.hash_line(hc, src.location) + e2lib.log(4, string.format("hash data for source %s\n%s", src.name, + hc.data)) + src.sourceid[source_set] = hash.hash_finish(hc) + return true, nil, src.sourceid[source_set] end function svn.toresult(info, sourcename, sourceset, directory) --OK - -- /source/.tar.gz - -- /makefile - -- /licences - local rc, re - local e = err.new("converting result") - rc, re = git.generic_source_check(info, sourcename, true) - if not rc then - return false, e:cat(re) - end - local src = info.sources[sourcename] - -- write makefile - local makefile = "makefile" - local source = "source" - local sourcedir = string.format("%s/%s", directory, source) - local archive = string.format("%s.tar.gz", sourcename) - local fname = string.format("%s/%s", directory, makefile) - rc, re = e2lib.mkdir(sourcedir, "-p") - if not rc then - return false, e:cat(re) - end - local f, msg = io.open(fname, "w") - if not f then - return false, e:cat(msg) - end - f:write(string.format( - ".PHONY:\tplace\n\n".. - "place:\n".. - "\ttar xzf \"%s/%s\" -C \"$(BUILD)\"\n", - source, archive)) - f:close() - -- export the source tree to a temporary directory - local tmpdir = e2lib.mktempdir() - rc, re = svn.prepare_source(info, sourcename, sourceset, tmpdir) - if not rc then - return false, e:cat(re) - end - -- create a tarball in the final location - local archive = string.format("%s.tar.gz", src.name) - local tar_args = string.format("-C '%s' -czf '%s/%s' '%s'", - tmpdir, sourcedir, archive, sourcename) - rc, re = e2lib.tar(tar_args) - if not rc then - return false, e:cat(re) - end - -- write licences - local destdir = string.format("%s/licences", directory) - local fname = string.format("%s/%s.licences", destdir, archive) - local licence_list = table.concat(src.licences, "\n") .. "\n" - rc, re = e2lib.mkdir(destdir, "-p") - if not rc then - return false, e:cat(re) - end - rc, re = e2lib.write_file(fname, licence_list) - if not rc then - return false, e:cat(re) - end - e2lib.rmtempdir(tmpdir) - return true, nil + -- /source/.tar.gz + -- /makefile + -- /licences + local rc, re + local e = err.new("converting result") + rc, re = git.generic_source_check(info, sourcename, true) + if not rc then + return false, e:cat(re) + end + local src = info.sources[sourcename] + -- write makefile + local makefile = "makefile" + local source = "source" + local sourcedir = string.format("%s/%s", directory, source) + local archive = string.format("%s.tar.gz", sourcename) + local fname = string.format("%s/%s", directory, makefile) + rc, re = e2lib.mkdir(sourcedir, "-p") + if not rc then + return false, e:cat(re) + end + local f, msg = io.open(fname, "w") + if not f then + return false, e:cat(msg) + end + f:write(string.format( + ".PHONY:\tplace\n\n".. + "place:\n".. + "\ttar xzf \"%s/%s\" -C \"$(BUILD)\"\n", + source, archive)) + f:close() + -- export the source tree to a temporary directory + local tmpdir = e2lib.mktempdir() + rc, re = svn.prepare_source(info, sourcename, sourceset, tmpdir) + if not rc then + return false, e:cat(re) + end + -- create a tarball in the final location + local archive = string.format("%s.tar.gz", src.name) + local tar_args = string.format("-C '%s' -czf '%s/%s' '%s'", + tmpdir, sourcedir, archive, sourcename) + rc, re = e2lib.tar(tar_args) + if not rc then + return false, e:cat(re) + end + -- write licences + local destdir = string.format("%s/licences", directory) + local fname = string.format("%s/%s.licences", destdir, archive) + local licence_list = table.concat(src.licences, "\n") .. "\n" + rc, re = e2lib.mkdir(destdir, "-p") + if not rc then + return false, e:cat(re) + end + rc, re = e2lib.write_file(fname, licence_list) + if not rc then + return false, e:cat(re) + end + e2lib.rmtempdir(tmpdir) + return true, nil end function svn.update(info, sourcename) - local rc, re = svn.validate_source(info, sourcename) - if not rc then - e2lib.abort(re) - end - local e = err.new("updating svn source failed") - local src = info.sources[ sourcename ] - local working = string.format("%s/%s", info.root, src.working) - rc, re = e2lib.chdir(working) - if not rc then - return false, e:cat(re) - end - rc, re = e2lib.svn({ "update", }) - if not rc then - return false, e:cat(re) - end - return true + local rc, re = svn.validate_source(info, sourcename) + if not rc then + e2lib.abort(re) + end + local e = err.new("updating svn source failed") + local src = info.sources[ sourcename ] + local working = string.format("%s/%s", info.root, src.working) + rc, re = e2lib.chdir(working) + if not rc then + return false, e:cat(re) + end + rc, re = e2lib.svn({ "update", }) + if not rc then + return false, e:cat(re) + end + return true end --- validate source configuration, log errors to the debug log @@ -328,54 +328,56 @@ end -- @param sourcename the source name -- @return bool function svn.validate_source(info, sourcename) --OK - local rc, re = scm.generic_source_validate(info, sourcename) - if not rc then - -- error in generic configuration. Don't try to go on. - return false, re - end - local src = info.sources[ sourcename ] - if not src.sourceid then - src.sourceid = {} - end - local e = err.new("in source %s:", sourcename) - rc, re = scm.generic_source_default_working(info, sourcename) - if not rc then - return false, e:cat(re) - end - e:setcount(0) - if not src.server then - e:append("source has no `server' attribute") - end - if not src.licences then - e:append("source has no `licences' attribute") - end - if not src.location then - e:append("source has no `location' attribute") - end - if src.remote then - e:append("source has `remote' attribute, not allowed for svn sources") - end - if not src.branch then - e:append("source has no `branch' attribute") - end - if not type(src.tag) == "string" then - e:append("source has no `tag' attribute or tag attribute has wrong type") - end - if not type(src.workingcopy_subdir) == "string" then - e2lib.warnf("WDEFAULT", "in source %s", sourcename) - e2lib.warnf("WDEFAULT", - " workingcopy_subdir defaults to the branch: %s", src.branch) - src.workingcopy_subdir = src.branch - end - if not src.working then - e:append("source has no `working' attribute") - end - local rc, re = tools.check_tool("svn") - if not rc then - e:cat(re) - end - if e:getcount() > 0 then - return false, e - end - return true, nil + local rc, re = scm.generic_source_validate(info, sourcename) + if not rc then + -- error in generic configuration. Don't try to go on. + return false, re + end + local src = info.sources[ sourcename ] + if not src.sourceid then + src.sourceid = {} + end + local e = err.new("in source %s:", sourcename) + rc, re = scm.generic_source_default_working(info, sourcename) + if not rc then + return false, e:cat(re) + end + e:setcount(0) + if not src.server then + e:append("source has no `server' attribute") + end + if not src.licences then + e:append("source has no `licences' attribute") + end + if not src.location then + e:append("source has no `location' attribute") + end + if src.remote then + e:append("source has `remote' attribute, not allowed for svn sources") + end + if not src.branch then + e:append("source has no `branch' attribute") + end + if not type(src.tag) == "string" then + e:append("source has no `tag' attribute or tag attribute has wrong type") + end + if not type(src.workingcopy_subdir) == "string" then + e2lib.warnf("WDEFAULT", "in source %s", sourcename) + e2lib.warnf("WDEFAULT", + " workingcopy_subdir defaults to the branch: %s", src.branch) + src.workingcopy_subdir = src.branch + end + if not src.working then + e:append("source has no `working' attribute") + end + local rc, re = tools.check_tool("svn") + if not rc then + e:cat(re) + end + if e:getcount() > 0 then + return false, e + end + return true, nil end + +-- vim:sw=4:sts=4:et: -- 2.39.5