]> git.e2factory.org Git - e2factory.git/commitdiff
env: use environment module
authorGordon Hecker <gh@emlix.com>
Tue, 22 Dec 2009 14:03:32 +0000 (15:03 +0100)
committerGordon Hecker <gh@emlix.com>
Fri, 12 Feb 2010 09:51:57 +0000 (10:51 +0100)
Signed-off-by: Gordon Hecker <gh@emlix.com>
local/e2build.lua
local/e2tool.lua

index 1da91f9a68fd1fd10c9df2a2f97f8a7612445cdc..e68344705f27fd9edfeddec2711cc7c1b655818b 100644 (file)
@@ -179,17 +179,19 @@ function e2build.build_config(info, r)
   tab.buildrc_file = string.format("buildrc")
   tab.buildrc_noinit_file = string.format("buildrc-noinit")
   tab.profile = string.format("/tmp/bashrc")
-  tab.builtin_env = {
-       E2_BUILD_NUMBER = res.buildno,
-       E2_TMPDIR = res.build_config.Tc,
-       E2_RESULT = r,
-       E2_RELEASE_ID = info.project.release_id,
-       E2_PROJECT_NAME = info.project.name,
-       E2_BUILDID = buildid,
-       T = res.build_config.Tc,
-       r = r,
-       R = r,
-  }
+  tab.builtin_env = environment.new()
+  tab.builtin_env:set("E2_BUILD_NUMBER", res.buildno)
+  tab.builtin_env:set("E2_TMPDIR", res.build_config.Tc)
+  tab.builtin_env:set("E2_RESULT", r)
+  tab.builtin_env:set("E2_RELEASE_ID", info.project.release_id)
+  tab.builtin_env:set("E2_PROJECT_NAME", info.project.name)
+  tab.builtin_env:set("E2_BUILDID", buildid)
+  tab.builtin_env:set("T", res.build_config.Tc)
+  tab.builtin_env:set("r", r)
+  tab.builtin_env:set("R", r)
+  tab.env = environment.new()
+  tab.env:merge(info.global_env)
+  tab.env:merge(res.env, true)
   e2lib.logf(4, "build config for result %s: ", r)
   for k,v in pairs(tab) do
      v = tostring(v)
@@ -493,7 +495,7 @@ function e2build.sources(info, r, return_flags)
     local e = new_error("installing environment files failed")
     -- install builtin environment variables
     local file = string.format("%s/env/builtin", res.build_config.T)
-    rc, re = write_environment_script(res.build_config.builtin_env, r, file)
+    rc, re = write_environment_script(res.build_config.builtin_env, file)
     if not rc then
       return false, e:cat(re)
     end
@@ -501,7 +503,7 @@ function e2build.sources(info, r, return_flags)
                                                        res.build_config.Tc))
     -- install project specific environment variables
     local file = string.format("%s/env/env", res.build_config.T)
-    rc, re = write_environment_script(info.env, r, file)
+    rc, re = write_environment_script(res.build_config.env, file)
     if not rc then
       return false, e:cat(re)
     end
@@ -928,31 +930,19 @@ function write_build_driver(info, r, destdir)
 end
 
 --- write the environment script for a result into a file
--- @param env table: the env table
--- @param r string: the result name
+-- @param env env object
 -- @param file string: the target filename
 -- @return bool
 -- @return an error object on failure
-function write_environment_script(env, r, file)
+function write_environment_script(env, file)
        local e = new_error("writing environment script")
        local f, msg = io.open(file, "w")
        if not f then
                e:append("%s: %s", file, msg)
                return false, e
        end
-       -- export global variables first 
-       for k,v in pairs(env) do
-               if type(v) == "string" then
-                       f:write(string.format("%s=\"%s\"\n", k, v))
-               end
-       end
-       -- export result local variables
-       for k,v in pairs(env) do
-               if type(v) == "table" and r == k then
-                       for k2, v2 in pairs(v) do
-                               f:write(string.format("%s=\"%s\"\n", k2, v2))
-                       end
-               end
+       for var, val in env:iter() do
+               f:write(string.format("%s=\"%s\"\n", var, val))
        end
        f:close()
        return true, nil
@@ -1105,14 +1095,14 @@ function e2build.collect_project(info, r, return_flags)
                local file, line
                -- generate environment script
                file = string.format("%s/env", destdir)
