summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-12-24 21:48:22 +0800
committerGitHub <[email protected]>2020-12-24 21:48:22 +0800
commit95cfe53e0e9963b1c791f3bd3a3a9b7eda3b3b10 (patch)
tree137fac8018667ad280eb6f2bb7a1171c02ae8d6a
parent9d1ea2ecbc19153c1fcc2355aab3e6e09cbe7b12 (diff)
parent3118b46c20edbdade2aed0b50b7ed668e4301d70 (diff)
Merge pull request #1152 from xmake-io/cache
Improve cache
-rw-r--r--tests/modules/cache/test.lua42
-rw-r--r--xmake/actions/config/main.lua26
-rw-r--r--xmake/actions/require/clean.lua6
-rw-r--r--xmake/actions/require/impl/package.lua23
-rw-r--r--xmake/actions/require/install.lua4
-rw-r--r--xmake/core/base/os.lua2
-rw-r--r--xmake/core/cache/detectcache.lua22
-rw-r--r--xmake/core/cache/globalcache.lua206
-rw-r--r--xmake/core/cache/localcache.lua205
-rw-r--r--xmake/core/cache/memcache.lua164
-rw-r--r--xmake/core/main.lua10
-rw-r--r--xmake/core/package/package.lua57
-rw-r--r--xmake/core/package/repository.lua41
-rw-r--r--xmake/core/project/config.lua5
-rw-r--r--xmake/core/project/history.lua92
-rw-r--r--xmake/core/project/option.lua24
-rw-r--r--xmake/core/project/project.lua125
-rw-r--r--xmake/core/project/requireinfo.lua32
-rw-r--r--xmake/core/project/target.lua1
-rw-r--r--xmake/core/sandbox/modules/import/core/cache/detectcache.lua23
-rw-r--r--xmake/core/sandbox/modules/import/core/cache/globalcache.lua23
-rw-r--r--xmake/core/sandbox/modules/import/core/cache/localcache.lua (renamed from xmake/core/sandbox/modules/import/core/project/history.lua)5
-rw-r--r--xmake/core/sandbox/modules/import/core/cache/memcache.lua (renamed from xmake/core/sandbox/modules/import/core/project/cache.lua)4
-rw-r--r--xmake/core/sandbox/modules/import/core/project/project.lua6
-rw-r--r--xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua31
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/cache.lua94
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_program.lua41
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_programver.lua27
-rw-r--r--xmake/core/tool/toolchain.lua12
-rw-r--r--xmake/languages/c++/xmake.lua3
-rw-r--r--xmake/modules/core/tools/cl.lua19
-rw-r--r--xmake/modules/core/tools/link.lua7
-rw-r--r--xmake/modules/detect/sdks/find_android_sdk.lua9
-rw-r--r--xmake/modules/detect/sdks/find_cuda.lua9
-rw-r--r--xmake/modules/detect/sdks/find_dotnet.lua9
-rw-r--r--xmake/modules/detect/sdks/find_mingw.lua9
-rw-r--r--xmake/modules/detect/sdks/find_ndk.lua9
-rw-r--r--xmake/modules/detect/sdks/find_qt.lua9
-rw-r--r--xmake/modules/detect/sdks/find_wdk.lua9
-rw-r--r--xmake/modules/detect/sdks/find_xcode.lua7
-rw-r--r--xmake/modules/detect/tools/ar/has_flags.lua11
-rw-r--r--xmake/modules/detect/tools/cl/has_flags.lua13
-rw-r--r--xmake/modules/detect/tools/clang_cl/has_flags.lua13
-rw-r--r--xmake/modules/detect/tools/dmd/has_flags.lua13
-rw-r--r--xmake/modules/detect/tools/gcc/has_flags.lua13
-rw-r--r--xmake/modules/detect/tools/gdc/has_flags.lua13
-rw-r--r--xmake/modules/detect/tools/gfortran/has_flags.lua13
-rw-r--r--xmake/modules/detect/tools/go/has_flags.lua13
-rw-r--r--xmake/modules/detect/tools/link/has_flags.lua11
-rw-r--r--xmake/modules/detect/tools/ml/has_flags.lua13
-rw-r--r--xmake/modules/detect/tools/nvcc/has_flags.lua13
-rw-r--r--xmake/modules/detect/tools/rustc/has_flags.lua13
-rw-r--r--xmake/modules/detect/tools/sdcc/has_flags.lua13
-rw-r--r--xmake/modules/detect/tools/swiftc/has_flags.lua13
-rw-r--r--xmake/modules/detect/tools/zig/has_flags.lua13
-rw-r--r--xmake/modules/lib/detect/find_cudadevices.lua7
-rw-r--r--xmake/modules/lib/detect/find_package.lua7
-rw-r--r--xmake/modules/lib/detect/has_flags.lua7
-rw-r--r--xmake/modules/net/ping.lua7
-rw-r--r--xmake/modules/package/tools/cmake.lua13
-rw-r--r--xmake/modules/package/tools/xmake.lua3
-rw-r--r--xmake/modules/private/tools/cl/parse_include.lua11
-rw-r--r--xmake/platforms/windows/xmake.lua2
-rw-r--r--xmake/plugins/macro/main.lua82
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua16
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua2
-rw-r--r--xmake/plugins/project/vsxmake/getinfo.lua24
-rw-r--r--xmake/rules/c++/xmake.lua3
-rw-r--r--xmake/rules/utils/compiler_runtime/xmake.lua31
69 files changed, 1146 insertions, 712 deletions
diff --git a/tests/modules/cache/test.lua b/tests/modules/cache/test.lua
new file mode 100644
index 000000000..0096f0f03
--- /dev/null
+++ b/tests/modules/cache/test.lua
@@ -0,0 +1,42 @@
+import("core.cache.memcache")
+import("core.cache.localcache")
+import("core.cache.globalcache")
+
+function test_memcache(t)
+ memcache.set("mycache", "xyz", {1, 2, 3})
+ memcache.set2("mycache", "foo", "bar", "1")
+ t:are_equal(memcache.get("mycache", "xyz"), {1, 2, 3})
+ t:are_equal(memcache.get2("mycache", "foo", "bar"), "1")
+ memcache.clear("mycache")
+ t:are_equal(memcache.get2("mycache", "foo", "bar"), nil)
+ memcache.set2("mycache", "foo", "bar", "1")
+ memcache.clear()
+ t:are_equal(memcache.get("mycache", "xyz"), nil)
+ t:are_equal(memcache.get2("mycache", "foo", "bar"), nil)
+end
+
+function test_localcache(t)
+ localcache.set("mycache", "xyz", {1, 2, 3})
+ localcache.set2("mycache", "foo", "bar", "1")
+ t:are_equal(localcache.get("mycache", "xyz"), {1, 2, 3})
+ t:are_equal(localcache.get2("mycache", "foo", "bar"), "1")
+ localcache.clear("mycache")
+ t:are_equal(localcache.get2("mycache", "foo", "bar"), nil)
+ localcache.set2("mycache", "foo", "bar", "1")
+ localcache.clear()
+ t:are_equal(localcache.get("mycache", "xyz"), nil)
+ t:are_equal(localcache.get2("mycache", "foo", "bar"), nil)
+end
+
+function test_globalcache(t)
+ globalcache.set("mycache", "xyz", {1, 2, 3})
+ globalcache.set2("mycache", "foo", "bar", "1")
+ t:are_equal(globalcache.get("mycache", "xyz"), {1, 2, 3})
+ t:are_equal(globalcache.get2("mycache", "foo", "bar"), "1")
+ globalcache.clear("mycache")
+ t:are_equal(globalcache.get2("mycache", "foo", "bar"), nil)
+ globalcache.set2("mycache", "foo", "bar", "1")
+ globalcache.clear()
+ t:are_equal(globalcache.get("mycache", "xyz"), nil)
+ t:are_equal(globalcache.get2("mycache", "foo", "bar"), nil)
+end
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index 599224d42..9e7110c7f 100644
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -25,9 +25,8 @@ import("core.base.hashset")
import("core.project.config")
import("core.project.project")
import("core.platform.platform")
-import("core.project.cache")
import("private.detect.find_platform")
-import("lib.detect.cache", {alias = "detectcache"})
+import("core.cache.localcache")
import("scangen")
import("menuconf", {alias = "menuconf_show"})
import("configfiles", {alias = "generate_configfiles"})
@@ -69,9 +68,8 @@ function _need_check(changed)
local mtimes = project.mtimes()
-- get the previous mtimes
- local configcache = cache("local.config")
if not changed then
- local mtimes_prev = configcache:get("mtimes")
+ local mtimes_prev = localcache.get("config", "mtimes")
if mtimes_prev then
-- check for all project files
@@ -96,7 +94,7 @@ function _need_check(changed)
end
-- update mtimes
- configcache:set("mtimes", mtimes)
+ localcache.set("config", "mtimes", mtimes)
-- changed?
return changed
@@ -204,9 +202,6 @@ force to build in current directory via run `xmake -P .`]], os.projectdir())
-- the target name
local targetname = option.get("target") or "all"
- -- get config cache
- local configcache = cache("local.config")
-
-- load the project configure
--
-- priority: option > option_cache > global > option_default > config_check > project_check > config_cache
@@ -224,7 +219,7 @@ force to build in current directory via run `xmake -P .`]], os.projectdir())
-- override configure from the options or cache
local options_history = {}
if not option.get("clean") and not autogen then
- options_history = configcache:get("options") or {}
+ options_history = localcache.get("config", "options") or {}
options = options or options_history
end
for name, value in pairs(options) do
@@ -281,8 +276,9 @@ force to build in current directory via run `xmake -P .`]], os.projectdir())
local recheck = _need_check(options_changed or not configcache_loaded or autogen)
if recheck then
- -- clear detect cache
- detectcache.clear()
+ -- clear and flush local cache to disk
+ localcache.clear()
+ localcache.save()
-- check platform
instance_plat:check()
@@ -329,12 +325,10 @@ force to build in current directory via run `xmake -P .`]], os.projectdir())
config.dump()
end
- -- save options and configure for the given target
+ -- save options and config cache
config.save()
- configcache:set("options", options)
-
- -- flush config cache
- configcache:flush()
+ localcache.set("config", "options", options)
+ localcache.save("config")
-- unlock the whole project
project.unlock()
diff --git a/xmake/actions/require/clean.lua b/xmake/actions/require/clean.lua
index d06617783..fb93e6304 100644
--- a/xmake/actions/require/clean.lua
+++ b/xmake/actions/require/clean.lua
@@ -20,8 +20,8 @@
-- imports
import("core.base.option")
-import("core.project.cache")
import("core.package.package")
+import("core.cache.localcache")
-- clear the unused or invalid package directories
function _clear_packagedirs(packagedir)
@@ -96,8 +96,8 @@ function main(package_names)
os.rm(package.cachedir())
-- clear require cache
- local require_cache = cache("local.require")
+ local require_cache = localcache.cache("package")
require_cache:clear()
- require_cache:flush()
+ require_cache:save()
end
diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua
index b4bb5e069..a63c948dc 100644
--- a/xmake/actions/require/impl/package.lua
+++ b/xmake/actions/require/impl/package.lua
@@ -27,7 +27,8 @@ import("core.base.scheduler")
import("core.base.tty")
import("private.async.runjobs")
import("private.utils.progress")
-import("lib.detect.cache", {alias = "detectcache"})
+import("core.cache.memcache")
+import("core.cache.localcache")
import("core.project.project")
import("core.package.package", {alias = "core_package"})
import("actions.install", {alias = "action_install"})
@@ -36,6 +37,11 @@ import("devel.git")
import("net.fasturl")
import("repository")
+-- get memcache
+function _memcache()
+ return memcache.cache("require.impl.package")
+end
+
--
-- parse require string
--
@@ -76,7 +82,7 @@ import("repository")
function _parse_require(require_str, requires_extra, parentinfo)
-- get it from cache first
- local requires = _g._REQUIRES or {}
+ local requires = _memcache():get("requires") or {}
local required = requires[require_str]
if required then
return required.packagename, required.requireinfo
@@ -174,7 +180,7 @@ function _parse_require(require_str, requires_extra, parentinfo)
-- save this required item to cache
requires[require_str] = required
- _g._REQUIRES = requires
+ _memcache():set("requires", requires)
-- ok
return required.packagename, required.requireinfo
@@ -231,13 +237,14 @@ end
-- add some builtin configurations to package
function _add_package_configurations(package)
+ local vs_runtime = project.get("target.runtimes") or get_config("vs_runtime") or "MT"
package:add("configs", "debug", {builtin = true, description = "Enable debug symbols.", default = false, type = "boolean"})
package:add("configs", "shared", {builtin = true, description = "Enable shared library.", default = false, type = "boolean"})
package:add("configs", "cflags", {builtin = true, description = "Set the C compiler flags."})
package:add("configs", "cxflags", {builtin = true, description = "Set the C/C++ compiler flags."})
package:add("configs", "cxxflags", {builtin = true, description = "Set the C++ compiler flags."})
package:add("configs", "asflags", {builtin = true, description = "Set the assembler flags."})
- package:add("configs", "vs_runtime", {builtin = true, description = "Set vs compiler runtime.", default = "MT", values = {"MT", "MD"}})
+ package:add("configs", "vs_runtime", {builtin = true, description = "Set vs compiler runtime.", default = vs_runtime, values = {"MT", "MTd", "MD", "MDd"}})
end
-- select package version
@@ -324,7 +331,7 @@ function _load_package(packagename, requireinfo, opt)
-- attempt to get it from cache first
opt = opt or {}
- local packages = _g._PACKAGES or {}
+ local packages = _memcache():get("packages") or {}
local package = packages[packagename]
if package then
@@ -380,7 +387,7 @@ function _load_package(packagename, requireinfo, opt)
-- save this package package to cache
packages[packagename] = package
- _g._PACKAGES = packages
+ _memcache():set("packages", packages)
return package
end
@@ -838,8 +845,8 @@ function uninstall_packages(requires, opt)
-- do not remove dependent packages
opt.nodeps = true
- -- clear the detect cache
- detectcache.clear()
+ -- clear the local cache
+ localcache.clear()
-- remove all packages
local packages = {}
diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua
index d76ecfd3e..cedc3e434 100644
--- a/xmake/actions/require/install.lua
+++ b/xmake/actions/require/install.lua
@@ -165,10 +165,6 @@ end
-- install packages
function main(requires_raw)
- -- avoid to run this task repeatly
- if _g.installed then return end
- _g.installed = true
-
-- get requires and extra config
local requires_extra = nil
local requires, requires_extra = get_requires(requires_raw)
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 62b0c34de..099ceb799 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -764,8 +764,6 @@ function os.iorunv(program, argv, opt)
-- remove the temporary output and error file
os.rm(outfile)
os.rm(errfile)
-
- -- ok?
return ok == 0, outdata, errdata, errors
end
diff --git a/xmake/core/cache/detectcache.lua b/xmake/core/cache/detectcache.lua
new file mode 100644
index 000000000..65f2fadf9
--- /dev/null
+++ b/xmake/core/cache/detectcache.lua
@@ -0,0 +1,22 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file detectcache.lua
+--
+
+return require("cache/localcache").cache("detect")
+
diff --git a/xmake/core/cache/globalcache.lua b/xmake/core/cache/globalcache.lua
new file mode 100644
index 000000000..a18b36ccf
--- /dev/null
+++ b/xmake/core/cache/globalcache.lua
@@ -0,0 +1,206 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file globalcache.lua
+--
+
+-- define module: globalcache
+local globalcache = globalcache or {}
+local _instance = _instance or {}
+
+-- load modules
+local table = require("base/table")
+local io = require("base/io")
+local os = require("base/os")
+local path = require("base/path")
+local global = require("base/global")
+
+-- new an instance
+function _instance.new(name)
+ local instance = table.inherit(_instance)
+ instance._NAME = name
+ instance:load()
+ instance._DATA = instance._DATA or {}
+ return instance
+end
+
+-- get cache name
+function _instance:name()
+ return self._NAME
+end
+
+-- get cache data
+function _instance:data()
+ return self._DATA
+end
+
+-- load cache
+function _instance:load()
+ local result = io.load(path.join(global.cachedir(), self:name()))
+ if result ~= nil then
+ self._DATA = result
+ end
+end
+
+-- save cache
+function _instance:save()
+ local ok, errors = io.save(path.join(global.cachedir(), self:name()), self._DATA)
+ if not ok then
+ os.raise(errors)
+ end
+end
+
+-- get cache value in level/1
+function _instance:get(key)
+ return self._DATA[key]
+end
+
+-- get cache value in level/2
+function _instance:get2(key1, key2)
+ local value1 = self:get(key1)
+ if value1 ~= nil then
+ return value1[key2]
+ end
+end
+
+-- get cache value in level/3
+function _instance:get3(key1, key2, key3)
+ local value2 = self:get2(key1)
+ if value2 ~= nil then
+ return value2[key3]
+ end
+end
+
+-- set cache value in level/1
+function _instance:set(key, value)
+ self._DATA[key] = value
+end
+
+-- set cache value in level/2
+function _instance:set2(key1, key2, value2)
+ local value1 = self:get(key1)
+ if value1 == nil then
+ value1 = {}
+ self:set(key1, value1)
+ end
+ value1[key2] = value2
+end
+
+-- set cache value in level/3
+function _instance:set3(key1, key2, key3, value3)
+ local value2 = self:get2(key1, key2)
+ if value2 == nil then
+ value2 = {}
+ self:set2(key1, key2, value2)
+ end
+ value2[key3] = value3
+end
+
+-- clear cache scopes
+function _instance:clear()
+ self._DATA = {}
+end
+
+-- get cache instance
+function globalcache.cache(cachename)
+ local caches = globalcache._CACHES
+ if not caches then
+ caches = {}
+ globalcache._CACHES = caches
+ end
+ local instance = caches[cachename]
+ if not instance then
+ instance = _instance.new(cachename)
+ caches[cachename] = instance
+ end
+ return instance
+end
+
+-- get all caches
+function globalcache.caches(opt)
+ opt = opt or {}
+ if opt.flush then
+ for _, cachefile in ipairs(os.files(path.join(global.cachedir(), "*"))) do
+ local cachename = path.filename(cachefile)
+ globalcache.cache(cachename)
+ end
+ end
+ return globalcache._CACHES
+end
+
+-- get cache value in level/1
+function globalcache.get(cachename, key)
+ return globalcache.cache(cachename):get(key)
+end
+
+-- get cache value in level/2
+function globalcache.get2(cachename, key1, key2)
+ return globalcache.cache(cachename):get2(key1, key2)
+end
+
+-- get cache value in level/3
+function globalcache.get3(cachename, key1, key2, key3)
+ return globalcache.cache(cachename):get3(key1, key2, key3)
+end
+
+-- set cache value in level/1
+function globalcache.set(cachename, key, value)
+ return globalcache.cache(cachename):set(key, value)
+end
+
+-- set cache value in level/2
+function globalcache.set2(cachename, key1, key2, value)
+ return globalcache.cache(cachename):set2(key1, key2, value)
+end
+
+-- set cache value in level/3
+function globalcache.set3(cachename, key1, key2, key3, value)
+ return globalcache.cache(cachename):set3(key1, key2, key3, value)
+end
+
+-- save the given cache, it will save all caches if cache name is nil
+function globalcache.save(cachename)
+ if cachename then
+ globalcache.cache(cachename):save()
+ else
+ local caches = globalcache.caches()
+ if caches then
+ for _, cache in pairs(caches) do
+ cache:save()
+ end
+ end
+ end
+end
+
+-- clear the given cache, it will clear all caches if cache name is nil
+function globalcache.clear(cachename)
+ if cachename then
+ globalcache.cache(cachename):clear()
+ else
+ local caches = globalcache.caches({flush = true})
+ if caches then
+ for _, cache in pairs(caches) do
+ cache:clear()
+ end
+ end
+ end
+end
+
+-- return module: globalcache
+return globalcache
+
+
diff --git a/xmake/core/cache/localcache.lua b/xmake/core/cache/localcache.lua
new file mode 100644
index 000000000..3fd5d040f
--- /dev/null
+++ b/xmake/core/cache/localcache.lua
@@ -0,0 +1,205 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file localcache.lua
+--
+
+-- define module: localcache
+local localcache = localcache or {}
+local _instance = _instance or {}
+
+-- load modules
+local table = require("base/table")
+local io = require("base/io")
+local os = require("base/os")
+local path = require("base/path")
+local config = require("project/config")
+
+-- new an instance
+function _instance.new(name)
+ local instance = table.inherit(_instance)
+ instance._NAME = name
+ instance:load()
+ instance._DATA = instance._DATA or {}
+ return instance
+end
+
+-- get cache name
+function _instance:name()
+ return self._NAME
+end
+
+-- get cache data
+function _instance:data()
+ return self._DATA
+end
+
+-- load cache
+function _instance:load()
+ local result = io.load(path.join(config.cachedir(), self:name()))
+ if result ~= nil then
+ self._DATA = result
+ end
+end
+
+-- save cache
+function _instance:save()
+ local ok, errors = io.save(path.join(config.cachedir(), self:name()), self._DATA)
+ if not ok then
+ os.raise(errors)
+ end
+end
+
+-- get cache value in level/1
+function _instance:get(key)
+ return self._DATA[key]
+end
+
+-- get cache value in level/2
+function _instance:get2(key1, key2)
+ local value1 = self:get(key1)
+ if value1 ~= nil then
+ return value1[key2]
+ end
+end
+
+-- get cache value in level/3
+function _instance:get3(key1, key2, key3)
+ local value2 = self:get2(key1)
+ if value2 ~= nil then
+ return value2[key3]
+ end
+end
+
+-- set cache value in level/1
+function _instance:set(key, value)
+ self._DATA[key] = value
+end
+
+-- set cache value in level/2
+function _instance:set2(key1, key2, value2)
+ local value1 = self:get(key1)
+ if value1 == nil then
+ value1 = {}
+ self:set(key1, value1)
+ end
+ value1[key2] = value2
+end
+
+-- set cache value in level/3
+function _instance:set3(key1, key2, key3, value3)
+ local value2 = self:get2(key1, key2)
+ if value2 == nil then
+ value2 = {}
+ self:set2(key1, key2, value2)
+ end
+ value2[key3] = value3
+end
+
+-- clear cache scopes
+function _instance:clear()
+ self._DATA = {}
+end
+
+-- get cache instance
+function localcache.cache(cachename)
+ local caches = localcache._CACHES
+ if not caches then
+ caches = {}
+ localcache._CACHES = caches
+ end
+ local instance = caches[cachename]
+ if not instance then
+ instance = _instance.new(cachename)
+ caches[cachename] = instance
+ end
+ return instance
+end
+
+-- get all caches
+function localcache.caches(opt)
+ opt = opt or {}
+ if opt.flush then
+ for _, cachefile in ipairs(os.files(path.join(config.cachedir(), "*"))) do
+ local cachename = path.filename(cachefile)
+ localcache.cache(cachename)
+ end
+ end
+ return localcache._CACHES
+end
+
+-- get cache value in level/1
+function localcache.get(cachename, key)
+ return localcache.cache(cachename):get(key)
+end
+
+-- get cache value in level/2
+function localcache.get2(cachename, key1, key2)
+ return localcache.cache(cachename):get2(key1, key2)
+end
+
+-- get cache value in level/3
+function localcache.get3(cachename, key1, key2, key3)
+ return localcache.cache(cachename):get3(key1, key2, key3)
+end
+
+-- set cache value in level/1
+function localcache.set(cachename, key, value)
+ return localcache.cache(cachename):set(key, value)
+end
+
+-- set cache value in level/2
+function localcache.set2(cachename, key1, key2, value)
+ return localcache.cache(cachename):set2(key1, key2, value)
+end
+
+-- set cache value in level/3
+function localcache.set3(cachename, key1, key2, key3, value)
+ return localcache.cache(cachename):set3(key1, key2, key3, value)
+end
+
+-- save the given cache, it will save all caches if cache name is nil
+function localcache.save(cachename)
+ if cachename then
+ localcache.cache(cachename):save()
+ else
+ local caches = localcache.caches()
+ if caches then
+ for _, cache in pairs(caches) do
+ cache:save()
+ end
+ end
+ end
+end
+
+-- clear the given cache, it will clear all caches if cache name is nil
+function localcache.clear(cachename)
+ if cachename then
+ localcache.cache(cachename):clear()
+ else
+ local caches = localcache.caches({flush = true})
+ if caches then
+ for _, cache in pairs(caches) do
+ cache:clear()
+ end
+ end
+ end
+end
+
+-- return module: localcache
+return localcache
+
diff --git a/xmake/core/cache/memcache.lua b/xmake/core/cache/memcache.lua
new file mode 100644
index 000000000..2a3b9802e
--- /dev/null
+++ b/xmake/core/cache/memcache.lua
@@ -0,0 +1,164 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file memcache.lua
+--
+
+-- define module: memcache
+local memcache = memcache or {}
+local _instance = _instance or {}
+
+-- load modules
+local table = require("base/table")
+
+-- new an instance
+function _instance.new(name)
+ local instance = table.inherit(_instance)
+ instance._NAME = name
+ instance._DATA = {}
+ return instance
+end
+
+-- get cache name
+function _instance:name()
+ return self._NAME
+end
+
+-- get cache data
+function _instance:data()
+ return self._DATA
+end
+
+-- get cache value in level/1
+function _instance:get(key)
+ return self._DATA[key]
+end
+
+-- get cache value in level/2
+function _instance:get2(key1, key2)
+ local value1 = self:get(key1)
+ if value1 ~= nil then
+ return value1[key2]
+ end
+end
+
+-- get cache value in level/3
+function _instance:get3(key1, key2, key3)
+ local value2 = self:get2(key1)
+ if value2 ~= nil then
+ return value2[key3]
+ end
+end
+
+-- set cache value in level/1
+function _instance:set(key, value)
+ self._DATA[key] = value
+end
+
+-- set cache value in level/2
+function _instance:set2(key1, key2, value2)
+ local value1 = self:get(key1)
+ if value1 == nil then
+ value1 = {}
+ self:set(key1, value1)
+ end
+ value1[key2] = value2
+end
+
+-- set cache value in level/3
+function _instance:set3(key1, key2, key3, value3)
+ local value2 = self:get2(key1, key2)
+ if value2 == nil then
+ value2 = {}
+ self:set2(key1, key2, value2)
+ end
+ value2[key3] = value3
+end
+
+-- clear cache scopes
+function _instance:clear()
+ self._DATA = {}
+end
+
+-- get cache instance
+function memcache.cache(cachename)
+ local caches = memcache._CACHES
+ if not caches then
+ caches = {}
+ memcache._CACHES = caches
+ end
+ local instance = caches[cachename]
+ if not instance then
+ instance = _instance.new(cachename)
+ caches[cachename] = instance
+ end
+ return instance
+end
+
+-- get all caches
+function memcache.caches()
+ return memcache._CACHES
+end
+
+-- get cache value in level/1
+function memcache.get(cachename, key)
+ return memcache.cache(cachename):get(key)
+end
+
+-- get cache value in level/2
+function memcache.get2(cachename, key1, key2)
+ return memcache.cache(cachename):get2(key1, key2)
+end
+
+-- get cache value in level/3
+function memcache.get3(cachename, key1, key2, key3)
+ return memcache.cache(cachename):get3(key1, key2, key3)
+end
+
+-- set cache value in level/1
+function memcache.set(cachename, key, value)
+ return memcache.cache(cachename):set(key, value)
+end
+
+-- set cache value in level/2
+function memcache.set2(cachename, key1, key2, value)
+ return memcache.cache(cachename):set2(key1, key2, value)
+end
+
+-- set cache value in level/3
+function memcache.set3(cachename, key1, key2, key3, value)
+ return memcache.cache(cachename):set3(key1, key2, key3, value)
+end
+
+-- clear the given cache, it will clear all caches if cache name is nil
+function memcache.clear(cachename)
+ local caches = memcache.caches()
+ if caches then
+ for _, cache in pairs(caches) do
+ if cachename then
+ if cache:name() == cachename then
+ cache:clear()
+ end
+ else
+ cache:clear()
+ end
+ end
+ end
+end
+
+-- return module: memcache
+return memcache
diff --git a/xmake/core/main.lua b/xmake/core/main.lua
index d9638459f..8eb3e065b 100644
--- a/xmake/core/main.lua
+++ b/xmake/core/main.lua
@@ -37,7 +37,7 @@ local scheduler = require("base/scheduler")
local theme = require("theme/theme")
local config = require("project/config")
local project = require("project/project")
-local history = require("project/history")
+local localcache = require("cache/localcache")
--local profiler = require("base/profiler")
-- init the option menu
@@ -267,7 +267,13 @@ Or you can add `--root` option or XMAKE_ROOT=y to allow run as root temporarily.
-- save command lines to history and we need to make sure that the .xmake directory is not generated everywhere
local skip_history = (os.getenv('XMAKE_SKIP_HISTORY') or ''):trim()
if os.projectfile() and os.isfile(os.projectfile()) and os.isdir(config.directory()) and skip_history == '' then
- history("local.history"):save("cmdlines", option.cmdline())
+ local cmdlines = table.wrap(localcache.get("history", "cmdlines"))
+ if #cmdlines > 64 then
+ table.remove(cmdlines, 1)
+ end
+ table.insert(cmdlines, option.cmdline())
+ localcache.set("history", "cmdlines", cmdlines)
+ localcache.save("history")
end
-- get task instance
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 8d828b961..52c9a0c7c 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -33,6 +33,7 @@ local semver = require("base/semver")
local option = require("base/option")
local scopeinfo = require("base/scopeinfo")
local interpreter = require("base/interpreter")
+local memcache = require("cache/memcache")
local sandbox = require("sandbox/sandbox")
local config = require("project/config")
local platform = require("platform/platform")
@@ -710,7 +711,8 @@ end
-- get the build hash
function _instance:buildhash()
- if self._BUILDHASH == nil then
+ local buildhash = self._BUILDHASH
+ if buildhash == nil then
local str = self:plat() .. self:arch()
local configs = self:configs()
if configs then
@@ -727,9 +729,10 @@ function _instance:buildhash()
configs_str = configs_str:gsub("\"", "")
str = str .. configs_str
end
- self._BUILDHASH = hash.uuid4(str):gsub('-', ''):lower()
+ buildhash = hash.uuid4(str):gsub('-', ''):lower()
+ self._BUILDHASH = buildhash
end
- return self._BUILDHASH
+ return buildhash
end
-- get the group name
@@ -1095,8 +1098,13 @@ function _instance:_generate_build_configs(configs)
if self:is_plat("windows") then
local ld = self:build_getenv("ld")
local vs_runtime = self:config("vs_runtime")
- if ld and path.basename(ld:lower()) == "link" and vs_runtime and vs_runtime == "MT" then
- configs.ldflags = "-nodefaultlib:msvcrt.lib"
+ if vs_runtime and ld and path.basename(ld:lower()) == "link" then -- for msvc?
+ configs.cxflags = table.wrap(configs.cxflags)
+ table.insert(configs.cxflags, "/" .. vs_runtime)
+ if vs_runtime:startswith("MT") then
+ configs.ldflags = table.wrap(configs.ldflags)
+ table.insert(configs.ldflags, "-nodefaultlib:msvcrt.lib")
+ end
end
end
return configs
@@ -1283,6 +1291,11 @@ function package._interpreter()
return interp
end
+-- get package memcache
+function package._memcache()
+ return memcache.cache("core.base.package")
+end
+
-- get package apis
function package.apis()
@@ -1364,9 +1377,9 @@ end
function package.load_from_system(packagename)
-- get it directly from cache first
- package._PACKAGES = package._PACKAGES or {}
- if package._PACKAGES[packagename] then
- return package._PACKAGES[packagename]
+ local instance = package._memcache():get2("packages", packagename)
+ if instance then
+ return instance
end
-- get package info
@@ -1389,7 +1402,7 @@ function package.load_from_system(packagename)
end
-- make sandbox instance with the given script
- local instance, errors = sandbox.new(on_install, interp:filter())
+ instance, errors = sandbox.new(on_install, interp:filter())
if not instance then
return nil, errors
end
@@ -1404,7 +1417,7 @@ function package.load_from_system(packagename)
end
-- new an instance
- local instance = _instance.new(packagename, scopeinfo.new("package", packageinfo))
+ instance = _instance.new(packagename, scopeinfo.new("package", packageinfo))
-- mark as system or 3rd package
instance._isSys = true
@@ -1424,9 +1437,7 @@ function package.load_from_system(packagename)
end
-- save instance to the cache
- package._PACKAGES[packagename] = instance
-
- -- ok
+ package._memcache():set2("packages", instance)
return instance
end
@@ -1434,9 +1445,9 @@ end
function package.load_from_project(packagename, project)
-- get it directly from cache first
- package._PACKAGES = package._PACKAGES or {}
- if package._PACKAGES[packagename] then
- return package._PACKAGES[packagename]
+ local instance = package._memcache():get2("packages", packagename)
+ if instance then
+ return instance
end
-- load packages (with cache)
@@ -1458,8 +1469,8 @@ function package.load_from_project(packagename, project)
end
-- new an instance
- local instance = _instance.new(packagename, packageinfo)
- package._PACKAGES[packagename] = instance
+ instance = _instance.new(packagename, packageinfo)
+ package._memcache():set2("packages", instance)
return instance
end
@@ -1467,9 +1478,9 @@ end
function package.load_from_repository(packagename, repo, packagedir, packagefile)
-- get it directly from cache first
- package._PACKAGES = package._PACKAGES or {}
- if package._PACKAGES[packagename] then
- return package._PACKAGES[packagename]
+ local instance = package._memcache():get2("packages", packagename)
+ if instance then
+ return instance
end
-- load repository first for checking the xmake minimal version
@@ -1516,13 +1527,13 @@ function package.load_from_repository(packagename, repo, packagedir, packagefile
end
-- new an instance
- local instance = _instance.new(packagename, packageinfo, path.directory(scriptpath))
+ instance = _instance.new(packagename, packageinfo, path.directory(scriptpath))
-- save repository
instance._REPO = repo
-- save instance to the cache
- package._PACKAGES[packagename] = instance
+ package._memcache():set2("packages", instance)
return instance
end
diff --git a/xmake/core/package/repository.lua b/xmake/core/package/repository.lua
index 38f0c15b1..736517d00 100644
--- a/xmake/core/package/repository.lua
+++ b/xmake/core/package/repository.lua
@@ -26,9 +26,10 @@ local _instance = _instance or {}
local utils = require("base/utils")
local string = require("base/string")
local global = require("base/global")
-local cache = require("project/cache")
local config = require("project/config")
local interpreter = require("base/interpreter")
+local localcache = require("cache/localcache")
+local globalcache = require("cache/globalcache")
-- new an instance
function _instance.new(name, url, branch, directory, is_global)
@@ -42,8 +43,6 @@ function _instance.new(name, url, branch, directory, is_global)
instance._BRANCH = branch
instance._DIRECTORY = directory
instance._IS_GLOBAL = is_global
-
- -- ok
return instance
end
@@ -119,21 +118,11 @@ end
-- get cache
function repository._cache(is_global)
-
- -- get position
- local position = is_global and "global" or "local"
-
- -- get it from cache first if exists
- if repository._CACHE and repository._CACHE[position] then
- return repository._CACHE[position]
+ if is_global then
+ return globalcache.cache("repository")
+ else
+ return localcache.cache("repository")
end
-
- -- init cache
- repository._CACHE = repository._CACHE or {}
- repository._CACHE[position] = cache(position .. ".repository")
-
- -- ok
- return repository._CACHE[position]
end
-- the interpreter
@@ -153,8 +142,6 @@ function repository._interpreter()
-- save interpreter
repository._INTERPRETER = interp
-
- -- ok?
return interp
end
@@ -207,8 +194,6 @@ function repository.load(name, url, branch, is_global)
-- save instance to the cache
repository._REPOS[name] = instance
-
- -- ok
return instance
end
@@ -243,9 +228,7 @@ function repository.add(name, url, branch, is_global)
-- save repositories
repository._cache(is_global):set("repositories", repositories)
-
- -- flush it
- repository._cache(is_global):flush()
+ repository._cache(is_global):save()
return true
end
@@ -263,20 +246,14 @@ function repository.remove(name, is_global)
-- save repositories
repository._cache(is_global):set("repositories", repositories)
-
- -- flush it
- repository._cache(is_global):flush()
+ repository._cache(is_global):save()
return true
end
-- clear all repositories
function repository.clear(is_global)
-
- -- clear repositories
repository._cache(is_global):set("repositories", {})
-
- -- flush it
- repository._cache(is_global):flush()
+ repository._cache(is_global):save()
return true
end
diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua
index 2ccc6ff1a..f27fc2857 100644
--- a/xmake/core/project/config.lua
+++ b/xmake/core/project/config.lua
@@ -148,6 +148,11 @@ function config.filepath()
return path.join(config.directory(), xmake._NAME .. ".conf")
end
+-- get the local cache directory
+function config.cachedir()
+ return path.join(config.directory(), "cache")
+end
+
-- get the configure directory on the current host/arch platform
function config.directory()
if config._DIRECTORY == nil then
diff --git a/xmake/core/project/history.lua b/xmake/core/project/history.lua
deleted file mode 100644
index 9f36167b3..000000000
--- a/xmake/core/project/history.lua
+++ /dev/null
@@ -1,92 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
--- Copyright (C) 2015-present, TBOOX Open Source Group.
---
--- @author ruki
--- @file history.lua
---
-
--- define module: history
-local history = history or {}
-
--- load modules
-local os = require("base/os")
-local io = require("base/io")
-local table = require("base/table")
-local utils = require("base/utils")
-local string = require("base/string")
-local cache = require("project/cache")
-
--- the cache instance
---
--- @param scopename local.xxxx
--- global.xxxx
---
-function history._instance(scopename)
-
- -- check
- assert(scopename)
-
- -- init instances
- history._INSTANCES = history._INSTANCES or {}
- local instances = history._INSTANCES
-
- -- this instance has been initialized?
- if instances[scopename] then
- return instances[scopename]
- end
-
- -- init instance
- local instance = table.inherit(history)
-
- -- init cache
- instance._CACHE = cache(scopename)
-
- -- save instance
- instances[scopename] = instance
-
- -- ok
- return instance
-end
-
--- save history
-function history:save(key, value)
-
- -- check
- assert(key and value ~= nil)
-
- -- load history values first
- local values = self:load(key) or {}
-
- -- remove the oldest value if be full
- if #values > 64 then
- table.remove(values, 1)
- end
-
- -- append this value
- table.insert(values, value)
-
- -- save history
- self._CACHE:set(key, values)
- self._CACHE:flush()
-end
-
--- load history
-function history:load(key)
- return self._CACHE:get(key)
-end
-
--- return module: history
-return history._instance
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index fd343b8a6..e7d1c159c 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -33,7 +33,7 @@ local global = require("base/global")
local scopeinfo = require("base/scopeinfo")
local interpreter = require("base/interpreter")
local config = require("project/config")
-local cache = require("project/cache")
+local localcache = require("cache/localcache")
local linker = require("tool/linker")
local compiler = require("tool/compiler")
local sandbox = require("sandbox/sandbox")
@@ -239,21 +239,13 @@ end
-- set the option value
function _instance:set_value(value)
-
- -- set value to option
config.set(self:name(), value)
-
- -- save option
self:_save()
end
-- clear the option status and need recheck it
function _instance:clear()
-
- -- clear config
config.set(self:name(), nil)
-
- -- clear this option in cache
self:_clear()
end
@@ -373,17 +365,7 @@ end
-- get cache
function option._cache()
-
- -- get it from cache first if exists
- if option._CACHE then
- return option._CACHE
- end
-
- -- init cache
- option._CACHE = cache("local.option")
-
- -- ok
- return option._CACHE
+ return localcache.cache("option")
end
-- get option apis
@@ -496,7 +478,7 @@ end
-- save all options to the cache file
function option.save()
- option._cache():flush()
+ option._cache():save()
end
-- return module
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 4749e19bb..db00493ea 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -32,6 +32,7 @@ local global = require("base/global")
local process = require("base/process")
local deprecated = require("base/deprecated")
local interpreter = require("base/interpreter")
+local memcache = require("cache/memcache")
local rule = require("project/rule")
local target = require("project/target")
local config = require("project/config")
@@ -107,7 +108,7 @@ end
-- some packages are enabled?
function project._api_has_package(interp, ...)
-- only for loading targets
- local requires = project._REQUIRES
+ local requires = project._memcache():get("requires")
if requires then
for _, name in ipairs(table.join(...)) do
local pkg = requires[name]
@@ -151,7 +152,7 @@ end
function project._load(force, disable_filter)
-- has already been loaded?
- if project._INFO and not force then
+ if project._memcache():get("rootinfo") and not force then
return true
end
@@ -195,7 +196,7 @@ function project._load(force, disable_filter)
for name, value in pairs(rootinfo_target:info()) do
rootinfo:set("target." .. name, value)
end
- project._INFO = rootinfo
+ project._memcache():set("rootinfo", rootinfo)
-- leave the project directory
oldir, errors = os.cd(oldir)
@@ -401,7 +402,7 @@ function project._load_targets()
-- mark targets have been loaded even if it may fail to load.
-- because once loaded, there will be some cached state, such as options,
-- so if we load it a second time, there will be some hidden state inconsistencies.
- project._TARGETS_LOADED = true
+ project._memcache():set("targets_loaded", true)
-- load all requires first and reload the project file to ensure has_package() works for targets
local requires = project.requires()
@@ -671,16 +672,21 @@ function project._sort_targets(targets, ordertargets, targetrefs, target)
end
end
+-- get project memcache
+function project._memcache()
+ return memcache.cache("core.project.project")
+end
+
-- get project toolchain infos (@note only with toolchain info)
function project._toolchains()
- local toolchains = project._TOOLCHAINS
+ local toolchains = project._memcache():get("toolchains")
if not toolchains then
local errors
toolchains, errors = project._load_toolchains()
if not toolchains then
os.raise(errors)
end
- project._TOOLCHAINS = toolchains
+ project._memcache():set("toolchains", toolchains)
end
return toolchains
end
@@ -880,7 +886,8 @@ end
-- get the project info from the given name
function project.get(name)
- return project._INFO and project._INFO:get(name) or nil
+ local rootinfo = project._memcache():get("rootinfo")
+ return rootinfo and rootinfo:get(name) or nil
end
-- get the project name
@@ -901,10 +908,10 @@ end
-- get the project policy, the root policy of the target scope
function project.policy(name)
- local policies = project._POLICIES
+ local policies = project._memcache():get("policies")
if not policies then
policies = project.get("target.policy")
- project._POLICIES = policies
+ project._memcache():set("policies", policies)
if policies then
local defined_policies = policy.policies()
for name, _ in pairs(policies) do
@@ -917,22 +924,9 @@ function project.policy(name)
return policy.check(name, policies and policies[name])
end
--- clear project cache to reload targets and options
-function project.clear()
-
- -- clear options status in config file first
- for _, opt in ipairs(table.wrap(project._OPTIONS)) do
- opt:clear()
- end
-
- -- clear targets and options
- project._TARGETS = nil
- project._OPTIONS = nil
-end
-
-- project has been loaded?
function project.is_loaded()
- return project._TARGETS_LOADED
+ return project._memcache():get("targets_loaded")
end
-- get the given target
@@ -942,24 +936,27 @@ end
-- get targets
function project.targets()
- if not project._TARGETS then
- local targets, ordertargets, errors = project._load_targets()
+ local targets = project._memcache():get("targets")
+ if not targets then
+ local ordertargets, errors
+ targets, ordertargets, errors = project._load_targets()
if not targets or not ordertargets then
os.raise(errors)
end
- project._TARGETS = targets
- project._ORDERTARGETS = ordertargets
+ project._memcache():set("targets", targets)
+ project._memcache():set("ordertargets", ordertargets)
end
- return project._TARGETS
+ return targets
end
-- get order targets
function project.ordertargets()
- if not project._ORDERTARGETS then
- -- ensure _ORDERTARGETS to be initialized
+ local ordertargets = project._memcache():get("ordertargets")
+ if not ordertargets then
+ -- ensure ordertargets to be cached
project.targets()
end
- return project._ORDERTARGETS
+ return ordertargets
end
-- get the given option
@@ -969,18 +966,16 @@ end
-- get options
function project.options()
-
- -- load options and enable filter
- if not project._OPTIONS then
- local options, errors = project._load_options()
+ local options = project._memcache():get("options")
+ if not options then
+ local errors
+ options, errors = project._load_options()
if not options then
os.raise(errors)
end
- project._OPTIONS = options
+ project._memcache():set("options", options)
end
-
- -- ok
- return project._OPTIONS
+ return options
end
-- get the given require info
@@ -990,19 +985,23 @@ end
-- get requires info
function project.requires()
- if not project._REQUIRES then
- local requires, errors = project._load_requires()
+ local requires = project._memcache():get("requires")
+ if not requires then
+ local errors
+ requires, errors = project._load_requires()
if not requires then
os.raise(errors)
end
- project._REQUIRES = requires
+ project._memcache():set("requires", requires)
end
- return project._REQUIRES
+ return requires
end
-- get string requires
function project.requires_str()
- if not project._REQUIRES_STR then
+ local requires_str = project._memcache():get("requires_str")
+ local requires_extra = project._memcache():get("requires_extra")
+ if not requires_str then
-- reload the project file to handle `has_config()`
local ok, errors = project._load(true)
@@ -1011,11 +1010,11 @@ function project.requires_str()
end
-- get raw requires
- local requires_str, requires_extra = project.get("requires"), project.get("__extra_requires")
- project._REQUIRES_STR = requires_str or false
- project._REQUIRES_EXTRA = requires_extra
+ requires_str, requires_extra = project.get("requires"), project.get("__extra_requires")
+ project._memcache():set("requires_str", requires_str or false)
+ project._memcache():set("requires_extra", requires_extra)
end
- return project._REQUIRES_STR or nil, project._REQUIRES_EXTRA
+ return requires_str or nil, requires_extra
end
-- get the given rule
@@ -1025,14 +1024,16 @@ end
-- get project rules
function project.rules()
- if not project._RULES then
- local rules, errors = project._load_rules()
+ local rules = project._memcache():get("rules")
+ if not rules then
+ local errors
+ rules, errors = project._load_rules()
if not rules then
os.raise(errors)
end
- project._RULES = rules
+ project._memcache():set("rules", rules)
end
- return project._RULES
+ return rules
end
-- get the given toolchain
@@ -1055,26 +1056,30 @@ end
-- get tasks
function project.tasks()
- if not project._TASKS then
- local tasks, errors = project._load_tasks()
+ local tasks = project._memcache():get("tasks")
+ if not tasks then
+ local errors
+ tasks, errors = project._load_tasks()
if not tasks then
os.raise(errors)
end
- project._TASKS = tasks
+ project._memcache():set("tasks", tasks)
end
- return project._TASKS
+ return tasks
end
-- get packages
function project.packages()
- if not project._PACKAGES then
- local packages, errors = project._load_packages()
+ local packages = project._memcache():get("packages")
+ if not packages then
+ local errors
+ packages, errors = project._load_packages()
if not packages then
return nil, errors
end
- project._PACKAGES = packages
+ project._memcache():set("packages", packages)
end
- return project._PACKAGES
+ return packages
end
-- get the mtimes
diff --git a/xmake/core/project/requireinfo.lua b/xmake/core/project/requireinfo.lua
index 04d8e89e4..205b7f6e9 100644
--- a/xmake/core/project/requireinfo.lua
+++ b/xmake/core/project/requireinfo.lua
@@ -22,29 +22,19 @@
local requireinfo = requireinfo or {}
-- load modules
-local io = require("base/io")
-local os = require("base/os")
-local path = require("base/path")
-local table = require("base/table")
-local utils = require("base/utils")
-local cache = require("project/cache")
-local config = require("project/config")
-local semver = require("base/semver")
-local sandbox = require("sandbox/sandbox")
+local io = require("base/io")
+local os = require("base/os")
+local path = require("base/path")
+local table = require("base/table")
+local utils = require("base/utils")
+local config = require("project/config")
+local semver = require("base/semver")
+local sandbox = require("sandbox/sandbox")
+local localcache = require("cache/localcache")
-- get cache
function requireinfo._cache()
-
- -- get it from cache first if exists
- if requireinfo._CACHE then
- return requireinfo._CACHE
- end
-
- -- init cache
- requireinfo._CACHE = cache("local.requires")
-
- -- ok
- return requireinfo._CACHE
+ return localcache.cache("package")
end
-- save the requires info to the cache
@@ -64,7 +54,7 @@ function requireinfo:save()
-- save it
requireinfo._cache():set(self:name(), self._INFO)
- requireinfo._cache():flush()
+ requireinfo._cache():save()
end
-- clear the requireinfo
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 76b4d0cbb..204236394 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -1880,6 +1880,7 @@ function target.apis()
, "target.set_warnings"
, "target.set_fpmodels"
, "target.set_optimize"
+ , "target.set_runtimes"
, "target.set_languages"
, "target.set_toolchains"
-- target.add_xxx
diff --git a/xmake/core/sandbox/modules/import/core/cache/detectcache.lua b/xmake/core/sandbox/modules/import/core/cache/detectcache.lua
new file mode 100644
index 000000000..8e3631cb1
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/cache/detectcache.lua
@@ -0,0 +1,23 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file detectcache.lua
+--
+
+-- return module
+return require("cache/detectcache")
+
diff --git a/xmake/core/sandbox/modules/import/core/cache/globalcache.lua b/xmake/core/sandbox/modules/import/core/cache/globalcache.lua
new file mode 100644
index 000000000..695f2e799
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/cache/globalcache.lua
@@ -0,0 +1,23 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file globalcache.lua
+--
+
+-- return module
+return require("cache/globalcache")
+
diff --git a/xmake/core/sandbox/modules/import/core/project/history.lua b/xmake/core/sandbox/modules/import/core/cache/localcache.lua
index 40e32e719..fb112ec53 100644
--- a/xmake/core/sandbox/modules/import/core/project/history.lua
+++ b/xmake/core/sandbox/modules/import/core/cache/localcache.lua
@@ -15,8 +15,9 @@
-- Copyright (C) 2015-present, TBOOX Open Source Group.
--
-- @author ruki
--- @file history.lua
+-- @file localcache.lua
--
-- return module
-return require("project/history")
+return require("cache/localcache")
+
diff --git a/xmake/core/sandbox/modules/import/core/project/cache.lua b/xmake/core/sandbox/modules/import/core/cache/memcache.lua
index 1397e7cfe..5b975f8ac 100644
--- a/xmake/core/sandbox/modules/import/core/project/cache.lua
+++ b/xmake/core/sandbox/modules/import/core/cache/memcache.lua
@@ -15,9 +15,9 @@
-- Copyright (C) 2015-present, TBOOX Open Source Group.
--
-- @author ruki
--- @file cache.lua
+-- @file memcache.lua
--
-- return module
-return require("project/cache")
+return require("cache/memcache")
diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua
index 8095971c2..1e5faa2a9 100644
--- a/xmake/core/sandbox/modules/import/core/project/project.lua
+++ b/xmake/core/sandbox/modules/import/core/project/project.lua
@@ -50,7 +50,6 @@ sandbox_core_project.rootfile = project.rootfile
sandbox_core_project.allfiles = project.allfiles
sandbox_core_project.rcfile = project.rcfile
sandbox_core_project.directory = project.directory
-sandbox_core_project.clear = project.clear
sandbox_core_project.name = project.name
sandbox_core_project.modes = project.modes
sandbox_core_project.mtimes = project.mtimes
@@ -63,11 +62,6 @@ sandbox_core_project.tmpdir = project.tmpdir
sandbox_core_project.tmpfile = project.tmpfile
sandbox_core_project.is_loaded = project.is_loaded
--- load project
-function sandbox_core_project.load()
- deprecated.add("project.clear() or only remove it", "project.load()")
-end
-
-- check project options
function sandbox_core_project.check()
diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
index 58c3ec783..c8a44d266 100644
--- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
+++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
@@ -22,17 +22,17 @@
local sandbox_core_sandbox = sandbox_core_sandbox or {}
-- load modules
-local sandbox = require("sandbox/sandbox")
-local raise = require("sandbox/modules/raise")
-local try = require("sandbox/modules/try")
-local catch = require("sandbox/modules/catch")
-local utils = require("base/utils")
-local table = require("base/table")
-local colors = require("base/colors")
-local dump = require("base/dump")
-local option = require("base/option")
-local scheduler = require("base/scheduler")
-local history = require("project/history")
+local sandbox = require("sandbox/sandbox")
+local raise = require("sandbox/modules/raise")
+local try = require("sandbox/modules/try")
+local catch = require("sandbox/modules/catch")
+local utils = require("base/utils")
+local table = require("base/table")
+local colors = require("base/colors")
+local dump = require("base/dump")
+local option = require("base/option")
+local scheduler = require("base/scheduler")
+local globalcache = require("cache/globalcache")
-- print variables for interactive mode
function sandbox_core_sandbox._interactive_dump(...)
@@ -82,7 +82,7 @@ function sandbox_core_sandbox.interactive()
readline.clear_history()
-- load history
- replhistory = history("global.history"):load("replhistory") or {}
+ replhistory = table.wrap(globalcache.get("history", "replhistory"))
for _, ln in ipairs(replhistory) do
readline.add_history(ln)
end
@@ -110,8 +110,13 @@ function sandbox_core_sandbox.interactive()
local entries = readline.history_list()
if #entries > #replhistory then
for i = #replhistory + 1, #entries do
- history("global.history"):save("replhistory", entries[i].line)
+ if #replhistory > 64 then
+ table.remove(replhistory, 1)
+ end
+ table.insert(replhistory, entries[i].line)
+ globalcache.set("history", "replhistory", replhistory)
end
+ globalcache.save("history")
end
-- clear history
diff --git a/xmake/core/sandbox/modules/import/lib/detect/cache.lua b/xmake/core/sandbox/modules/import/lib/detect/cache.lua
deleted file mode 100644
index d8b568416..000000000
--- a/xmake/core/sandbox/modules/import/lib/detect/cache.lua
+++ /dev/null
@@ -1,94 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
--- Copyright (C) 2015-present, TBOOX Open Source Group.
---
--- @author ruki
--- @file cache.lua
---
-
--- define module
-local sandbox_lib_detect_cache = sandbox_lib_detect_cache or {}
-
--- load modules
-local os = require("base/os")
-local path = require("base/path")
-local table = require("base/table")
-local utils = require("base/utils")
-local option = require("base/option")
-local cache = require("project/cache")
-local project = require("project/project")
-local sandbox = require("sandbox/sandbox")
-local raise = require("sandbox/modules/raise")
-
--- get detect cache instance
-function sandbox_lib_detect_cache._instance()
- local detectcache = sandbox_lib_detect_cache._INSTANCE or cache(os.isfile(project.rootfile()) and "local.detect" or "memory.detect")
- sandbox_lib_detect_cache._INSTANCE = detectcache
- return detectcache
-end
-
--- load detect cache
---
--- @param name the cache name. e.g. find_program, find_programver, ..
---
-function sandbox_lib_detect_cache.load(name)
-
- -- get detect cache
- local detectcache = sandbox_lib_detect_cache._instance()
-
- -- attempt to get result from cache first
- local cacheinfo = detectcache:get(name)
- if cacheinfo == nil then
- cacheinfo = {}
- detectcache:set(name, cacheinfo)
- end
- return cacheinfo
-end
-
--- save detect cache
---
--- @param name the cache name. e.g. find_program, find_programver, ..
--- @param info the cache info
---
-function sandbox_lib_detect_cache.save(name, info)
-
- -- get detect cache
- local detectcache = sandbox_lib_detect_cache._instance()
-
- -- save cache info
- detectcache:set(name, info)
- detectcache:flush()
-end
-
--- clear detect cache
---
--- @param name the cache name. e.g. find_program, find_programver, ..
---
-function sandbox_lib_detect_cache.clear(name)
-
- -- get detect cache
- local detectcache = sandbox_lib_detect_cache._instance()
-
- -- clear cache info
- if name then
- detectcache:set(name, {})
- else
- detectcache:clear()
- end
- detectcache:flush()
-end
-
--- return module
-return sandbox_lib_detect_cache
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
index dc375251c..8e466bbd2 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
@@ -22,18 +22,18 @@
local sandbox_lib_detect_find_program = sandbox_lib_detect_find_program or {}
-- load modules
-local os = require("base/os")
-local path = require("base/path")
-local option = require("base/winos")
-local table = require("base/table")
-local utils = require("base/utils")
-local option = require("base/option")
-local project = require("project/project")
-local sandbox = require("sandbox/sandbox")
-local raise = require("sandbox/modules/raise")
-local vformat = require("sandbox/modules/vformat")
-local cache = require("sandbox/modules/import/lib/detect/cache")
-local scheduler = require("sandbox/modules/import/core/base/scheduler")
+local os = require("base/os")
+local path = require("base/path")
+local option = require("base/winos")
+local table = require("base/table")
+local utils = require("base/utils")
+local option = require("base/option")
+local project = require("project/project")
+local detectcache = require("cache/detectcache")
+local sandbox = require("sandbox/sandbox")
+local raise = require("sandbox/modules/raise")
+local vformat = require("sandbox/modules/vformat")
+local scheduler = require("sandbox/modules/import/core/base/scheduler")
-- globals
local checking = nil
@@ -55,7 +55,11 @@ function sandbox_lib_detect_find_program._check(program, opt)
-- no check script? attempt to run it directly
if not opt.check then
- return 0 == os.execv(program, {"--version"}, {stdout = os.nuldev(), stderr = os.nuldev(), envs = opt.envs})
+ local ok, errors = os.runv(program, {"--version"}, {envs = opt.envs})
+ if not ok and option.get("verbose") and option.get("diagnosis") then
+ utils.cprint("${color.warning}checkinfo: ${clear dim}" .. errors)
+ end
+ return ok
end
-- check it
@@ -68,7 +72,7 @@ function sandbox_lib_detect_find_program._check(program, opt)
end
-- check failed? print verbose error info
- if not ok and option.get("diagnosis") then
+ if not ok and option.get("verbose") and option.get("diagnosis") then
utils.cprint("${color.warning}checkinfo: ${clear dim}" .. errors)
end
return ok
@@ -255,8 +259,7 @@ function sandbox_lib_detect_find_program.main(name, opt)
end
-- attempt to get result from cache first
- local cacheinfo = cache.load(cachekey)
- local result = cacheinfo[name]
+ local result = detectcache:get2(cachekey, name)
if result ~= nil and not opt.force then
return result and result or nil
end
@@ -279,10 +282,8 @@ function sandbox_lib_detect_find_program.main(name, opt)
checking = nil
-- cache result
- cacheinfo[name] = result and result or false
-
- -- save cache info
- cache.save(cachekey, cacheinfo)
+ detectcache:set2(cachekey, name, result and result or false)
+ detectcache:save()
-- trace
if option.get("verbose") or opt.verbose then
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua b/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua
index df5cae0eb..daa6b3ea5 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua
@@ -22,16 +22,16 @@
local sandbox_lib_detect_find_programver = sandbox_lib_detect_find_programver or {}
-- load modules
-local os = require("base/os")
-local path = require("base/path")
-local table = require("base/table")
-local utils = require("base/utils")
-local option = require("base/option")
-local semver = require("base/semver")
-local project = require("project/project")
-local sandbox = require("sandbox/sandbox")
-local raise = require("sandbox/modules/raise")
-local cache = require("sandbox/modules/import/lib/detect/cache")
+local os = require("base/os")
+local path = require("base/path")
+local table = require("base/table")
+local utils = require("base/utils")
+local option = require("base/option")
+local semver = require("base/semver")
+local project = require("project/project")
+local detectcache = require("cache/detectcache")
+local sandbox = require("sandbox/sandbox")
+local raise = require("sandbox/modules/raise")
-- find program version
--
@@ -62,8 +62,7 @@ function sandbox_lib_detect_find_programver.main(program, opt)
end
-- attempt to get result from cache first
- local cacheinfo = cache.load(cachekey)
- local result = cacheinfo[program]
+ local result = detectcache:get2(cachekey, program)
if result ~= nil and not opt.force then
return result and result or nil
end
@@ -99,8 +98,8 @@ function sandbox_lib_detect_find_programver.main(program, opt)
end
-- save result
- cacheinfo[program] = result and result or false
- cache.save(cachekey, cacheinfo)
+ detectcache:set2(cachekey, program, result and result or false)
+ detectcache:save()
return result
end
diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua
index ec07d1a24..78caadc12 100644
--- a/xmake/core/tool/toolchain.lua
+++ b/xmake/core/tool/toolchain.lua
@@ -31,6 +31,7 @@ local global = require("base/global")
local option = require("base/option")
local interpreter = require("base/interpreter")
local config = require("project/config")
+local localcache = require("cache/localcache")
local language = require("language/language")
local sandbox = require("sandbox/sandbox")
local sandbox_module = require("sandbox/modules/import/core/sandbox/module")
@@ -40,9 +41,9 @@ function _instance.new(name, info, cachekey, configs)
local instance = table.inherit(_instance)
instance._NAME = name
instance._INFO = info
- instance._CACHE = require("sandbox/modules/import/lib/detect/cache")
+ instance._CACHE = localcache.cache("toolchain")
instance._CACHEKEY = cachekey
- instance._CONFIGS = instance._CACHE.load(cachekey) or {}
+ instance._CONFIGS = instance._CACHE:get(cachekey) or {}
for k, v in pairs(configs) do
instance._CONFIGS[k] = v
end
@@ -227,7 +228,8 @@ end
-- save user configs
function _instance:configs_save()
- self._CACHE.save(self:cachekey(), self._CONFIGS)
+ self._CACHE:set(self:cachekey(), self._CONFIGS)
+ self._CACHE:save()
end
-- do check, we only check it once for all architectures
@@ -408,8 +410,6 @@ function toolchain._interpreter()
-- save interpreter
toolchain._INTERPRETER = interp
-
- -- ok?
return interp
end
@@ -417,7 +417,7 @@ end
function toolchain._cachekey(name, opt)
local cachekey = opt.cachekey
if not cachekey then
- cachekey = "toolchain_" .. name
+ cachekey = name
for _, k in ipairs(table.orderkeys(opt)) do
local v = opt[k]
cachekey = cachekey .. "_" .. k .. "_" .. tostring(v)
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua
index ef324f548..f21db9e5b 100644
--- a/xmake/languages/c++/xmake.lua
+++ b/xmake/languages/c++/xmake.lua
@@ -62,6 +62,7 @@ language("c++")
, "target.optimize:check"
, "target.vectorexts:check"
, "target.languages"
+ , "target.runtimes"
, "target.includedirs"
, "target.defines"
, "target.undefines"
@@ -100,6 +101,7 @@ language("c++")
, "target.rpathdirs"
, "target.strip"
, "target.symbols"
+ , "target.runtimes"
, "option.strip"
, "option.symbols"
, "option.linkdirs"
@@ -130,6 +132,7 @@ language("c++")
, "target.rpathdirs"
, "target.strip"
, "target.symbols"
+ , "target.runtimes"
, "option.strip"
, "option.symbols"
, "option.linkdirs"
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index ba9e82d84..64d4d2773 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -142,8 +142,6 @@ end
-- make the warning flag
function nf_warning(self, level)
-
- -- the maps
local maps =
{
none = "-W0"
@@ -154,15 +152,11 @@ function nf_warning(self, level)
, everything = "-Wall"
, error = "-WX"
}
-
- -- make it
return maps[level]
end
-- make the optimize flag
function nf_optimize(self, level)
-
- -- the maps
local maps =
{
none = "-Od"
@@ -171,15 +165,18 @@ function nf_optimize(self, level)
, smallest = "-O1 -GL" -- /GL and (/OPT:REF is on by default in linker), we need enable /ltcg
, aggressive = "-Ox -fp:fast"
}
-
- -- make it
return maps[level]
end
+-- make vs runtime flag
+function nf_runtime(self, vs_runtime)
+ if vs_runtime then
+ return "-" .. vs_runtime
+ end
+end
+
-- make the vector extension flag
function nf_vectorext(self, extension)
-
- -- the maps
local maps =
{
sse = "-arch:SSE"
@@ -187,8 +184,6 @@ function nf_vectorext(self, extension)
, avx = "-arch:AVX"
, avx2 = "-arch:AVX2"
}
-
- -- check it
local flag = maps[extension]
if flag and self:has_flags(flag, "cxflags") then
return flag
diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua
index 844b5d67a..26abc8983 100644
--- a/xmake/modules/core/tools/link.lua
+++ b/xmake/modules/core/tools/link.lua
@@ -96,6 +96,13 @@ function nf_syslink(self, lib)
return nf_link(self, lib)
end
+-- make vs runtime flag
+function nf_runtime(self, vs_runtime)
+ if vs_runtime and vs_runtime:startswith("MT") then
+ return "-nodefaultlib:msvcrt.lib"
+ end
+end
+
-- make the linkdir flag
function nf_linkdir(self, dir)
return "-libpath:" .. os.args(path.translate(dir))
diff --git a/xmake/modules/detect/sdks/find_android_sdk.lua b/xmake/modules/detect/sdks/find_android_sdk.lua
index a15cab02b..047f2aac4 100644
--- a/xmake/modules/detect/sdks/find_android_sdk.lua
+++ b/xmake/modules/detect/sdks/find_android_sdk.lua
@@ -19,11 +19,11 @@
--
-- imports
-import("lib.detect.cache")
import("core.base.semver")
import("core.base.option")
import("core.base.global")
import("core.project.config")
+import("core.cache.detectcache")
import("lib.detect.find_directory")
-- find sdk directory
@@ -95,7 +95,7 @@ function main(sdkdir, opt)
-- attempt to load cache first
local key = "detect.sdks.find_android_sdk"
- local cacheinfo = cache.load(key)
+ local cacheinfo = detectcache:get(key) or {}
if not opt.force and cacheinfo.sdk and cacheinfo.sdk.sdkdir and os.isdir(cacheinfo.sdk.sdkdir) then
return cacheinfo.sdk
end
@@ -123,8 +123,7 @@ function main(sdkdir, opt)
-- save to cache
cacheinfo.sdk = sdk or false
- cache.save(key, cacheinfo)
-
- -- ok?
+ detectcache:set(key, cacheinfo)
+ detectcache:save()
return sdk
end
diff --git a/xmake/modules/detect/sdks/find_cuda.lua b/xmake/modules/detect/sdks/find_cuda.lua
index f8e6b954e..0f2b28cef 100644
--- a/xmake/modules/detect/sdks/find_cuda.lua
+++ b/xmake/modules/detect/sdks/find_cuda.lua
@@ -19,11 +19,11 @@
--
-- imports
-import("lib.detect.cache")
import("lib.detect.find_file")
import("core.base.option")
import("core.base.global")
import("core.project.config")
+import("core.cache.detectcache")
-- find cuda sdk directory
function _find_sdkdir()
@@ -108,7 +108,7 @@ function main(sdkdir, opt)
-- attempt to load cache first
local key = "detect.sdks.find_cuda"
- local cacheinfo = cache.load(key)
+ local cacheinfo = detectcache:get(key) or {}
if not opt.force and cacheinfo.cuda and cacheinfo.cuda.sdkdir and os.isdir(cacheinfo.cuda.sdkdir) then
return cacheinfo.cuda
end
@@ -134,8 +134,7 @@ function main(sdkdir, opt)
-- save to cache
cacheinfo.cuda = cuda or false
- cache.save(key, cacheinfo)
-
- -- ok?
+ detectcache:set(key, cacheinfo)
+ detectcache:save()
return cuda
end
diff --git a/xmake/modules/detect/sdks/find_dotnet.lua b/xmake/modules/detect/sdks/find_dotnet.lua
index 1557edd50..fcfa4c966 100644
--- a/xmake/modules/detect/sdks/find_dotnet.lua
+++ b/xmake/modules/detect/sdks/find_dotnet.lua
@@ -19,12 +19,12 @@
--
-- imports
-import("lib.detect.cache")
import("lib.detect.find_file")
import("core.tool.toolchain")
import("core.base.option")
import("core.base.global")
import("core.project.config")
+import("core.cache.detectcache")
-- find dotnet directory
function _find_sdkdir(sdkdir)
@@ -101,7 +101,7 @@ function main(sdkdir, opt)
-- attempt to load cache first
local key = "detect.sdks.find_dotnet." .. (sdkdir or "")
- local cacheinfo = cache.load(key)
+ local cacheinfo = detectcache:get(key) or {}
if not opt.force and cacheinfo.dotnet then
return cacheinfo.dotnet
end
@@ -129,8 +129,7 @@ function main(sdkdir, opt)
-- save to cache
cacheinfo.dotnet = dotnet or false
- cache.save(key, cacheinfo)
-
- -- ok?
+ detectcache:set(key, cacheinfo)
+ detectcache:save()
return dotnet
end
diff --git a/xmake/modules/detect/sdks/find_mingw.lua b/xmake/modules/detect/sdks/find_mingw.lua
index 77ef47f98..7be315a9c 100644
--- a/xmake/modules/detect/sdks/find_mingw.lua
+++ b/xmake/modules/detect/sdks/find_mingw.lua
@@ -19,11 +19,11 @@
--
-- imports
-import("lib.detect.cache")
import("lib.detect.find_path")
import("core.base.option")
import("core.base.global")
import("core.project.config")
+import("core.cache.detectcache")
import("detect.sdks.find_cross_toolchain")
-- find mingw directory
@@ -121,7 +121,7 @@ function main(sdkdir, opt)
-- attempt to load cache first
local key = "detect.sdks.find_mingw"
- local cacheinfo = cache.load(key)
+ local cacheinfo = detectcache:get(key) or {}
if not opt.force and cacheinfo.mingw and cacheinfo.mingw.sdkdir and os.isdir(cacheinfo.mingw.sdkdir) then
return cacheinfo.mingw
end
@@ -147,8 +147,7 @@ function main(sdkdir, opt)
-- save to cache
cacheinfo.mingw = mingw or false
- cache.save(key, cacheinfo)
-
- -- ok?
+ detectcache:set(key, cacheinfo)
+ detectcache:save()
return mingw
end
diff --git a/xmake/modules/detect/sdks/find_ndk.lua b/xmake/modules/detect/sdks/find_ndk.lua
index 3298d0eec..996b63e8c 100644
--- a/xmake/modules/detect/sdks/find_ndk.lua
+++ b/xmake/modules/detect/sdks/find_ndk.lua
@@ -19,10 +19,10 @@
--
-- imports
-import("lib.detect.cache")
import("core.base.option")
import("core.base.global")
import("core.project.config")
+import("core.cache.detectcache")
import("lib.detect.find_directory")
-- find ndk directory
@@ -196,7 +196,7 @@ function main(sdkdir, opt)
-- attempt to load cache first
local key = "detect.sdks.find_ndk"
- local cacheinfo = cache.load(key)
+ local cacheinfo = detectcache:get(key) or {}
if not opt.force and cacheinfo.ndk and cacheinfo.ndk.sdkdir and os.isdir(cacheinfo.ndk.sdkdir) then
return cacheinfo.ndk
end
@@ -230,8 +230,7 @@ function main(sdkdir, opt)
-- save to cache
cacheinfo.ndk = ndk or false
- cache.save(key, cacheinfo)
-
- -- ok?
+ detectcache:set(key, cacheinfo)
+ detectcache:save()
return ndk
end
diff --git a/xmake/modules/detect/sdks/find_qt.lua b/xmake/modules/detect/sdks/find_qt.lua
index 663b50afe..1996ac2f9 100644
--- a/xmake/modules/detect/sdks/find_qt.lua
+++ b/xmake/modules/detect/sdks/find_qt.lua
@@ -19,12 +19,12 @@
--
-- imports
-import("lib.detect.cache")
import("lib.detect.find_file")
import("lib.detect.find_tool")
import("core.base.option")
import("core.base.global")
import("core.project.config")
+import("core.cache.detectcache")
-- find qt sdk directory
function _find_sdkdir(sdkdir, sdkver)
@@ -195,7 +195,7 @@ function main(sdkdir, opt)
-- attempt to load cache first
local key = "detect.sdks.find_qt"
- local cacheinfo = cache.load(key)
+ local cacheinfo = detectcache:get(key) or {}
if not opt.force and cacheinfo.qt and cacheinfo.qt.sdkdir and os.isdir(cacheinfo.qt.sdkdir) then
return cacheinfo.qt
end
@@ -227,8 +227,7 @@ function main(sdkdir, opt)
-- save to cache
cacheinfo.qt = qt or false
- cache.save(key, cacheinfo)
-
- -- ok?
+ detectcache:set(key, cacheinfo)
+ detectcache:save()
return qt
end
diff --git a/xmake/modules/detect/sdks/find_wdk.lua b/xmake/modules/detect/sdks/find_wdk.lua
index 3c7b989b7..b7683211c 100644
--- a/xmake/modules/detect/sdks/find_wdk.lua
+++ b/xmake/modules/detect/sdks/find_wdk.lua
@@ -19,12 +19,12 @@
--
-- imports
-import("lib.detect.cache")
import("lib.detect.find_file")
import("core.base.option")
import("core.base.global")
import("core.project.config")
import("core.tool.toolchain")
+import("core.cache.detectcache")
import("detect.sdks.find_vstudio")
-- find WDK directory
@@ -153,7 +153,7 @@ function main(sdkdir, opt)
-- attempt to load cache first
local key = "detect.sdks.find_wdk"
- local cacheinfo = cache.load(key)
+ local cacheinfo = detectcache:get(key) or {}
if not opt.force and cacheinfo.wdk and cacheinfo.wdk.sdkdir and os.isdir(cacheinfo.wdk.sdkdir) then
return cacheinfo.wdk
end
@@ -181,8 +181,7 @@ function main(sdkdir, opt)
-- save to cache
cacheinfo.wdk = wdk or false
- cache.save(key, cacheinfo)
-
- -- ok?
+ detectcache:set(key, cacheinfo)
+ detectcache:save()
return wdk
end
diff --git a/xmake/modules/detect/sdks/find_xcode.lua b/xmake/modules/detect/sdks/find_xcode.lua
index 80d7cf5cf..02ea606bf 100644
--- a/xmake/modules/detect/sdks/find_xcode.lua
+++ b/xmake/modules/detect/sdks/find_xcode.lua
@@ -19,10 +19,10 @@
--
-- imports
-import("lib.detect.cache")
import("core.base.option")
import("core.base.global")
import("core.project.config")
+import("core.cache.detectcache")
import("lib.detect.find_directory")
import("private.tools.codesign")
@@ -144,7 +144,7 @@ function main(sdkdir, opt)
-- attempt to load cache first
local key = "detect.sdks.find_xcode"
- local cacheinfo = cache.load(key)
+ local cacheinfo = detectcache:get(key) or {}
if not opt.force and cacheinfo.xcode and cacheinfo.xcode.sdkdir and os.isdir(cacheinfo.xcode.sdkdir) then
return cacheinfo.xcode
end
@@ -158,6 +158,7 @@ function main(sdkdir, opt)
-- save to cache
cacheinfo.xcode = xcode or false
- cache.save(key, cacheinfo)
+ detectcache:set(key, cacheinfo)
+ detectcache:save()
return xcode
end
diff --git a/xmake/modules/detect/tools/ar/has_flags.lua b/xmake/modules/detect/tools/ar/has_flags.lua
index 9a528a4a5..914680d69 100644
--- a/xmake/modules/detect/tools/ar/has_flags.lua
+++ b/xmake/modules/detect/tools/ar/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
-- attempt to check it from the argument list
function _check_from_arglist(flags, opt)
@@ -35,11 +35,8 @@ function _check_from_arglist(flags, opt)
-- make allflags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all allflags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- get argument list
@@ -65,8 +62,8 @@ function _check_from_arglist(flags, opt)
end
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
-- ok?
diff --git a/xmake/modules/detect/tools/cl/has_flags.lua b/xmake/modules/detect/tools/cl/has_flags.lua
index bfa738fab..2a398041d 100644
--- a/xmake/modules/detect/tools/cl/has_flags.lua
+++ b/xmake/modules/detect/tools/cl/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
-- attempt to check it from the argument list
function _check_from_arglist(flags, opt)
@@ -35,11 +35,8 @@ function _check_from_arglist(flags, opt)
-- make allflags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all allflags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- get argument list
@@ -52,11 +49,9 @@ function _check_from_arglist(flags, opt)
end
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
-
- -- ok?
return allflags[flags[1]:gsub("/", "-")]
end
diff --git a/xmake/modules/detect/tools/clang_cl/has_flags.lua b/xmake/modules/detect/tools/clang_cl/has_flags.lua
index ffd3ad99a..27728697f 100644
--- a/xmake/modules/detect/tools/clang_cl/has_flags.lua
+++ b/xmake/modules/detect/tools/clang_cl/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
import("core.language.language")
-- attempt to check it from the argument list
@@ -36,11 +36,8 @@ function _check_from_arglist(flags, opt)
-- make allflags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all allflags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- get argument list
@@ -53,11 +50,9 @@ function _check_from_arglist(flags, opt)
end
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
-
- -- ok?
return allflags[flags[1]:gsub("/", "-")]
end
diff --git a/xmake/modules/detect/tools/dmd/has_flags.lua b/xmake/modules/detect/tools/dmd/has_flags.lua
index 372b25416..459db9228 100644
--- a/xmake/modules/detect/tools/dmd/has_flags.lua
+++ b/xmake/modules/detect/tools/dmd/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
-- is linker?
function _islinker(flags, opt)
@@ -57,11 +57,8 @@ function _check_from_arglist(flags, opt, islinker)
-- make allflags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all allflags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- get argument list
@@ -74,11 +71,9 @@ function _check_from_arglist(flags, opt, islinker)
end
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
-
- -- ok?
return allflags[flags[1]]
end
diff --git a/xmake/modules/detect/tools/gcc/has_flags.lua b/xmake/modules/detect/tools/gcc/has_flags.lua
index fd1abd9ed..391ff2bfb 100644
--- a/xmake/modules/detect/tools/gcc/has_flags.lua
+++ b/xmake/modules/detect/tools/gcc/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
import("core.language.language")
-- is linker?
@@ -56,11 +56,8 @@ function _check_from_arglist(flags, opt, islinker)
-- make flags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all flags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- get argument list
@@ -73,11 +70,9 @@ function _check_from_arglist(flags, opt, islinker)
end
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
-
- -- ok?
return allflags[flags[1]]
end
diff --git a/xmake/modules/detect/tools/gdc/has_flags.lua b/xmake/modules/detect/tools/gdc/has_flags.lua
index 8520240b7..1ba8c98b0 100644
--- a/xmake/modules/detect/tools/gdc/has_flags.lua
+++ b/xmake/modules/detect/tools/gdc/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
import("core.language.language")
-- is linker?
@@ -56,11 +56,8 @@ function _check_from_arglist(flags, opt, islinker)
-- make flags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all flags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- get argument list
@@ -73,11 +70,9 @@ function _check_from_arglist(flags, opt, islinker)
end
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
-
- -- ok?
return allflags[flags[1]]
end
diff --git a/xmake/modules/detect/tools/gfortran/has_flags.lua b/xmake/modules/detect/tools/gfortran/has_flags.lua
index 9fad1e779..62a35c653 100644
--- a/xmake/modules/detect/tools/gfortran/has_flags.lua
+++ b/xmake/modules/detect/tools/gfortran/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
import("core.language.language")
-- is linker?
@@ -56,11 +56,8 @@ function _check_from_arglist(flags, opt, islinker)
-- make flags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all flags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- get argument list
@@ -73,11 +70,9 @@ function _check_from_arglist(flags, opt, islinker)
end
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
-
- -- ok?
return allflags[flags[1]]
end
diff --git a/xmake/modules/detect/tools/go/has_flags.lua b/xmake/modules/detect/tools/go/has_flags.lua
index 006e26c7f..267d4de8a 100644
--- a/xmake/modules/detect/tools/go/has_flags.lua
+++ b/xmake/modules/detect/tools/go/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
import("core.language.language")
-- is linker?
@@ -52,11 +52,8 @@ function _check_from_arglist(flags, opt, islinker)
-- make flags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all flags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- attempt to get argument list from the error info (help menu)
@@ -78,11 +75,9 @@ function _check_from_arglist(flags, opt, islinker)
}
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
-
- -- ok?
return allflags[flags[1]]
end
diff --git a/xmake/modules/detect/tools/link/has_flags.lua b/xmake/modules/detect/tools/link/has_flags.lua
index 82d4f6854..819a84279 100644
--- a/xmake/modules/detect/tools/link/has_flags.lua
+++ b/xmake/modules/detect/tools/link/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
import("lib.detect.find_tool")
-- try running
@@ -42,11 +42,8 @@ function _check_from_arglist(flags, opt)
-- make allflags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all allflags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- get argument list
@@ -67,8 +64,8 @@ function _check_from_arglist(flags, opt)
end
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
return allflags[flags[1]:gsub("/", "-"):lower()]
end
diff --git a/xmake/modules/detect/tools/ml/has_flags.lua b/xmake/modules/detect/tools/ml/has_flags.lua
index 439c0fa5a..53576fa22 100644
--- a/xmake/modules/detect/tools/ml/has_flags.lua
+++ b/xmake/modules/detect/tools/ml/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
-- attempt to check it from the argument list
function _check_from_arglist(flags, opt)
@@ -35,11 +35,8 @@ function _check_from_arglist(flags, opt)
-- make allflags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all allflags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- get argument list
@@ -52,11 +49,9 @@ function _check_from_arglist(flags, opt)
end
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
-
- -- ok?
return allflags[flags[1]:gsub("/", "-")]
end
diff --git a/xmake/modules/detect/tools/nvcc/has_flags.lua b/xmake/modules/detect/tools/nvcc/has_flags.lua
index 594368e81..9a66c5f42 100644
--- a/xmake/modules/detect/tools/nvcc/has_flags.lua
+++ b/xmake/modules/detect/tools/nvcc/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
import("core.language.language")
-- is linker?
@@ -78,11 +78,8 @@ function _check_from_arglist(flags, opt, islinker)
-- make flags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all flags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- get argument list
@@ -95,11 +92,9 @@ function _check_from_arglist(flags, opt, islinker)
end
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
-
- -- ok?
return allflags[flags[1]]
end
diff --git a/xmake/modules/detect/tools/rustc/has_flags.lua b/xmake/modules/detect/tools/rustc/has_flags.lua
index 1e8506249..e7c55a180 100644
--- a/xmake/modules/detect/tools/rustc/has_flags.lua
+++ b/xmake/modules/detect/tools/rustc/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
-- try running
function _try_running(...)
@@ -43,11 +43,8 @@ function _check_from_arglist(flags, opt)
-- make allflags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all allflags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- get argument list
@@ -60,11 +57,9 @@ function _check_from_arglist(flags, opt)
end
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
-
- -- ok?
return allflags[flags[1]]
end
diff --git a/xmake/modules/detect/tools/sdcc/has_flags.lua b/xmake/modules/detect/tools/sdcc/has_flags.lua
index c2b144334..1198b6f44 100644
--- a/xmake/modules/detect/tools/sdcc/has_flags.lua
+++ b/xmake/modules/detect/tools/sdcc/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
import("core.language.language")
-- is linker?
@@ -58,11 +58,8 @@ function _check_from_arglist(flags, opt, islinker)
-- make flags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all flags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- get argument list
@@ -75,11 +72,9 @@ function _check_from_arglist(flags, opt, islinker)
end
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
-
- -- ok?
return allflags[flags[1]]
end
diff --git a/xmake/modules/detect/tools/swiftc/has_flags.lua b/xmake/modules/detect/tools/swiftc/has_flags.lua
index 3a0749edb..541b897a9 100644
--- a/xmake/modules/detect/tools/swiftc/has_flags.lua
+++ b/xmake/modules/detect/tools/swiftc/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
-- try running
function _try_running(...)
@@ -43,11 +43,8 @@ function _check_from_arglist(flags, opt)
-- make allflags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all allflags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- get argument list
@@ -60,11 +57,9 @@ function _check_from_arglist(flags, opt)
end
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
-
- -- ok?
return allflags[flags[1]]
end
diff --git a/xmake/modules/detect/tools/zig/has_flags.lua b/xmake/modules/detect/tools/zig/has_flags.lua
index 12091eb87..b12f3defb 100644
--- a/xmake/modules/detect/tools/zig/has_flags.lua
+++ b/xmake/modules/detect/tools/zig/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
-- is linker?
function _islinker(flags, opt)
@@ -51,11 +51,8 @@ function _check_from_arglist(flags, opt, islinker)
-- make allflags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
- -- load cache
- local cacheinfo = cache.load(key)
-
-- get all allflags from argument list
- local allflags = cacheinfo[flagskey]
+ local allflags = detectcache:get2(key, flagskey)
if not allflags then
-- get argument list
@@ -68,11 +65,9 @@ function _check_from_arglist(flags, opt, islinker)
end
-- save cache
- cacheinfo[flagskey] = allflags
- cache.save(key, cacheinfo)
+ detectcache:set2(key, flagskey, allflags)
+ detectcache:save()
end
-
- -- ok?
return allflags[flags[1]]
end
diff --git a/xmake/modules/lib/detect/find_cudadevices.lua b/xmake/modules/lib/detect/find_cudadevices.lua
index 92ffcf5cd..c55cc26f8 100644
--- a/xmake/modules/lib/detect/find_cudadevices.lua
+++ b/xmake/modules/lib/detect/find_cudadevices.lua
@@ -22,7 +22,7 @@
import("core.base.option")
import("core.platform.platform")
import("core.project.config")
-import("lib.detect.cache")
+import("core.cache.detectcache")
import("lib.detect.find_tool")
-- a magic string to filter output
@@ -181,7 +181,7 @@ function _get_devices(opt)
end
-- check cache
- local cachedata = cache.load(cachekey)
+ local cachedata = detectcache:get(cachekey) or {}
if cachedata.succeed and not opt.force then
return cachedata.data
end
@@ -196,7 +196,8 @@ function _get_devices(opt)
end
-- fill cache
- cache.save(cachekey, cachedata)
+ detectcache:set(cachekey, cachedata)
+ detectcache:save()
return devices
end
diff --git a/xmake/modules/lib/detect/find_package.lua b/xmake/modules/lib/detect/find_package.lua
index e6f4c8f21..5e50c2345 100644
--- a/xmake/modules/lib/detect/find_package.lua
+++ b/xmake/modules/lib/detect/find_package.lua
@@ -21,7 +21,7 @@
-- imports
import("core.base.option")
import("core.project.config")
-import("lib.detect.cache")
+import("core.cache.detectcache")
import("package.manager.find_package")
-- find package using the package manager
@@ -71,7 +71,7 @@ function main(name, opt)
end
-- attempt to get result from cache first
- local cacheinfo = cache.load(key)
+ local cacheinfo = detectcache:get(key) or {}
local result = cacheinfo[name]
if result == nil or opt.force then
@@ -87,7 +87,8 @@ function main(name, opt)
-- cache result
cacheinfo[name] = result and result or false
- cache.save(key, cacheinfo)
+ detectcache:set(key, cacheinfo)
+ detectcache:save()
-- trace
if opt.verbose or option.get("verbose") then
diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua
index 4f151740f..4559f7959 100644
--- a/xmake/modules/lib/detect/has_flags.lua
+++ b/xmake/modules/lib/detect/has_flags.lua
@@ -22,7 +22,7 @@
import("core.base.option")
import("core.base.scheduler")
import("core.project.config")
-import("lib.detect.cache")
+import("core.cache.detectcache")
import("lib.detect.find_tool")
-- has the given flags for the current tool?
@@ -84,7 +84,7 @@ function main(name, flags, opt)
end
-- attempt to get result from cache first
- local cacheinfo = cache.load("lib.detect.has_flags")
+ local cacheinfo = detectcache:get("lib.detect.has_flags") or {}
local result = cacheinfo[key]
if result ~= nil and not opt.force then
return result
@@ -137,7 +137,8 @@ function main(name, flags, opt)
-- save result to cache
cacheinfo[key] = result
- cache.save("lib.detect.has_flags", cacheinfo)
+ detectcache:set("lib.detect.has_flags", cacheinfo)
+ detectcache:save()
return result
end
diff --git a/xmake/modules/net/ping.lua b/xmake/modules/net/ping.lua
index a783866fc..1f361a5d6 100644
--- a/xmake/modules/net/ping.lua
+++ b/xmake/modules/net/ping.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("lib.detect.cache")
+import("core.cache.detectcache")
import("detect.tools.find_ping")
import("detect.tools.find_nmap")
import("private.async.runjobs")
@@ -45,7 +45,7 @@ function main(hosts, opt)
-- do not force ping? enable cache
local cacheinfo = nil
if not opt.force then
- cacheinfo = cache.load("net.ping")
+ cacheinfo = detectcache:get("net.ping")
end
-- run tasks
@@ -111,7 +111,8 @@ function main(hosts, opt)
-- save cache
if cacheinfo then
- cache.save("net.ping", cacheinfo)
+ detectcache:set("net.ping", cacheinfo)
+ detectcache:save()
end
-- ok?
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua
index 3835e0d3b..a126fe514 100644
--- a/xmake/modules/package/tools/cmake.lua
+++ b/xmake/modules/package/tools/cmake.lua
@@ -197,10 +197,19 @@ function _get_configs_for_windows(package, configs, opt)
end
end
local vs_runtime = package:config("vs_runtime")
+ if vs_runtime == "MT" then
+ table.insert(configs, "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded")
+ elseif vs_runtime == "MTd" then
+ table.insert(configs, "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug")
+ elseif vs_runtime == "MD" then
+ table.insert(configs, "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL")
+ elseif vs_runtime == "MDd" then
+ table.insert(configs, "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL")
+ end
if vs_runtime then
- table.insert(configs, '-DCMAKE_CXX_FLAGS_DEBUG="/' .. vs_runtime .. 'd"')
+ table.insert(configs, '-DCMAKE_CXX_FLAGS_DEBUG="/' .. vs_runtime .. '"')
table.insert(configs, '-DCMAKE_CXX_FLAGS_RELEASE="/' .. vs_runtime .. '"')
- table.insert(configs, '-DCMAKE_C_FLAGS_DEBUG="/' .. vs_runtime .. 'd"')
+ table.insert(configs, '-DCMAKE_C_FLAGS_DEBUG="/' .. vs_runtime .. '"')
table.insert(configs, '-DCMAKE_C_FLAGS_RELEASE="/' .. vs_runtime .. '"')
end
_get_configs_for_generic(package, configs, opt)
diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua
index 84ef7ef5b..115a5fbe8 100644
--- a/xmake/modules/package/tools/xmake.lua
+++ b/xmake/modules/package/tools/xmake.lua
@@ -33,8 +33,7 @@ function _get_configs(package, configs)
if package:is_plat("windows") then
local vs_runtime = package:config("vs_runtime")
if vs_runtime then
- local vs_runtime_cxflags = "/" .. vs_runtime .. (package:debug() and "d" or "")
- table.insert(cxflags, vs_runtime_cxflags)
+ table.insert(configs, "--vs_runtime=" .. vs_runtime)
end
end
table.insert(configs, "--mode=" .. (package:debug() and "debug" or "release"))
diff --git a/xmake/modules/private/tools/cl/parse_include.lua b/xmake/modules/private/tools/cl/parse_include.lua
index 32088b890..afb43b056 100644
--- a/xmake/modules/private/tools/cl/parse_include.lua
+++ b/xmake/modules/private/tools/cl/parse_include.lua
@@ -22,15 +22,14 @@
import("core.project.project")
import("core.base.hashset")
import("core.tool.toolchain")
-import("lib.detect.cache")
+import("core.cache.detectcache")
import("lib.detect.find_tool")
import("private.tools.vstool")
-- probe include note prefix from cl
function _probe_include_note_from_cl()
- local key = "note_include"
- local cacheinfo = cache.load("cldeps.parse_include")
- local note = cacheinfo[key]
+ local key = "cldeps.parse_include.note"
+ local note = detectcache:get(key)
if not note then
local cl = find_tool("cl")
if cl then
@@ -60,8 +59,8 @@ function _probe_include_note_from_cl()
end
os.tryrm(projectdir)
end
- cacheinfo[key] = note
- cache.save("cldeps.parse_include", cacheinfo)
+ detectcache:set(key, note)
+ detectcache:save()
end
return note
end
diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua
index 0c0f88912..589522730 100644
--- a/xmake/platforms/windows/xmake.lua
+++ b/xmake/platforms/windows/xmake.lua
@@ -51,6 +51,8 @@ platform("windows")
, " e.g. --vs_toolset=14.0" }
, {nil, "vs_sdkver", "kv", nil, "The Windows SDK Version of Visual Studio"
, " e.g. --vs_sdkver=10.0.15063.0" }
+ , {nil, "vs_runtime", "kv", nil, "The Runtime library of Visual Studio"
+ , values = {"MT", "MTd", "MD", "MDd"} }
, {category = "Cuda SDK Configuration" }
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
, {category = "Qt SDK Configuration" }
diff --git a/xmake/plugins/macro/main.lua b/xmake/plugins/macro/main.lua
index dbc94efe7..cf0929792 100644
--- a/xmake/plugins/macro/main.lua
+++ b/xmake/plugins/macro/main.lua
@@ -21,7 +21,7 @@
-- imports
import("core.base.option")
import("core.project.config")
-import("core.project.history")
+import("core.cache.localcache")
-- the macro directories
function _directories()
@@ -46,32 +46,22 @@ function _directory(macroname)
-- check
assert(macrodir, "macro(%s) not found!", macroname)
-
- -- ok
return macrodir
end
-- the readable macro file
function _rfile(macroname)
-
- -- is anonymous?
if macroname == '.' then
macroname = "anonymous"
end
-
- -- get it
return path.join(_directory(macroname), macroname .. ".lua")
end
-- the writable macro file
function _wfile(macroname)
-
- -- is anonymous?
if macroname == '.' then
macroname = "anonymous"
end
-
- -- get it
return path.join(path.join(config.directory(), "macros"), macroname .. ".lua")
end
@@ -86,11 +76,9 @@ function macros(anonymousname)
-- get macro name
local macroname = path.basename(macrofile)
-
if macroname == "anonymous" and anonymousname then
macroname = anonymousname
end
-
table.insert(results, macroname)
end
end
@@ -99,21 +87,14 @@ end
-- list macros
function _list()
-
- -- trace
cprint("${bright}macros:")
-
- -- find all macros
for _, macroname in ipairs(macros(".<anonymous>")) do
- -- show it
print(" " .. macroname)
end
end
-- show macro
function _show(macroname)
-
- -- show it
local file = _rfile(macroname)
if os.isfile(file) then
io.cat(file)
@@ -124,8 +105,6 @@ end
-- clear all macros
function _clear()
-
- -- clear all
os.rm(path.join(config.directory(), "macros"))
end
@@ -207,49 +186,46 @@ end
-- begin to record macro
function _begin()
-
- -- patch begin tag to the history: cmdlines
- history("local.history"):save("cmdlines", "__macro_begin__")
+ localcache.set("history", "cmdlines", "__macro_begin__")
+ localcache.save("history")
end
-- end to record macro
function _end(macroname)
-- load the history: cmdlines
- local cmdlines = history("local.history"):load("cmdlines")
+ local cmdlines = table.wrap(localcache.get("history", "cmdlines"))
-- get the last macro block
local begin = false
local block = {}
- if cmdlines then
- local total = #cmdlines
- local index = total
- while index ~= 0 do
+ local total = #cmdlines
+ local index = total
+ while index ~= 0 do
- -- the command line
- local cmdline = cmdlines[index]
+ -- the command line
+ local cmdline = cmdlines[index]
- -- found begin? break it
- if cmdline == "__macro_begin__" then
- begin = true
- break
- end
-
- -- found end? break it
- if cmdline == "__macro_end__" then
- break
- end
+ -- found begin? break it
+ if cmdline == "__macro_begin__" then
+ begin = true
+ break
+ end
- -- ignore "xmake m .." and "xmake macro .."
- if not cmdline:find("xmake%s+macro%s*") and not cmdline:find("xmake%s+m%s*") then
+ -- found end? break it
+ if cmdline == "__macro_end__" then
+ break
+ end
- -- save this command line to block
- table.insert(block, 1, cmdline)
- end
+ -- ignore "xmake m .." and "xmake macro .."
+ if not cmdline:find("xmake%s+macro%s*") and not cmdline:find("xmake%s+m%s*") then
- -- the previous line
- index = index - 1
+ -- save this command line to block
+ table.insert(block, 1, cmdline)
end
+
+ -- the previous line
+ index = index - 1
end
-- the begin tag not found?
@@ -258,7 +234,9 @@ function _end(macroname)
end
-- patch end tag to the history: cmdlines
- history("local.history"):save("cmdlines", "__macro_end__")
+ table.insert(cmdlines, "__macro_end__")
+ localcache.set("history", "cmdlines", cmdlines)
+ localcache.save("history")
-- open the macro file
local file = io.open(_wfile(macroname), "w")
@@ -268,8 +246,6 @@ function _end(macroname)
-- save the macro block
for _, cmdline in ipairs(block) do
-
- -- save command line
file:print(" os.exec(\"%s\")", (cmdline:gsub("[\\\"]", function (w) return "\\" .. w end)))
end
@@ -293,7 +269,7 @@ function _run(macroname)
if macroname == ".." then
-- load the history: cmdlines
- local cmdlines = history("local.history"):load("cmdlines")
+ local cmdlines = localcache.get("history", "cmdlines")
-- get the last command
local lastcmd = nil
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index 5c4276326..f0a98ac53 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -29,7 +29,8 @@ import("core.tool.toolchain")
import("vs201x_solution")
import("vs201x_vcxproj")
import("vs201x_vcxproj_filters")
-import("lib.detect.cache", {alias = "detectcache"})
+import("core.cache.memcache")
+import("core.cache.localcache")
import("actions.require.install", {alias = "install_requires", rootdir = os.programdir()})
import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()})
import("actions.config.configheader", {alias = "generate_configheader", rootdir = os.programdir()})
@@ -232,16 +233,19 @@ function make(outputdir, vsinfo)
-- reload config, project and platform
if mode ~= config.mode() or arch ~= config.arch() then
- -- clear detect cache
- detectcache.clear()
-
-- modify config
config.set("as", nil, {force = true}) -- force to re-check as for ml/ml64
config.set("mode", mode, {readonly = true, force = true})
config.set("arch", arch, {readonly = true, force = true})
- -- clear project to reload and recheck it
- project.clear()
+ -- clear all options
+ for _, opt in ipairs(project.options()) do
+ opt:clear()
+ end
+
+ -- clear cache
+ memcache.clear()
+ localcache.clear()
-- check platform
platform.load(config.plat(), arch):check()
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
index ff2cad388..04a53b052 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
@@ -305,7 +305,7 @@ function _make_source_options(vcxprojfile, flags, condition)
vcxprojfile:print("<RuntimeLibrary%s>MultiThreadedDLL</RuntimeLibrary>", condition)
elseif flagstr:find("[%-/]MTd") then
vcxprojfile:print("<RuntimeLibrary%s>MultiThreadedDebug</RuntimeLibrary>", condition)
- elseif flagstr:find("[%-/]MT") then
+ else
vcxprojfile:print("<RuntimeLibrary%s>MultiThreaded</RuntimeLibrary>", condition)
end
diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua
index dd5ed48fe..b31f9a729 100644
--- a/xmake/plugins/project/vsxmake/getinfo.lua
+++ b/xmake/plugins/project/vsxmake/getinfo.lua
@@ -23,13 +23,15 @@ import("core.base.option")
import("core.base.semver")
import("core.base.hashset")
import("core.project.config")
-import("core.project.cache")
import("core.project.project")
import("core.platform.platform")
import("core.tool.compiler")
import("core.tool.linker")
+import("core.cache.memcache")
+import("core.cache.localcache")
import("lib.detect.find_tool")
import("private.action.run.make_runenvs")
+import("actions.require.install", {alias = "install_requires", rootdir = os.programdir()})
import("actions.config.configheader", {alias = "generate_configheader", rootdir = os.programdir()})
import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()})
@@ -155,9 +157,8 @@ function _make_targetinfo(mode, arch, target)
if targetinfo.languages:find("c++17", 1, true) or targetinfo.languages:find("cxx17", 1, true) then
targetinfo.cxxlanguage = "stdcpp17"
end
- local configcache = cache("local.config")
local flags = {}
- for k, v in pairs(configcache:get("options_" .. target:name())) do
+ for k, v in pairs(localcache.get("config", "options_" .. target:name())) do
if k ~= "plat" and k ~= "mode" and k ~= "arch" and k ~= "clean" and k ~= "buildir" then
table.insert(flags, "--" .. k .. "=" .. tostring(v));
end
@@ -293,8 +294,14 @@ function main(outputdir, vsinfo)
config.set("mode", mode, {readonly = true, force = true})
config.set("arch", arch, {readonly = true, force = true})
- -- clear project to reload and recheck it
- project.clear()
+ -- clear all options
+ for _, opt in ipairs(project.options()) do
+ opt:clear()
+ end
+
+ -- clear cache
+ memcache.clear()
+ localcache.clear()
-- check platform
platform.load(config.plat(), arch):check()
@@ -302,11 +309,12 @@ function main(outputdir, vsinfo)
-- check project options
project.check()
- -- re-generate configheader
- generate_configheader()
+ -- install and update requires
+ install_requires()
- -- re-generate configfiles
+ -- update config files
generate_configfiles()
+ generate_configheader()
-- ensure to enter project directory
os.cd(project.directory())
diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua
index 926662975..1b188566a 100644
--- a/xmake/rules/c++/xmake.lua
+++ b/xmake/rules/c++/xmake.lua
@@ -48,6 +48,9 @@ rule("c++")
-- add build rules
add_deps("c++.build", "c.build")
+ -- set compiler runtime, e.g. vs runtime
+ add_deps("utils.compiler.runtime")
+
-- inherit links and linkdirs of all dependent targets by default
add_deps("utils.inherit.links")
diff --git a/xmake/rules/utils/compiler_runtime/xmake.lua b/xmake/rules/utils/compiler_runtime/xmake.lua
new file mode 100644
index 000000000..a00ef170e
--- /dev/null
+++ b/xmake/rules/utils/compiler_runtime/xmake.lua
@@ -0,0 +1,31 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+-- define rule: utils.compiler.runtime
+rule("utils.compiler.runtime")
+ after_load(function (target)
+
+ -- set vs runtime
+ local vs_runtime = get_config("vs_runtime")
+ if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then
+ target:set("runtimes", vs_runtime)
+ end
+ end)
+