From 6a8d3b24a15d35d234916f81849586060993bb07 Mon Sep 17 00:00:00 2001 From: Gordon Hecker Date: Tue, 27 Apr 2010 14:56:44 +0200 Subject: [PATCH] sources: allow assigning environment to sources This is done by assigning a dictionary to the 'env' attribute of a source configuration. The environment configured this way is merged into the environment of any result that uses the particular source. BuildId is handled by including the dictionary into the sourceid calculation. Signed-off-by: Gordon Hecker --- doc/manual/sources.text | 2 ++ local/cvs.lua | 1 + local/e2tool.lua | 3 +++ local/files.lua | 1 + local/git.lua | 20 ++++++++++++++++++++ local/svn.lua | 1 + templates/local/source.cvs | 4 ++++ templates/local/source.files | 4 ++++ templates/local/source.git | 4 ++++ templates/local/source.svn | 4 ++++ 10 files changed, 44 insertions(+) diff --git a/doc/manual/sources.text b/doc/manual/sources.text index b6687d5..eee5f67 100644 --- a/doc/manual/sources.text +++ b/doc/manual/sources.text @@ -10,6 +10,8 @@ generic configuration: * type: string * server: string * licences: (old: licence) table of strings +* env: dictionary, merged into result specific env for results that use + this source files source (type = files, default) diff --git a/local/cvs.lua b/local/cvs.lua index 08964dc..c43b224 100644 --- a/local/cvs.lua +++ b/local/cvs.lua @@ -322,6 +322,7 @@ function cvs.sourceid(info, sourcename, source_set) local hc = hash.hash_start() hash.hash_line(hc, src.name) hash.hash_line(hc, src.type) + hash.hash_line(hc, src._env:id()) for _,l in ipairs(src.licences) do hash.hash_line(hc, l) local licenceid, re = e2tool.licenceid(info, l) diff --git a/local/e2tool.lua b/local/e2tool.lua index 5772efd..4207f96 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -1657,6 +1657,9 @@ function env_by_result(info, resultname) local res = info.results[resultname] local env = environment.new() env:merge(info.global_env, false) + for _, s in ipairs(res.sources) do + env:merge(info.sources[s]._env, true) + end env:merge(res._env, true) return env end diff --git a/local/files.lua b/local/files.lua index 1b372f5..54886a5 100644 --- a/local/files.lua +++ b/local/files.lua @@ -324,6 +324,7 @@ function files.sourceid(info, sourcename, sourceset) local hc = hash.hash_start() hash.hash_line(hc, src.name) hash.hash_line(hc, src.type) + hash.hash_line(hc, src._env:id()) for _,l in ipairs(src.licences) do hash.hash_line(hc, l) local licenceid, re = e2tool.licenceid(info, l) diff --git a/local/git.lua b/local/git.lua index 3ab4758..bf9019c 100644 --- a/local/git.lua +++ b/local/git.lua @@ -188,6 +188,25 @@ function generic_validate_source(info, sourcename) if not src.type then e:append("source has no `type' attribute") end + if src.env and type(src.env) ~= "table" then + e:append("source has invalid `env' attribute") + else + if not src.env then + e2lib.warnf("WDEFAULT", + "source has no `env' attribute. Defaulting to empty dictionary") + src.env = {} + end + src._env = environment.new() + for k,v in pairs(src.env) do + if type(k) ~= "string" then + e:append("in `env' dictionary: key is not a string: %s", tostring(k)) + elseif type(v) ~= "string" then + e:append("in `env' dictionary: value is not a string: %s", tostring(v)) + else + src._env:set(k, v) + end + end + end if e:getcount() > 1 then return false, e end @@ -613,6 +632,7 @@ function git.sourceid(info, sourcename, sourceset) local hc = hash.hash_start() hash.hash_line(hc, src.name) hash.hash_line(hc, src.type) + hash.hash_line(hc, src._env:id()) for _,l in ipairs(src.licences) do hash.hash_line(hc, l) local licenceid, re = e2tool.licenceid(info, l) diff --git a/local/svn.lua b/local/svn.lua index 9f5fa2f..4772851 100644 --- a/local/svn.lua +++ b/local/svn.lua @@ -219,6 +219,7 @@ function svn.sourceid(info, sourcename, source_set) --OK local hc = hash.hash_start() hash.hash_line(hc, src.name) hash.hash_line(hc, src.type) + hash.hash_line(hc, src._env:id()) for _,l in pairs(src.licences) do hash.hash_line(hc, l) end diff --git a/templates/local/source.cvs b/templates/local/source.cvs index a5507b4..ebb1ddd 100644 --- a/templates/local/source.cvs +++ b/templates/local/source.cvs @@ -7,6 +7,10 @@ e2source { name = "name", -- the source type type = "cvs", + -- environment + env = { + key = "value", + }, -- a list of licences from proj/licences licences={ }, -- cvs specific attributes diff --git a/templates/local/source.files b/templates/local/source.files index b942182..846cfa1 100644 --- a/templates/local/source.files +++ b/templates/local/source.files @@ -7,6 +7,10 @@ e2source { name = "name", -- the source type type = "files", + -- environment + env = { + key = "value", + }, -- a list of licences from proj/licences licences = { }, -- the server. Files can specify their own one or inherit this one. diff --git a/templates/local/source.git b/templates/local/source.git index 7c61ab4..8701252 100644 --- a/templates/local/source.git +++ b/templates/local/source.git @@ -7,6 +7,10 @@ e2source { name = "name", -- the source type type = "git", + -- environment + env = { + key = "value", + }, -- a list of licences from proj/licences licences = { }, -- git specific attributes diff --git a/templates/local/source.svn b/templates/local/source.svn index 00853d0..a8f334d 100644 --- a/templates/local/source.svn +++ b/templates/local/source.svn @@ -7,6 +7,10 @@ e2source { name = "name", -- the source type type = "svn", + -- environment + env = { + key = "value", + }, -- a list of licences from proj/licences licences={ }, -- svn specific attributes -- 2.39.5