-               rc, re = write_environment_script(info.env, n, file)
+               rc, re = write_environment_script(rn.build_config.env, file)
                if not rc then
                        return false, e:cat(re)
                end
                -- generate builtin environment script
                local file = string.format("%s/builtin", destdir)
                rc, re = write_environment_script(
-                                       rn.build_config.builtin_env, n, file)
+                                       rn.build_config.builtin_env, file)
                if not rc then
                        return false, e:cat(re)
                end
index b14ea4deab2b79176d08872e054181fcf6dc1a2b..c9187182ae2445d7e242ab85092526b9fea4ae6f 100644 (file)
@@ -504,8 +504,8 @@ The newest configuration syntax supported by the tools is %s.
   -- read environment configuration
   info.env = {}                -- global and result specfic env (deprecated)
   info.env_files = {}   -- a list of environment files
-  info.global_env = {} -- global env only
-  info.result_env = {}  -- result specific env only
+  info.global_env = environment.new()
+  info.result_env = {} -- result specific env only
   local rc, re = e2tool.load_env_config(info, "proj/env")
   if not rc then
     return false, e:cat(re)
@@ -627,20 +627,16 @@ The newest configuration syntax supported by the tools is %s.
   end
 
   -- distribute result specific environment to the results
+  for r, res in pairs(info.results) do
+    res.env = info.result_env[r] or environment.new()
+  end
+
+  -- check for environment for non-existent results
   for r, t in pairs(info.result_env) do
     if not info.results[r] then
       return false, e:append(
                "configured environment for non existent result: %s", r)
     end
-    info.results[r].env = info.results[r].env or {}
-    for key,val in pairs(t) do
-      if info.results[r].env[key] then
-        e2lib.warn("WHINT", "ignoring duplicate environment from global "..
-                       "configuration for result: %s %s=%s", r, key, val)
-      else
-        info.results[r].env[key] = val
-      end
-    end
   end
 
   -- servers
@@ -1788,24 +1784,11 @@ end
 -- @param resultname string: name of a result
 -- @return table: environment variables valid for the result
 function e2tool.env_by_result(info, resultname)
-       local e = {}
-       -- take global variables first
-       for k,v in pairs(info.env) do
-               if type(v) == "string" or
-                  type(v) == "number" then
-                       e[k] = v
-               end
-       end
-       -- result specific variables override global ones
-       for k,v in pairs(info.env) do
-               if type(v) == "table" and
-                  k == resultname then
-                       for k1,v1 in pairs(v) do
-                               e[k1] = v1
-                       end
-               end
-       end
-       return e
+       local res = info.results[resultname]
+       local env = environment.new()
+       env:merge(info.global_env, false)
+       env:merge(res.env, true)
+       return env
 end
 
 --- envid: calculate a value represennting the environment for a result
@@ -1813,13 +1796,7 @@ end
 -- @param resultname string: name of a result
 -- @return string: envid value
 function e2tool.envid(info, resultname)
-       local e = e2tool.env_by_result(info, resultname)
-       local hc = hash.hash_start()
-       for k,v in pairs(e) do
-               hc:hash_line(string.format("%s=%s", k, v))
-       end
-       local envid = hc:hash_finish()
-       return envid
+       return e2tool.env_by_result(info, resultname):id()
 end
 
 function e2tool.add_source_result(info, sourcename, source_set)
@@ -3018,7 +2995,7 @@ function e2tool.load_env_config(info, file)
        if type(val) == "string" then
          e2lib.logf(4, "global env: %-15s = %-15s", var, val)
          info.env[var] = val
-         info.global_env[var] = val
+         info.global_env:set(var, val)
        elseif type(val) == "table" then
          for var1, val1 in pairs(val) do
             if type(var1) ~= "string" or
@@ -3032,8 +3009,8 @@ function e2tool.load_env_config(info, file)
                                                        var1, val1, var)
            info.env[var] = info.env[var] or {}
            info.env[var][var1] = val1
-           info.result_env[var] = info.result_env[var] or {}
-           info.result_env[var][var1] = val1
+           info.result_env[var] = info.result_env[var] or environment.new()
+           info.result_env[var]:set(var1, val1)
          end
        end
       end