summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmake/core/package/package.lua26
-rw-r--r--xmake/core/project/target.lua48
-rw-r--r--xmake/core/tool/toolchain.lua16
3 files changed, 50 insertions, 40 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index bf07fa8e8..4a32bbdf7 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -83,7 +83,7 @@ function _instance.new(name, info, opt)
end
-- get memcache
-function _instance:_memcache()
+function _instance:memcache()
local cache = self._MEMCACHE
if not cache then
cache = memcache.cache("core.package.package." .. tostring(self))
@@ -484,13 +484,13 @@ end
-- get library dep
function _instance:librarydep(name, opt)
local key = "librarydeps_map_" .. ((opt and opt.private) and "private" or "")
- local librarydeps_map = self:_memcache():get(key)
+ local librarydeps_map = self:memcache():get(key)
if not librarydeps_map then
librarydeps_map = {}
for _, dep in ipairs(self:librarydeps()) do
librarydeps_map[dep:name()] = dep
end
- self:_memcache():set(key, librarydeps_map)
+ self:memcache():set(key, librarydeps_map)
end
return librarydeps_map[name]
end
@@ -1298,7 +1298,7 @@ end
-- get runtimes
function _instance:runtimes()
- local runtimes = self:_memcache():get("runtimes")
+ local runtimes = self:memcache():get("runtimes")
if runtimes == nil then
runtimes = self:config("runtimes")
if runtimes then
@@ -1306,17 +1306,17 @@ function _instance:runtimes()
runtimes = table.unwrap(runtimes_current)
end
runtimes = runtimes or false
- self:_memcache():set("runtimes", runtimes)
+ self:memcache():set("runtimes", runtimes)
end
return runtimes or nil
end
-- has the given runtime for the current toolchains?
function _instance:has_runtime(...)
- local runtimes_set = self:_memcache():get("runtimes_set")
+ local runtimes_set = self:memcache():get("runtimes_set")
if runtimes_set == nil then
runtimes_set = hashset.from(table.wrap(self:runtimes()))
- self:_memcache():set("runtimes_set", runtimes_set)
+ self:memcache():set("runtimes_set", runtimes_set)
end
for _, v in ipairs(table.pack(...)) do
if runtimes_set:has(v) then
@@ -1327,7 +1327,7 @@ end
-- get the given toolchain
function _instance:toolchain(name)
- local toolchains_map = self:_memcache():get("toolchains_map")
+ local toolchains_map = self:memcache():get("toolchains_map")
if toolchains_map == nil then
toolchains_map = {}
local toolchains = self:toolchains()
@@ -1336,7 +1336,7 @@ function _instance:toolchain(name)
toolchains_map[toolchain_inst:name()] = toolchain_inst
end
end
- self:_memcache():set("toolchains_map", toolchains_map)
+ self:memcache():set("toolchains_map", toolchains_map)
end
if not toolchains_map[name] then
toolchains_map[name] = toolchain.load(name, {plat = self:plat(), arch = self:arch()})
@@ -1391,7 +1391,7 @@ end
-- get the package compiler
function _instance:compiler(sourcekind)
- local compilerinst = self:_memcache():get2("compiler", sourcekind)
+ local compilerinst = self:memcache():get2("compiler", sourcekind)
if not compilerinst then
if not sourcekind then
os.raise("please pass sourcekind to the first argument of package:compiler(), e.g. cc, cxx, as")
@@ -1401,14 +1401,14 @@ function _instance:compiler(sourcekind)
os.raise(errors)
end
compilerinst = instance
- self:_memcache():set2("compiler", sourcekind, compilerinst)
+ self:memcache():set2("compiler", sourcekind, compilerinst)
end
return compilerinst
end
-- get the package linker
function _instance:linker(targetkind, sourcekinds)
- local linkerinst = self:_memcache():get3("linker", targetkind, sourcekinds)
+ local linkerinst = self:memcache():get3("linker", targetkind, sourcekinds)
if not linkerinst then
if not sourcekinds then
os.raise("please pass sourcekinds to the second argument of package:linker(), e.g. cc, cxx, as")
@@ -1418,7 +1418,7 @@ function _instance:linker(targetkind, sourcekinds)
os.raise(errors)
end
linkerinst = instance
- self:_memcache():set3("linker", targetkind, sourcekinds, linkerinst)
+ self:memcache():set3("linker", targetkind, sourcekinds, linkerinst)
end
return linkerinst
end
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 40af6a2b4..b3b318e26 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -64,7 +64,7 @@ function _instance.new(name, info)
end
-- get memcache
-function _instance:_memcache()
+function _instance:memcache()
local cache = self._MEMCACHE
if not cache then
cache = memcache.cache("core.project.target." .. tostring(self))
@@ -232,7 +232,7 @@ end
function _instance:_invalidate(name)
self._CACHEID = self._CACHEID + 1
self._POLICIES = nil
- self:_memcache():clear()
+ self:memcache():clear()
-- we need to flush the source files cache if target/files are modified, e.g. `target:add("files", "xxx.c")`
if name == "files" then
self._SOURCEFILES = nil
@@ -1074,28 +1074,28 @@ function _instance:compiler(sourcekind)
if not sourcekind then
os.raise("please pass sourcekind to the first argument of target:compiler(), e.g. cc, cxx, as")
end
- local compilerinst = self:_memcache():get("compiler_" .. sourcekind)
+ local compilerinst = self:memcache():get("compiler_" .. sourcekind)
if not compilerinst then
local instance, errors = compiler.load(sourcekind, self)
if not instance then
os.raise(errors)
end
compilerinst = instance
- self:_memcache():set("compiler_" .. sourcekind, compilerinst)
+ self:memcache():set("compiler_" .. sourcekind, compilerinst)
end
return compilerinst
end
-- get the target linker
function _instance:linker()
- local linkerinst = self:_memcache():get("linker")
+ local linkerinst = self:memcache():get("linker")
if not linkerinst then
local instance, errors = linker.load(self:kind(), self:sourcekinds(), self)
if not instance then
os.raise(errors)
end
linkerinst = instance
- self:_memcache():set("linker", linkerinst)
+ self:memcache():set("linker", linkerinst)
end
return linkerinst
end
@@ -1282,13 +1282,13 @@ function _instance:opts(opt)
elseif opt.interface then
cachekey = cachekey .. "_interface"
end
- local opts = self:_memcache():get(cachekey)
+ local opts = self:memcache():get(cachekey)
if not opts then
opts = {}
for _, opt_ in ipairs(self:orderopts(opt)) do
opts[opt_:name()] = opt_
end
- self:_memcache():set(cachekey, opts)
+ self:memcache():set(cachekey, opts)
end
return opts
end
@@ -1302,7 +1302,7 @@ function _instance:orderopts(opt)
elseif opt.interface then
cachekey = cachekey .. "_interface"
end
- local orderopts = self:_memcache():get(cachekey)
+ local orderopts = self:memcache():get(cachekey)
if not orderopts then
orderopts = {}
for _, name in ipairs(table.wrap(self:get("options", opt))) do
@@ -1318,7 +1318,7 @@ function _instance:orderopts(opt)
table.insert(orderopts, opt_)
end
end
- self:_memcache():set(cachekey, orderopts)
+ self:memcache():set(cachekey, orderopts)
end
return orderopts
end
@@ -1337,13 +1337,13 @@ function _instance:pkgs(opt)
elseif opt.interface then
cachekey = cachekey .. "_interface"
end
- local packages = self:_memcache():get(cachekey)
+ local packages = self:memcache():get(cachekey)
if not packages then
packages = {}
for _, pkg in ipairs(self:orderpkgs(opt)) do
packages[pkg:name()] = pkg
end
- self:_memcache():set(cachekey, packages)
+ self:memcache():set(cachekey, packages)
end
return packages
end
@@ -1357,7 +1357,7 @@ function _instance:orderpkgs(opt)
elseif opt.interface then
cachekey = cachekey .. "_interface"
end
- local packages = self:_memcache():get(cachekey)
+ local packages = self:memcache():get(cachekey)
if not packages then
packages = {}
local requires = target._project().required_packages()
@@ -1380,7 +1380,7 @@ function _instance:orderpkgs(opt)
end
end
end
- self:_memcache():set(cachekey, packages)
+ self:memcache():set(cachekey, packages)
end
return packages
end
@@ -1850,7 +1850,7 @@ function _instance:filerules(sourcefile)
end
-- load all rules for this target with sourcekinds and extensions
- local key2rules = self:_memcache():get("key2rules")
+ local key2rules = self:memcache():get("key2rules")
if not key2rules then
key2rules = {}
for _, r in pairs(table.wrap(self:rules())) do
@@ -1868,7 +1868,7 @@ function _instance:filerules(sourcefile)
table.insert(key2rules[extension], r)
end
end
- self:_memcache():set("key2rules", key2rules)
+ self:memcache():set("key2rules", key2rules)
end
-- get target rules from the given sourcekind or extension
@@ -2513,7 +2513,7 @@ end
-- get runtimes
function _instance:runtimes()
- local runtimes = self:_memcache():get("runtimes")
+ local runtimes = self:memcache():get("runtimes")
if runtimes == nil then
runtimes = self:get("runtimes")
if runtimes then
@@ -2537,17 +2537,17 @@ function _instance:runtimes()
runtimes = table.unwrap(runtimes_current)
end
runtimes = runtimes or false
- self:_memcache():set("runtimes", runtimes)
+ self:memcache():set("runtimes", runtimes)
end
return runtimes or nil
end
-- has the given runtime for the current toolchains?
function _instance:has_runtime(...)
- local runtimes_set = self:_memcache():get("runtimes_set")
+ local runtimes_set = self:memcache():get("runtimes_set")
if runtimes_set == nil then
runtimes_set = hashset.from(table.wrap(self:runtimes()))
- self:_memcache():set("runtimes_set", runtimes_set)
+ self:memcache():set("runtimes_set", runtimes_set)
end
for _, v in ipairs(table.pack(...)) do
if runtimes_set:has(v) then
@@ -2558,20 +2558,20 @@ end
-- get the given toolchain
function _instance:toolchain(name)
- local toolchains_map = self:_memcache():get("toolchains_map")
+ local toolchains_map = self:memcache():get("toolchains_map")
if toolchains_map == nil then
toolchains_map = {}
for _, toolchain_inst in ipairs(self:toolchains()) do
toolchains_map[toolchain_inst:name()] = toolchain_inst
end
- self:_memcache():set("toolchains_map", toolchains_map)
+ self:memcache():set("toolchains_map", toolchains_map)
end
return toolchains_map[name]
end
-- get the toolchains
function _instance:toolchains()
- local toolchains = self:_memcache():get("toolchains")
+ local toolchains = self:memcache():get("toolchains")
if toolchains == nil then
-- load target toolchains first
@@ -2615,7 +2615,7 @@ function _instance:toolchains()
toolchains = self:platform():toolchains()
end
- self:_memcache():set("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 2230aae9e..1da1634db 100644
--- a/xmake/core/tool/toolchain.lua
+++ b/xmake/core/tool/toolchain.lua
@@ -98,6 +98,16 @@ function _instance:fullname()
return namespace and namespace .. "::" .. name or name
end
+-- get memcache
+function _instance:memcache()
+ local cache = self._MEMCACHE
+ if not cache then
+ cache = memcache.cache("core.tool.toolchain." .. self:cachekey())
+ self._MEMCACHE = cache
+ end
+ return cache
+end
+
-- get toolchain platform
function _instance:plat()
return self._PLAT or self:config("plat")
@@ -482,8 +492,7 @@ end
function _instance:_checktool(toolkind, toolpath)
-- get result from cache first
- local cachekey = self:cachekey() .. "_checktool" .. toolkind
- local result = toolchain._memcache():get3(cachekey, toolkind, toolpath)
+ local result = self:memcache():get2("checktool_" .. toolkind, toolpath)
if result then
return result[1], result[2]
end
@@ -526,6 +535,7 @@ function _instance:_checktool(toolkind, toolpath)
end
-- find tool program
+ local cachekey = self:cachekey() .. "_checktool" .. toolkind
local tool = find_tool(toolpath, {toolchain = self,
cachekey = cachekey,
program = program or toolpath,
@@ -552,7 +562,7 @@ function _instance:_checktool(toolkind, toolpath)
utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, toolpath)
end
end
- toolchain._memcache():set3(cachekey, toolkind, toolpath, {program, toolname})
+ self:memcache():set2("checktool_" .. toolkind, toolpath, {program, toolname})
return program, toolname
end