summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-04-12 22:42:25 +0800
committerruki <[email protected]>2022-04-12 22:42:25 +0800
commit314c329ed33997af84bb0971965a15f3cc7cdbb4 (patch)
tree8361481eeab3d019b27cc1083196cb285f2dfa33
parent1ef23a02096321059a14afd8b6bc38eeb3b3d282 (diff)
improve sync
-rw-r--r--xmake/modules/private/service/clean_files.lua2
-rw-r--r--xmake/modules/private/service/remote_build/client.lua41
-rw-r--r--xmake/modules/private/service/remote_build/session.lua6
-rw-r--r--xmake/modules/private/service/sync_files.lua30
-rw-r--r--xmake/plugins/service/main.lua3
-rw-r--r--xmake/plugins/service/xmake.lua1
6 files changed, 74 insertions, 9 deletions
diff --git a/xmake/modules/private/service/clean_files.lua b/xmake/modules/private/service/clean_files.lua
index ecd826b38..caacbeda4 100644
--- a/xmake/modules/private/service/clean_files.lua
+++ b/xmake/modules/private/service/clean_files.lua
@@ -15,7 +15,7 @@
-- Copyright (C) 2015-present, TBOOX Open Source Group.
--
-- @author ruki
--- @file clean_service.lua
+-- @file clean_files.lua
--
-- imports
diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua
index 56cce3d3f..fee9ef6a6 100644
--- a/xmake/modules/private/service/remote_build/client.lua
+++ b/xmake/modules/private/service/remote_build/client.lua
@@ -82,7 +82,6 @@ function remote_build_client:connect()
end
end
if connected then
- self:_syncfiles()
print("%s: connected!", self)
else
print("%s: connect %s:%d failed", self, addr, port)
@@ -95,6 +94,11 @@ function remote_build_client:connect()
status.connected = connected
status.session_id = session_id
self:status_save()
+
+ -- sync files
+ if connected then
+ self:sync()
+ end
end
-- disconnect server
@@ -135,6 +139,36 @@ function remote_build_client:disconnect()
self:status_save()
end
+-- sync server files
+function remote_build_client:sync()
+ assert(self:is_connected(), "%s: has been not connected!", self)
+ local addr = self:addr()
+ local port = self:port()
+ local sock = socket.connect(addr, port)
+ local session_id = self:session_id()
+ local synced = false
+ print("%s: sync files in %s:%d ..", self, addr, port)
+ if sock then
+ local stream = socket_stream(sock)
+ if stream:send_msg(message.new_sync(session_id)) and stream:flush() then
+ local msg = stream:recv_msg()
+ if msg then
+ vprint(msg:body())
+ if msg:success() then
+ synced = true
+ else
+ print("%s: sync files in %s:%d failed, %s", self, addr, port, msg:errors())
+ end
+ end
+ end
+ end
+ if synced then
+ print("%s: synced!", self)
+ else
+ print("%s: sync files in %s:%d failed", self, addr, port)
+ end
+end
+
-- clean server files
function remote_build_client:clean()
assert(self:is_connected(), "%s: has been not connected!", self)
@@ -209,11 +243,6 @@ function remote_build_client:session_id()
return self:status().session_id or hash.uuid():split("-", {plain = true})[1]:lower()
end
--- sync files
-function remote_build_client:_syncfiles()
- -- TODO
-end
-
function remote_build_client:__tostring()
return "<remote_build_client>"
end
diff --git a/xmake/modules/private/service/remote_build/session.lua b/xmake/modules/private/service/remote_build/session.lua
index fdce8d3a6..34a247f59 100644
--- a/xmake/modules/private/service/remote_build/session.lua
+++ b/xmake/modules/private/service/remote_build/session.lua
@@ -48,13 +48,15 @@ end
-- sync files
function session:sync()
+ vprint("%s: sync files in %s ..", self, self:sourcedir())
+ vprint("%s: sync files ok", self)
end
-- clean files
function session:clean()
- vprint("%s: cleaning files in %s ..", self, self:workdir())
+ vprint("%s: clean files in %s ..", self, self:workdir())
os.tryrm(self:workdir())
- vprint("%s: cleaning files ok", self)
+ vprint("%s: clean files ok", self)
end
-- get work directory
diff --git a/xmake/modules/private/service/sync_files.lua b/xmake/modules/private/service/sync_files.lua
new file mode 100644
index 000000000..da002f8a4
--- /dev/null
+++ b/xmake/modules/private/service/sync_files.lua
@@ -0,0 +1,30 @@
+--!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 sync_files.lua
+--
+
+-- imports
+import("core.base.option")
+import("private.service.config")
+import("private.service.remote_build.client", {alias = "remote_build_client"})
+
+function main()
+ remote_build_client():sync()
+end
+
+
diff --git a/xmake/plugins/service/main.lua b/xmake/plugins/service/main.lua
index 82c7cd7b8..355b43b41 100644
--- a/xmake/plugins/service/main.lua
+++ b/xmake/plugins/service/main.lua
@@ -28,6 +28,7 @@ import("private.service.connect_service")
import("private.service.reconnect_service")
import("private.service.disconnect_service")
import("private.service.clean_files")
+import("private.service.sync_files")
import("private.service.import_config")
import("private.service.show_logs")
import("private.service.show_status")
@@ -49,6 +50,8 @@ function main()
disconnect_service()
elseif option.get("clean") then
clean_files()
+ elseif option.get("sync") then
+ sync_files()
elseif option.get("config") then
import_config()
elseif option.get("logs") then
diff --git a/xmake/plugins/service/xmake.lua b/xmake/plugins/service/xmake.lua
index 0cd101972..f45e2a0f8 100644
--- a/xmake/plugins/service/xmake.lua
+++ b/xmake/plugins/service/xmake.lua
@@ -31,6 +31,7 @@ task("service")
{nil, "connect" , "k", nil, "Connect current project to the remote daemon service." },
{nil, "reconnect", "k", nil, "Reconnect current project to the remote daemon service." },
{nil, "disconnect", "k", nil, "Disconnect current project in the remote daemon service." },
+ {nil, "sync", "k", nil, "Sync current project files in the remote daemon service." },
{nil, "clean", "k", nil, "Clean current project files in the remote daemon service." },
{nil, "config", "kv", nil, "Import the configuration file. (default: ~/.xmake/service.conf)",
"e.g.",