]> git.e2factory.org Git - e2factory.git/commitdiff
Remove calls to e2lib.abort() in global tools
authorTobias Ulmer <tu@emlix.com>
Mon, 15 Apr 2013 15:38:54 +0000 (17:38 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 13:58:55 +0000 (14:58 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
global/e2-create-project.lua
global/e2-fetch-project.lua
global/e2-install-e2.lua
global/e2.lua

index 0c18d9e9a40306a8995c57d2ac53507b58bbd315..bb1137cedc8c8aee2583d899498703e666c7b0da 100644 (file)
@@ -41,18 +41,18 @@ local function e2_create_project(arg)
     local opts, arguments = e2option.parse(arg)
     local rc, e = e2lib.read_global_config()
     if not rc then
-        e2lib.abort(e)
+        return false, e
     end
     e2lib.init2()
     local e = err.new("creating project failed")
 
     local config, re = e2lib.get_global_config()
     if not config then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
     local scache, re = e2lib.setup_cache()
     if not scache then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     -- standard global tool setup finished
@@ -78,7 +78,7 @@ local function e2_create_project(arg)
     local sl, re = e2lib.parse_server_location(arguments[1],
     e2lib.globals.default_projects_server)
     if not sl then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     local p = {}
@@ -108,11 +108,11 @@ local function e2_create_project(arg)
         local dir = e2lib.dirname(f.filename)
         rc, re = e2lib.mkdir(dir, "-p")
         if not rc then
-            e2lib.abort(e:cat(re))
+            return false, e:cat(re)
         end
         rc, re = e2lib.write_file(f.filename, f.content)
         if not rc then
-            e2lib.abort(e:cat(re))
+            return false, e:cat(re)
         end
         local sourcefile = string.format("%s/%s", tmpdir, f.filename)
         local flocation = string.format("%s/%s", p.location, f.filename)
@@ -120,7 +120,7 @@ local function e2_create_project(arg)
         rc, re = cache.push_file(scache, sourcefile, p.server, flocation,
         cache_flags)
         if not rc then
-            e2lib.abort(e:cat(re))
+            return false, e:cat(re)
         end
     end
     e2lib.chdir("/")
@@ -133,7 +133,7 @@ local function e2_create_project(arg)
     local rlocation = string.format("%s/proj/%s.git", p.location, p.name)
     local rc, re = generic_git.git_init_db(scache, p.server, rlocation)
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     -- works up to this point
@@ -142,28 +142,28 @@ local function e2_create_project(arg)
     local url = string.format("file://%s/.git", tmpdir)
     rc, re = e2lib.git(nil, "init-db")
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     local gitignore = e2lib.read_template("gitignore")
     if not gitignore then
-        e2lib.abort(re)
+        return false, re
     end
     local chroot, re = e2lib.read_template("proj/chroot")
     if not chroot then
-        e2lib.abort(re)
+        return false, re
     end
     local licences, re = e2lib.read_template("proj/licences")
     if not licences then
-        e2lib.abort(re)
+        return false, re
     end
     local env, re = e2lib.read_template("proj/env")
     if not env then
-        e2lib.abort(re)
+        return false, re
     end
     local pconfig, re = e2lib.read_template("proj/config")
     if not pconfig then
-        e2lib.abort(re)
+        return false, re
     end
     pconfig = pconfig:gsub("<<release_id>>", p.name)
     pconfig = pconfig:gsub("<<name>>", p.name)
@@ -192,40 +192,41 @@ local function e2_create_project(arg)
         local dir = e2lib.dirname(f.filename)
         rc, re = e2lib.mkdir(dir, "-p")
         if not rc then
-            e2lib.abort(e:cat(re))
+            return false, e:cat(re)
         end
         rc, re = e2lib.write_file(f.filename, f.content)
         if not rc then
-            e2lib.abort(e:cat(re))
+            return false, e:cat(re)
         end
         rc, re = e2lib.git(nil, "add", f.filename)
         if not rc then
-            e2lib.abort(e:cat(re))
+            return false, e:cat(re)
         end
     end
     rc, re = e2lib.write_extension_config(config.site.default_extensions)
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
     rc, re = e2lib.git(nil, "add", e2lib.globals.extension_config)
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
     rc, re = e2lib.git(nil, "commit", "-m \"project setup\"")
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     local refspec = "master:refs/heads/master"
     local rlocation = string.format("%s/proj/%s.git", p.location, p.name)
     rc, re = generic_git.git_push(scache, ".git", p.server, rlocation, refspec)
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     e2lib.chdir("/")
     e2lib.rmtempdir(tmpdir)
-    e2lib.finish()
+
+    return true
 end
 
 local rc, re = e2_create_project(arg)
@@ -233,4 +234,6 @@ if not rc then
     e2lib.abort(re)
 end
 
+e2lib.finish(0)
+
 -- vim:sw=4:sts=4:et:
index 890ba73907aed32048368ab9b818acc1abdbe5d4..f9784b0aeb2bf80a7d5d18a300ba9799486bdec7 100644 (file)
@@ -45,7 +45,7 @@ local function e2_fetch_project(arg)
     local opts, arguments = e2option.parse(arg)
     local rc, re = e2lib.read_global_config()
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
     e2lib.init2()
 
@@ -55,22 +55,22 @@ local function e2_fetch_project(arg)
     -- setup cache
     local scache, re = e2lib.setup_cache()
     if not scache then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     -- standard global tool setup finished
 
     if #arguments < 1 then
-        e2lib.abort("specify path to a project to fetch")
+        return false, err.new("specify path to a project to fetch")
     end
     if #arguments > 2 then
-        e2lib.abort("too many arguments")
+        return false, err.new("too many arguments")
     end
 
     local sl, re = e2lib.parse_server_location(arguments[1],
     e2lib.globals.default_projects_server)
     if not sl then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     local p = {}
@@ -99,20 +99,20 @@ local function e2_fetch_project(arg)
     local rc, re = cache.fetch_file(scache, p.server, location, tmpdir, nil,
     { cache = false })
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     -- read the version from the first line
     local version_file = string.format("%s/version", tmpdir)
     local line, re = e2lib.read_line(version_file)
     if not line then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
     e2lib.rmtempdir()
 
     local v = tonumber(line:match("[0-9]+"))
     if not v or v < 1 or v > 2 then
-        e2lib.abort(e:append("unhandled project version"))
+        return false, e:append("unhandled project version")
     end
 
     -- version is 1 or 2
@@ -124,7 +124,7 @@ local function e2_fetch_project(arg)
     local rc, re = generic_git.git_clone_from_server(scache, p.server, location,
     p.destdir, skip_checkout)
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     e2lib.chdir(p.destdir)
@@ -139,7 +139,7 @@ local function e2_fetch_project(arg)
             "--track -b '%s' 'origin/%s'", p.branch, p.branch)
             local rc, re = e2lib.git(nil, "checkout", args)
             if not rc then
-                e2lib.abort(e:cat(re))
+                return false, e:cat(re)
             end
         end
     end
@@ -157,7 +157,7 @@ local function e2_fetch_project(arg)
         local args = string.format("'refs/tags/%s'", p.tag)
         local rc, re = e2lib.git(nil, "checkout", args)
         if not rc then
-            e2lib.abort(e:cat(re))
+            return false, e:cat(re)
         end
     end
 
@@ -166,7 +166,7 @@ local function e2_fetch_project(arg)
     local data = string.format("%s\n", p.location)
     local rc, re = e2lib.write_file(file, data)
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     -- write version file
@@ -178,9 +178,8 @@ local function e2_fetch_project(arg)
     e2lib.shquote(buildconfig.LUA), e2lib.shquote(buildconfig.TOOLDIR))
     rc, re = e2lib.callcmd_log(e2_install_e2)
     if rc ~= 0 then
