local build_process = {}
--- TODO
-local function linklast(info, r, return_flags)
- local res = info.results[r]
+local function linklast(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re
local e = err.new("creating link to last results")
-- calculate the path to the result
local server, location = res.build_mode.storage(info.project_location,
project.release_id())
- local buildid, re = e2tool.buildid(info, r)
+ local buildid, re = e2tool.buildid(info, resultname)
if not buildid then
return false, e:cat(re)
end
- local location1 = e2lib.join(location, r, buildid)
+ local location1 = e2lib.join(location, resultname, buildid)
local cache_flags = {
check_only = true
}
return false, e:cat(re)
end
-- create the last link
- local lnk_location = e2lib.join("out", r, "last")
+ local lnk_location = e2lib.join("out", resultname, "last")
local lnk, re = cache.file_path(info.cache, info.root_server_name, lnk_location)
if not lnk then
return false, e:cat(re)
-- return the path to the result
-- check if a result is already available
-- @param info
--- @param r string: result name
+-- @param resultname string: result name
-- @param return_flags table: return values through this table
-- @return bool
-- @return an error object on failure
-local function result_available(info, r, return_flags)
- local res = info.results[r]
+local function result_available(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re
local buildid, sbid
- local e = err.new("error while checking if result is available: %s", r)
+ local e = err.new("error while checking if result is available: %s", resultname)
local columns = tonumber(e2lib.globals.osenv["COLUMNS"])
- buildid, re = e2tool.buildid(info, r)
+ buildid, re = e2tool.buildid(info, resultname)
if not buildid then
return false, e:cat(re)
end
if res.playground then
return_flags.message = e2lib.align(columns,
- 0, string.format("building %-20s", r),
+ 0, string.format("building %-20s", resultname),
columns, string.format("[%s] [playground]", sbid))
return_flags.stop = false
return true, nil
if res.build_mode.source_set() == "working-copy" or
res.force_rebuild == true then
return_flags.message = e2lib.align(columns,
- 0, string.format("building %-20s", r),
+ 0, string.format("building %-20s", resultname),
columns, string.format("[%s]", sbid))
return_flags.stop = false
return true, nil
local dep_set = res.build_mode.dep_set(buildid)
-- cache the result
- local result_location = e2lib.join(location, r, dep_set, "result.tar")
+ local result_location = e2lib.join(location, resultname, dep_set, "result.tar")
local cache_flags = {}
rc, re = cache.cache_file(info.cache, server, result_location, cache_flags)
if not rc then
if not rc then
-- result is not available. Build.
return_flags.message = e2lib.align(columns,
- 0, string.format("building %-20s", r),
+ 0, string.format("building %-20s", resultname),
columns, string.format("[%s]", sbid))
return_flags.stop = false
return true, nil
-- and push the updated metadata to the server again, if the result
-- exists on the server.
]]
- rc, re = linklast(info, r, return_flags)
+ rc, re = linklast(info, resultname, return_flags)
if not rc then
return false, e:cat(re)
end
-- return true
return_flags.message = e2lib.align(columns,
- 0, string.format("skipping %-20s", r),
+ 0, string.format("skipping %-20s", resultname),
columns, string.format("[%s]", sbid))
return_flags.stop = true
return true, nil
-- @field T string: absolute path to the temporary build directory
-- inside chroot
-- @field Tc string: same as c.T but relative to c
--- @field r string: result name
+-- @field resultname string: result name
-- @field chroot_call_prefix XXX
-- @field buildlog string: build log file
-- @field scriptdir XXX
--- Generate build_config and store in res.build_config.
-- @param info Info table.
--- @param r Result name (string).
+-- @param resultname Result name (string).
-- @return True on success, false on error.
-- @return Error object on failure.
-function e2build.build_config(info, r)
- local e = err.new("setting up build configuration for result `%s' failed", r)
- local res = info.results[r]
+function e2build.build_config(info, resultname)
+ local e = err.new("setting up build configuration for result `%s' failed", resultname)
+ local res = info.results[resultname]
if not res then
- return false, e:append("no such result: %s", r)
+ return false, e:append("no such result: %s", resultname)
end
- local buildid, re = e2tool.buildid(info, r)
+ local buildid, re = e2tool.buildid(info, resultname)
if not buildid then
return false, e:cat(re)
end
buildconfig.PATCHLEVEL, e2lib.globals.osenv["USER"])
local builddir = "tmp/e2"
- bc.base = e2lib.join(tmpdir, project.name(), r)
+ bc.base = e2lib.join(tmpdir, project.name(), resultname)
bc.c = e2lib.join(bc.base, "chroot")
bc.chroot_marker = e2lib.join(bc.base, "e2factory-chroot")
bc.chroot_lock = e2lib.join(bc.base, "e2factory-chroot-lock")
- bc.T = e2lib.join(tmpdir, project.name(), r, "chroot", builddir)
+ bc.T = e2lib.join(tmpdir, project.name(), resultname, "chroot", builddir)
bc.Tc = e2lib.join("/", builddir)
- bc.r = r
+ bc.r = resultname
bc.chroot_call_prefix = info.chroot_call_prefix[project.chroot_arch()]
- bc.buildlog = string.format("%s/log/build.%s.log", info.root, r)
+ bc.buildlog = string.format("%s/log/build.%s.log", info.root, resultname)
bc.scriptdir = "script"
bc.build_driver = ""
bc.build_driver_file = "build-driver"
bc.profile = "/tmp/bashrc"
bc.builtin_env = environment.new()
bc.builtin_env:set("E2_TMPDIR", bc.Tc)
- bc.builtin_env:set("E2_RESULT", r)
+ bc.builtin_env:set("E2_RESULT", resultname)
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", r)
- bc.builtin_env:set("R", r)
+ bc.builtin_env:set("r", resultname)
+ bc.builtin_env:set("R", resultname)
res.build_config = strict.lock(bc)
end
--- TODO
-local function chroot_lock(info, r, return_flags)
- local res = info.results[r]
+local function chroot_lock(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re
local e = err.new("error locking chroot")
rc, re = e2lib.mkdir_recursive(res.build_config.c)
end
--- TODO
-local function chroot_unlock(info, r, return_flags)
- local res = info.results[r]
+local function chroot_unlock(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re
local e = err.new("error unlocking chroot")
rc, re = e2lib.globals.lock:unlock(res.build_config.chroot_lock)
end
--- TODO
-local function setup_chroot(info, r, return_flags)
- local res = info.results[r]
+local function setup_chroot(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re
local e = err.new("error setting up chroot")
-- create the chroot path and create the chroot marker file without root
--- Enter playground.
-- @param info
--- @param r
+-- @param resultname
-- @param chroot_command (optional)
-- @return True on success, false on error.
-- @return Error object on failure.
-function e2build.enter_playground(info, r, chroot_command)
+function e2build.enter_playground(info, resultname, chroot_command)
local rc, re, e, res, e2_su, cmd
- res = info.results[r]
+ res = info.results[resultname]
e = err.new("entering playground")
e2_su = tools.get_tool("e2-su-2.2")
end
--- TODO
-local function fix_permissions(info, r, return_flags)
- local res = info.results[r]
+local function fix_permissions(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re
local e = err.new("fixing permissions failed")
e2lib.log(3, "fix permissions")
end
--- TODO
-local function playground(info, r, return_flags)
- local res = info.results[r]
+local function playground(info, resultname, return_flags)
+ local res = info.results[resultname]
if res.playground then
- return_flags.message = string.format("playground done for: %-20s", r)
+ return_flags.message = string.format("playground done for: %-20s", resultname)
return_flags.stop = true
return true, nil
end
end
--- TODO
-local function runbuild(info, r, return_flags)
- local res = info.results[r]
+local function runbuild(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re, out
local e = err.new("build failed")
- e2lib.logf(3, "building %s ...", r)
+ e2lib.logf(3, "building %s ...", resultname)
local e2_su, re = tools.get_tool("e2-su-2.2")
if not e2_su then
return false, e:cat(re)
e2tool.reset_umask(info)
if rc ~= 0 then
eio.fclose(out)
- e = err.new("build script for %s failed with exit status %d", r, rc)
+ e = err.new("build script for %s failed with exit status %d", resultname, rc)
e:append("see %s for more information", res.build_config.buildlog)
return false, e
end
end
--- TODO
-local function chroot_remove(info, r, return_flags)
- local res = info.results[r]
+local function chroot_remove(info, resultname, return_flags)
+ local res = info.results[resultname]
local e = err.new("removing chroot failed")
e2tool.set_umask(info)
local rc, re = e2lib.e2_su_2_2({"remove_chroot_2_3", res.build_config.base})
end
--- TODO
-local function chroot_cleanup(info, r, return_flags)
- local res = info.results[r]
+local function chroot_cleanup(info, resultname, return_flags)
+ local res = info.results[resultname]
-- do not remove chroot if the user requests to keep it
if res.keep_chroot then
return true, nil
end
- return chroot_remove(info, r, return_flags)
+ return chroot_remove(info, resultname, return_flags)
end
--- TODO
-local function chroot_cleanup_if_exists(info, r, return_flags)
- local res = info.results[r]
- if chroot_remove(info, r, return_flags) then
- return chroot_cleanup(info, r, return_flags)
+local function chroot_cleanup_if_exists(info, resultname, return_flags)
+ local res = info.results[resultname]
+ if chroot_remove(info, resultname, return_flags) then
+ return chroot_cleanup(info, resultname, return_flags)
end
return true, nil
end
--- check if a chroot exists for this result
-- @param info Info table
--- @param r Result name
+-- @param resultname Result name
-- @return True if chroot for result could be found, false otherwise.
-function e2build.chroot_exists(info, r)
- local res = info.results[r]
+function e2build.chroot_exists(info, resultname)
+ local res = info.results[resultname]
return e2lib.isfile(res.build_config.chroot_marker)
end
--- TODO
-function e2build.unpack_result(info, r, dep, destdir)
- local res = info.results[r]
+function e2build.unpack_result(info, resultname, dep, destdir)
+ local res = info.results[resultname]
local rc, re
local e = err.new("unpacking result failed: %s", dep)
local d = info.results[dep]
--- write build driver files
-- @param info
--- @param r string: result name
+-- @param resultname string: result name
-- @param destdir string: where to store the scripts
-- @return bool
-- @return an error object on failure
-function e2build.write_build_driver(info, r, destdir)
+function e2build.write_build_driver(info, resultname, destdir)
local rc, re, e, res, bd, buildrc_noinit_file, buildrc_file
local build_driver_file
e = err.new("generating build driver script failed")
- res = info.results[r]
+ res = info.results[resultname]
bd = {
string.format("source %s/env/builtin\n", res.build_config.Tc),
end
--- TODO
-local function sources(info, r, return_flags)
+local function sources(info, resultname, return_flags)
local e = err.new("installing sources")
local i, k, l, source, cp
-- prepare_source
-- end
- local function append_to_build_driver(info, r, script)
- local res = info.results[r]
+ local function append_to_build_driver(info, resultname, script)
+ local res = info.results[resultname]
res.build_config.build_driver =
res.build_config.build_driver .. string.format("%s\n", script)
end
- local function install_directory_structure(info, r, return_flags)
- local res = info.results[r]
+ local function install_directory_structure(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re
local e = err.new("installing directory structure")
local dirs = {"out", "init", "script", "build", "root", "env", "dep"}
return true, nil
end
- local function install_build_script(info, r, return_flags)
- local res = info.results[r]
+ local function install_build_script(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re
local e = err.new("installing build script")
- local location = e2tool.resultbuildscript(info.results[r].directory)
+ local location = e2tool.resultbuildscript(info.results[resultname].directory)
local destdir = e2lib.join(res.build_config.T, "script")
rc, re = transport.fetch_file(info.root_server, location, destdir, nil)
if not rc then
return true, nil
end
- local function install_env(info, r, return_flags)
- local res = info.results[r]
+ local function install_env(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re
local e = err.new("installing environment files failed")
-- install builtin environment variables
if not rc then
return false, e:cat(re)
end
- append_to_build_driver(info, r, string.format("source %s/env/builtin",
+ append_to_build_driver(info, resultname, string.format("source %s/env/builtin",
res.build_config.Tc))
-- install project specific environment variables
local file = e2lib.join(res.build_config.T, "env/env")
- rc, re = write_environment_script(e2tool.env_by_result(info, r), file)
+ rc, re = write_environment_script(e2tool.env_by_result(info, resultname), file)
if not rc then
return false, e:cat(re)
end
- append_to_build_driver(info, r, string.format("source %s/env/env",
+ append_to_build_driver(info, resultname, string.format("source %s/env/env",
res.build_config.Tc))
return true, nil
end
- local function install_init_files(info, r, return_flags)
- local res = info.results[r]
+ local function install_init_files(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re
local e = err.new("installing init files")
for x, re in e2lib.directory(info.root .. "/proj/init") do
if not rc then
return false, e:cat(re)
end
- append_to_build_driver(info, r,
+ append_to_build_driver(info, resultname,
string.format("source %s/init/%s", res.build_config.Tc, x))
end
end
return true, nil
end
- local function install_build_driver(info, r, return_flags)
- local res = info.results[r]
+ local function install_build_driver(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re
local e = err.new("writing build driver script failed")
local bc = res.build_config
local destdir = e2lib.join(bc.T, bc.scriptdir)
- rc, re = e2build.write_build_driver(info, r, destdir)
+ rc, re = e2build.write_build_driver(info, resultname, destdir)
if not rc then
return false, e:cat(re)
end
return true, nil
end
- local function install_build_time_dependencies(info, r, return_flags)
- local res = info.results[r]
+ local function install_build_time_dependencies(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re
local e = err.new("installing build time dependencies")
local deps
- deps, re = e2tool.dlist(info, r)
+ deps, re = e2tool.dlist(info, resultname)
if not deps then
return false, e:cat(re)
end
for i, dep in pairs(deps) do
local destdir = e2lib.join(res.build_config.T, "dep", dep)
- rc, re = e2build.unpack_result(info, r, dep, destdir)
+ rc, re = e2build.unpack_result(info, resultname, dep, destdir)
if not rc then
return false, e:cat(re)
end
return true, nil
end
- local function install_sources(info, r, return_flags)
- local res = info.results[r]
+ local function install_sources(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re
local e = err.new("installing sources")
e2lib.log(3, "install sources")
}
for _,f in ipairs(steps) do
local rflags = {}
- local rc, re = f(info, r, rflags)
+ local rc, re = f(info, resultname, rflags)
if not rc then
return false, re
end
--- deploy a result to the archive
-- @param info
--- @param r string: result name
+-- @param resultname string: result name
-- @param tmpdir Directory containing the result etc.
-- @return bool
-- @return an error object on failure
-local function deploy(info, r, tmpdir)
+local function deploy(info, resultname, tmpdir)
--[[
This function is given a temporary directory that contains
the unpacked result structure and the result tarball itself as follows:
-- result/files/*
-- -> releases:<project>/<archive>/<release_id>/<result>/files/*
--]]
- local res = info.results[r]
+ local res = info.results[resultname]
if not res.build_mode.deploy then
e2lib.log(4, "deployment disabled for this build mode")
return true
info.project_location, project.release_id())
-- do not re-deploy if this release was already done earlier
- local location1 = e2lib.join(location, r, "checksums")
+ local location1 = e2lib.join(location, resultname, "checksums")
local cache_flags = {
cache = false,
}
end
- e2lib.logf(1, "deploying %s to %s:%s", r, server, location)
+ e2lib.logf(1, "deploying %s to %s:%s", resultname, server, location)
local cache_flags = {}
for _,f in ipairs(files) do
local sourcefile, location1
sourcefile = e2lib.join(resdir, f)
- location1 = e2lib.join(location, r, f)
+ location1 = e2lib.join(location, resultname, f)
rc, re = cache.push_file(info.cache, sourcefile, server, location1,
cache_flags)
if not rc then
--- store the result
-- @param info
--- @param r string: result name
+-- @param resultname string: result name
-- @param return_flags table
-- @return bool
-- @return an error object on failure
-local function store_result(info, r, return_flags)
- local res = info.results[r]
+local function store_result(info, resultname, return_flags)
+ local res = info.results[resultname]
local rc, re
local e = err.new("fetching build results from chroot")
local dt
local server, location = res.build_mode.storage(info.project_location,
project.release_id())
- local buildid, re = e2tool.buildid(info, r)
+ local buildid, re = e2tool.buildid(info, resultname)
if not buildid then
return false, re
end
local sourcefile = e2lib.join(tmpdir, "result.tar")
- local location1 = e2lib.join(location, r, buildid, "result.tar")
+ local location1 = e2lib.join(location, resultname, buildid, "result.tar")
local cache_flags = {
try_hardlink = true,
}
if not rc then
return false, e:cat(re)
end
- rc, re = deploy(info, r, tmpdir)
+ rc, re = deploy(info, resultname, tmpdir)
if not rc then
return false, e:cat(re)
end
--- build a result
-- @param info
--- @param result string: result name
+-- @param resultname string: result name
-- @param return_flags
-- @return bool
-- @return an error object on failure
-local function build_result(info, result, return_flags)
- e2lib.logf(3, "building result: %s", result)
- local res = info.results[result]
+local function build_result(info, resultname, return_flags)
+ e2lib.logf(3, "building result: %s", resultname)
+ local res = info.results[resultname]
for _,f in ipairs(build_process) do
local t1 = os.time()
local flags = {}
- local rc, re = f.func(info, result, flags)
+ local rc, re = f.func(info, resultname, flags)
local t2 = os.time()
local deltat = os.difftime(t2, t1)
- e2lib.logf(3, "timing: step: %s [%s] %d", f.name, result, deltat)
+ e2lib.logf(3, "timing: step: %s [%s] %d", f.name, resultname, deltat)
if not rc then
-- do not insert an error message from this layer.
return false, re
function e2build.build_results(info, results)
e2lib.logf(3, "building results")
- for _, r in ipairs(results) do
- local e = err.new("building result failed: %s", r)
+ for _, resultname in ipairs(results) do
+ local e = err.new("building result failed: %s", resultname)
local flags = {}
local t1 = os.time()
- local rc, re = build_result(info, r, flags)
+ local rc, re = build_result(info, resultname, flags)
if not rc then
return false, e:cat(re)
end
local t2 = os.time()
local deltat = os.difftime(t2, t1)
- e2lib.logf(3, "timing: result [%s] %d", r, deltat)
+ e2lib.logf(3, "timing: result [%s] %d", resultname, deltat)
if flags.stop then
return true, nil
end