summaryrefslogtreecommitdiff
path: root/xmake/modules/private
diff options
context:
space:
mode:
authorruki <[email protected]>2022-06-25 16:23:23 +0800
committerruki <[email protected]>2022-06-25 16:23:23 +0800
commit9c9cb6c16989be41c73fcf200370da73f070d0db (patch)
tree06b6b6238e5719f53b7951595409dfe1c6abe37c /xmake/modules/private
parent4ec508fb733cca5dc89a303dab8b398339b43fb7 (diff)
improve distcc
Diffstat (limited to 'xmake/modules/private')
-rw-r--r--xmake/modules/private/service/distcc_build/client.lua28
-rw-r--r--xmake/modules/private/service/distcc_build/client_session.lua11
2 files changed, 30 insertions, 9 deletions
diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua
index 7d3aed752..a34c17aa9 100644
--- a/xmake/modules/private/service/distcc_build/client.lua
+++ b/xmake/modules/private/service/distcc_build/client.lua
@@ -24,6 +24,7 @@ import("core.base.base64")
import("core.base.socket")
import("core.base.option")
import("core.base.scheduler")
+import("core.project.policy")
import("core.project.config", {alias = "project_config"})
import("lib.detect.find_tool")
import("private.service.client_config", {alias = "config"})
@@ -257,16 +258,27 @@ function distcc_build_client:compile(program, argv, opt)
-- do distcc compilation
if not cached then
-- we just compile the large preprocessed file in remote
- if os.filesize(cppinfo.cppfile) > 4096 then
+ if os.filesize(cppinfo.cppfile) > 4096 and not session:is_unreachable() then
local compile_fallback = opt.compile_fallback
if compile_fallback then
- local ok = try {function ()
- local outdata, errdata = session:compile(cppinfo.sourcefile, cppinfo.objectfile, cppinfo.cppfile, cppinfo.cppflags,
- table.join(opt, {cachekey = cachekey}))
- cppinfo.outdata = outdata
- cppinfo.errdata = errdata
- return true
- end}
+ local ok = try
+ {
+ function ()
+ local outdata, errdata = session:compile(cppinfo.sourcefile, cppinfo.objectfile, cppinfo.cppfile, cppinfo.cppflags,
+ table.join(opt, {cachekey = cachekey}))
+ cppinfo.outdata = outdata
+ cppinfo.errdata = errdata
+ return true
+ end,
+ catch
+ {
+ function (errors)
+ if errors and policy.build_warnings() then
+ cprint("${color.warning}fallback to the local compiler, %s", tostring(errors))
+ end
+ 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
diff --git a/xmake/modules/private/service/distcc_build/client_session.lua b/xmake/modules/private/service/distcc_build/client_session.lua
index c3a24f075..1c3d37efb 100644
--- a/xmake/modules/private/service/distcc_build/client_session.lua
+++ b/xmake/modules/private/service/distcc_build/client_session.lua
@@ -58,13 +58,22 @@ function client_session:client()
return self._CLIENT
end
+-- server unreachable?
+function client_session:is_unreachable()
+ return self._UNREACHABLE
+end
+
-- get stream
function client_session:stream()
local stream = self._STREAM
if stream == nil then
local addr = self._ADDR
local port = self._PORT
- local sock = assert(socket.connect(addr, port), "%s: server unreachable!", self)
+ local sock = socket.connect(addr, port)
+ if not sock then
+ self._UNREACHABLE = true
+ raise("%s: server unreachable!", self)
+ end
stream = socket_stream(sock)
self._STREAM = stream
end