-        e2lib.abort(err.new("installing local e2 failed"))
+        return false, err.new("installing local e2 failed")
     end
-    e2lib.finish()
 
     return true
 end
@@ -190,4 +189,6 @@ if not rc then
     e2lib.abort(re)
 end
 
+e2lib.finish(0)
+
 -- vim:sw=4:sts=4:et:
index 75968ca65f00ce1f42e6ce5ad5594936ce46712c..a64f232282d608b6803aa5f975b5e83567f092bd 100644 (file)
@@ -41,7 +41,7 @@ local function e2_install_e2(arg)
 
     local root = e2lib.locate_project_root()
     if not root then
-        e2lib.abort("can't locate project root.")
+        return false, err.new("can't locate project root.")
     end
 
     -- try to get project specific config file paht
@@ -51,7 +51,7 @@ local function e2_install_e2(arg)
 
     local rc, e = e2lib.read_global_config(config_file)
     if not rc then
-        e2lib.abort(e)
+        return false, e
     end
     e2lib.init2()
     local e = err.new("e2-install-e2 failed")
@@ -59,12 +59,12 @@ local function e2_install_e2(arg)
     local config = e2lib.get_global_config()
     local servers = config.servers
     if not servers then
-        e2lib.abort("no servers configured in global config")
+        return false, err.new("no servers configured in global config")
     end
 
     local scache, re = e2lib.setup_cache()
     if not scache then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     -- standard global tool setup finished
