From: Tobias Ulmer Date: Wed, 24 Apr 2013 15:44:45 +0000 (+0200) Subject: e2lib.init() can now return errors X-Git-Tag: e2factory-2.3.15rc1~518 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=bad210e72a074df07eb16279c7e45d3d32d34bac;p=e2factory.git e2lib.init() can now return errors Signed-off-by: Tobias Ulmer --- diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 3a25892..76e6062 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -126,8 +126,9 @@ function e2lib.interrupt_hook() end --- Make sure the environment variables inside the globals table are --- initialized properly, and abort otherwise. --- This function always succeeds or aborts. +-- initialized properly. +-- @return True on success, false on error. +-- @return Error object on failure. function e2lib.init() e2lib.log(4, "e2lib.init()") -- DEBUG: change to "cr" to log return from function @@ -194,7 +195,7 @@ function e2lib.init() for _, var in pairs(getenv) do var.val = os.getenv(var.name) if var.required and not var.val then - e2lib.abort(string.format("%s is not set in the environment", var.name)) + return false, err.new("%s is not set in the environment", var.name) end if var.default and not var.val then var.val = var.default @@ -216,16 +217,18 @@ function e2lib.init() -- get the host name local hostname = io.popen("hostname") if not hostname then - e2lib.abort("execution of \"hostname\" failed") + return false, err.new("execution of \"hostname\" failed") end e2lib.globals.hostname = hostname:read("*a") hostname:close() if not e2lib.globals.hostname then - e2lib.abort("hostname ist not set") + return false, err.new("hostname ist not set") end e2lib.globals.lock = lock.new() + + return true end --- init2. diff --git a/global/e2-create-project.lua b/global/e2-create-project.lua index d3f3c09..04db30d 100644 --- a/global/e2-create-project.lua +++ b/global/e2-create-project.lua @@ -36,7 +36,10 @@ local e2option = require("e2option") require("buildconfig") local function e2_create_project(arg) - e2lib.init() + local rc, re = e2lib.init() + if not rc then + return false, re + end local opts, arguments = e2option.parse(arg) if not opts then diff --git a/global/e2-fetch-project.lua b/global/e2-fetch-project.lua index 6d8db9d..c5e97a3 100644 --- a/global/e2-fetch-project.lua +++ b/global/e2-fetch-project.lua @@ -36,7 +36,10 @@ local err = require("err") require("buildconfig") local function e2_fetch_project(arg) - e2lib.init() + local rc, re = e2lib.init() + if not rc then + return false, re + end local e = err.new("fetching project failed") e2option.option("branch", "retrieve a specific project branch") diff --git a/global/e2-install-e2.lua b/global/e2-install-e2.lua index 3960751..4e13f69 100644 --- a/global/e2-install-e2.lua +++ b/global/e2-install-e2.lua @@ -35,7 +35,10 @@ local err = require("err") require("buildconfig") local function e2_install_e2(arg) - e2lib.init() + local rc, re = e2lib.init() + if not rc then + return false, re + end local opts, arguments = e2option.parse(arg) if not opts then diff --git a/global/e2.lua b/global/e2.lua index 24b6dd2..6dd4cca 100644 --- a/global/e2.lua +++ b/global/e2.lua @@ -35,7 +35,10 @@ require("buildconfig") require("e2util") local function e2(arg) - e2lib.init() + local rc, re = e2lib.init() + if not rc then + return false, re + end e2option.flag("prefix", "print installation prefix", function() diff --git a/local/e2-build-numbers.lua b/local/e2-build-numbers.lua index 8228ab2..3b21ad7 100644 --- a/local/e2-build-numbers.lua +++ b/local/e2-build-numbers.lua @@ -32,7 +32,11 @@ local e2tool = require("e2tool") local err = require("err") local function e2_build_numbers(arg) - e2lib.init() + local rc, re = e2lib.init() + if not rc then + return false, re + end + local info, re = e2tool.local_init(nil, "build-numbers") if not info then return false, re diff --git a/local/e2-build.lua b/local/e2-build.lua index 08739bb..0e19c89 100644 --- a/local/e2-build.lua +++ b/local/e2-build.lua @@ -37,7 +37,11 @@ local scm = require("scm") local policy = require("policy") local function e2_build(arg) - e2lib.init() + local rc, re = e2lib.init() + if not rc then + return false, re + end + local info, re = e2tool.local_init(nil, "build") if not info then return false, re diff --git a/local/e2-cf.lua b/local/e2-cf.lua index ac60d1e..669afeb 100644 --- a/local/e2-cf.lua +++ b/local/e2-cf.lua @@ -317,7 +317,11 @@ local function editbuildscript(info, ...) end local function e2_cf(arg) - e2lib.init() + local rc, re = e2lib.init() + if not rc then + return false, re + end + local info, re = e2tool.local_init(nil, "cf") if not info then return false, re diff --git a/local/e2-dlist.lua b/local/e2-dlist.lua index d64672f..de7b7f7 100644 --- a/local/e2-dlist.lua +++ b/local/e2-dlist.lua @@ -33,7 +33,11 @@ local e2tool = require("e2tool") local e2option = require("e2option") local function e2_dlist(arg) - e2lib.init() + local rc, re = e2lib.init() + if not rc then + return false, re + end + local info, re = e2tool.local_init(nil, "dlist") if not info then return false, re diff --git a/local/e2-dsort.lua b/local/e2-dsort.lua index 7aee799..c2b9f83 100644 --- a/local/e2-dsort.lua +++ b/local/e2-dsort.lua @@ -33,7 +33,11 @@ local e2tool = require("e2tool") local e2option = require("e2option") local function e2_dsort(arg) - e2lib.init() + local rc, re = e2lib.init() + if not rc then + return false, re + end + local info, re = e2tool.local_init(nil, "dsort") if not info then return false, re diff --git a/local/e2-fetch-sources.lua b/local/e2-fetch-sources.lua index 6168355..7fa37b3 100644 --- a/local/e2-fetch-sources.lua +++ b/local/e2-fetch-sources.lua @@ -37,7 +37,11 @@ local e2option = require("e2option") local scm = require("scm") local function e2_fetch_source(arg) - e2lib.init() + local rc, re = e2lib.init() + if not rc then + return false, re + end + local info, re = e2tool.local_init(nil, "fetch-sources") if not info then return false, re diff --git a/local/e2-help.lua b/local/e2-help.lua index 0b2dcaa..cf9c25a 100644 --- a/local/e2-help.lua +++ b/local/e2-help.lua @@ -232,7 +232,10 @@ end -- @return Error object on failure. local function e2_help(arg) local rc, re, e - e2lib.init() + rc, re = e2lib.init() + if not rc then + return false, re + end local info, re = e2tool.local_init(nil, "help") if not info then diff --git a/local/e2-ls-project.lua b/local/e2-ls-project.lua index 4cd9d76..dc8f271 100644 --- a/local/e2-ls-project.lua +++ b/local/e2-ls-project.lua @@ -38,7 +38,11 @@ local scm = require("scm") local policy = require("policy") local function e2_ls_project(arg) - e2lib.init() + local rc, re = e2lib.init() + if not rc then + return false, re + end + local info, re = e2tool.local_init(nil, "ls-project") if not info then return false, re diff --git a/local/e2-new-source.lua b/local/e2-new-source.lua index 181a323..8d46195 100644 --- a/local/e2-new-source.lua +++ b/local/e2-new-source.lua @@ -212,7 +212,11 @@ local function new_files_source(c, server, location, source_file, checksum_file, end local function e2_new_source(arg) - e2lib.init() + local rc, re = e2lib.init() + if not rc then + return false, re + end + local info, re = e2tool.local_init(nil, "new-source") if not info then return false, re diff --git a/local/e2-playground.lua b/local/e2-playground.lua index b5ad2d5..eaeae93 100644 --- a/local/e2-playground.lua +++ b/local/e2-playground.lua @@ -38,7 +38,11 @@ local e2option = require("e2option") local policy = require("policy") local function e2_playground(arg) - e2lib.init() + local rc, re = e2lib.init() + if not rc then + return false, re + end + local info, re = e2tool.local_init(nil, "playground") if not info then return false, re