From 662799e55f5f3fc72134b2c43f2367b625d27f1c Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Thu, 15 Sep 2016 14:41:39 +0200 Subject: [PATCH] cache: move server names and local cache setup into one place Signed-off-by: Tobias Ulmer --- generic/cache.lua | 58 +++++++++++++++++++++++++++++++++++++ local/chroot.lua | 2 +- local/e2-new-source.lua | 7 +++-- local/e2build.lua | 6 ++-- local/e2tool.lua | 33 ++++----------------- local/licence.lua | 3 +- local/policy.lua | 11 ++++--- local/project.lua | 3 +- local/result.lua | 3 +- plugins/collect_project.lua | 8 ++--- plugins/files.lua | 2 +- 11 files changed, 90 insertions(+), 46 deletions(-) diff --git a/generic/cache.lua b/generic/cache.lua index ebdb7be..89bfcc3 100644 --- a/generic/cache.lua +++ b/generic/cache.lua @@ -104,9 +104,67 @@ function cache.setup_cache(config) return false, e:cat(re) end end + + -- It would make sense to check for the required global servers here. + -- Required meaning servers to fetch a project. + return c 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 +-- @param project_root path to the local project root +-- @param project_location location of the project relative to "upstream". +-- @return True on success, false on error +-- @return Error object on failure. +function cache.setup_cache_local(c, project_root, project_location) + assertIsTable(c) + assertIsStringN(project_root) + assertIsString(project_location) + + local rc, re + local servers + + servers = cache.server_names() + + rc, re = cache.new_cache_entry(c, servers.root_server, + "file://" .. project_root, { writeback=true }, nil, nil) + if not rc then + return false, re + end + + rc, re = cache.new_cache_entry(c, servers.proj_storage, + nil, nil, servers.default_repo, project_location) + if not rc then + return false, re + end + + -- Check for required local servers here. These tests are currently + -- spread out, but mainly live in policy.init() + + return true +end + +local _server_names = strict.lock({ + -- XXX: inconsistent, confusing naming scheme + root_server = ".", + -- the proj_storage server is equivalent to + -- default_repo_server:info.project-locaton + proj_storage = "proj-storage", + default_repo = "projects", + default_files = "upstream", + result_server = "results", + releases = "releases", +}) + +--- Return a table of fixed server names whose existence we rely on +-- throughout the program. The table is locked. +-- @return Locked dictionary with fixed server names. +function cache.server_names() + return _server_names +end + --- get a sorted list of servers -- @param c a cache table -- @return table: a list of servers diff --git a/local/chroot.lua b/local/chroot.lua index 6b1df60..98a55e3 100644 --- a/local/chroot.lua +++ b/local/chroot.lua @@ -291,7 +291,7 @@ function chroot.load_chroot_config(info) return false, e end - if f.server ~= info.root_server_name and not f.sha1 then + if f.server ~= cache.server_names().root_server and not f.sha1 then e:append("in group: %s", grp.name) e:append("file entry for remote file without `sha1` attribute") return false, e diff --git a/local/e2-new-source.lua b/local/e2-new-source.lua index 065e6ea..7bb6238 100644 --- a/local/e2-new-source.lua +++ b/local/e2-new-source.lua @@ -249,14 +249,14 @@ local function e2_new_source(arg) error(err.new(" argument required")) end -- remote - local rserver = info.default_repo_server + local rserver = cache.server_names().default_repo if opts["server"] then rserver = opts["server"] end local name = arguments[1] local rlocation = string.format("%s/git/%s.git", info.project_location, name) -- local - local lserver = info.root_server_name + local lserver = cache.server_names().root_server local llocation = string.format("in/%s/.git", name) local rc, re = generic_git.new_repository(info.cache, lserver, llocation, rserver, rlocation) @@ -270,7 +270,8 @@ local function e2_new_source(arg) end local location = arguments[1] - local sl, re = e2lib.parse_server_location(location, info.default_files_server) + local sl, re = e2lib.parse_server_location(location, + cache.server_names().default_files) if not sl then error(re) end diff --git a/local/e2build.lua b/local/e2build.lua index 3dc1144..c5f668a 100644 --- a/local/e2build.lua +++ b/local/e2build.lua @@ -411,7 +411,7 @@ function e2build.build_process_class:_install_build_script(res, return_flags) destdir = e2lib.join(bc.T, "script") info = e2tool.info() - rc, re = cache.fetch_file(info.cache, info.root_server_name, + rc, re = cache.fetch_file(info.cache, cache.server_names().root_server, location, destdir) if not rc then e = err.new("installing build script") @@ -460,8 +460,8 @@ function e2build.build_process_class:_install_init_files(res, return_flags) abslocation) end - rc, re = cache.fetch_file(info.cache, info.root_server_name, - location, destdir) + rc, re = cache.fetch_file(info.cache, + cache.server_names().root_server, location, destdir) if not rc then return false, e:cat(re) end diff --git a/local/e2tool.lua b/local/e2tool.lua index 0b77c9b..90185ae 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -65,11 +65,6 @@ local e2tool_ftab = {} -- @field chroot_umask Umask setting for chroot (decimal number). -- @field host_umask Default umask of the process (decimal number). -- @field root Project root directory (string). --- @field root_server string: url pointing to the project root --- @field root_server_name string: name of the root server (".") --- @field default_repo_server string: name of the default scm repo server --- @field default_files_server string: name of the default files server --- @field result_storage (deprecated) -- @field project_location string: project location relative to the servers -- @field local_template_path Path to the local templates (string). local _info = false @@ -481,25 +476,8 @@ function e2tool.collect_project_info(info, skip_load_config) e2lib.logf(4, "VERSION: %s", buildconfig.VERSION) e2lib.logf(4, "VERSIONSTRING: %s", buildconfig.VERSIONSTRING) - hash.hcache_load(e2lib.join(info.root, ".e2/hashcache")) -- no error check required - - --XXX create some policy module where the following policy settings - --XXX and functions reside (server names, paths, etc.) - - -- the '.' server as url - info.root_server = "file://" .. info.root - info.root_server_name = "." - - -- the proj_storage server is equivalent to - -- info.default_repo_server:info.project-locaton - info.proj_storage_server_name = "proj-storage" - - -- need to configure the results server in the configuration, named 'results' - info.result_server_name = "results" - - info.default_repo_server = "projects" - info.default_files_server = "upstream" + hash.hcache_load(e2lib.join(info.root, ".e2/hashcache")) -- read .e2/proj-location local plf = e2lib.join(info.root, e2lib.globals.project_location_file) @@ -524,10 +502,11 @@ function e2tool.collect_project_info(info, skip_load_config) if not info.cache then return false, e:cat(re) end - rc = cache.new_cache_entry(info.cache, info.root_server_name, - info.root_server, { writeback=true }, nil, nil ) - rc = cache.new_cache_entry(info.cache, info.proj_storage_server_name, - nil, nil, info.default_repo_server, info.project_location) + + rc, re = cache.setup_cache_local(info.cache, info.root, info.project_location) + if not rc then + return false, e:cat(re) + end local f = e2lib.join(info.root, e2lib.globals.e2version_file) local v, re = e2lib.parse_e2versionfile(f) diff --git a/local/licence.lua b/local/licence.lua index f9294ab..7e57ae8 100644 --- a/local/licence.lua +++ b/local/licence.lua @@ -21,6 +21,7 @@ local licence = {} package.loaded["licence"] = licence +local cache = require("cache") local class = require("class") local e2lib = require("e2lib") local e2tool = require("e2tool") @@ -244,7 +245,7 @@ function licence.load_licence_config(info) if not rc then return false, e:cat(re) end - if file.server ~= info.root_server_name and not file.sha1 then + if file.server ~= cache.server_names().root_server and not file.sha1 then return false, e:append( "file entry for remote file without sha1 attribute") end diff --git a/local/policy.lua b/local/policy.lua index 2db605d..af92ddb 100644 --- a/local/policy.lua +++ b/local/policy.lua @@ -67,7 +67,8 @@ end -- @return Server name (string). -- @return Location path to store results in (string). local function storage_release(location, release_id) - return "results", string.format("%s/release/%s", location, release_id) + return cache.server_names().result_server, + string.format("%s/release/%s", location, release_id) end --- Get results server and location. @@ -76,7 +77,8 @@ end -- @return Server name (string). -- @return Location path to store results in (string). local function storage_default(location, release_id) - return "results", string.format("%s/shared", location) + return cache.server_names().result_server, + string.format("%s/shared", location) end --- Get local server and location. @@ -85,7 +87,7 @@ end -- @return Server name (string). -- @return Location path to store results in (string). local function storage_local(location, release_id) - return "." , string.format("out") + return cache.server_names().root_server , string.format("out") end --- Get deploy server and location. @@ -94,7 +96,8 @@ end -- @return Server name (string). -- @return Location path to store results in (string). local function deploy_storage_default(location, release_id) - return "releases", string.format("%s/archive/%s", location, release_id) + return cache.server_names().releases, + string.format("%s/archive/%s", location, release_id) end --- Get the buildid for a build diff --git a/local/project.lua b/local/project.lua index 055a22a..bab28d6 100644 --- a/local/project.lua +++ b/local/project.lua @@ -22,6 +22,7 @@ local project = {} package.loaded["project"] = project local buildconfig = require("buildconfig") +local cache = require("cache") local e2lib = require("e2lib") local e2tool = require("e2tool") local err = require("err") @@ -263,7 +264,7 @@ function project.projid(info) if not e2lib.is_backup_file(f) then location = e2lib.join("proj/init", f) file = { - server = info.root_server_name, + server = cache.server_names().root_server, location = location, } diff --git a/local/result.lua b/local/result.lua index 6013e5c..2a7d93d 100644 --- a/local/result.lua +++ b/local/result.lua @@ -22,6 +22,7 @@ local result = {} package.loaded["result"] = result local buildconfig = require("buildconfig") +local cache = require("cache") local chroot = require("chroot") local class = require("class") local e2build = require("e2build") @@ -492,7 +493,7 @@ function result.result_class:buildid() -- buildscript local file = { - server = info.root_server_name, + server = cache.server_names().root_server, location = e2tool.resultbuildscript(self:get_name_as_path()), } diff --git a/plugins/collect_project.lua b/plugins/collect_project.lua index 1ed7c0a..1fa3dad 100644 --- a/plugins/collect_project.lua +++ b/plugins/collect_project.lua @@ -233,7 +233,7 @@ function collect_project_class:buildid() -- buildscript local file = { - server = info.root_server_name, + server = cache.server_names().root_server, location = e2tool.resultbuildscript(self:get_name_as_path()), } @@ -420,7 +420,7 @@ function cp_build_process_class:_build_collect_project(res, return_flags) end e2lib.logf(3, "init file: %s", f) - local server = info.root_server_name + local server = cache.server_names().root_server local location = e2lib.join("proj/init", f) local cache_flags = {} rc, re = cache.fetch_file(info.cache, server, location, @@ -540,7 +540,7 @@ function cp_build_process_class:_build_collect_project(res, return_flags) e2tool.resultbuildscript(dep:get_name_as_path()) } for _,file in pairs(files) do - local server = info.root_server_name + local server = cache.server_names().root_server local cache_flags = {} rc, re = cache.fetch_file(info.cache, server, file, destdir, nil, cache_flags) @@ -611,7 +611,7 @@ function cp_build_process_class:_build_collect_project(res, return_flags) return false, e:cat(re) end -- install the global Makefiles - local server = info.root_server_name + local server = cache.server_names().root_server local destdir = e2lib.join(bc.T, "project") local cache_flags = {} local locations = { diff --git a/plugins/files.lua b/plugins/files.lua index 331a52d..5828f74 100644 --- a/plugins/files.lua +++ b/plugins/files.lua @@ -145,7 +145,7 @@ function files.files_source:initialize(rawsrc) if not f.location then error(e:append("file entry without `location' attribute")) end - if f.server ~= info.root_server_name and not f.sha1 then + if f.server ~= cache.server_names().root_server and not f.sha1 then error(e:append("file entry for remote file without ".. "`sha1` attribute")) end -- 2.39.5