@@ -78,18 +78,18 @@ local function e2_install_e2(arg)
     -- change to the project root directory
     rc, re = e2lib.chdir(root)
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     -- read the version from the first line
     local line, re = e2lib.read_line(e2lib.globals.global_interface_version_file)
     if not line then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     local v = tonumber(line:match("[0-9]+"))
     if not v or v < 1 or v > 2 then
-        e2lib.abort(e:append("unhandled project version"))
+        return false, e:append("unhandled project version")
     end
 
     -- version is 1 or 2
@@ -97,7 +97,7 @@ local function e2_install_e2(arg)
     -- remove the old e2 source, installation and plugins, if it exists
     rc, re = e2lib.rm(".e2/e2 .e2/bin .e2/lib .e2/plugins", "-fr")
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     e2lib.logf(2, "installing local tools")
@@ -106,7 +106,7 @@ local function e2_install_e2(arg)
     if e2util.exists(e2lib.globals.extension_config) then
         extensions, re = e2lib.read_extension_config()
         if not extensions then
-            e2lib.abort(e:cat(re))
+            return false, e:cat(re)
         end
     else
         e2lib.warnf("WOTHER", "extension configuration not available")
@@ -116,7 +116,7 @@ local function e2_install_e2(arg)
     local s = e2lib.read_line(".e2/e2version")
     local branch, tag = s:match("(%S+) (%S+)")
     if not branch or not tag then
-        e2lib.abort(e:append("cannot parse e2 version"))
+        return false, e:append("cannot parse e2 version")
     end
     local ref
     if tag == "^" then
@@ -132,7 +132,7 @@ local function e2_install_e2(arg)
 
     rc, re = e2lib.chdir(".e2")
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     -- checkout e2factory itself
@@ -143,7 +143,7 @@ local function e2_install_e2(arg)
     rc, re = generic_git.git_clone_from_server(scache, server, location,
     destdir, false)
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
     e2lib.chdir(destdir)
 
@@ -151,14 +151,14 @@ local function e2_install_e2(arg)
     local args = string.format("%s --", ref)
     rc, re = e2lib.git(nil, "checkout", args)
     if not rc then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
     for _,ex in ipairs(extensions) do
         -- change to the e2factory extensions directory
         rc, re = e2lib.chdir(root .. "/.e2/e2/extensions")
         if not rc then
