From 5c6c686abfc718015ff8fe5df33e6c122c9ed17a Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Thu, 11 Apr 2013 19:46:23 +0200 Subject: [PATCH] Put global tool code into functions Signed-off-by: Tobias Ulmer --- global/e2-create-project.lua | 331 ++++++++++++++++++----------------- global/e2-fetch-project.lua | 243 ++++++++++++------------- global/e2-install-e2.lua | 259 ++++++++++++++------------- global/e2.lua | 129 +++++++------- 4 files changed, 496 insertions(+), 466 deletions(-) diff --git a/global/e2-create-project.lua b/global/e2-create-project.lua index 99932e2..0c18d9e 100644 --- a/global/e2-create-project.lua +++ b/global/e2-create-project.lua @@ -35,195 +35,202 @@ local err = require("err") local e2option = require("e2option") require("buildconfig") -e2lib.init() +local function e2_create_project(arg) + e2lib.init() -local opts, arguments = e2option.parse(arg) -local rc, e = e2lib.read_global_config() -if not rc then - e2lib.abort(e) -end -e2lib.init2() -local e = err.new("creating project failed") + local opts, arguments = e2option.parse(arg) + local rc, e = e2lib.read_global_config() + if not rc then + e2lib.abort(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)) -end -local scache, re = e2lib.setup_cache() -if not scache then - e2lib.abort(e:cat(re)) -end + local config, re = e2lib.get_global_config() + if not config then + e2lib.abort(e:cat(re)) + end + local scache, re = e2lib.setup_cache() + if not scache then + e2lib.abort(e:cat(re)) + end --- standard global tool setup finished - -if e2lib.globals.osenv["E2_LOCAL_TAG"] and e2lib.globals.osenv["E2_LOCAL_BRANCH"] then - e2lib.globals.local_e2_branch = e2lib.globals.osenv["E2_LOCAL_BRANCH"] - e2lib.globals.local_e2_tag = e2lib.globals.osenv["E2_LOCAL_TAG"] -elseif e2lib.globals.osenv["E2_LOCAL_TAG"] then - e2lib.globals.local_e2_branch = "-" - e2lib.globals.local_e2_tag = e2lib.globals.osenv["E2_LOCAL_TAG"] -elseif e2lib.globals.osenv["E2_LOCAL_BRANCH"] then - e2lib.globals.local_e2_branch = e2lib.globals.osenv["E2_LOCAL_BRANCH"] - e2lib.globals.local_e2_tag = "^" -else - e2lib.globals.local_e2_branch = config.site.e2_branch - e2lib.globals.local_e2_tag = config.site.e2_tag -end + -- standard global tool setup finished + + if e2lib.globals.osenv["E2_LOCAL_TAG"] and e2lib.globals.osenv["E2_LOCAL_BRANCH"] then + e2lib.globals.local_e2_branch = e2lib.globals.osenv["E2_LOCAL_BRANCH"] + e2lib.globals.local_e2_tag = e2lib.globals.osenv["E2_LOCAL_TAG"] + elseif e2lib.globals.osenv["E2_LOCAL_TAG"] then + e2lib.globals.local_e2_branch = "-" + e2lib.globals.local_e2_tag = e2lib.globals.osenv["E2_LOCAL_TAG"] + elseif e2lib.globals.osenv["E2_LOCAL_BRANCH"] then + e2lib.globals.local_e2_branch = e2lib.globals.osenv["E2_LOCAL_BRANCH"] + e2lib.globals.local_e2_tag = "^" + else + e2lib.globals.local_e2_branch = config.site.e2_branch + e2lib.globals.local_e2_tag = config.site.e2_tag + end -if #arguments ~= 1 then - e2option.usage(1) -end + if #arguments ~= 1 then + e2option.usage(1) + end -local sl, re = e2lib.parse_server_location(arguments[1], -e2lib.globals.default_projects_server) -if not sl then - e2lib.abort(e:cat(re)) -end + local sl, re = e2lib.parse_server_location(arguments[1], + e2lib.globals.default_projects_server) + if not sl then + e2lib.abort(e:cat(re)) + end + + local p = {} + p.version = buildconfig.GLOBAL_INTERFACE_VERSION[1] -- the project version + p.e2version = string.format("%s %s", e2lib.globals.local_e2_branch, + e2lib.globals.local_e2_tag) + p.server = sl.server -- the server + p.location = sl.location -- the project location + p.name = e2lib.basename(sl.location) -- the project basename + p.server = sl.server -- the server + + -- create the server side structure + local tmpdir = e2lib.mktempdir() + e2lib.chdir(tmpdir) + + local version = string.format("%d\n", p.version) + local empty = "" + local files = { + { filename = "version", content=version }, + { filename = "proj/.keep", content=empty }, + { filename = "git/.keep", content=empty }, + { filename = "files/.keep", content=empty }, + { filename = "cvs/.keep", content=empty }, + { filename = "svn/.keep", content=empty }, + } + for _,f in ipairs(files) do + local dir = e2lib.dirname(f.filename) + rc, re = e2lib.mkdir(dir, "-p") + if not rc then + e2lib.abort(e:cat(re)) + end + rc, re = e2lib.write_file(f.filename, f.content) + if not rc then + e2lib.abort(e:cat(re)) + end + local sourcefile = string.format("%s/%s", tmpdir, f.filename) + local flocation = string.format("%s/%s", p.location, f.filename) + local cache_flags = {} + rc, re = cache.push_file(scache, sourcefile, p.server, flocation, + cache_flags) + if not rc then + e2lib.abort(e:cat(re)) + end + end + e2lib.chdir("/") + e2lib.rmtempdir(tmpdir) -local p = {} -p.version = buildconfig.GLOBAL_INTERFACE_VERSION[1] -- the project version -p.e2version = string.format("%s %s", e2lib.globals.local_e2_branch, -e2lib.globals.local_e2_tag) -p.server = sl.server -- the server -p.location = sl.location -- the project location -p.name = e2lib.basename(sl.location) -- the project basename -p.server = sl.server -- the server - --- create the server side structure -local tmpdir = e2lib.mktempdir() -e2lib.chdir(tmpdir) - -local version = string.format("%d\n", p.version) -local empty = "" -local files = { - { filename = "version", content=version }, - { filename = "proj/.keep", content=empty }, - { filename = "git/.keep", content=empty }, - { filename = "files/.keep", content=empty }, - { filename = "cvs/.keep", content=empty }, - { filename = "svn/.keep", content=empty }, -} -for _,f in ipairs(files) do - local dir = e2lib.dirname(f.filename) - rc, re = e2lib.mkdir(dir, "-p") + local tmpdir = e2lib.mktempdir() + e2lib.chdir(tmpdir) + + -- create the initial repository on server side + 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)) end - rc, re = e2lib.write_file(f.filename, f.content) + + -- works up to this point + + -- create the initial (git) repository + local url = string.format("file://%s/.git", tmpdir) + rc, re = e2lib.git(nil, "init-db") if not rc then e2lib.abort(e:cat(re)) end - local sourcefile = string.format("%s/%s", tmpdir, f.filename) - local flocation = string.format("%s/%s", p.location, f.filename) - local cache_flags = {} - rc, re = cache.push_file(scache, sourcefile, p.server, flocation, - cache_flags) + + local gitignore = e2lib.read_template("gitignore") + if not gitignore then + e2lib.abort(re) + end + local chroot, re = e2lib.read_template("proj/chroot") + if not chroot then + e2lib.abort(re) + end + local licences, re = e2lib.read_template("proj/licences") + if not licences then + e2lib.abort(re) + end + local env, re = e2lib.read_template("proj/env") + if not env then + e2lib.abort(re) + end + local pconfig, re = e2lib.read_template("proj/config") + if not pconfig then + e2lib.abort(re) + end + pconfig = pconfig:gsub("<>", p.name) + pconfig = pconfig:gsub("<>", p.name) + local name = string.format("%s\n", p.name) + local release_id = string.format("%s\n", p.name) -- use the name for now + local version = string.format("%s\n", p.version) + local e2version = string.format("%s\n", p.e2version) + local syntax = string.format("%s\n", buildconfig.SYNTAX[1]) + local empty = "" + local files = { + { filename = ".e2/.keep", content=empty }, + { filename = "in/.keep", content=empty }, + { filename = "log/.keep", content=empty }, + { filename = "proj/init/.keep", content=empty }, + { filename = "res/.keep", content=empty }, + { filename = "src/.keep", content=empty }, + { filename = "proj/chroot", content=chroot }, + { filename = "proj/licences", content=licences }, + { filename = "proj/env", content=env }, + { filename = "proj/config", content=pconfig }, + { filename = ".e2/syntax", content=syntax }, + { filename = ".e2/e2version", content=e2version }, + { filename = ".gitignore", content=gitignore }, + } + for _,f in ipairs(files) do + local dir = e2lib.dirname(f.filename) + rc, re = e2lib.mkdir(dir, "-p") + if not rc then + e2lib.abort(e:cat(re)) + end + rc, re = e2lib.write_file(f.filename, f.content) + if not rc then + e2lib.abort(e:cat(re)) + end + rc, re = e2lib.git(nil, "add", f.filename) + if not rc then + e2lib.abort(e:cat(re)) + end + end + rc, re = e2lib.write_extension_config(config.site.default_extensions) if not rc then e2lib.abort(e:cat(re)) end -end -e2lib.chdir("/") -e2lib.rmtempdir(tmpdir) - -local tmpdir = e2lib.mktempdir() -e2lib.chdir(tmpdir) - --- create the initial repository on server side -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)) -end - --- works up to this point - --- create the initial (git) repository -local url = string.format("file://%s/.git", tmpdir) -rc, re = e2lib.git(nil, "init-db") -if not rc then - e2lib.abort(e:cat(re)) -end - -local gitignore = e2lib.read_template("gitignore") -if not gitignore then - e2lib.abort(re) -end -local chroot, re = e2lib.read_template("proj/chroot") -if not chroot then - e2lib.abort(re) -end -local licences, re = e2lib.read_template("proj/licences") -if not licences then - e2lib.abort(re) -end -local env, re = e2lib.read_template("proj/env") -if not env then - e2lib.abort(re) -end -local pconfig, re = e2lib.read_template("proj/config") -if not pconfig then - e2lib.abort(re) -end -pconfig = pconfig:gsub("<>", p.name) -pconfig = pconfig:gsub("<>", p.name) -local name = string.format("%s\n", p.name) -local release_id = string.format("%s\n", p.name) -- use the name for now -local version = string.format("%s\n", p.version) -local e2version = string.format("%s\n", p.e2version) -local syntax = string.format("%s\n", buildconfig.SYNTAX[1]) -local empty = "" -local files = { - { filename = ".e2/.keep", content=empty }, - { filename = "in/.keep", content=empty }, - { filename = "log/.keep", content=empty }, - { filename = "proj/init/.keep", content=empty }, - { filename = "res/.keep", content=empty }, - { filename = "src/.keep", content=empty }, - { filename = "proj/chroot", content=chroot }, - { filename = "proj/licences", content=licences }, - { filename = "proj/env", content=env }, - { filename = "proj/config", content=pconfig }, - { filename = ".e2/syntax", content=syntax }, - { filename = ".e2/e2version", content=e2version }, - { filename = ".gitignore", content=gitignore }, -} -for _,f in ipairs(files) do - local dir = e2lib.dirname(f.filename) - rc, re = e2lib.mkdir(dir, "-p") + rc, re = e2lib.git(nil, "add", e2lib.globals.extension_config) if not rc then e2lib.abort(e:cat(re)) end - rc, re = e2lib.write_file(f.filename, f.content) + rc, re = e2lib.git(nil, "commit", "-m \"project setup\"") if not rc then e2lib.abort(e:cat(re)) end - rc, re = e2lib.git(nil, "add", f.filename) + + 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)) end -end -rc, re = e2lib.write_extension_config(config.site.default_extensions) -if not rc then - e2lib.abort(e:cat(re)) -end -rc, re = e2lib.git(nil, "add", e2lib.globals.extension_config) -if not rc then - e2lib.abort(e:cat(re)) -end -rc, re = e2lib.git(nil, "commit", "-m \"project setup\"") -if not rc then - e2lib.abort(e:cat(re)) + + e2lib.chdir("/") + e2lib.rmtempdir(tmpdir) + e2lib.finish() 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) +local rc, re = e2_create_project(arg) if not rc then - e2lib.abort(e:cat(re)) + e2lib.abort(re) end -e2lib.chdir("/") -e2lib.rmtempdir(tmpdir) -e2lib.finish() - -- vim:sw=4:sts=4:et: diff --git a/global/e2-fetch-project.lua b/global/e2-fetch-project.lua index 4640b36..890ba73 100644 --- a/global/e2-fetch-project.lua +++ b/global/e2-fetch-project.lua @@ -35,150 +35,159 @@ local cache = require("cache") local err = require("err") require("buildconfig") -e2lib.init() +local function e2_fetch_project(arg) + e2lib.init() -local e = err.new("fetching project failed") -e2option.option("branch", "retrieve a specific project branch") -e2option.option("tag", "retrieve a specific project tag") + local e = err.new("fetching project failed") + e2option.option("branch", "retrieve a specific project branch") + e2option.option("tag", "retrieve a specific project tag") -local opts, arguments = e2option.parse(arg) -local rc, re = e2lib.read_global_config() -if not rc then - e2lib.abort(e:cat(re)) -end -e2lib.init2() + local opts, arguments = e2option.parse(arg) + local rc, re = e2lib.read_global_config() + if not rc then + e2lib.abort(e:cat(re)) + end + e2lib.init2() --- get the global configuration -local config = e2lib.get_global_config() + -- get the global configuration + local config = e2lib.get_global_config() --- setup cache -local scache, re = e2lib.setup_cache() -if not scache then - e2lib.abort(e:cat(re)) -end + -- setup cache + local scache, re = e2lib.setup_cache() + if not scache then + e2lib.abort(e:cat(re)) + end --- standard global tool setup finished + -- standard global tool setup finished -if #arguments < 1 then - e2lib.abort("specify path to a project to fetch") -end -if #arguments > 2 then - e2lib.abort("too many arguments") -end + if #arguments < 1 then + e2lib.abort("specify path to a project to fetch") + end + if #arguments > 2 then + e2lib.abort("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)) -end + local sl, re = e2lib.parse_server_location(arguments[1], + e2lib.globals.default_projects_server) + if not sl then + e2lib.abort(e:cat(re)) + end -local p = {} -p.server = sl.server -p.location = sl.location -p.name = e2lib.basename(p.location) -if arguments[2] then - p.destdir = arguments[2] -else - p.destdir = p.name -end -if opts["branch"] then - p.branch = opts["branch"] -else - p.branch = nil -end -if opts["tag"] then - p.tag = opts["tag"] -else - p.tag = nil -end + local p = {} + p.server = sl.server + p.location = sl.location + p.name = e2lib.basename(p.location) + if arguments[2] then + p.destdir = arguments[2] + else + p.destdir = p.name + end + if opts["branch"] then + p.branch = opts["branch"] + else + p.branch = nil + end + if opts["tag"] then + p.tag = opts["tag"] + else + p.tag = nil + end --- fetch project descriptor file -local tmpdir = e2lib.mktempdir() -local location = string.format("%s/version", p.location) -local rc, re = cache.fetch_file(scache, p.server, location, tmpdir, nil, -{ cache = false }) -if not rc then - e2lib.abort(e:cat(re)) -end + -- fetch project descriptor file + local tmpdir = e2lib.mktempdir() + local location = string.format("%s/version", p.location) + local rc, re = cache.fetch_file(scache, p.server, location, tmpdir, nil, + { cache = false }) + if not rc then + e2lib.abort(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)) -end -e2lib.rmtempdir() + -- 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)) + 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")) -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")) + end --- version is 1 or 2 + -- version is 1 or 2 --- clone the git repository -local location = string.format("%s/proj/%s.git", p.location, p.name) -local skip_checkout = false -local destdir = p.destdir -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)) -end + -- clone the git repository + local location = string.format("%s/proj/%s.git", p.location, p.name) + local skip_checkout = false + local destdir = p.destdir + 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)) + end -e2lib.chdir(p.destdir) + e2lib.chdir(p.destdir) --- checkout the desired branch, if a branch was given -if p.branch then - local e = e:append("checking out branch failed: %s", p.branch) - local args = string.format("-n1 refs/heads/%s", p.branch) - local rc, re = e2lib.git(nil, "rev-list", args) - if not rc then - local args = string.format( - "--track -b '%s' 'origin/%s'", p.branch, p.branch) + -- checkout the desired branch, if a branch was given + if p.branch then + local e = e:append("checking out branch failed: %s", p.branch) + local args = string.format("-n1 refs/heads/%s", p.branch) + local rc, re = e2lib.git(nil, "rev-list", args) + if not rc then + local args = string.format( + "--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)) + end + end + end + + -- checkout the desired tag, if a tag was given + if p.tag then + local e = e:append("checking out tag failed: %s", p.tag) + if p.branch then + -- branch and tag were specified. The working branch was created above. + -- Warn and go on checking out the tag... + e2lib.warnf("WOTHER", + "switching to tag '%s' after checking out branch '%s'", + p.tag, p.branch) + end + 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)) end end -end --- checkout the desired tag, if a tag was given -if p.tag then - local e = e:append("checking out tag failed: %s", p.tag) - if p.branch then - -- branch and tag were specified. The working branch was created above. - -- Warn and go on checking out the tag... - e2lib.warnf("WOTHER", - "switching to tag '%s' after checking out branch '%s'", - p.tag, p.branch) - end - local args = string.format("'refs/tags/%s'", p.tag) - local rc, re = e2lib.git(nil, "checkout", args) + -- write project location file + local file = ".e2/project-location" + 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)) end -end --- write project location file -local file = ".e2/project-location" -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)) -end + -- write version file + local rc, re = e2lib.write_file(e2lib.globals.global_interface_version_file, + string.format("%d\n", v)) --- write version file -local rc, re = e2lib.write_file(e2lib.globals.global_interface_version_file, -string.format("%d\n", v)) - --- call e2-install-e2 -local e2_install_e2 = string.format("%s %s/e2-install-e2", + -- call e2-install-e2 + local e2_install_e2 = string.format("%s %s/e2-install-e2", 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")) + rc, re = e2lib.callcmd_log(e2_install_e2) + if rc ~= 0 then + e2lib.abort(err.new("installing local e2 failed")) + end + e2lib.finish() + + return true +end + +local rc, re = e2_fetch_project(arg) +if not rc then + e2lib.abort(re) end -e2lib.finish() -- vim:sw=4:sts=4:et: diff --git a/global/e2-install-e2.lua b/global/e2-install-e2.lua index cfd02ab..75968ca 100644 --- a/global/e2-install-e2.lua +++ b/global/e2-install-e2.lua @@ -34,172 +34,179 @@ local generic_git = require("generic_git") local err = require("err") require("buildconfig") -e2lib.init() +local function e2_install_e2(arg) + e2lib.init() -local opts, arguments = e2option.parse(arg) + local opts, arguments = e2option.parse(arg) -local root = e2lib.locate_project_root() -if not root then - e2lib.abort("can't locate project root.") -end - --- try to get project specific config file paht -local config_file_config = string.format("%s/%s", root, e2lib.globals.e2config) -local config_file = e2lib.read_line(config_file_config) --- don't care if this succeeds, the parameter is optional. - -local rc, e = e2lib.read_global_config(config_file) -if not rc then - e2lib.abort(e) -end -e2lib.init2() -local e = err.new("e2-install-e2 failed") + local root = e2lib.locate_project_root() + if not root then + e2lib.abort("can't locate project root.") + end -local config = e2lib.get_global_config() -local servers = config.servers -if not servers then - e2lib.abort("no servers configured in global config") -end + -- try to get project specific config file paht + local config_file_config = string.format("%s/%s", root, e2lib.globals.e2config) + local config_file = e2lib.read_line(config_file_config) + -- don't care if this succeeds, the parameter is optional. -local scache, re = e2lib.setup_cache() -if not scache then - e2lib.abort(e:cat(re)) -end + local rc, e = e2lib.read_global_config(config_file) + if not rc then + e2lib.abort(e) + end + e2lib.init2() + local e = err.new("e2-install-e2 failed") --- standard global tool setup finished + local config = e2lib.get_global_config() + local servers = config.servers + if not servers then + e2lib.abort("no servers configured in global config") + end -if #arguments > 0 then - e2option.usage(1) -end + local scache, re = e2lib.setup_cache() + if not scache then + e2lib.abort(e:cat(re)) + end -local rc, re + -- standard global tool setup finished --- change to the project root directory -rc, re = e2lib.chdir(root) -if not rc then - e2lib.abort(e:cat(re)) -end + if #arguments > 0 then + e2option.usage(1) + 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)) -end + local rc, re -local v = tonumber(line:match("[0-9]+")) -if not v or v < 1 or v > 2 then - e2lib.abort(e:append("unhandled project version")) -end + -- change to the project root directory + rc, re = e2lib.chdir(root) + if not rc then + e2lib.abort(e:cat(re)) + end --- version is 1 or 2 + -- 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)) + end --- 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)) -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")) + end -e2lib.logf(2, "installing local tools") + -- version is 1 or 2 -local extensions -if e2util.exists(e2lib.globals.extension_config) then - extensions, re = e2lib.read_extension_config() - if not extensions then + -- 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)) end -else - e2lib.warnf("WOTHER", "extension configuration not available") - extensions = {} -- empty list -end -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")) -end -local ref -if tag == "^" then - e2lib.warnf("WOTHER", "using e2 version by branch") - if branch:match("/") then - ref = branch + e2lib.logf(2, "installing local tools") + + local extensions + if e2util.exists(e2lib.globals.extension_config) then + extensions, re = e2lib.read_extension_config() + if not extensions then + e2lib.abort(e:cat(re)) + end else - ref = string.format("remotes/origin/%s", branch) + e2lib.warnf("WOTHER", "extension configuration not available") + extensions = {} -- empty list end -else - ref = string.format("refs/tags/%s", tag) -end - -rc, re = e2lib.chdir(".e2") -if not rc then - e2lib.abort(e:cat(re)) -end - --- checkout e2factory itself -local server = config.site.e2_server -local location = config.site.e2_location -local destdir = "e2" -e2lib.logf(2, "fetching e2factory (ref %s)", ref) -rc, re = generic_git.git_clone_from_server(scache, server, location, - destdir, false) -if not rc then - e2lib.abort(e:cat(re)) -end -e2lib.chdir(destdir) --- checkout ref -local args = string.format("%s --", ref) -rc, re = e2lib.git(nil, "checkout", args) -if not rc then - e2lib.abort(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)) + 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")) end local ref - if ex.ref:match("/") then - ref = ex.ref + if tag == "^" then + e2lib.warnf("WOTHER", "using e2 version by branch") + if branch:match("/") then + ref = branch + else + ref = string.format("remotes/origin/%s", branch) + end else - ref = string.format("refs/tags/%s", ex.ref) + ref = string.format("refs/tags/%s", tag) end - e2lib.logf(2, "fetching extension: %s (%s)", ex.name, ref) - local server = config.site.e2_server - local location = string.format("%s/%s.git", config.site.e2_base, ex.name) - local destdir = ex.name - rc, re = e2lib.rm(destdir, "-fr") + + rc, re = e2lib.chdir(".e2") if not rc then e2lib.abort(e:cat(re)) end + + -- checkout e2factory itself + local server = config.site.e2_server + local location = config.site.e2_location + local destdir = "e2" + e2lib.logf(2, "fetching e2factory (ref %s)", ref) rc, re = generic_git.git_clone_from_server(scache, server, location, - destdir, false) + destdir, false) if not rc then e2lib.abort(e:cat(re)) end e2lib.chdir(destdir) -- checkout ref - rc, re = e2lib.git(nil, "checkout", ref) + local args = string.format("%s --", ref) + rc, re = e2lib.git(nil, "checkout", args) if not rc then e2lib.abort(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)) + end + local ref + if ex.ref:match("/") then + ref = ex.ref + else + ref = string.format("refs/tags/%s", ex.ref) + end + e2lib.logf(2, "fetching extension: %s (%s)", ex.name, ref) + local server = config.site.e2_server + local location = string.format("%s/%s.git", config.site.e2_base, ex.name) + local destdir = ex.name + rc, re = e2lib.rm(destdir, "-fr") + if not rc then + e2lib.abort(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)) + end + e2lib.chdir(destdir) + + -- checkout ref + rc, re = e2lib.git(nil, "checkout", ref) + if not rc then + e2lib.abort(e:cat(re)) + end + end + + -- build and install + e2lib.logf(2, "building e2factory") + rc, re = e2lib.chdir(root .. "/.e2/e2") + if not rc then + e2lib.abort(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)) + end + + e2lib.finish() end --- build and install -e2lib.logf(2, "building e2factory") -rc, re = e2lib.chdir(root .. "/.e2/e2") +local rc, re = e2_install_e2(arg) if not rc then - e2lib.abort(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)) + e2lib.abort(re) end -e2lib.finish() - -- vim:sw=4:sts=4:et: diff --git a/global/e2.lua b/global/e2.lua index 00dd08f..2e39f6a 100644 --- a/global/e2.lua +++ b/global/e2.lua @@ -33,79 +33,86 @@ local e2option = require("e2option") require("buildconfig") require("e2util") -e2lib.init() +local function e2(arg) + e2lib.init() -e2option.flag("prefix", "print installation prefix", -function() - print(buildconfig.PREFIX) - os.exit(0) -end) + e2option.flag("prefix", "print installation prefix", + function() + print(buildconfig.PREFIX) + os.exit(0) + end) -local root = e2lib.locate_project_root() + local root = e2lib.locate_project_root() -local e2call = {} -e2call.basename = e2lib.basename(arg[0]) + local e2call = {} + e2call.basename = e2lib.basename(arg[0]) -local function quoteargs(argstr) -- probably has to do escaping? - if #argstr == 0 then return "" - else return "'" .. argstr .. "'" end -end + local function quoteargs(argstr) -- probably has to do escaping? + if #argstr == 0 then return "" + else return "'" .. argstr .. "'" end + end -if e2call.basename == "e2" and arg[1] and string.sub(arg[1], 1, 1) ~= "-" then - e2call.toolname = "e2-" .. arg[1] - e2call.arg_string = quoteargs(table.concat(arg, "' '", 2)) -elseif e2call.basename == "e2" then - e2call.toolname = "e2" - local opts = e2option.parse(arg) - if #opts == 0 then - e2option.usage(1) + if e2call.basename == "e2" and arg[1] and string.sub(arg[1], 1, 1) ~= "-" then + e2call.toolname = "e2-" .. arg[1] + e2call.arg_string = quoteargs(table.concat(arg, "' '", 2)) + elseif e2call.basename == "e2" then + e2call.toolname = "e2" + local opts = e2option.parse(arg) + if #opts == 0 then + e2option.usage(1) + end + e2lib.finish(0) + else + e2call.toolname = e2call.basename + e2call.arg_string = quoteargs(table.concat(arg, "' '", 1)) end - e2lib.finish(0) -else - e2call.toolname = e2call.basename - e2call.arg_string = quoteargs(table.concat(arg, "' '", 1)) -end -e2call.globaltool = buildconfig.TOOLDIR .. "/" .. e2call.toolname -if root then - e2call.localtool = root .. "/.e2/bin/" .. e2call.toolname -end + e2call.globaltool = buildconfig.TOOLDIR .. "/" .. e2call.toolname + if root then + e2call.localtool = root .. "/.e2/bin/" .. e2call.toolname + end -local env, cmd -if e2util.stat(e2call.globaltool) then - e2call.tool = e2call.globaltool - env = string.format("LUA_PATH='%s/?.lua' LUA_CPATH='%s/?.so'", - buildconfig.LIBDIR, buildconfig.LIBDIR) - cmd = string.format("%s %s %s %s", env, buildconfig.LUA, e2call.tool, + local env, cmd + if e2util.stat(e2call.globaltool) then + e2call.tool = e2call.globaltool + env = string.format("LUA_PATH='%s/?.lua' LUA_CPATH='%s/?.so'", + buildconfig.LIBDIR, buildconfig.LIBDIR) + 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") -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 - env = "LUA_PATH='" .. root .. "/.e2/lib/e2/?.lc;" .. - root .. "/.e2/lib/e2/?.lua' " .. - "LUA_CPATH=" .. root .. "/.e2/lib/e2/?.so" - cmd = env .. " " .. - root .. "/.e2/bin/e2-lua " .. - e2call.tool .. " " .. e2call.arg_string -else - e2lib.abort(e2call.toolname .. " is neither local nor global tool") -end + elseif not root then + e2lib.abort(e2call.toolname .. + " is not a global tool and we're not in a project environment") + 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 + env = "LUA_PATH='" .. root .. "/.e2/lib/e2/?.lc;" .. + root .. "/.e2/lib/e2/?.lua' " .. + "LUA_CPATH=" .. root .. "/.e2/lib/e2/?.so" + cmd = env .. " " .. + root .. "/.e2/bin/e2-lua " .. + e2call.tool .. " " .. e2call.arg_string + else + e2lib.abort(e2call.toolname .. " is neither local nor global tool") + end -local function table_log(loglevel, t) - e2lib.log(loglevel, tostring(t)) - for k,v in pairs(t) do - e2lib.log(loglevel, k .. "\t->\t" .. v) + local function table_log(loglevel, t) + e2lib.log(loglevel, tostring(t)) + for k,v in pairs(t) do + e2lib.log(loglevel, k .. "\t->\t" .. v) + end end -end -table_log(3, e2call) + table_log(3, e2call) -e2lib.log(3, "calling " .. e2call.tool) -e2lib.log(4, cmd) -local rc = os.execute(cmd) -e2lib.finish(rc/256) + e2lib.log(3, "calling " .. e2call.tool) + e2lib.log(4, cmd) + local rc = os.execute(cmd) + e2lib.finish(rc/256) +end + +local rc, re = e2(arg) +if not rc then + e2lib.abort(re) +end -- vim:sw=4:sts=4:et: -- 2.39.5