summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-03-09 22:45:46 +0800
committerruki <[email protected]>2021-03-09 22:45:46 +0800
commit202981361d27bcf8fbce8d47d11a9490853bd1e0 (patch)
tree92e3a7945359f66d583bc043f90e77759e0f0973
parent8b1b39ce7a9f342699c73aaede4b627ae151c31a (diff)
improve toolchain cache
-rw-r--r--xmake/core/platform/platform.lua48
-rw-r--r--xmake/core/project/target.lua6
-rw-r--r--xmake/core/tool/toolchain.lua26
3 files changed, 47 insertions, 33 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua
index 0cdc7c1be..b9913f1b8 100644
--- a/xmake/core/platform/platform.lua
+++ b/xmake/core/platform/platform.lua
@@ -29,6 +29,7 @@ local utils = require("base/utils")
local table = require("base/table")
local interpreter = require("base/interpreter")
local toolchain = require("tool/toolchain")
+local memcache = require("cache/memcache")
local sandbox = require("sandbox/sandbox")
local config = require("project/config")
local global = require("base/global")
@@ -42,6 +43,16 @@ function _instance.new(name, arch, info)
return instance
end
+-- get memcache
+function _instance:_memcache()
+ local cache = self._MEMCACHE
+ if not cache then
+ cache = memcache.cache("core.platform.platform." .. tostring(self))
+ self._MEMCACHE = cache
+ end
+ return cache
+end
+
-- get platform name
function _instance:name()
return self._NAME
@@ -138,7 +149,7 @@ end
-- get the toolchains
function _instance:toolchains(opt)
- local toolchains = self._TOOLCHAINS
+ local toolchains = self:_memcache():get("toolchains")
if not toolchains then
-- get current valid toolchains from configuration cache
@@ -181,7 +192,7 @@ function _instance:toolchains(opt)
table.insert(toolchains, toolchain_inst)
end
end
- self._TOOLCHAINS = toolchains
+ self:_memcache():set("toolchains", toolchains)
end
return toolchains
end
@@ -345,6 +356,11 @@ function platform._apis()
}
end
+-- get memcache
+function platform._memcache()
+ return memcache.cache("core.platform.platform")
+end
+
-- get platform directories
function platform.directories()
@@ -499,26 +515,22 @@ end
-- get the all toolchains
function platform.toolchains()
-
- -- return it directly if exists
- if platform._TOOLCHAINS then
- return platform._TOOLCHAINS
- end
-
- -- get all toolchains
- local toolchains = {}
- local dirs = toolchain.directories()
- for _, dir in ipairs(dirs) do
- local dirs = os.dirs(path.join(dir, "*"))
- if dirs then
- for _, dir in ipairs(dirs) do
- if os.isfile(path.join(dir, "xmake.lua")) then
- table.insert(toolchains, path.basename(dir))
+ local toolchains = self._memcache():get("toolchains")
+ if not toolchains then
+ toolchains = {}
+ local dirs = toolchain.directories()
+ for _, dir in ipairs(dirs) do
+ local dirs = os.dirs(path.join(dir, "*"))
+ if dirs then
+ for _, dir in ipairs(dirs) do
+ if os.isfile(path.join(dir, "xmake.lua")) then
+ table.insert(toolchains, path.basename(dir))
+ end
end
end
end
+ self._memcache():set("toolchains", toolchains)
end
- platform._TOOLCHAINS = toolchains
return toolchains
end
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index ee7e3f519..273601780 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -60,7 +60,7 @@ end
function _instance:_memcache()
local cache = self._MEMCACHE
if not cache then
- cache = memcache.cache("core.project.target." .. self:name())
+ cache = memcache.cache("core.project.target." .. tostring(self))
self._MEMCACHE = cache
end
return cache
@@ -1784,10 +1784,10 @@ end
-- get the toolchains
function _instance:toolchains()
- local toolchains = self._TOOLCHAINS
+ local toolchains = self:_memcache():get("toolchains")
if toolchains == nil then
toolchains = self:platform():toolchains()
- self._TOOLCHAINS = toolchains
+ self:_memcache():set("toolchains", toolchains)
end
return toolchains
end
diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua
index 43782f2e8..24cff77f3 100644
--- a/xmake/core/tool/toolchain.lua
+++ b/xmake/core/tool/toolchain.lua
@@ -535,15 +535,16 @@ function toolchain.load(name, opt)
name, packages = toolchain._parsename(name)
opt.packages = opt.packages or packages
- -- get cache key
+ -- get cache
opt.plat = opt.plat or config.get("plat") or os.host()
opt.arch = opt.arch or config.get("arch") or os.arch()
+ local cache = toolchain._memcache()
local cachekey = toolchain._cachekey(name, opt)
-- get it directly from cache dirst
- toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {}
- if toolchain._TOOLCHAINS[cachekey] then
- return toolchain._TOOLCHAINS[cachekey]
+ local instance = cache:get(cachekey)
+ if instance then
+ return instance
end
-- find the toolchain script path
@@ -580,8 +581,8 @@ function toolchain.load(name, opt)
end
-- save instance to the cache
- local instance = _instance.new(name, result, cachekey, opt)
- toolchain._TOOLCHAINS[cachekey] = instance
+ instance = _instance.new(name, result, cachekey, opt)
+ cache:set(cachekey, instance)
return instance
end
@@ -597,17 +598,18 @@ function toolchain.load_withinfo(name, info, opt)
-- get cache key
opt.plat = opt.plat or config.get("plat") or os.host()
opt.arch = opt.arch or config.get("arch") or os.arch()
+ local cache = toolchain._memcache()
local cachekey = toolchain._cachekey(name, opt)
-- get it directly from cache dirst
- toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {}
- if toolchain._TOOLCHAINS[cachekey] then
- return toolchain._TOOLCHAINS[cachekey]
+ local instance = cache:get(cachekey)
+ if instance then
+ return instance
end
-- save instance to the cache
- local instance = _instance.new(name, info, cachekey, opt)
- toolchain._TOOLCHAINS[cachekey] = instance
+ instance = _instance.new(name, info, cachekey, opt)
+ cache:set(cachekey, instance)
return instance
end
@@ -620,7 +622,7 @@ function toolchain.tool(toolchains, toolkind, opt)
local arch = opt.arch or config.get("arch") or os.arch()
-- get cache and cachekey
- local cache = toolchain:_localcache()
+ local cache = toolchain._localcache()
local cachekey = "tool_" .. (opt.cachekey or "") .. "_" .. plat .. "_" .. arch .. "_" .. toolkind
local updatecache = false