From 784712ce205493ad6b3ef05530ffe37eb29f5e54 Mon Sep 17 00:00:00 2001 From: Gordon Hecker Date: Tue, 5 May 2009 16:00:23 +0200 Subject: [PATCH] extension config in .e2/extensions is a lua table now .e2/e2version becomes obsolete, the user must move the configuration to use this version of e2factory. Signed-off-by: Gordon Hecker --- generic/e2lib.lua | 56 ++++++++++++++++++++++++++- global/e2-create-project.lua.in | 9 ++++- global/e2-install-e2.lua.in | 68 +++++++++++++++++---------------- scripts/e2-locate-project-root | 2 +- 4 files changed, 100 insertions(+), 35 deletions(-) diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 9f8bc59..76ec227 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -90,6 +90,7 @@ e2lib = { git_skip_checkout = true, buildnumber_server_url = nil, template_path = "/etc/e2/templates", + extension_config = ".e2/extensions", } -- Interrupt handling @@ -798,6 +799,59 @@ function e2lib.read_global_config(e2_config_file) return false, "no config file available" end +function e2lib.write_extension_config(extensions) + local e = new_error("writing extensions config: %s", e2lib.extension_config) + local f, re = io.open(e2lib.extension_config, "w") + if not f then + return false, e:cat(re) + end + f:write(string.format("extensions {\n")) + for _,ex in ipairs(extensions) do + f:write(string.format(" {\n")) + for k,v in pairs(ex) do + f:write(string.format(" %s=\"%s\",\n", k, v)) + end + f:write(string.format(" },\n")) + end + f:write(string.format("}\n")) + f:close() + return true, nil +end + +--- read the local extension configuration +-- This function must run while being located in the projects root directory +-- @param root string: path to project +-- @return the extension configuration table +-- @return an error object on failure +function e2lib.read_extension_config() + if e2util.exists(".e2/e2version") then + return false, new_error( + "Deprecated configuration file .e2/e2version exists.\n".. + "Move configuration to .e2/extensions") + end + local e = new_error("reading extension config file: %s", + e2lib.extension_config) + + local rc = e2util.exists(e2lib.extension_config) + if not rc then + return false, e:append("config file does not exist") + end + e2lib.logf(3, "reading extension file: %s", e2lib.extension_config) + local c = {} + c.extensions = function(x) + c.data = x + end + local rc, re = e2lib.dofile_protected(e2lib.extension_config, c, true) + if not rc then + return false, e:cat(re) + end + local extension = c.data + if not extension then + return false, e:append("invalid extension configuration") + end + return extension, nil +end + --- use the global parameters from the global configuration -- this function always succeeds or aborts -- @return nothing @@ -1183,7 +1237,7 @@ function e2lib.locate_project_root(path) end end while true do - if e2util.exists(".e2/e2version") then + if e2util.exists(".e2") then e2lib.logf(3, "project is located in: %s", path) e2lib.chdir(save_path) return path diff --git a/global/e2-create-project.lua.in b/global/e2-create-project.lua.in index f006022..bcd75de 100755 --- a/global/e2-create-project.lua.in +++ b/global/e2-create-project.lua.in @@ -194,7 +194,6 @@ files = { { filename = "proj/licences", content=licences }, { filename = "proj/env", content=env }, { filename = "proj/config", content=pconfig }, - { filename = ".e2/e2version", content=e2version }, { filename = ".e2/version", content=version }, { filename = ".e2/syntax", content=syntax }, { filename = ".gitignore", content=gitignore }, @@ -214,6 +213,14 @@ for _,f in ipairs(files) do e2lib.abort(e:cat(re)) end end +rc, re = e2lib.write_extension_config(extensions) +if not rc then + e2lib.abort(e:cat(re)) +end +rc, re = e2lib.git(nil, "add", e2lib.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)) diff --git a/global/e2-install-e2.lua.in b/global/e2-install-e2.lua.in index a7d56ed..66e2fc3 100755 --- a/global/e2-install-e2.lua.in +++ b/global/e2-install-e2.lua.in @@ -26,6 +26,9 @@ ]] require("e2global") + +install_prefix = getinstallpath("PREFIX") + e2lib.init() e2option.documentation = [[ @@ -99,52 +102,53 @@ if not rc then e2lib.abort(e:cat(re)) end --- get e2 version -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") - ref = string.format("refs/heads/%s", branch) +e2lib.logf(2, "installing local tools") + +local extensions +if e2util.exists(e2lib.extension_config) then + extensions, re = e2lib.read_extension_config() + if not extensions then + e2lib.abort(e:cat(re)) + end else - ref = string.format("refs/tags/%s", tag) + -- parse .e2/e2version for compatibility to e2factory versions without + -- extension support (e2factory-2.3.0) + 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") + ref = string.format("refs/heads/%s", branch) + else + ref = string.format("refs/tags/%s", tag) + end + -- build an extension table pointing to e2factory core only + extensions = { + { + name = "e2factory", + ref=ref, + } + } end -e2lib.logf(2, "installing tool version: %s", ref) - rc, re = e2lib.chdir(".e2") if not rc then e2lib.abort(e:cat(re)) end -local _ext = {} -local extensions = {} --- 'e2factory' is handled like any other extension, but enabled by default -_ext["e2factory"] = true -exf = io.open("extensions", "r") -if exf then - for ex in exf:lines() do - _ext[ex] = true - end - exf:close() -end -for ex,_ in pairs(_ext) do - table.insert(extensions, ex) -end - for _,ex in ipairs(extensions) do -- change to the project root directory rc, re = e2lib.chdir(root .. "/.e2") if not rc then e2lib.abort(e:cat(re)) end - print("installing extension: " .. ex) + print(string.format("installing extension: %s (tag %s)", ex.name, ex.ref)) local server = config.site.e2_server - local location = string.format("%s/%s.git", config.site.e2_base, ex) - local destdir = ex + local location = string.format("%s/%s.git", config.site.e2_base, ex.name) + local destdir = ex.name local skip_checkout = false rc, re = e2lib.rm(destdir, "-fr") if not rc then @@ -158,7 +162,7 @@ for _,ex in ipairs(extensions) do e2lib.chdir(destdir) -- checkout ref - local args = string.format("--track -b tmp '%s'", ref) + local args = string.format("--track -b tmp '%s'", ex.ref) rc, re = e2lib.git(nil, "checkout", args) if not rc then e2lib.abort(e:cat(re)) diff --git a/scripts/e2-locate-project-root b/scripts/e2-locate-project-root index 50b8bcc..5606c3d 100755 --- a/scripts/e2-locate-project-root +++ b/scripts/e2-locate-project-root @@ -1,6 +1,6 @@ #!/bin/sh export LC_ALL=C -while [ '!' -f .e2/e2version ] ; do +while [ '!' -d .e2 ] ; do if [ "$PWD" = "/" ] ; then echo >&2 \ "e2-locate-project-root: Not in a project environment." -- 2.39.5