summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-11-01 22:54:09 +0800
committerruki <[email protected]>2022-11-01 22:54:09 +0800
commite639c493025b5d6c5cbdbe588759d34ff8d772b4 (patch)
tree1e91823aee729fb798f61e38480a2ad61a580e06
parent055c7aa757886af0faa87c21e407495ead4c066e (diff)
disable ccache for c++modules
-rw-r--r--xmake/modules/core/tools/cl.lua3
-rw-r--r--xmake/modules/core/tools/gcc.lua5
-rw-r--r--xmake/modules/private/action/build/object.lua2
-rw-r--r--xmake/modules/private/cache/build_cache.lua35
-rw-r--r--xmake/modules/private/service/distcc_build/client.lua4
-rw-r--r--xmake/rules/c++/modules/xmake.lua8
6 files changed, 42 insertions, 15 deletions
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index 31bdce256..7905668a9 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -514,6 +514,7 @@ end
-- do compile
function _compile(self, sourcefile, objectfile, compflags, opt)
+ opt = opt or {}
local function _compile_fallback()
local program, argv = compargv(self, sourcefile, objectfile, compflags, opt)
return vstool.iorunv(program, argv, {envs = self:runenvs()})
@@ -524,7 +525,7 @@ function _compile(self, sourcefile, objectfile, compflags, opt)
cppinfo = distcc_build_client.singleton():compile(program, argv, {envs = self:runenvs(),
preprocess = _preprocess, compile = _compile_preprocessed_file, compile_fallback = _compile_fallback,
target = opt.target, tool = self, remote = true})
- elseif build_cache.is_enabled() and build_cache.is_supported(self:kind()) then
+ elseif build_cache.is_enabled(opt.target) and build_cache.is_supported(self:kind()) then
local program, argv = compargv(self, sourcefile, objectfile, compflags, table.join(opt, {rawargs = true}))
cppinfo = build_cache.build(program, argv, {envs = self:runenvs(),
preprocess = _preprocess, compile = _compile_preprocessed_file, compile_fallback = _compile_fallback,
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 1c3a29c01..897103404 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -555,6 +555,7 @@ end
-- do compile
function _compile(self, sourcefile, objectfile, compflags, opt)
+ opt = opt or {}
local program, argv = compargv(self, sourcefile, objectfile, compflags)
local function _compile_fallback()
return os.iorunv(program, argv, {envs = self:runenvs()})
@@ -564,7 +565,7 @@ function _compile(self, sourcefile, objectfile, compflags, opt)
cppinfo = distcc_build_client.singleton():compile(program, argv, {envs = self:runenvs(),
preprocess = _preprocess, compile = _compile_preprocessed_file, compile_fallback = _compile_fallback,
tool = self, remote = true})
- elseif build_cache.is_enabled() and build_cache.is_supported(self:kind()) then
+ elseif build_cache.is_enabled(opt.target) and build_cache.is_supported(self:kind()) then
cppinfo = build_cache.build(program, argv, {envs = self:runenvs(),
preprocess = _preprocess, compile = _compile_preprocessed_file, compile_fallback = _compile_fallback,
tool = self})
@@ -614,7 +615,7 @@ function compargv(self, sourcefile, objectfile, flags)
end
-- compile the source file
-function compile(self, sourcefile, objectfile, dependinfo, flags)
+function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua
index a89b149ff..00493cf4d 100644
--- a/xmake/modules/private/action/build/object.lua
+++ b/xmake/modules/private/action/build/object.lua
@@ -67,7 +67,7 @@ function _do_build_file(target, sourcefile, opt)
-- exists ccache or distcc?
-- we just show cache/distc to avoid confusion with third-party ccache/distcc
local prefix = ""
- if build_cache.is_enabled() and build_cache.is_supported(sourcekind) then
+ if build_cache.is_enabled(target) and build_cache.is_supported(sourcekind) then
prefix = "cache "
end
if distcc_build_client.is_distccjob() and distcc_build_client.singleton():has_freejobs() then
diff --git a/xmake/modules/private/cache/build_cache.lua b/xmake/modules/private/cache/build_cache.lua
index 4cb1be5ca..24124417c 100644
--- a/xmake/modules/private/cache/build_cache.lua
+++ b/xmake/modules/private/cache/build_cache.lua
@@ -21,12 +21,23 @@
-- imports
import("core.base.bytes")
import("core.base.hashset")
+import("core.cache.memcache")
import("core.project.config")
import("core.project.policy")
import("core.project.project")
import("private.service.client_config")
import("private.service.remote_cache.client", {alias = "remote_cache_client"})
+-- get memcache
+function _memcache()
+ local cache = _g.memcache
+ if not cache then
+ cache = memcache.cache("build_cache")
+ _g.memcache = cache
+ end
+ return cache
+end
+
-- get exist info
function _get_existinfo()
local existinfo = _g.existinfo
@@ -38,21 +49,27 @@ function _get_existinfo()
end
-- is enabled?
-function is_enabled()
- local build_cache = _g.build_cache
- if build_cache == nil then
- if build_cache == nil and os.isfile(os.projectfile()) then
+function is_enabled(target)
+ local key = tostring(target or "all")
+ local result = _memcache():get2("enabled", key)
+ if result == nil then
+ -- target may be option instance
+ if target and target.policy then
+ result = target:policy("build.ccache")
+ end
+ if result == nil and os.isfile(os.projectfile()) then
local policy = project.policy("build.ccache")
if policy ~= nil then
- build_cache = policy
+ result = policy
end
end
- if build_cache == nil then
- build_cache = config.get("ccache") or false
+ if result == nil then
+ result = config.get("ccache")
end
- _g.build_cache = build_cache
+ result = result or false
+ _memcache():set2("enabled", key)
end
- return build_cache or false
+ return result
end
-- is supported?
diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua
index 50bf82f21..38b2145ef 100644
--- a/xmake/modules/private/service/distcc_build/client.lua
+++ b/xmake/modules/private/service/distcc_build/client.lua
@@ -244,7 +244,7 @@ function distcc_build_client:compile(program, argv, opt)
-- get objectfile from the build cache first
local cached = false
local cachekey
- if build_cache.is_enabled() then
+ if build_cache.is_enabled(opt.target) then
cachekey = build_cache.cachekey(program, cppinfo, opt.envs)
local objectfile_cached, objectfile_infofile = build_cache.get(cachekey)
if objectfile_cached then
@@ -341,7 +341,7 @@ function distcc_build_client:compile(program, argv, opt)
else
compile(program, cppinfo, opt)
end
- if build_cache.is_enabled() then
+ if build_cache.is_enabled(opt.target) then
local cachekey = build_cache.cachekey(program, cppinfo, opt.envs)
if cachekey then
local extrainfo
diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua
index 4a7193710..5c90cd3ea 100644
--- a/xmake/rules/c++/modules/xmake.lua
+++ b/xmake/rules/c++/modules/xmake.lua
@@ -36,6 +36,14 @@ rule("c++.build.modules")
-- maybe we will have a more fine-grained configuration strategy to disable it in the future.
target:set("policy", "build.across_targets_in_parallel", false)
+ -- disable ccache for this target
+ --
+ -- Caching can affect incremental compilation, for example
+ -- by interfering with the results of depfile generation for msvc.
+ --
+ -- @see https://github.com/xmake-io/xmake/issues/3000
+ target:set("policy", "build.ccache", false)
+
-- get modules support
local modules_support = common.modules_support(target)