summaryrefslogtreecommitdiff
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
parent4ec508fb733cca5dc89a303dab8b398339b43fb7 (diff)
improve distcc
-rw-r--r--xmake/core/sandbox/modules/import/core/project/policy.lua18
-rw-r--r--xmake/modules/core/tools/cl.lua22
-rw-r--r--xmake/modules/core/tools/gcc.lua36
-rw-r--r--xmake/modules/private/service/distcc_build/client.lua28
-rw-r--r--xmake/modules/private/service/distcc_build/client_session.lua11
5 files changed, 64 insertions, 51 deletions
diff --git a/xmake/core/sandbox/modules/import/core/project/policy.lua b/xmake/core/sandbox/modules/import/core/project/policy.lua
index 91431df0b..254ab8620 100644
--- a/xmake/core/sandbox/modules/import/core/project/policy.lua
+++ b/xmake/core/sandbox/modules/import/core/project/policy.lua
@@ -23,6 +23,8 @@ local sandbox_core_project_policy = sandbox_core_project_policy or {}
-- load modules
local table = require("base/table")
+local global = require("base/global")
+local option = require("base/option")
local policy = require("project/policy")
local project = require("project/project")
local raise = require("sandbox/modules/raise")
@@ -30,5 +32,21 @@ local raise = require("sandbox/modules/raise")
-- export some readonly interfaces
sandbox_core_project_policy.policies = policy.policies
+-- has build warnings?
+function sandbox_core_project_policy.build_warnings()
+ local warnings = sandbox_core_project_policy._BUILD_WARNINGS
+ if warnings == nil then
+ warnings = option.get("diagnosis") or option.get("warning")
+ if warnings == nil and os.isfile(os.projectfile()) and project.policy("build.warning") ~= nil then
+ warnings = project.policy("build.warning")
+ end
+ if warnings == nil then
+ warnings = global.get("build_warning")
+ end
+ sandbox_core_project_policy._BUILD_WARNINGS = warnings or false
+ end
+ return warnings
+end
+
-- return module
return sandbox_core_project_policy
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index 84f30235e..e07ba783d 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -23,6 +23,7 @@ import("core.base.option")
import("core.base.global")
import("core.base.hashset")
import("core.project.project")
+import("core.project.policy")
import("core.language.language")
import("private.tools.vstool")
import("private.tools.cl.parse_include")
@@ -366,22 +367,6 @@ function _compargv_pch(self, pcheaderfile, pcoutputfile, flags)
return self:program(), table.join("-c", "-Yc", pchflags, "-Fp" .. pcoutputfile, "-Fo" .. pcoutputfile .. ".obj", pcheaderfile)
end
--- has warnings output?
-function _has_warnings()
- local warnings = _g.warnings
- if warnings == nil then
- warnings = option.get("diagnosis") or option.get("warning")
- if warnings == nil and os.isfile(os.projectfile()) and project.policy("build.warning") ~= nil then
- warnings = project.policy("build.warning")
- end
- if warnings == nil then
- warnings = global.get("build_warning")
- end
- _g.warnings = warnings or false
- end
- return warnings
-end
-
-- has /sourceDependencies xxx.json @see https://github.com/xmake-io/xmake/issues/868?
function _has_source_dependencies(self)
local has_source_dependencies = _g._HAS_SOURCE_DEPENDENCIES
@@ -520,8 +505,7 @@ end
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
+ return vstool.iorunv(program, argv, {envs = self:runenvs()})
end
local cppinfo
if distcc_build_client.is_distccjob() and distcc_build_client.singleton():has_freejobs() then
@@ -632,7 +616,7 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
function (ok, outdata, errdata)
-- show warnings?
- if ok and _has_warnings() then
+ if ok and policy.build_warnings() then
local output = outdata or ""
if #output:trim() == 0 then
output = errdata or ""
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 2ebecb4ca..0c4627e64 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -25,6 +25,7 @@ import("core.base.colors")
import("core.base.global")
import("core.cache.memcache")
import("core.project.config")
+import("core.project.policy")
import("core.project.project")
import("core.language.language")
import("utils.progress")
@@ -368,22 +369,6 @@ function link(self, objectfiles, targetkind, targetfile, flags)
os.runv(program, argv, {envs = self:runenvs()})
end
--- has warnings output?
-function _has_warnings()
- local warnings = _g.warnings
- if warnings == nil then
- warnings = option.get("diagnosis") or option.get("warning")
- if warnings == nil and os.isfile(os.projectfile()) and project.policy("build.warning") ~= nil then
- warnings = project.policy("build.warning")
- end
- if warnings == nil then
- warnings = global.get("build_warning")
- end
- _g.warnings = warnings or false
- end
- return warnings
-end
-
-- has color diagnostics?
function _has_color_diagnostics(self)
local colors_diagnostics = _g._HAS_COLOR_DIAGNOSTICS
@@ -549,19 +534,24 @@ end
-- do compile
function _compile(self, sourcefile, objectfile, compflags, opt)
- local cppinfo
local program, argv = compargv(self, sourcefile, objectfile, compflags)
+ local function _compile_fallback()
+ return os.iorunv(program, argv, {envs = self:runenvs()})
+ end
+ local cppinfo
if distcc_build_client.is_distccjob() and distcc_build_client.singleton():has_freejobs() then
- cppinfo = distcc_build_client.singleton():compile(program, argv,
- {envs = self:runenvs(), preprocess = _preprocess, compile = _compile_preprocessed_file, tool = self, remote = true})
+ 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
- cppinfo = build_cache.build(program, argv,
- {envs = self:runenvs(), preprocess = _preprocess, compile = _compile_preprocessed_file, tool = self})
+ cppinfo = build_cache.build(program, argv, {envs = self:runenvs(),
+ preprocess = _preprocess, compile = _compile_preprocessed_file, compile_fallback = _compile_fallback,
+ tool = self})
end
if cppinfo then
return cppinfo.outdata, cppinfo.errdata
else
- return os.iorunv(program, argv, {envs = self:runenvs()})
+ return _compile_fallback()
end
end
@@ -672,7 +662,7 @@ function compile(self, sourcefile, objectfile, dependinfo, flags)
{
function (ok, outdata, errdata)
-- show warnings?
- if ok and errdata and #errdata > 0 and _has_warnings() then
+ if ok and errdata and #errdata > 0 and policy.build_warnings() then
local lines = errdata:split('\n', {plain = true})
if #lines > 0 then
if not option.get("diagnosis") then
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