]> git.e2factory.org Git - e2factory.git/commitdiff
extension config in .e2/extensions is a lua table now
authorGordon Hecker <gh@emlix.com>
Tue, 5 May 2009 14:00:23 +0000 (16:00 +0200)
committerGordon Hecker <gh@emlix.com>
Tue, 5 May 2009 15:08:12 +0000 (17:08 +0200)
.e2/e2version becomes obsolete, the user must move the configuration to
use this version of e2factory.

Signed-off-by: Gordon Hecker <gh@emlix.com>
generic/e2lib.lua
global/e2-create-project.lua.in
global/e2-install-e2.lua.in
scripts/e2-locate-project-root

index 9f8bc59848e5f21b5258e1fcbb3bc9f4ee84e329..76ec2270487034b5ec71c5c6e8b439308c01dc06 100644 (file)
@@ -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
index f0060222c088e62aa4b275925e319d3878a9e228..bcd75de1499dfb7049704d3b0c7bfc2c775c281e 100755 (executable)
@@ -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))
index a7d56ed4d07dc868ec9233181df663e9bfcb4c98..66e2fc3e5b47237066675ed6eb99d86bf9c18483 100755 (executable)
@@ -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))
index 50b8bccc909356aeb041ab87a59b70e0879eb70f..5606c3d99b08ca586e1cb2347b1b343c965fdc36 100755 (executable)
@@ -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."