diff options
| author | ruki <[email protected]> | 2022-04-05 00:42:04 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-05 00:42:04 +0800 |
| commit | ea532e409179feadb227148a67fd4b22c889cea6 (patch) | |
| tree | 91b91e5307f98ea9c8e79e025e47c11ce2d06c15 /xmake/plugins | |
| parent | 4679c558ab35d246c177ed77028f776ecc8373d2 (diff) | |
add remote build server stub
Diffstat (limited to 'xmake/plugins')
| -rw-r--r-- | xmake/plugins/service/main.lua | 33 | ||||
| -rw-r--r-- | xmake/plugins/service/remote_build_server/main.lua | 42 | ||||
| -rw-r--r-- | xmake/plugins/service/server.lua | 49 | ||||
| -rw-r--r-- | xmake/plugins/service/service.lua | 36 | ||||
| -rw-r--r-- | xmake/plugins/service/xmake.lua | 29 |
5 files changed, 167 insertions, 22 deletions
diff --git a/xmake/plugins/service/main.lua b/xmake/plugins/service/main.lua index 8249154c2..8e1ba8c4b 100644 --- a/xmake/plugins/service/main.lua +++ b/xmake/plugins/service/main.lua @@ -20,9 +20,38 @@ -- imports import("core.base.option") +import("service") + +function _start_service(opt) + opt = opt or {} + if opt.daemon then + os.execv(os.programfile(), {"lua", path.join(os.scriptdir(), "service.lua")}, {detach = true}) + else + service() + end +end + +function _restart_service() +end + +function _show_service_logs() +end + +function _show_service_status() +end --- main function main() - cprint("${color.warning}Experimental, still in development!") + cprint("${color.warning}It's experimental feature, still in development!") + if option.get("start") then + _start_service({daemon = true}) + elseif option.get("restart") then + _restart_service() + elseif option.get("logs") then + _show_service_logs() + elseif option.get("status") then + _show_service_status() + else + _start_service() + end end diff --git a/xmake/plugins/service/remote_build_server/main.lua b/xmake/plugins/service/remote_build_server/main.lua new file mode 100644 index 000000000..2dc89cf95 --- /dev/null +++ b/xmake/plugins/service/remote_build_server/main.lua @@ -0,0 +1,42 @@ +--!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 main.lua +-- + +-- imports +import(".server") + +-- define module +local remote_build_server = remote_build_server or server() + +-- init server +function remote_build_server:init() + self:super():init(self) +end + +-- run main loop +function remote_build_server:runloop() + self:super():runloop(self) +end + +function main() + local instance = remote_build_server() + instance._super = remote_build_server + instance:init() + return instance +end diff --git a/xmake/plugins/service/server.lua b/xmake/plugins/service/server.lua new file mode 100644 index 000000000..e63f04662 --- /dev/null +++ b/xmake/plugins/service/server.lua @@ -0,0 +1,49 @@ +--!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 server.lua +-- + +-- imports +import("core.base.object") + +-- define module +local server = server or object() + +-- init server +function server:init() +end + +-- get super +function server:super() + return self._super +end + +-- run main loop +function server:runloop() + while true do + print("hello xmake!") + os.sleep(1000) + end +end + +function main() + local instance = server() + instance._super = server + instance:init() + return instance +end diff --git a/xmake/plugins/service/service.lua b/xmake/plugins/service/service.lua new file mode 100644 index 000000000..964da636c --- /dev/null +++ b/xmake/plugins/service/service.lua @@ -0,0 +1,36 @@ +--!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 main.lua +-- + +-- imports +import("core.base.option") +import("core.base.scheduler") +import("remote_build_server") + +function _start_remote_build_server() + remote_build_server():runloop() +end + +function main() + local starters = {_start_remote_build_server} + for _, start_server in ipairs(starters) do + scheduler.co_start(start_server) + end +end + diff --git a/xmake/plugins/service/xmake.lua b/xmake/plugins/service/xmake.lua index ec163ad61..024eca0d6 100644 --- a/xmake/plugins/service/xmake.lua +++ b/xmake/plugins/service/xmake.lua @@ -18,27 +18,16 @@ -- @file service.lua -- --- define task task("service") - - -- set category set_category("plugin") - - -- on run on_run("main") - -- set menu - set_menu { - -- usage - usage = "xmake service [options]" - - -- description - , description = "Start service for remote or distributed compilation and etc. ${color.warning}(Experimental, still in development)" - - -- options - , options = - { - {'d', "daemon", "k", nil, "Run service as daemon." } - , {nil, "status", "k", nil, "Show service status if the daemon service has been started." } - } - } + set_menu {usage = "xmake service [options]", + description = "Start service for remote or distributed compilation and etc. ${color.warning}(Experimental, still in development)", + options = { + {nil, "start", "k", nil, "Start daemon service." }, + {nil, "restart", "k", nil, "Restart daemon service." }, + {nil, "stop" , "k", nil, "Stop daemon service." }, + {nil, "logs", "k", nil, "Show service logs if the daemon service has been started." }, + {nil, "status", "k", nil, "Show service status if the daemon service has been started." } + }} |
