return c
end
+local _cache
+--- Set or return the current cache object.
+-- @param the_cache New cache object. Optional.
+-- @return Current cache object.
+-- @raise Assertion if unset/invalid
+function cache.cache(the_cache)
+ if the_cache then
+ _cache = the_cache
+ end
+ assertIsTable(_cache)
+ assert(_cache._name == "local cache")
+ return _cache
+end
+
--- Add local servers to the cache configuration. As the name implies,
-- this function should not be called from a global context.
-- @param c cache object
error(e:cat(re))
end
- local scache, re = cache.setup_cache(config)
- if not scache then
+ rc, re = cache.setup_cache(config)
+ if not rc then
error(e:cat(re))
end
- rc, re = cache.setup_cache_apply_opts(scache)
+ cache.cache(rc)
+
+ rc, re = cache.setup_cache_apply_opts(cache.cache())
if not rc then
error(e:cat(re))
end
error(e:cat(re))
end
- if not cache.writeback_enabled(scache, sl.server) then
+ if not cache.writeback_enabled(cache.cache(), sl.server) then
e2lib.warnf("WOTHER", "enabling writeback for server: %s",
sl.server)
- rc, re = cache.set_writeback(scache, sl.server, true)
+ rc, re = cache.set_writeback(cache.cache(), sl.server, true)
if not rc then
error(e:cat(re))
end
end
flocation = e2lib.join(p.location, f.filename)
- rc, re = cache.push_file(scache, sourcefile, p.server, flocation)
+ rc, re = cache.push_file(cache.cache(), sourcefile, p.server, flocation)
if not rc then
error(e:cat(re))
end
-- create the initial repository on server side
local rlocation = string.format("%s/proj/%s.git", p.location, p.name)
- rc, re = generic_git.git_init_db(scache, p.server, rlocation)
+ rc, re = generic_git.git_init_db(cache.cache(), p.server, rlocation)
if not rc then
error(e:cat(re))
end
local refspec = "master:refs/heads/master"
local rlocation = string.format("%s/proj/%s.git", p.location, p.name)
- rc, re = generic_git.git_push(scache, tmp_repo_path, p.server,
+ rc, re = generic_git.git_push(cache.cache(), tmp_repo_path, p.server,
rlocation, refspec)
if not rc then
error(e:cat(re))
end
-- setup cache
- local scache, re = cache.setup_cache(config)
- if not scache then
+ rc, re = cache.setup_cache(config)
+ if not rc then
error(e:cat(re))
end
- rc, re = cache.setup_cache_apply_opts(scache)
+ cache.cache(rc)
+
+ rc, re = cache.setup_cache_apply_opts(cache.cache())
if not rc then
error(e:cat(re))
end
end
local location = string.format("%s/version", p.location)
- local rc, re = cache.fetch_file(scache, p.server, location, tmpdir, nil,
+ local rc, re = cache.fetch_file(cache.cache(), p.server, location, tmpdir, nil,
{ cache = false })
if not rc then
error(e:cat(re))
-- clone the git repository
local location = string.format("%s/proj/%s.git", p.location, p.name)
local skip_checkout = false
- local rc, re = generic_git.git_clone_from_server(scache, p.server, location,
+ local rc, re = generic_git.git_clone_from_server(cache.cache(), p.server, location,
p.destdir, skip_checkout)
if not rc then
error(e:cat(re))
error(re)
end
- local scache, re = cache.setup_cache(config)
- if not scache then
+ rc, re = cache.setup_cache(config)
+ if not rc then
error(e:cat(re))
end
- rc, re = cache.setup_cache_apply_opts(scache)
+ cache.cache(rc)
+
+ rc, re = cache.setup_cache_apply_opts(cache.cache())
if not rc then
error(e:cat(re))
end
local location = config.site.e2_location
local destdir = e2lib.join(root, ".e2/e2")
e2lib.logf(2, "fetching e2factory (ref %s)", ref)
- rc, re = generic_git.git_clone_from_server(scache, server, location,
+ rc, re = generic_git.git_clone_from_server(cache.cache(), server, location,
destdir, false)
if not rc then
error(e:cat(re))
end
end
- rc, re = generic_git.git_clone_from_server(scache, server, location,
+ rc, re = generic_git.git_clone_from_server(cache.cache(), server, location,
destdir, false)
if not rc then
error(e:cat(re))
e:append(" `server' attribute missing")
return false, e
end
- if not cache.valid_server(info.cache, grp.server) then
+ if not cache.valid_server(cache.cache(), grp.server) then
e:append("in group: %s", grp.name)
e:append(" no such server: %s", grp.server)
return false, e
for _,g in ipairs(chroot.groups_sorted) do
grp = chroot.groups_byname[g]
for file in grp:file_iter() do
- if cache.cache_enabled(info.cache, file:server()) then
- rc, re = cache.fetch_file_path(info.cache, file:server(),
+ if cache.cache_enabled(cache.cache(), file:server()) then
+ rc, re = cache.fetch_file_path(cache.cache(), file:server(),
file:location())
if not rc then
return false, re
local s1 = "|"
local s2 = "|"
p1(s1, s2, "servers")
- local servers_sorted = cache.servers(info.cache)
+ local servers_sorted = cache.servers(cache.cache())
for i = 1, #servers_sorted, 1 do
- local ce = cache.ce_by_server(info.cache, servers_sorted[i])
+ local ce = cache.ce_by_server(cache.cache(), servers_sorted[i])
if i < #servers_sorted then
s2 = "|"
else
-- local
local lserver = cache.server_names().dot
local llocation = string.format("in/%s/.git", name)
- local rc, re = generic_git.new_repository(info.cache, lserver, llocation,
+ local rc, re = generic_git.new_repository(cache.cache(), lserver, llocation,
rserver, rlocation)
if not rc then
error(re)
error(err.new("checksum file argument missing"))
end
- local rc, re = new_files_source(info.cache, server, location, source_file,
+ local rc, re = new_files_source(cache.cache(), server, location, source_file,
checksum_file, verify)
if not rc then
error(re)
local result_location = e2lib.join(location, res:get_name(),
buildid, "result.tar")
- rc, re = cache.file_exists(info.cache, server, result_location)
+ rc, re = cache.file_exists(cache.cache(), server, result_location)
if re then
return false, e:cat(re)
end
return false, e:cat(re)
end
- path, re = cache.fetch_file_path(info.cache, file:server(), file:location())
+ path, re = cache.fetch_file_path(cache.cache(), file:server(), file:location())
if not path then
return false, e:cat(re)
end
destdir = e2lib.join(bc.T, "script")
info = e2tool.info()
- rc, re = cache.fetch_file(info.cache, cache.server_names().dot,
+ rc, re = cache.fetch_file(cache.cache(), cache.server_names().dot,
location, destdir)
if not rc then
e = err.new("installing build script")
abslocation)
end
- rc, re = cache.fetch_file(info.cache,
+ rc, re = cache.fetch_file(cache.cache(),
cache.server_names().dot, location, destdir)
if not rc then
return false, e:cat(re)
dep:get_name(), server, location)
resulttarpath = e2lib.join(location, dep:get_name(), buildid, "result.tar")
- path, re = cache.fetch_file_path(info.cache, server, resulttarpath)
+ path, re = cache.fetch_file_path(cache.cache(), server, resulttarpath)
if not path then
return false, e:cat(re)
end
local cache_flags = {
cache = false,
}
- local rc, re = cache.fetch_file(info.cache, server, location1, tmpdir,
+ local rc, re = cache.fetch_file(cache.cache(), server, location1, tmpdir,
nil, cache_flags)
if rc then
e2lib.warnf("WOTHER",
sourcefile = e2lib.join(resdir, f)
location1 = e2lib.join(location, res:get_name(), f)
- rc, re = cache.push_file(info.cache, sourcefile, server, location1,
+ rc, re = cache.push_file(cache.cache(), sourcefile, server, location1,
cache_flags)
if not rc then
return false, re
end
end
- if cache.writeback_enabled(info.cache, server, cache_flags) == false then
+ if cache.writeback_enabled(cache.cache(), server, cache_flags) == false then
e2lib.warnf("WOTHER",
"Writeback is disabled for server %q. Release not deployed!", server)
end
local cache_flags = {
try_hardlink = true,
}
- rc, re = cache.push_file(info.cache, sourcefile, server,
+ rc, re = cache.push_file(cache.cache(), sourcefile, server,
location1, cache_flags)
if not rc then
return false, e:cat(re)
location = e2lib.join(location, res:get_name(), buildid, "result.tar")
-- if we don't have cache or server on local fs, fetch a copy into "out"
- if not cache.cache_enabled(info.cache, server) and not
- cache.islocal_enabled(info.cache, server) then
+ if not cache.cache_enabled(cache.cache(), server) and not
+ cache.islocal_enabled(cache.cache(), server) then
e2lib.logf(3, "%s: copy to out/%s/last, server %q has no cache/not local",
res:get_name(), res:get_name(), server)
return e:cat(re)
end
- rc, re = cache.fetch_file(info.cache, server, location, lnk, nil)
+ rc, re = cache.fetch_file(cache.cache(), server, location, lnk, nil)
if not rc then
return false, e:cat(re)
end
return true
else -- otherwise create a symlink
- dst, re = cache.fetch_file_path(info.cache, server, location)
+ dst, re = cache.fetch_file_path(cache.cache(), server, location)
if not dst then
return false, e:cat(re)
end
info = e2tool.info()
- if not cache.valid_server(info.cache, server) then
+ if not cache.valid_server(cache.cache(), server) then
return false, err.new("file entry with unknown server: %s", server)
end
info = e2tool.info()
- path, re = cache.fetch_file_path(info.cache, self._server, self._location,
+ path, re = cache.fetch_file_path(cache.cache(), self._server, self._location,
flags)
if not path then
return false, re
info = e2tool.info()
- surl, re = cache.remote_url(info.cache, self._server, self._location)
+ surl, re = cache.remote_url(cache.cache(), self._server, self._location)
if not surl then
return false, re
end
for _,digest_type in ipairs(digest_types) do
- if cache.cache_enabled(info.cache, self._server) then
+ if cache.cache_enabled(cache.cache(), self._server) then
cs_cache, re = self:_compute_checksum(digest_type)
if not cs_cache then
return false, e:cat(re)
return false, e:cat(re)
end
- info.cache, re = cache.setup_cache(config)
- if not info.cache then
+ rc, re = cache.setup_cache(config)
+ if not rc then
return false, e:cat(re)
end
- rc, re = cache.setup_cache_local(info.cache, e2tool.root(), info.project_location)
+ cache.cache(rc)
+
+ rc, re = cache.setup_cache_local(cache.cache(), e2tool.root(), info.project_location)
if not rc then
return false, e:cat(re)
end
- rc, re = cache.setup_cache_apply_opts(info.cache)
+ rc, re = cache.setup_cache_apply_opts(cache.cache())
if not rc then
return false, e:cat(re)
end
local release_id = "release-id"
local server, location = s(location, release_id)
local se = err.new("checking server configuration for '%s'", server)
- local ce, re = cache.ce_by_server(info.cache, server)
+ local ce, re = cache.ce_by_server(cache.cache(), server)
if not ce then
se:cat(re)
- elseif not cache.writeback_enabled(info.cache, server) then
+ elseif not cache.writeback_enabled(cache.cache(), server) then
e2lib.warnf("WPOLICY",
"Results will not be pushed to server: '%s'"..
" (Writeback disabled)", server)
end
- if ce and not (cache.writeback_enabled(info.cache, server)
- or cache.cache_enabled(info.cache, server)) then
+ if ce and not (cache.writeback_enabled(cache.cache(), server)
+ or cache.cache_enabled(cache.cache(), server)) then
se:append(
"Cannot store results. "..
"Enable cache or writeback.")
return false, err.new("'server' attribute must be a string")
end
- if rawsrc.server and (not cache.valid_server(info.cache, rawsrc.server)) then
+ if rawsrc.server and (not cache.valid_server(cache.cache(), rawsrc.server)) then
return false, err.new("invalid server: %s", rawsrc.server)
end
local server = cache.server_names().dot
local location = e2lib.join("proj/init", f)
local cache_flags = {}
- rc, re = cache.fetch_file(info.cache, server, location,
+ rc, re = cache.fetch_file(cache.cache(), server, location,
destdir, nil, cache_flags)
if not rc then
return false, e:cat(re)
for file in grp:file_iter() do
local cache_flags = {}
- rc, re = cache.fetch_file(info.cache, file:server(),
+ rc, re = cache.fetch_file(cache.cache(), file:server(),
file:location(), destdir, nil, cache_flags)
if not rc then
return false, e:cat(re)
if not rc then
return false, e:cat(re)
end
- rc, re = cache.fetch_file(info.cache, file:server(), file:location(),
+ rc, re = cache.fetch_file(cache.cache(), file:server(), file:location(),
destdir, nil, cache_flags)
if not rc then
return false, e:cat(re)
for _,file in pairs(files) do
local server = cache.server_names().dot
local cache_flags = {}
- rc, re = cache.fetch_file(info.cache, server, file, destdir,
+ rc, re = cache.fetch_file(cache.cache(), server, file, destdir,
nil, cache_flags)
if not rc then
return false, e:cat(re)
".e2/lib/make/detect_tool",
}
for _,location in ipairs(locations) do
- rc, re = cache.fetch_file(info.cache, server, location,
+ rc, re = cache.fetch_file(cache.cache(), server, location,
destdir, nil, cache_flags)
if not rc then
return false, e:cat(re)
src = source.sources[sourcename]
- surl, re = cache.remote_url(info.cache, src:get_server(), src:get_cvsroot())
+ surl, re = cache.remote_url(cache.cache(), src:get_server(), src:get_cvsroot())
if not surl then
return false, e:cat(re)
end
local e = err.new("fetching source failed: %s", sourcename)
for file in src:file_iter() do
- if cache.cache_enabled(info.cache, file:server()) then
+ if cache.cache_enabled(cache.cache(), file:server()) then
e2lib.logf(3, "files.fetch_source: caching file %s", file:servloc())
- rc, re = cache.fetch_file_path(info.cache, file:server(), file:location())
+ rc, re = cache.fetch_file_path(cache.cache(), file:server(), file:location())
if not rc then
return false, e:cat(re)
end
return false, e:cat(re)
end
if file:unpack() then
- local path, re = cache.fetch_file_path(info.cache,
+ local path, re = cache.fetch_file_path(cache.cache(),
file:server(), file:location())
if not path then
return false, e:cat(re)
end
end
if file:patch() then
- local path, re = cache.fetch_file_path(info.cache,
+ local path, re = cache.fetch_file_path(cache.cache(),
file:server(), file:location())
if not path then
return false, e:append(re)
return false, e:cat(re)
end
- local rc, re = cache.fetch_file(info.cache, file:server(),
+ local rc, re = cache.fetch_file(cache.cache(), file:server(),
file:location(), destdir, destname, {})
if not rc then
return false, e:cat(re)
sourcename, destname)
end
- rc, re = cache.fetch_file(info.cache, file:server(), file:location(),
+ rc, re = cache.fetch_file(cache.cache(), file:server(), file:location(),
destdir, destname, {})
if not rc then
return false, e:cat(re)
local hash = require("hash")
local licence = require("licence")
local scm = require("scm")
+local source = require("source")
local strict = require("strict")
local tools = require("tools")
local url = require("url")
-local source = require("source")
--- Initialize git plugin.
-- @param ctx Plugin context. See plugin module.
-- git config remote.origin.url == server:location
query = string.format("remote.origin.url")
- expect, re = git_url(e2tool.info().cache, self._server, self._location)
+ expect, re = git_url(cache.cache(), self._server, self._location)
if not expect then
return false, e:cat(re)
end
e2lib.logf(2, "cloning %s:%s [%s]", src:get_server(), src:get_location(),
src:get_branch())
- rc, re = generic_git.git_clone_from_server(info.cache, src:get_server(),
+ rc, re = generic_git.git_clone_from_server(cache.cache(), src:get_server(),
src:get_location(), work_tree, false --[[always checkout]])
if not rc then
return false, e:cat(re)
-- git config remote.origin.url == server:location
query = string.format("remote.origin.url")
- expect, re = git_url(e2tool.info().cache, self._server, self._location)
+ expect, re = git_url(cache.cache(), self._server, self._location)
if not expect then
return false, e:cat(re)
end
e2lib.logf(2, "cloning %s:%s [%s]", src:get_server(), src:get_location(),
src:get_branch())
- rc, re = generic_git.git_clone_from_server(info.cache, src:get_server(),
+ rc, re = generic_git.git_clone_from_server(cache.cache(), src:get_server(),
src:get_location(), work_tree, false --[[always checkout]])
if not rc then
return false, e:cat(re)
info = e2tool.info()
assert(type(info) == "table")
- surl, re = cache.remote_url(info.cache, self._server, self._location)
+ surl, re = cache.remote_url(cache.cache(), self._server, self._location)
if not surl then
return false, re
end
local src = source.sources[sourcename]
local location = src:get_location()
local server = src:get_server()
- local surl, re = cache.remote_url(info.cache, server, location)
+ local surl, re = cache.remote_url(cache.cache(), server, location)
if not surl then
return false, e:cat(re)
end
local src = source.sources[sourcename]
local location = src:get_location()
local server = src:get_server()
- local surl, re = cache.remote_url(info.cache, server, location)
+ local surl, re = cache.remote_url(cache.cache(), server, location)
if not surl then
return false, e:cat(re)
end