From d5e1d12df28cc5c88965ac6bef70a2636eac3904 Mon Sep 17 00:00:00 2001 From: "rk@emlix.com" Date: Thu, 30 Apr 2009 12:29:18 +0200 Subject: [PATCH] adding support for subdirectories in src/ and res/ --- doc/man/e2config.5 | 16 ++++++ doc/manual/results.text | 5 ++ local/e2build.lua | 2 +- local/e2tool.lua | 106 ++++++++++++++++++++++++++++++++++++---- 4 files changed, 118 insertions(+), 11 deletions(-) diff --git a/doc/man/e2config.5 b/doc/man/e2config.5 index 1dfc24d..77de841 100644 --- a/doc/man/e2config.5 +++ b/doc/man/e2config.5 @@ -37,12 +37,23 @@ sub-directories: | | |-- config result configuration file | | |-- build-script build instructions executed in chroot | | o-- project-local files (related to result) + |-- results can be grouped in subfolders +| | o-- +| | | |-- config +| | | |-- build-script +| | | o-- + | : | : | o-- src source descriptions for each source |-- one directory for each source | |-- config source configuration | o-- project-local files (related to source) + |-- sources can be groupd in subfolders + | o-- + | | |-- config + | | o-- + | : : .fi @@ -291,6 +302,11 @@ patches referenced by configuration entries in the "src" directory which are to be copied into the build environment. Only the sources given in this property will be copied/extracted. +It is possible to group sources in subfolders. When a folder for a source does +NOT contain a config file e2 factory tries to search its subfolders for further +sources. To name sources in subfolders you have to add the foldername to the source name +separated with a dot (e.g. xorg.libXau). This occurrs when specify sources in the result config. + The properties may omit the "{ ... }" braces, if only a single entry is used. Note that you can specify multiple sources for any single result. diff --git a/doc/manual/results.text b/doc/manual/results.text index 9a55da5..43b99a9 100644 --- a/doc/manual/results.text +++ b/doc/manual/results.text @@ -20,6 +20,11 @@ in addition: In addition creating a `build-script` is required. The build script must be stored in `./res//build-script` and runs in the build environment. +It is possible to group the results in subfolders. When a folder for a result does +NOT contain a config file e2 factory tries to search its subfolders for further +results. To name results in subfolders you have to add the foldername to the result name +separated with a dot (e.g. xorg.libXau). This occurrs when specify dependencies oder sources. + The `collect_project` flag provides a tree holding everything to rebuild the result configured in `collect_project_default_result` in $E2_TMPDIR/project. The user must write a build-script to package that tree to a file in diff --git a/local/e2build.lua b/local/e2build.lua index bf59e0d..32f92be 100644 --- a/local/e2build.lua +++ b/local/e2build.lua @@ -447,7 +447,7 @@ function e2build.sources(info, r, return_flags) local res = info.results[r] local rc, re local e = new_error("installing build script") - local location = e2lib.resultbuildscript(r) + local location = e2lib.resultbuildscript(info.results[r].directory) local destdir = string.format("%s/script", res.build_config.T) rc, re = transport.fetch_file(info.root_server, location, destdir, nil) if not rc then diff --git a/local/e2tool.lua b/local/e2tool.lua index 5974ee3..6b51a64 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -134,6 +134,7 @@ local config_syntax_compat = { -- @field url string: server url -- @field cachable bool: cachable flag -- @field cache bool: cache enable flag +-- @field directory string: dirname where the config and build-script reside --- table of chroot configuration -- @name chroot @@ -1350,7 +1351,7 @@ function e2tool.pbuildid(info, resultname) r.envid = e2tool.envid(info, resultname) hc:hash_line(r.envid) if not r.pseudo_result then - local location = e2lib.resultbuildscript(resultname) + local location = e2lib.resultbuildscript(info.results[resultname].directory) local hash, re = e2tool.hash_file(info,info.root_server_name, location) if not hash then @@ -1699,7 +1700,7 @@ function e2tool.check_result(info, resultname) res.buildno = "0" end local build_script = string.format("%s/%s", info.root, - e2lib.resultbuildscript(resultname)) + e2lib.resultbuildscript(info.results[resultname].directory)) if not e2lib.isfile(build_script) then e:append("build-script does not exist: %s", build_script) end @@ -2304,37 +2305,107 @@ function e2tool.check_chroot_config(info) return true end +local function gather_result_paths(info, basedir, results) + results = results or {} + for dir in e2lib.directory(info.root .. "/" .. e2lib.resultdir(basedir)) do + local tmp + if basedir then + tmp = basedir .. "/" .. dir + else + tmp = dir + end + if e2util.exists(e2lib.resultconfig(tmp)) then + table.insert(results, tmp) + else + --try subfolder + gather_result_paths(info,tmp, results) + end + end + return results +end + + +local function gather_source_paths(info, basedir, sources) + sources = sources or {} + for dir in e2lib.directory(info.root .. "/" .. e2lib.sourcedir(basedir)) do + local tmp + if basedir then + tmp = basedir .. "/" .. dir + else + tmp = dir + end + if e2util.exists(e2lib.sourceconfig(tmp)) then + table.insert(sources, tmp) + else + --try subfolder + gather_source_paths(info,tmp, sources) + end + end + return sources +end + +-- checks for valid characters in str +local function checkFilenameInvalidCharacters(str) + if not str:match("^[-_0-9a-zA-Z/]+$") then + return false + else + return true + end +end + +-- replaces all slashed in str with dots +local function slashToDot(str) + return string.gsub(str,"/",".",100) +end + function e2tool.load_source_config(info) local e = new_error("error loading source configuration") info.sources = {} - for src in e2lib.directory(info.root .. "/src") do + + for _,src in ipairs(gather_source_paths(info)) do local list, re local path = e2lib.sourceconfig(src) local types = { "e2source", } + + if not checkFilenameInvalidCharacters(src) then + e:append("invalid source file name: %s") + e:append("only digits, alphabetic characters, and `-', `_' and `/' ".. + "are allowed") + return false, e + end + list, re = e2tool.load_user_config2(info, path, types) if not list then return false, e:cat(re) end + + for _,item in ipairs(list) do local name = item.data.name + if not name and #list == 1 then e2lib.warnf("WDEFAULT", "`name' attribute missing in source config.") e2lib.warnf("WDEFAULT", " Defaulting to directory name") - item.data.name = src - name = src + item.data.directory = src + item.data.name = slashToDot(src) + name = slashToDot(src) end + if not name then return false, e:append("`name' attribute missing in source config") end - if not name:match("^[-._0-9a-zA-Z]+$") then + + if not name:match("^[-_0-9a-zA-Z.]+$") then e:append("invalid source name: %s") e:append("only digits, alphabetic characters, and `-', `_' and `.' ".. "are allowed") return false, e end + if info.sources[name] then return false, e:append("duplicate source: %s", name) end + item.data.configfile = item.filename info.sources[name] = item.data end @@ -2345,10 +2416,19 @@ end function e2tool.load_result_config(info) local e = new_error("error loading result configuration") info.results = {} - for res in e2lib.directory(info.root .. "/" .. e2lib.resultdir()) do + + for _,res in ipairs(gather_result_paths(info)) do local list, re local path = e2lib.resultconfig(res) local types = { "e2result", } + + if not checkFilenameInvalidCharacters(res) then + e:append("invalid result file name: %s") + e:append("only digits, alphabetic characters, and `-', `_' and `/' ".. + "are allowed") + return false, e + end + list, re = e2tool.load_user_config2(info, path, types) if not list then return false, e:cat(re) @@ -2358,21 +2438,27 @@ function e2tool.load_result_config(info) end for _,item in ipairs(list) do local name = item.data.name + item.data.directory = res + if name and name ~= res then e:append("`name' attribute does not match configuration path") return false, e end - item.data.name = res - name = res - if not name:match("^[-._0-9a-zA-Z]+$") then + + item.data.name = slashToDot(res) + name = slashToDot(res) + + if not name:match("^[-_0-9a-zA-Z.]+$") then e:append("invalid result name: %s",name) e:append("only digits, alphabetic characters, and `-', `_' and `.' ".. "are allowed") return false, e end + if info.results[name] then return false, e:append("duplicate result: %s", name) end + item.data.configfile = item.filename info.results[name] = item.data end -- 2.39.5