diff options
| author | ruki <[email protected]> | 2022-06-16 23:58:42 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-06-16 23:58:42 +0800 |
| commit | 618e06bdbf3e588916ae523e65e1de9e65c10fd3 (patch) | |
| tree | e618f115abca7783d3e80658593eb80d312874e5 | |
| parent | cc1caaa566b08212d484eb2565e671c418789110 (diff) | |
add compile fallback for cl/ccache
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 15 | ||||
| -rw-r--r-- | xmake/modules/private/cache/build_cache.lua | 15 | ||||
| -rw-r--r-- | xmake/modules/private/service/distcc_build/client.lua | 30 |
3 files changed, 51 insertions, 9 deletions
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 6c558ce6b..d736c0ad2 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -502,22 +502,27 @@ end -- do compile function _compile(self, sourcefile, objectfile, compflags, opt) + local function _compile_fallback() + local program, argv = compargv(self, sourcefile, objectfile, compflags, opt) + local outdata, errdata = vstool.iorunv(program, argv, {envs = self:runenvs()}) + return outdata, errdata + end local cppinfo if distcc_build_client.is_distccjob() and distcc_build_client.singleton():has_freejobs() then local program, argv = compargv(self, sourcefile, objectfile, compflags, table.join(opt, {rawargs = true})) cppinfo = distcc_build_client.singleton():compile(program, argv, {envs = self:runenvs(), - preprocess = _preprocess, compile = _compile_preprocessed_file, target = opt.target, tool = self, remote = true}) + 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 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, target = opt.target, tool = self}) + preprocess = _preprocess, compile = _compile_preprocessed_file, compile_fallback = _compile_fallback, + target = opt.target, tool = self}) end if cppinfo then return cppinfo.outdata, cppinfo.errdata else - local program, argv = compargv(self, sourcefile, objectfile, compflags, opt) - local outdata, errdata = vstool.iorunv(program, argv, {envs = self:runenvs()}) - return outdata, errdata + return _compile_fallback() end end diff --git a/xmake/modules/private/cache/build_cache.lua b/xmake/modules/private/cache/build_cache.lua index 4f098c983..fc69b9b84 100644 --- a/xmake/modules/private/cache/build_cache.lua +++ b/xmake/modules/private/cache/build_cache.lua @@ -119,6 +119,7 @@ function dump_stats() local remote_hit_count = (_g.remote_hit_count or 0) local remote_newfiles_count = (_g.remote_newfiles_count or 0) local preprocess_error_count = (_g.preprocess_error_count or 0) + local compile_fallback_count = (_g.compile_fallback_count or 0) vprint("") vprint("build cache stats:") vprint("cache directory: %s", rootdir()) @@ -129,6 +130,7 @@ function dump_stats() vprint("remote cache hit: %d", remote_hit_count) vprint("remote new cached files: %d", remote_newfiles_count) vprint("preprocess failed: %d", preprocess_error_count) + vprint("compile fallback count: %d", compile_fallback_count) vprint("") end @@ -185,7 +187,18 @@ function build(program, argv, opt) os.cp(objectfile_cached, cppinfo.objectfile) else -- do compile - compile(program, cppinfo, opt) + local compile_fallback = opt.compile_fallback + if compile_fallback then + local ok = try {function () compile(program, cppinfo, opt); return true end} + if not ok then + -- we fallback to compile original source file if compiling preprocessed file fails. + -- https://github.com/xmake-io/xmake/issues/2467 + compile_fallback() + _g.compile_fallback_count = (_g.compile_fallback_count or 0) + 1 + end + else + compile(program, cppinfo, opt) + end if cachekey then put(cachekey, cppinfo.objectfile) end diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua index 9f0f4e0c9..946ce32b8 100644 --- a/xmake/modules/private/service/distcc_build/client.lua +++ b/xmake/modules/private/service/distcc_build/client.lua @@ -251,8 +251,22 @@ function distcc_build_client:compile(program, argv, opt) if not cached then -- we just compile the large preprocessed file in remote if os.filesize(cppinfo.cppfile) > 4096 then - session:compile(cppinfo.sourcefile, cppinfo.objectfile, cppinfo.cppfile, cppinfo.cppflags, - table.join(opt, {cachekey = cachekey})) + local compile_fallback = opt.compile_fallback + if compile_fallback then + local ok = try {function () + session:compile(cppinfo.sourcefile, cppinfo.objectfile, cppinfo.cppfile, cppinfo.cppflags, + table.join(opt, {cachekey = cachekey})) + return true + end} + if not ok then + -- we fallback to compile original source file if compiling preprocessed file fails. + -- https://github.com/xmake-io/xmake/issues/2467 + compile_fallback() + end + else + session:compile(cppinfo.sourcefile, cppinfo.objectfile, cppinfo.cppfile, cppinfo.cppflags, + table.join(opt, {cachekey = cachekey})) + end if cachekey then build_cache.put(cachekey, cppinfo.objectfile) end @@ -272,7 +286,17 @@ function distcc_build_client:compile(program, argv, opt) if build_in_local then if cppinfo and build_in_local then local compile = assert(opt.compile, "compiler not found!") - compile(program, cppinfo, opt) + local compile_fallback = opt.compile_fallback + if compile_fallback then + local ok = try {function () compile(program, cppinfo, opt); return true end} + if not ok then + -- we fallback to compile original source file if compiling preprocessed file fails. + -- https://github.com/xmake-io/xmake/issues/2467 + compile_fallback() + end + else + compile(program, cppinfo, opt) + end if build_cache.is_enabled() then local cachekey = build_cache.cachekey(program, cppinfo.cppfile, cppinfo.cppflags, opt.envs) if cachekey then |
