diff options
| author | ruki <[email protected]> | 2022-05-14 00:56:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-14 00:56:39 +0800 |
| commit | 6b8299c79e6b8f1548f52b02295a03dcfeccd995 (patch) | |
| tree | 39082e7f320f8b8bbff1103c334932f64f8a87e0 | |
| parent | 952c7a339855b32c83a9baaaa9e3f55929294fdf (diff) | |
wrap gcc to distcc
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 7 | ||||
| -rw-r--r-- | xmake/modules/private/service/distcc_build/client.lua | 39 |
2 files changed, 32 insertions, 14 deletions
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 49184a1d2..c967d222e 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -28,6 +28,7 @@ import("core.project.project") import("core.language.language") import("private.tools.ccache") import("utils.progress") +import("private.service.distcc_build.client", {alias = "distcc_build_client"}) -- init it function init(self) @@ -456,7 +457,11 @@ function compile(self, sourcefile, objectfile, dependinfo, flags) -- do compile local program, argv = compargv(self, sourcefile, objectfile, compflags) - return os.iorunv(program, argv, {envs = self:runenvs()}) + if distcc_build_client.is_connected() then + return distcc_build_client.singleton():iorunv(program, argv, {envs = self:runenvs()}) + else + return os.iorunv(program, argv, {envs = self:runenvs()}) + end end, catch { diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua index 19d44c086..9100a5e1c 100644 --- a/xmake/modules/private/service/distcc_build/client.lua +++ b/xmake/modules/private/service/distcc_build/client.lua @@ -162,6 +162,11 @@ function distcc_build_client:freejobs() return 8 end +-- run compilation job +function distcc_build_client:iorunv(program, argv, opt) + return os.iorunv(program, argv, opt) +end + -- get the status function distcc_build_client:status() local status = self._STATUS @@ -330,22 +335,30 @@ end -- is connected? we cannot depend on client:init when run action function is_connected() - -- the current process is in service? we cannot enable it - if os.getenv("XMAKE_IN_SERVICE") then - return false - end - local projectdir = os.projectdir() - local projectfile = os.projectfile() - if projectfile and os.isfile(projectfile) and projectdir then - local workdir = path.join(project_config.directory(), "distcc_build") - local statusfile = path.join(workdir, "status.txt") - if os.isfile(statusfile) then - local status = io.load(statusfile) - if status and status.connected then - return true + local connected = _g.connected + if connected == nil then + -- the current process is in service? we cannot enable it + if os.getenv("XMAKE_IN_SERVICE") then + connected = false + end + if connected == nil then + local projectdir = os.projectdir() + local projectfile = os.projectfile() + if projectfile and os.isfile(projectfile) and projectdir then + local workdir = path.join(project_config.directory(), "distcc_build") + local statusfile = path.join(workdir, "status.txt") + if os.isfile(statusfile) then + local status = io.load(statusfile) + if status and status.connected then + connected = true + end + end end end + connected = connected or false + _g.connected = connected end + return connected end -- new a client instance |
