]> git.e2factory.org Git - e2factory.git/commitdiff
cache: move server names and local cache setup into one place
authorTobias Ulmer <tu@emlix.com>
Thu, 15 Sep 2016 12:41:39 +0000 (14:41 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:18 +0000 (15:41 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/cache.lua
local/chroot.lua
local/e2-new-source.lua
local/e2build.lua
local/e2tool.lua
local/licence.lua
local/policy.lua
local/project.lua
local/result.lua
plugins/collect_project.lua
plugins/files.lua

index ebdb7bea017769c9017f21779b3b7ac8b80c1f42..89bfcc372cc2902fb343f9eabed6b7ec7a8073ad 100644 (file)
@@ -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
index 6b1df60347d3a3e8562388b9f18b428f12da1ab8..98a55e3dd5e6a96621d7df3a083346037f686473 100644 (file)
@@ -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
index 065e6eaff533231fe3411c74c77e41bd31df3df8..7bb62387b3ba13e861e6edebd270ba92338e869b 100644 (file)
@@ -249,14 +249,14 @@ local function e2_new_source(arg)
             error(err.new("<name> 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
index 3dc1144fe454b74a71d70274a80ea947be2b3f79..c5f668abad68263d3a6eb95d17eab13f1fada7ce 100644 (file)
@@ -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
index 0b77c9bc3a664c31e6d46d694bef94bef01dfb9d..90185ae1c82778909790bcfbd564c0468bae60a5 100644 (file)
@@ -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)
index f9294ab9ba1100483bbd857930f3d01c27fe0d66..7e57ae8bf495b088ac75622511f961518220e06f 100644 (file)
@@ -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
index 2db605d845f85e6b186d8594cc772fb732f339b5..af92ddb0ab769754161098b2f3b7b7c17a679009 100644 (file)
@@ -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
index 055a22acc02eefdf093b14c0702103ea0a23cedc..bab28d6549df998e12af3a60089c1f99031b75a9 100644 (file)
@@ -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,
             }
 
index 6013e5c5084a578626e69790c12e1af7b8a72bc5..2a7d93d1cb188f5c6f98e05655be230ac0f02a7d 100644 (file)
@@ -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()),
     }
 
index 1ed7c0a7b86bee05c7a78a62cc817610c74da2e8..1fa3dad2ebeba23df0c252b0be35b2928b20e651 100644 (file)
@@ -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 = {
index 331a52d42592d665ac1637cc8f5a6c84ebe60e8c..5828f74c7ec0ee26e1b66fa41973f67608c99259 100644 (file)
@@ -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