diff options
| author | ruki <[email protected]> | 2022-05-15 22:49:17 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-15 22:49:17 +0800 |
| commit | 03929cccff7008ff6a86177ff128ec525aa0dcbf (patch) | |
| tree | 9172cafc311b083cef8880fca7d76a703f3efbdb | |
| parent | 041c077d21b47bd5b6ce5bab60f36c44d71d355b (diff) | |
clean files in distcc server
4 files changed, 94 insertions, 2 deletions
diff --git a/xmake/modules/private/service/clean_files.lua b/xmake/modules/private/service/clean_files.lua index 2e70c6c64..7660065c9 100644 --- a/xmake/modules/private/service/clean_files.lua +++ b/xmake/modules/private/service/clean_files.lua @@ -20,10 +20,33 @@ -- imports import("core.base.option") +import("core.base.scheduler") +import("private.service.client_config", {alias = "config"}) import("private.service.remote_build.client", {alias = "remote_build_client"}) +import("private.service.distcc_build.client", {alias = "distcc_build_client"}) -function main() - remote_build_client():clean() +function _clean_remote_build_server(...) + remote_build_client(...):clean() +end + +function _clean_distcc_build_server(...) + distcc_build_client(...):clean() +end + +function main(...) + local cleaners = {} + if option.get("remote") then + table.insert(cleaners, _clean_remote_build_server) + elseif option.get("distcc") then + table.insert(cleaners, _clean_distcc_build_server) + else + if config.get("remote_build") then + table.insert(cleaners, _clean_remote_build_server) + end + end + for _, clean_server in ipairs(cleaners) do + scheduler.co_start(clean_server, ...) + end end diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua index ab319cb15..d3097c04d 100644 --- a/xmake/modules/private/service/distcc_build/client.lua +++ b/xmake/modules/private/service/distcc_build/client.lua @@ -197,6 +197,25 @@ function distcc_build_client:has_freejobs() return self:freejobs() > 0 end +-- clean server files +function distcc_build_client:clean() + if not self:is_connected() then + print("%s: has been disconnected!", self) + return + end + + -- do disconnect + local hosts = self:hosts() + assert(hosts and #hosts > 0, "hosts not found!") + local group_name = tostring(self) .. "/clean" + scheduler.co_group_begin(group_name, function () + for _, host in ipairs(hosts) do + scheduler.co_start(self._clean_host, self, host) + end + end) + scheduler.co_group_wait(group_name) +end + -- run compilation job function distcc_build_client:iorunv(program, argv, opt) @@ -492,6 +511,47 @@ function distcc_build_client:_disconnect_host(host) self:status_save() end +-- clean file for the host +function distcc_build_client:_clean_host(host) + local addr = host.addr + local port = host.port + if not self:_is_connected(addr, port) then + print("%s: %s:%d has been disconnected!", self, addr, port) + return + end + + -- do clean + local token = host.token + local sock = socket.connect(addr, port) + local session_id = self:_session_id(addr, port) + local errors + local ok = false + print("%s: clean files in %s:%d ..", self, addr, port) + if sock then + local stream = socket_stream(sock) + if stream:send_msg(message.new_clean(session_id, {token = token})) and stream:flush() then + local msg = stream:recv_msg() + if msg then + vprint(msg:body()) + if msg:success() then + ok = true + else + errors = msg:errors() + end + end + end + else + -- server unreachable, but we still disconnect it. + wprint("%s: server unreachable!", self) + ok = true + end + if ok then + print("%s: %s:%d clean files ok!", self, addr, port) + else + print("%s: clean files %s:%d failed, %s", self, addr, port, errors or "unknown") + end +end + -- is connected? we cannot depend on client:init when run action function is_connected() local connected = _g.connected diff --git a/xmake/modules/private/service/distcc_build/server.lua b/xmake/modules/private/service/distcc_build/server.lua index a7d253982..0dd0aa55c 100644 --- a/xmake/modules/private/service/distcc_build/server.lua +++ b/xmake/modules/private/service/distcc_build/server.lua @@ -92,6 +92,8 @@ function distcc_build_server:_on_handle(stream, msg) session_errs = errors return false end + elseif msg:is_clean() then + session:clean() end end return true diff --git a/xmake/modules/private/service/distcc_build/server_session.lua b/xmake/modules/private/service/distcc_build/server_session.lua index 5703b98a9..fb2617492 100644 --- a/xmake/modules/private/service/distcc_build/server_session.lua +++ b/xmake/modules/private/service/distcc_build/server_session.lua @@ -82,6 +82,13 @@ function server_session:close() self:status_save() end +-- do clean +function server_session:clean() + vprint("%s: clean files in %s ..", self, self:workdir()) + os.tryrm(self:workdir()) + vprint("%s: clean files ok", self) +end + -- do compile function server_session:compile(respmsg) |