-            e2lib.abort(e:cat(re))
+            return false, e:cat(re)
         end
         local ref
         if ex.ref:match("/") then
@@ -172,19 +172,19 @@ local function e2_install_e2(arg)
         local destdir = ex.name
         rc, re = e2lib.rm(destdir, "-fr")
         if not rc then
-            e2lib.abort(e:cat(re))
+            return false, e:cat(re)
         end
         rc, re = generic_git.git_clone_from_server(scache, server, location,
         destdir, false)
         if not rc then
-            e2lib.abort(e:cat(re))
+            return false, e:cat(re)
         end
         e2lib.chdir(destdir)
 
         -- checkout ref
         rc, re = e2lib.git(nil, "checkout", ref)
         if not rc then
-            e2lib.abort(e:cat(re))
+            return false, e:cat(re)
         end
     end
 
@@ -192,16 +192,16 @@ local function e2_install_e2(arg)
     e2lib.logf(2, "building e2factory")
     rc, re = e2lib.chdir(root .. "/.e2/e2")
     if not rc then
-        e2lib.abort(e:cat(re))
+       return false, e:cat(re)
     end
     local cmd = string.format("make PREFIX=%s BINDIR=%s local install-local",
     e2lib.shquote(buildconfig.PREFIX), e2lib.shquote(buildconfig.BINDIR))
     rc, re = e2lib.callcmd_capture(cmd)
     if rc ~= 0 then
-        e2lib.abort(e:cat(re))
+        return false, e:cat(re)
     end
 
-    e2lib.finish()
+    return true
 end
 
 local rc, re = e2_install_e2(arg)
@@ -209,4 +209,6 @@ if not rc then
     e2lib.abort(re)
 end
 
+e2lib.finish(0)
+
 -- vim:sw=4:sts=4:et:
index 2e39f6a6a473ed25e74b26d2a1a76dc941a9a75c..2c7f84d5ab1b2a07fdb50e96b6f9cacaae9abd94 100644 (file)
@@ -30,6 +30,7 @@
 
 local e2lib = require("e2lib")
 local e2option = require("e2option")
+local err = require("err")
 require("buildconfig")
 require("e2util")
 
@@ -61,7 +62,7 @@ local function e2(arg)
         if #opts == 0 then
             e2option.usage(1)
         end
-        e2lib.finish(0)
+        return 0
     else
         e2call.toolname = e2call.basename
         e2call.arg_string = quoteargs(table.concat(arg, "' '", 1))
@@ -80,8 +81,7 @@ local function e2(arg)
         cmd = string.format("%s %s %s %s", env, buildconfig.LUA, e2call.tool,
         e2call.arg_string)
     elseif not root then
-        e2lib.abort(e2call.toolname ..
-        " is not a global tool and we're not in a project environment")
+        return false, err.new("%s is not a global tool and we're not in a project environment", e2call.toolname)
     elseif root and e2util.stat(e2call.localtool) then
         e2call.tool = e2call.localtool
         -- Search for .lc files, the local e2 may be of an older version
@@ -92,7 +92,8 @@ local function e2(arg)
         root .. "/.e2/bin/e2-lua " ..
         e2call.tool .. " " .. e2call.arg_string
     else
-        e2lib.abort(e2call.toolname .. " is neither local nor global tool")
+        return false,
+            err.new("%s is neither local nor global tool", e2call.toolname)
     end
 
     local function table_log(loglevel, t)
@@ -107,7 +108,8 @@ local function e2(arg)
     e2lib.log(3, "calling " .. e2call.tool)
     e2lib.log(4, cmd)
     local rc = os.execute(cmd)
-    e2lib.finish(rc/256)
+
+    return rc/256
 end
 
 local rc, re = e2(arg)
@@ -115,4 +117,6 @@ if not rc then
     e2lib.abort(re)
 end
 
+e2lib.finish(rc)
+
 -- vim:sw=4:sts=4:et: