From 44cf38db096817adcf8a38cafbb86ca14567a9af Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Wed, 25 Jan 2017 17:37:32 +0100 Subject: [PATCH] plugins: remove scm remains, register to_result to collect_project plugin Signed-off-by: Tobias Ulmer --- plugins/cvs.lua | 71 +++++++++++++++++++++------------------ plugins/files.lua | 77 ++++++++++++++++++++++-------------------- plugins/git.lua | 81 ++++++++++++++++++++++++--------------------- plugins/gitrepo.lua | 37 +++++++++++---------- plugins/svn.lua | 68 ++++++++++++++++++++----------------- 5 files changed, 180 insertions(+), 154 deletions(-) diff --git a/plugins/cvs.lua b/plugins/cvs.lua index ae87c9d..ea13648 100644 --- a/plugins/cvs.lua +++ b/plugins/cvs.lua @@ -28,36 +28,12 @@ local eio = require("eio") local err = require("err") local hash = require("hash") local licence = require("licence") -local scm = require("scm") +local result = require("result") local source = require("source") local strict = require("strict") local tools = require("tools") local url = require("url") -plugin_descriptor = { - description = "CVS SCM Plugin", - init = function (ctx) - local rc, re - - rc, re = source.register_source_class("cvs", cvs.cvs_source) - if not rc then - return false, re - end - - rc, re = scm.register("cvs", cvs) - if not rc then - return false, re - end - - if e2tool.current_tool() == "fetch-sources" then - e2option.flag("cvs", "select cvs sources") - end - - return true - end, - exit = function (ctx) return true end, -} - -------------------------------------------------------------------------------- --- Build the cvsroot string. @@ -438,13 +414,10 @@ end -------------------------------------------------------------------------------- -function cvs.toresult(info, sourcename, sourceset, directory) - -- /source/.tar.gz - -- /makefile - -- /licences +--- Convert cvs source to result. +local function cvs_to_result(src, sourceset, directory) local rc, re, out - local e = err.new("converting result") - local src = source.sources[sourcename] + local e = err.new("converting %s to result", src:get_name()) rc, re = src:working_copy_available() if not rc then @@ -460,7 +433,7 @@ function cvs.toresult(info, sourcename, sourceset, directory) local makefile = "Makefile" local source = "source" local sourcedir = string.format("%s/%s", directory, source) - local archive = string.format("%s.tar.gz", sourcename) + local archive = string.format("%s.tar.gz", src:get_name()) local fname = string.format("%s/%s", directory, makefile) rc, re = e2lib.mkdir_recursive(sourcedir) if not rc then @@ -489,7 +462,7 @@ function cvs.toresult(info, sourcename, sourceset, directory) -- create a tarball in the final location local archive = string.format("%s.tar.gz", src:get_name()) rc, re = e2lib.tar({ "-C", tmpdir ,"-czf", sourcedir .. "/" .. archive, - sourcename }) + src:get_name() }) if not rc then return false, e:cat(re) end @@ -511,6 +484,38 @@ function cvs.toresult(info, sourcename, sourceset, directory) return true, nil end +-------------------------------------------------------------------------------- + +plugin_descriptor = { + description = "CVS SCM Plugin", + init = function (ctx) + local rc, re + + rc, re = source.register_source_class("cvs", cvs.cvs_source) + if not rc then + return false, re + end + + for typ, theclass in result.iterate_result_classes() do + if typ == "collect_project" then + theclass:add_source_to_result_fn("cvs", cvs_to_result) + break + end + end + + if e2tool.current_tool() == "fetch-sources" then + e2option.flag("cvs", "select cvs sources") + end + + return true + end, + exit = function (ctx) return true end, + depends = { + "collect_project.lua" + } +} + + strict.lock(cvs) -- vim:sw=4:sts=4:et: diff --git a/plugins/files.lua b/plugins/files.lua index ab13a7a..6edcf10 100644 --- a/plugins/files.lua +++ b/plugins/files.lua @@ -28,37 +28,13 @@ local eio = require("eio") local err = require("err") local hash = require("hash") local licence = require("licence") -local scm = require("scm") +local result = require("result") local sl = require("sl") local source = require("source") local strict = require("strict") local tools = require("tools") -plugin_descriptor = { - description = "Files SCM Plugin", - init = function (ctx) - local rc, re - - rc, re = source.register_source_class("files", files.files_source) - if not rc then - return false, re - end - - rc, re = scm.register("files", files) - if not rc then - return false, re - end - - if e2tool.current_tool() == "fetch-sources" then - e2option.flag("files", "select files sources") - end - - return true - end, - exit = function (ctx) return true end, -} - -------------------------------------------------------------------------------- --- Generates the command to unpack an archive file. @@ -556,23 +532,20 @@ function files.files_source:prepare_source(sourceset, buildpath) return true, nil end - -------------------------------------------------------------------------------- --- Create a source result containing the generated Makefile and files -- belonging to the source, for use with collect_project. -- Result refers to a collection of files to recreate an e2source for -- collect_project in this context. --- @param info The info table. --- @param sourcename Source name (string). +-- @param src Source object. -- @param sourceset Unused. -- @param directory Name of the source directory (string). -- @return Boolean, true on success. -- @return An error object on failure. -function files.toresult(info, sourcename, sourceset, directory) +local function files_to_result(src, sourceset, directory) local rc, re, out local e = err.new("converting result failed") - local src = source.sources[sourcename] local source = "source" -- directory to store source files in local makefile = e2lib.join(directory, "Makefile") @@ -594,7 +567,7 @@ function files.toresult(info, sourcename, sourceset, directory) if e2lib.stat(e2lib.join(destdir, destname)) then return false, e:cat("can not convert source %q due to multiple files named %q", - sourcename, destname) + src:get_name(), destname) end rc, re = cache.fetch_file(cache.cache(), file:server(), file:location(), @@ -635,9 +608,9 @@ function files.toresult(info, sourcename, sourceset, directory) end table.insert(out, "\n") - if file:unpack() ~= sourcename then + if file:unpack() ~= src:get_name() then table.insert(out, string.format("\tln -s %s $(BUILD)/%s\n", - file:unpack(), sourcename)) + file:unpack(), src:get_name())) end end if file:copy() then @@ -645,7 +618,7 @@ function files.toresult(info, sourcename, sourceset, directory) from = e2lib.shquote( e2lib.join(source, e2lib.basename(file:location()))) - local destdir, destname = gen_dest_dir_name("/", sourcename, + local destdir, destname = gen_dest_dir_name("/", src:get_name(), file:copy(), file:location(), "isdir") -- -- is a directory? @@ -660,7 +633,7 @@ function files.toresult(info, sourcename, sourceset, directory) -- -- not a directory -- - destdir, destname = gen_dest_dir_name("/", sourcename, file:copy(), + destdir, destname = gen_dest_dir_name("/", src:get_name(), file:copy(), file:location(), "no") to = string.format('"$(BUILD)"%s', e2lib.shquote(destdir)) @@ -674,7 +647,7 @@ function files.toresult(info, sourcename, sourceset, directory) if file:patch() then table.insert(out, string.format( "\tpatch -p%s -d \"$(BUILD)/%s\" -i \"$(shell pwd)/%s/%s\"\n", - file:patch(), sourcename, source, e2lib.basename(file:location()))) + file:patch(), src:get_name(), source, e2lib.basename(file:location()))) end -- write licences local destdir = string.format("%s/licences", directory) @@ -700,6 +673,38 @@ function files.toresult(info, sourcename, sourceset, directory) return true end +-------------------------------------------------------------------------------- + +plugin_descriptor = { + description = "Files SCM Plugin", + init = function (ctx) + local rc, re + + rc, re = source.register_source_class("files", files.files_source) + if not rc then + return false, re + end + + if e2tool.current_tool() == "fetch-sources" then + e2option.flag("files", "select files sources") + end + + for typ, theclass in result.iterate_result_classes() do + if typ == "collect_project" then + theclass:add_source_to_result_fn("files", files_to_result) + break + end + end + + return true + end, + exit = function (ctx) return true end, + depends = { + "collect_project.lua", + } +} + + strict.lock(files) -- vim:sw=4:sts=4:et: diff --git a/plugins/git.lua b/plugins/git.lua index 9c070a4..19ad701 100644 --- a/plugins/git.lua +++ b/plugins/git.lua @@ -29,44 +29,12 @@ local err = require("err") local generic_git = require("generic_git") local hash = require("hash") local licence = require("licence") -local scm = require("scm") +local result = require("result") local source = require("source") local strict = require("strict") local tools = require("tools") local url = require("url") ---- Initialize git plugin. --- @param ctx Plugin context. See plugin module. --- @return True on success, false on error. --- @return Error object on failure. -local function git_plugin_init(ctx) - local rc, re - - rc, re = source.register_source_class("git", git.git_source) - if not rc then - return false, re - end - - rc, re = scm.register("git", git) - if not rc then - return false, re - end - - if e2tool.current_tool() == "fetch-sources" then - e2option.flag("git", "select git sources") - end - - return true -end - -plugin_descriptor = { - description = "Git SCM Plugin", - init = git_plugin_init, - exit = function (ctx) return true end, -} - --------------------------------------------------------------------------------- - git.git_source = class("git_source", source.basic_source) function git.git_source.static:is_scm_source_class() @@ -693,10 +661,9 @@ end -------------------------------------------------------------------------------- -function git.toresult(info, sourcename, sourceset, directory) +local function git_to_result(src, sourceset, directory) local rc, re, argv - local e = err.new("converting result") - local src = source.sources[sourcename] + local e = err.new("converting %s to result", src:get_name()) rc, re = src:working_copy_available() if not rc then @@ -735,7 +702,7 @@ function git.toresult(info, sourcename, sourceset, directory) argv = generic_git.git_new_argv(nil, e2lib.join(e2tool.root(), src:get_working())) table.insert(argv, "archive") table.insert(argv, "--format=tar") -- older versions don't have "tar.gz" - table.insert(argv, string.format("--prefix=%s/", sourcename)) + table.insert(argv, string.format("--prefix=%s/", src:get_name())) table.insert(argv, "-o") table.insert(argv, tmpfn) table.insert(argv, ref) @@ -757,7 +724,7 @@ function git.toresult(info, sourcename, sourceset, directory) elseif sourceset == "working-copy" then argv = { "-C", e2lib.join(e2tool.root(), src:get_working()), - string.format("--transform=s,^./,./%s/,", sourcename), + string.format("--transform=s,^./,./%s/,", src:get_name()), "--exclude=.git", "-czf", e2lib.join(sourcedir, archive), @@ -797,6 +764,44 @@ function git.toresult(info, sourcename, sourceset, directory) return true, nil end +-------------------------------------------------------------------------------- + +--- Initialize git plugin. +-- @param ctx Plugin context. See plugin module. +-- @return True on success, false on error. +-- @return Error object on failure. +local function git_plugin_init(ctx) + local rc, re + + rc, re = source.register_source_class("git", git.git_source) + if not rc then + return false, re + end + + for typ, theclass in result.iterate_result_classes() do + if typ == "collect_project" then + theclass:add_source_to_result_fn("git", git_to_result) + break + end + end + + if e2tool.current_tool() == "fetch-sources" then + e2option.flag("git", "select git sources") + end + + return true +end + +plugin_descriptor = { + description = "Git SCM Plugin", + init = git_plugin_init, + exit = function (ctx) return true end, + depends = { + "collect_project.lua" + } +} + + strict.lock(git) -- vim:sw=4:sts=4:et: diff --git a/plugins/gitrepo.lua b/plugins/gitrepo.lua index a4e4976..2357d9c 100644 --- a/plugins/gitrepo.lua +++ b/plugins/gitrepo.lua @@ -29,7 +29,7 @@ local err = require("err") local generic_git = require("generic_git") local hash = require("hash") local licence = require("licence") -local scm = require("scm") +local result = require("result") local source = require("source") local strict = require("strict") local url = require("url") @@ -520,24 +520,21 @@ end -------------------------------------------------------------------------------- --- Archives the source and prepares the necessary files outside the archive --- @param info the info structure --- @param sourcename string +-- @param src source object -- @param sourceset string, should be "tag" "branch" or "working copy", in order for it to work -- @param the directory where the sources are and where the archive is to be created -- @return True on success, false on error. -- @return Error object on failure -function gitrepo.toresult(info, sourcename, sourceset, directory) - assertIsTable(info) - assertIsStringN(sourcename) +local function gitrepo_to_result(src, sourceset, directory) + assertIsTable(src) assertIsStringN(sourceset) assertIsStringN(directory) local rc, re, e - local src, srcdir, sourcedir, archive + local srcdir, sourcedir, archive local argv - e = err.new("converting source %q failed", sourcename) - src = source.sources[sourcename] + e = err.new("converting source %q failed", src:get_name()) rc, re = src:working_copy_available() if not rc then @@ -551,7 +548,7 @@ function gitrepo.toresult(info, sourcename, sourceset, directory) srcdir = "source" sourcedir = e2lib.join(directory, srcdir) - archive = string.format("%s.tar.gz", sourcename) + archive = string.format("%s.tar.gz", src:get_name()) rc, re = e2lib.mkdir(sourcedir) if not rc then @@ -561,7 +558,7 @@ function gitrepo.toresult(info, sourcename, sourceset, directory) if sourceset == "tag" or sourceset == "branch" then local tmpdir = e2lib.mktempdir() local worktree = e2lib.join(e2tool.root(), src:get_working()) - local destdir = e2lib.join(tmpdir, sourcename, ".git") + local destdir = e2lib.join(tmpdir, src:get_name(), ".git") rc, re = e2lib.mkdir_recursive(destdir) if not rc then @@ -576,13 +573,14 @@ function gitrepo.toresult(info, sourcename, sourceset, directory) end rc, rc = e2lib.tar({"-czf", e2lib.join(sourcedir, archive), - "-C", tmpdir, sourcename}) + "-C", tmpdir, src:get_name()}) if not rc then return false, e:cat(re) end elseif sourceset == "working-copy" then rc, rc = e2lib.tar({"-czf", e2lib.join(sourcedir, archive), - "-C", e2lib.join(e2tool.root(), src:get_working(), ".."), sourcename}) + "-C", e2lib.join(e2tool.root(), src:get_working(), ".."), + src:get_name()}) if not rc then return false, e:cat(re) end @@ -590,7 +588,7 @@ function gitrepo.toresult(info, sourcename, sourceset, directory) return false, e:cat("build mode %s not supported", source_set) end - local builddir = e2lib.join("$(BUILD)", sourcename) + local builddir = e2lib.join("$(BUILD)", src:get_name()) local makefile = e2lib.join(directory, "Makefile") if sourceset == "tag" then rc, re = eio.file_write(makefile, string.format( @@ -657,9 +655,11 @@ local function gitrepo_plugin_init() return false, re end - rc, re = scm.register("gitrepo", gitrepo) - if not rc then - return false, re + for typ, theclass in result.iterate_result_classes() do + if typ == "collect_project" then + theclass:add_source_to_result_fn("gitrepo", gitrepo_to_result) + break + end end if e2tool.current_tool() == "fetch-sources" then @@ -673,6 +673,9 @@ plugin_descriptor = { description = "Provides Git repository as source", init = gitrepo_plugin_init, exit = function(ctx) return true end, + depends = { + "collect_project.lua" + } } -------------------------------------------------------------------------------- diff --git a/plugins/svn.lua b/plugins/svn.lua index d86f6c6..f38ae0d 100644 --- a/plugins/svn.lua +++ b/plugins/svn.lua @@ -28,36 +28,12 @@ local eio = require("eio") local err = require("err") local hash = require("hash") local licence = require("licence") -local scm = require("scm") +local result = require("result") local source = require("source") local strict = require("strict") local tools = require("tools") local url = require("url") -plugin_descriptor = { - description = "SVN SCM Plugin", - init = function (ctx) - local rc, re - - rc, re = source.register_source_class("svn", svn.svn_source) - if not rc then - return false, re - end - - rc, re = scm.register("svn", svn) - if not rc then - return false, re - end - - if e2tool.current_tool() == "fetch-sources" then - e2option.flag("svn", "select svn sources") - end - - return true - end, - exit = function (ctx) return true end, -} - svn.svn_source = class("svn_source", source.basic_source) function svn.svn_source.static:is_scm_source_class() @@ -473,13 +449,13 @@ end -------------------------------------------------------------------------------- -function svn.toresult(info, sourcename, sourceset, directory) +local function svn_to_result(src, sourceset, directory) -- /source/.tar.gz -- /makefile -- /licences local rc, re - local e = err.new("converting result") - local src = source.sources[sourcename] + local e = err.new("converting %s to result", src:get_name()) + local src = source.sources[src:get_name()] rc, re = src:working_copy_available() if not rc then @@ -495,7 +471,7 @@ function svn.toresult(info, sourcename, sourceset, directory) local makefile = "Makefile" local source = "source" local sourcedir = e2lib.join(directory, source) - local archive = string.format("%s.tar.gz", sourcename) + local archive = string.format("%s.tar.gz", src:get_name()) local fname = e2lib.join(directory, makefile) rc, re = e2lib.mkdir_recursive(sourcedir) if not rc then @@ -519,7 +495,7 @@ function svn.toresult(info, sourcename, sourceset, directory) -- create a tarball in the final location local archive = string.format("%s.tar.gz", src:get_name()) rc, re = e2lib.tar({ "-C", tmpdir ,"-czf", sourcedir .. "/" .. archive, - sourcename }) + src:get_name() }) if not rc then return false, e:cat(re) end @@ -540,6 +516,38 @@ function svn.toresult(info, sourcename, sourceset, directory) return true, nil end +-------------------------------------------------------------------------------- + +plugin_descriptor = { + description = "SVN SCM Plugin", + init = function (ctx) + local rc, re + + rc, re = source.register_source_class("svn", svn.svn_source) + if not rc then + return false, re + end + + for typ, theclass in result.iterate_result_classes() do + if typ == "collect_project" then + theclass:add_source_to_result_fn("svn", svn_to_result) + break + end + end + + if e2tool.current_tool() == "fetch-sources" then + e2option.flag("svn", "select svn sources") + end + + return true + end, + exit = function (ctx) return true end, + depends = { + "collect_project.lua" + } +} + + strict.lock(svn) -- vim:sw=4:sts=4:et: -- 2.39.5