]> git.e2factory.org Git - e2factory.git/commitdiff
result: split build_config() into builtin_env()
authorTobias Ulmer <tu@emlix.com>
Tue, 14 Nov 2017 15:22:13 +0000 (16:22 +0100)
committerTobias Ulmer <tu@emlix.com>
Mon, 10 Dec 2018 17:00:11 +0000 (18:00 +0100)
Builtin env requires a BuildID, which in turn requires a fully set up
result with build modes etc. just to figure out the temporary directory.

Thus it makes sense to split build_config() into two methods operations,
with only builtin_env() requiring full setup work.

Signed-off-by: Tobias Ulmer <tu@emlix.com>
local/e2build.lua
local/result.lua
plugins/collect_project.lua

index e871d91782d229291c56244b5008291c0dd39ed4..b98d978b395572a5fe4767ff3ff2a18c579bb926 100644 (file)
@@ -540,12 +540,12 @@ end
 
 ---
 function e2build.build_process_class:_install_env(res, return_flags)
-    local rc, re, e, bc
+    local rc, re, e, bc, builtin_env
     e = err.new("installing environment files failed")
     bc = res:build_config()
 
     -- install builtin environment variables
-    rc, re = bc.builtin_env:tofile(e2lib.join(bc.T, "env/builtin"))
+    rc, re = res:builtin_env():tofile(e2lib.join(bc.T, "env/builtin"))
     if not rc then
         return false, e:cat(re)
     end
index 3f8af3c9a9367f1276fe983949c61a2006748150..565736194e26c23741cb93921c02248020cdde79 100644 (file)
@@ -141,6 +141,15 @@ function result.basic_result:build_config()
         self._type, self._name))
 end
 
+--- Get environment that's built into the result (E2_*, T, etc).
+-- Not part of the BuildID.
+-- @return Builtin environment
+-- @raise Error or assertion
+function result.basic_result:builtin_env()
+    error(err.new("called builtin_env() of result base class, type %s name %s",
+        self._type, self._name))
+end
+
 --- Get/set build_mode table for result. Needs to be set before certain
 -- operations, for example anything calculating the buildid.
 -- @param bm Optional build mode table to set a new one.
@@ -372,14 +381,7 @@ end
 
 ---
 function result.result_class:build_config()
-    local rc, re, e, buildid, bc, tmpdir, builddir
-
-    e = err.new("preparing build config for %s failed", self:get_name())
-
-    buildid, re = self:buildid()
-    if not buildid then
-        return false, e:cat(re)
-    end
+    local bc, tmpdir, builddir
 
     bc = {}
     tmpdir = string.format("%s/e2factory-%s.%s.%s-build/%s",
@@ -402,19 +404,33 @@ function result.result_class:build_config()
     bc.buildrc_noinit_file = "buildrc-noinit"
     bc.profile = "/tmp/bashrc"
 
-    bc.builtin_env = environment.new()
-    bc.builtin_env:set("E2_TMPDIR", bc.Tc)
-    bc.builtin_env:set("E2_RESULT", self:get_name())
-    bc.builtin_env:set("E2_RELEASE_ID", project.release_id())
-    bc.builtin_env:set("E2_PROJECT_NAME", project.name())
-    bc.builtin_env:set("E2_BUILDID", buildid)
-    bc.builtin_env:set("T", bc.Tc)
-    bc.builtin_env:set("r", self:get_name())
-    bc.builtin_env:set("R", self:get_name())
-
     return strict.readonly(bc)
 end
 
+---
+function result.result_class:builtin_env()
+    local builtin_env, buildid, re, bc
+
+    buildid, re = self:buildid()
+    if not buildid then
+        error(re)
+    end
+
+    bc = self:build_config()
+
+    builtin_env = environment.new()
+    builtin_env:set("E2_TMPDIR", bc.Tc)
+    builtin_env:set("E2_RESULT", self:get_name())
+    builtin_env:set("E2_RELEASE_ID", project.release_id())
+    builtin_env:set("E2_PROJECT_NAME", project.name())
+    builtin_env:set("E2_BUILDID", buildid)
+    builtin_env:set("T", bc.Tc)
+    builtin_env:set("r", self:get_name())
+    builtin_env:set("R", self:get_name())
+
+    return builtin_env
+end
+
 ---
 function result.result_class:merged_env()
     local e = environment.new()
index 1c4ad4d043e67a662e6fc4445f8861b0b5b8a4ed..28224f2be89d6ae675b0b1f4fe9c6c1408e03892 100644 (file)
@@ -260,7 +260,7 @@ local function _build_collect_project(self, res, return_flags)
     for depname in cp_depends:iter() do
         e2lib.logf(3, "result: %s", depname)
         local dep = result.results[depname]
-        local depbc = dep:build_config()
+        local builtin_env = dep:builtin_env()
 
         local destdir =
             e2lib.join(bc.T, "project", e2tool.resultdir(depname))
@@ -291,7 +291,7 @@ local function _build_collect_project(self, res, return_flags)
         end
         -- generate builtin environment script
         local file = e2lib.join(destdir, "builtin")
-        rc, re = environment.tofile(depbc.builtin_env, file)
+        rc, re = builtin_env:tofile(file)
         if not rc then
             return false, e:cat(re)
         end
@@ -498,6 +498,10 @@ function collect_project_class:build_config()
     return self._stdresult:build_config()
 end
 
+function collect_project_class:builtin_env()
+    return self._stdresult:builtin_env()
+end
+
 function collect_project_class:build_process_new()
     local bp = self._stdresult:build_process_new()