diff options
| author | ruki <[email protected]> | 2022-04-14 00:32:36 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-14 00:32:36 +0800 |
| commit | a39818c953e11781d2305e2ad3afe5b551c15eec (patch) | |
| tree | 92d9ff5487bc07363c0d51e69adaaf232c30340f | |
| parent | b3d43d26103d29ce04878b74ff101d8fcb321164 (diff) | |
add remote action stub
| -rw-r--r-- | xmake/actions/build/main.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/clean/main.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/clean/xmake.lua | 12 | ||||
| -rw-r--r-- | xmake/actions/config/main.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/run/main.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/service/main.lua (renamed from xmake/plugins/service/main.lua) | 0 | ||||
| -rw-r--r-- | xmake/actions/service/xmake.lua (renamed from xmake/plugins/service/xmake.lua) | 2 | ||||
| -rw-r--r-- | xmake/modules/private/service/remote_build/action.lua | 34 | ||||
| -rw-r--r-- | xmake/modules/private/service/remote_build/client.lua | 19 |
9 files changed, 76 insertions, 15 deletions
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua index c355ae4ae..0f5cdde40 100644 --- a/xmake/actions/build/main.lua +++ b/xmake/actions/build/main.lua @@ -32,6 +32,7 @@ import("build") import("build_files") import("cleaner") import("statistics") +import("private.service.remote_build.action", {alias = "remote_build_action"}) -- do build for the third-party buildsystem function _try_build() @@ -113,6 +114,11 @@ function main() -- post statistics before locking project statistics.post() + -- do action for remote? + if remote_build_action.enabled() then + return remote_build_action() + end + -- lock the whole project project.lock() diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua index c508d0566..ad0b4e15c 100644 --- a/xmake/actions/clean/main.lua +++ b/xmake/actions/clean/main.lua @@ -28,6 +28,7 @@ import("core.project.project") import("core.platform.platform") import("private.action.clean.remove_files") import("target.action.clean", {alias = "_do_clean_target"}) +import("private.service.remote_build.action", {alias = "remote_build_action"}) -- on clean target function _on_clean_target(target) @@ -150,6 +151,11 @@ function main() return _try_clean() end + -- do action for remote? + if remote_build_action.enabled() then + return remote_build_action() + end + -- lock the whole project project.lock() diff --git a/xmake/actions/clean/xmake.lua b/xmake/actions/clean/xmake.lua index 55d4d94b7..9af671f71 100644 --- a/xmake/actions/clean/xmake.lua +++ b/xmake/actions/clean/xmake.lua @@ -18,27 +18,15 @@ -- @file xmake.lua -- --- define task task("clean") - - -- set category set_category("action") - - -- on run on_run("main") - -- set menu set_menu { - -- usage usage = "xmake clean|c [options] [target]" - - -- description , description = "Remove all binary and temporary files." - - -- xmake c , shortname = 'c' - -- options , options = { {'a', "all", "k", nil , "Clean all auto-generated files by xmake." } diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 23ef3fe43..b1c59fd51 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -33,6 +33,7 @@ import("configfiles", {alias = "generate_configfiles"}) import("configheader", {alias = "generate_configheader"}) import("private.action.require.check", {alias = "check_packages"}) import("private.action.require.install", {alias = "install_packages"}) +import("private.service.remote_build.action", {alias = "remote_build_action"}) -- filter option function _option_filter(name) @@ -248,6 +249,11 @@ end -- main entry function main(opt) + -- do action for remote? + if remote_build_action.enabled() then + return remote_build_action() + end + -- avoid to run this task repeatly opt = opt or {} if _g.configured then return end diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 8a6129ba7..61c5b02ea 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -27,6 +27,7 @@ import("core.project.project") import("core.platform.platform") import("devel.debugger") import("private.action.run.make_runenvs") +import("private.service.remote_build.action", {alias = "remote_build_action"}) -- run target function _do_run_target(target) @@ -181,6 +182,11 @@ end -- main function main() + -- do action for remote? + if remote_build_action.enabled() then + return remote_build_action() + end + -- load config first config.load() diff --git a/xmake/plugins/service/main.lua b/xmake/actions/service/main.lua index 355b43b41..355b43b41 100644 --- a/xmake/plugins/service/main.lua +++ b/xmake/actions/service/main.lua diff --git a/xmake/plugins/service/xmake.lua b/xmake/actions/service/xmake.lua index f45e2a0f8..ede92d82e 100644 --- a/xmake/plugins/service/xmake.lua +++ b/xmake/actions/service/xmake.lua @@ -19,7 +19,7 @@ -- task("service") - set_category("plugin") + set_category("action") on_run("main") set_menu {usage = "xmake service [options]", diff --git a/xmake/modules/private/service/remote_build/action.lua b/xmake/modules/private/service/remote_build/action.lua new file mode 100644 index 000000000..3eff3d11f --- /dev/null +++ b/xmake/modules/private/service/remote_build/action.lua @@ -0,0 +1,34 @@ +--!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 action.lua +-- + +-- imports +import("private.service.config") +import("private.service.remote_build.client", {alias = "remote_build_client"}) + +-- is enabled? +function enabled() + return remote_build_client.is_connected() +end + +function main() + config.load() + local client = remote_build_client() + print("do remote action!") +end diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua index ac0ec077c..f3dde9586 100644 --- a/xmake/modules/private/service/remote_build/client.lua +++ b/xmake/modules/private/service/remote_build/client.lua @@ -40,11 +40,10 @@ function remote_build_client:init() local address = assert(config.get("remote_build.client.connect"), "config(remote_build.client.connect): not found!") super.address_set(self, address) - -- load project config + -- get project directory local projectdir = os.projectdir() local projectfile = os.projectfile() if projectfile and os.isfile(projectfile) and projectdir then - project_config.load() self._PROJECTDIR = projectdir self._WORKDIR = path.join(project_config.directory(), "remote_build") else @@ -280,6 +279,22 @@ function remote_build_client:__tostring() return "<remote_build_client>" end +-- is connected? we cannot depend on client:init when run action +function is_connected() + local projectdir = os.projectdir() + local projectfile = os.projectfile() + if projectfile and os.isfile(projectfile) and projectdir then + local workdir = path.join(project_config.directory(), "remote_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 + end + end + end +end + function main() local instance = remote_build_client() instance:init() |
