]> git.e2factory.org Git - e2factory.git/commitdiff
plugins: remove scm remains, register to_result to collect_project plugin
authorTobias Ulmer <tu@emlix.com>
Wed, 25 Jan 2017 16:37:32 +0000 (17:37 +0100)
committerTobias Ulmer <tu@emlix.com>
Mon, 30 Jan 2017 13:33:34 +0000 (14:33 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
plugins/cvs.lua
plugins/files.lua
plugins/git.lua
plugins/gitrepo.lua
plugins/svn.lua

index ae87c9d388b4fb5ff4f459fe87c01938f3cdcf84..ea1364860536d9c71553948cf412f4b43b2729ea 100644 (file)
@@ -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)
-    -- <directory>/source/<sourcename>.tar.gz
-    -- <directory>/makefile
-    -- <directory>/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:
index ab13a7a1319c7312052ce259028efffbe6d6e742..6edcf10c95612165e97d0ab8c07ab53926baa40e 100644 (file)
@@ -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:
index 9c070a43d73d30161c2932e6a93de95ae854b888..19ad701fc80d5145e3ce92ecd1bce8d7f7cf43b4 100644 (file)
@@ -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:
index a4e49763611f6a922f77006872c5132455808ef2..2357d9cff5a5c3607e77976cce73d3448b13d790 100644 (file)
@@ -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"
+    }
 }
 
 --------------------------------------------------------------------------------
index d86f6c6fd2c21e5290f1a85061aaac92a03a998c..f38ae0d3d9118cf5e31bff7348a45127765832af 100644 (file)
@@ -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)
     -- <directory>/source/<sourcename>.tar.gz
     -- <directory>/makefile
     -- <directory>/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: