diff options
| author | ruki <[email protected]> | 2022-05-12 00:44:58 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-12 00:44:58 +0800 |
| commit | 9442ba64fb5eb2e272a45c850376e4296ebfb761 (patch) | |
| tree | 2d50631b812dda6185ac4d3054d0c97c2cb26b8f | |
| parent | 1a3ccc694b0370707be4e1aad24ee7903040b100 (diff) | |
improve connect server
7 files changed, 102 insertions, 53 deletions
diff --git a/xmake/modules/private/service/connect_service.lua b/xmake/modules/private/service/connect_service.lua index 2f130a158..a2c9e2ee8 100644 --- a/xmake/modules/private/service/connect_service.lua +++ b/xmake/modules/private/service/connect_service.lua @@ -21,11 +21,31 @@ -- imports import("core.base.option") import("core.base.scheduler") +import("private.service.config") import("private.service.remote_build.client", {alias = "remote_build_client"}) +import("private.service.distcc_build.client", {alias = "distcc_build_client"}) -function main() - scheduler.co_start(function () - remote_build_client():connect() - end) +function _connect_remote_build_server(...) + remote_build_client(...):connect() +end + +function _connect_distcc_build_server(...) + distcc_build_client(...):connect() +end + +function main(...) + local connectors = {} + if option.get("remote") then + table.insert(connectors, _connect_remote_build_server) + elseif option.get("distcc") then + table.insert(connectors, _connect_distcc_build_server) + else + if config.get("remote_build.client") then + table.insert(connectors, _connect_remote_build_server) + end + end + for _, connect_server in ipairs(connectors) do + scheduler.co_start(connect_server, ...) + end end diff --git a/xmake/modules/private/service/disconnect_service.lua b/xmake/modules/private/service/disconnect_service.lua index a1f9e625d..3f2abaa13 100644 --- a/xmake/modules/private/service/disconnect_service.lua +++ b/xmake/modules/private/service/disconnect_service.lua @@ -20,11 +20,33 @@ -- imports import("core.base.option") +import("core.base.scheduler") import("private.service.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():disconnect() +function _disconnect_remote_build_server(...) + remote_build_client(...):disconnect() +end + +function _disconnect_distcc_build_server(...) + distcc_build_client(...):disconnect() +end + +function main(...) + local disconnectors = {} + if option.get("remote") then + table.insert(disconnectors, _disconnect_remote_build_server) + elseif option.get("distcc") then + table.insert(disconnectors, _disconnect_distcc_build_server) + else + if config.get("remote_build.client") then + table.insert(disconnectors, _disconnect_remote_build_server) + end + end + for _, disconnect_server in ipairs(disconnectors) do + scheduler.co_start(disconnect_server, ...) + end end diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua index f1036d44c..b2456e4e0 100644 --- a/xmake/modules/private/service/distcc_build/client.lua +++ b/xmake/modules/private/service/distcc_build/client.lua @@ -52,12 +52,14 @@ function distcc_build_client:init() else raise("we need enter a project directory with xmake.lua first!") end +end - -- check environment - environment.check(false) +-- get class +function distcc_build_client:class() + return distcc_build_client end --- connect to the remote server +-- connect to the distcc server function distcc_build_client:connect() if self:is_connected() then print("%s: has been connected!", self) @@ -115,11 +117,6 @@ function distcc_build_client:connect() status.connected = ok status.session_id = session_id self:status_save() - - -- sync files - if ok then - self:sync() - end end -- disconnect server @@ -166,9 +163,53 @@ function distcc_build_client:disconnect() self:status_save() end --- get class -function distcc_build_client:class() - return distcc_build_client +-- is connected? +function distcc_build_client:is_connected() + return self:status().connected +end + +-- get the status +function distcc_build_client:status() + local status = self._STATUS + local statusfile = self:statusfile() + if not status then + if os.isfile(statusfile) then + status = io.load(statusfile) + end + status = status or {} + self._STATUS = status + end + return status +end + +-- save status +function distcc_build_client:status_save() + io.save(self:statusfile(), self:status()) +end + +-- get the status file +function distcc_build_client:statusfile() + return path.join(self:workdir(), "status.txt") +end + +-- get the project directory +function distcc_build_client:projectdir() + return self._PROJECTDIR +end + +-- get working directory +function distcc_build_client:workdir() + return self._WORKDIR +end + +-- get user token +function distcc_build_client:token() + return self:status().token +end + +-- get the session id, only for unique project +function distcc_build_client:session_id() + return self:status().session_id or hash.uuid():split("-", {plain = true})[1]:lower() end -- is connected? we cannot depend on client:init when run action diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua index 642c616ea..6e2ddd279 100644 --- a/xmake/modules/private/service/remote_build/client.lua +++ b/xmake/modules/private/service/remote_build/client.lua @@ -31,7 +31,6 @@ import("private.service.message") import("private.service.client") import("private.service.stream", {alias = "socket_stream"}) import("private.service.remote_build.filesync", {alias = "new_filesync"}) -import("private.service.remote_build.environment") -- define module local remote_build_client = remote_build_client or client() @@ -60,9 +59,6 @@ function remote_build_client:init() filesync:ignorefiles_add(".git/**") filesync:ignorefiles_add(".xmake/**") self._FILESYNC = filesync - - -- check environment - environment.check(false) end -- get class diff --git a/xmake/modules/private/service/remote_build/environment.lua b/xmake/modules/private/service/remote_build/environment.lua deleted file mode 100644 index 019b502dc..000000000 --- a/xmake/modules/private/service/remote_build/environment.lua +++ /dev/null @@ -1,26 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file environment.lua --- - --- imports -import("lib.detect.find_tool") - --- check environment -function check(server_side) -end diff --git a/xmake/modules/private/service/service.lua b/xmake/modules/private/service/service.lua index 01492a219..446cfbee8 100644 --- a/xmake/modules/private/service/service.lua +++ b/xmake/modules/private/service/service.lua @@ -43,10 +43,10 @@ function main(daemon, ...) elseif option.get("distcc") then table.insert(starters, _start_distcc_build_server) else - if config.get("remote_build.server.listen") then + if config.get("remote_build.server") then table.insert(starters, _start_remote_build_server) end - if config.get("distcc_build.server.listen") then + if config.get("distcc_build.server") then table.insert(starters, _start_distcc_build_server) end end diff --git a/xmake/modules/private/service/start_service.lua b/xmake/modules/private/service/start_service.lua index d24ec242a..f75c98a10 100644 --- a/xmake/modules/private/service/start_service.lua +++ b/xmake/modules/private/service/start_service.lua @@ -23,13 +23,9 @@ import("core.base.option") import("core.project.project") import("private.service.config") import("private.service.service") -import("private.service.remote_build.environment") function main(opt) - -- check environment - environment.check(true) - -- start service opt = opt or {} if opt.daemon then |
