From: Tobias Ulmer Date: Tue, 14 Nov 2017 15:22:13 +0000 (+0100) Subject: result: split build_config() into builtin_env() X-Git-Tag: e2factory-2.3.18rc1~96 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=32aa54269179b8e4276696c369e015e7cdca4205;p=e2factory.git result: split build_config() into builtin_env() 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 --- diff --git a/local/e2build.lua b/local/e2build.lua index e871d91..b98d978 100644 --- a/local/e2build.lua +++ b/local/e2build.lua @@ -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 diff --git a/local/result.lua b/local/result.lua index 3f8af3c..5657361 100644 --- a/local/result.lua +++ b/local/result.lua @@ -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() diff --git a/plugins/collect_project.lua b/plugins/collect_project.lua index 1c4ad4d..28224f2 100644 --- a/plugins/collect_project.lua +++ b/plugins/collect_project.lua @@ -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()