summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-04-16 11:22:26 +0800
committerruki <[email protected]>2022-04-16 11:22:26 +0800
commitec42644f5fd2f522cb070f1ac0b33911b17f88ee (patch)
treeeaacd0cc1fce7c9a235f64a846c249d2fa242e49
parentbc28988cf61b1867f34929439f5014a68b123760 (diff)
reset sync
-rw-r--r--xmake/modules/private/service/message.lua28
-rw-r--r--xmake/modules/private/service/remote_build/client.lua42
-rw-r--r--xmake/modules/private/service/remote_build/server.lua4
-rw-r--r--xmake/modules/private/service/remote_build/session.lua30
-rw-r--r--xmake/modules/private/service/sync_files.lua2
5 files changed, 28 insertions, 78 deletions
diff --git a/xmake/modules/private/service/message.lua b/xmake/modules/private/service/message.lua
index 90bf43652..918175270 100644
--- a/xmake/modules/private/service/message.lua
+++ b/xmake/modules/private/service/message.lua
@@ -24,13 +24,15 @@ import("core.base.object")
-- define module
local message = message or object()
--- the message code
-message.CODE_CONNECT = 1
-message.CODE_DISCONNECT = 2
-message.CODE_SYNC = 3
-message.CODE_CLEAN = 4
-message.CODE_RUNCMD = 5
-message.CODE_DATA = 6
+-- the common message code
+message.CODE_CONNECT = 1 -- connect server
+message.CODE_DISCONNECT = 2 -- disconnect server
+message.CODE_CLEAN = 3 -- clean all cached files in server
+message.CODE_DATA = 4 -- send data
+message.CODE_RUNCMD = 5 -- run the given command in server
+message.CODE_DIFFDIR = 6 -- diff files in directory between server and client
+message.CODE_SYNCDIR = 7 -- sync files in directory between server and client
+message.CODE_PULL = 8 -- pull the given files from server
-- init message
function message:init(body)
@@ -57,9 +59,9 @@ function message:is_disconnect()
return self:code() == message.CODE_DISCONNECT
end
--- is sync message?
-function message:is_sync()
- return self:code() == message.CODE_SYNC
+-- is syncdir message?
+function message:is_syncdir()
+ return self:code() == message.CODE_SYNCDIR
end
-- is clean message?
@@ -137,10 +139,10 @@ function new_disconnect(session_id)
})
end
--- new sync message
-function new_sync(session_id, start)
+-- new syncdir message
+function new_syncdir(session_id, start)
return _new({
- code = message.CODE_SYNC,
+ code = message.CODE_SYNCDIR,
start = start,
session_id = session_id
})
diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua
index cbe5e89cf..afe99bc1e 100644
--- a/xmake/modules/private/service/remote_build/client.lua
+++ b/xmake/modules/private/service/remote_build/client.lua
@@ -23,7 +23,6 @@ import("core.base.bytes")
import("core.base.socket")
import("core.base.scheduler")
import("core.project.config", {alias = "project_config"})
-import("devel.git")
import("lib.detect.find_tool")
import("private.service.config")
import("private.service.message")
@@ -103,9 +102,9 @@ function remote_build_client:connect()
status.session_id = session_id
self:status_save()
- -- sync files
+ -- syncdir files
if ok then
- self:sync()
+ self:syncdir()
end
end
@@ -149,7 +148,7 @@ function remote_build_client:disconnect()
end
-- sync server files
-function remote_build_client:sync()
+function remote_build_client:syncdir()
assert(self:is_connected(), "%s: has been not connected!", self)
local addr = self:addr()
local port = self:port()
@@ -160,12 +159,12 @@ function remote_build_client:sync()
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, true)) and stream:flush() then
+ if stream:send_msg(message.new_syncdir(session_id, true)) and stream:flush() then
local msg = stream:recv_msg()
if msg and msg:success() then
vprint(msg:body())
- self:_do_syncfiles(msg:body().path, msg:body().branch)
- if stream:send_msg(message.new_sync(session_id, false)) and stream:flush() then
+ self:_do_syncdir(msg:body().path, msg:body().branch)
+ if stream:send_msg(message.new_syncdir(session_id, false)) and stream:flush() then
msg = stream:recv_msg()
if msg and msg:success() then
ok = true
@@ -320,33 +319,8 @@ function remote_build_client:session_id()
return self:status().session_id or hash.uuid():split("-", {plain = true})[1]:lower()
end
--- do syncfiles, e.g. git push user@addr:remote_path branch:remote_branch
---
--- @note on Windows/OpenSSH, we need solve the following issues
--- https://github.com/PowerShell/Win32-OpenSSH/wiki/Setting-up-a-Git-server-on-Windows-using-Git-for-Windows-and-Win32_OpenSSH
---
--- 1. Set powershell as default shell
--- @code
--- New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force
--- New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShellCommandOption -Value "/c" -PropertyType String -Force
--- @endcode
---
--- 2. Set git/mingw64/bin to %PATH%, to solve `git-receive-pack not found!`
--- @code
--- $gitPath = Join-Path -Path $env:ProgramFiles -ChildPath "git\mingw64\bin"
--- $machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE')
--- [Environment]::SetEnvironmentVariable('Path', "$gitPath;$machinePath", 'Machine')
--- @endcode
---
-function remote_build_client:_do_syncfiles(remote_path, remote_branch)
- local user = assert(config.get("remote_build.client.user"), "config(remote_build.client.user): not found!")
- local addr = self:addr()
- assert(remote_path, "git remote path not found!")
- assert(remote_branch, "git remote branch not found!")
-
- -- push to remote
- local remote_url = string.format("%s@%s:%s", user, addr, remote_path)
- git.push(remote_url, {remote_branch = remote_branch, verbose = true})
+-- do syncdir
+function remote_build_client:_do_syncdir(remote_path, remote_branch)
end
-- read stdin data
diff --git a/xmake/modules/private/service/remote_build/server.lua b/xmake/modules/private/service/remote_build/server.lua
index f5e695bc6..ff4e64dfc 100644
--- a/xmake/modules/private/service/remote_build/server.lua
+++ b/xmake/modules/private/service/remote_build/server.lua
@@ -70,8 +70,8 @@ function remote_build_server:_on_handle(stream, msg)
elseif msg:is_disconnect() then
session:close()
self._SESSIONS[session_id] = nil
- elseif msg:is_sync() then
- session:sync(respmsg)
+ elseif msg:is_syncdir() then
+ session:syncdir(respmsg)
elseif msg:is_clean() then
session:clean()
elseif msg:is_runcmd() then
diff --git a/xmake/modules/private/service/remote_build/session.lua b/xmake/modules/private/service/remote_build/session.lua
index b78ddf8c4..a8ca8a797 100644
--- a/xmake/modules/private/service/remote_build/session.lua
+++ b/xmake/modules/private/service/remote_build/session.lua
@@ -25,7 +25,6 @@ import("core.base.object")
import("core.base.global")
import("core.base.option")
import("core.base.scheduler")
-import("devel.git")
import("private.service.config")
import("private.service.message")
@@ -62,19 +61,10 @@ function session:stream()
return self._STREAM
end
--- sync files
-function session:sync(respmsg)
+-- sync directory
+function session:syncdir(respmsg)
local body = respmsg:body()
vprint("%s: %s sync files in %s ..", self, self:sourcedir(), body.start and "start" or "finish")
- local sourcedir = self:sourcedir()
- local source_branch = self:_source_branch()
- if body.start then
- self:_reset_sourcedir()
- body.path = sourcedir
- body.branch = source_branch
- else
- git.checkout(source_branch, {repodir = sourcedir})
- end
vprint("%s: %s sync files ok", self, body.start and "start" or "finish")
end
@@ -130,22 +120,6 @@ end
-- reset sourcedir
function session:_reset_sourcedir()
vprint("%s: reset %s", self, self:sourcedir())
-
- -- init sourcedir first if .git not exists
- local sourcedir = self:sourcedir()
- if not os.isdir(sourcedir) then
- os.mkdir(sourcedir)
- end
- if not os.isdir(path.join(sourcedir, ".git")) then
- git.init({repodir = sourcedir})
- end
-
- -- reset the current branch
- local branch = git.branch({repodir = sourcedir})
- if branch then
- git.clean({repodir = sourcedir, force = true, all = true})
- git.reset({repodir = sourcedir, hard = true})
- end
end
-- write data from pipe
diff --git a/xmake/modules/private/service/sync_files.lua b/xmake/modules/private/service/sync_files.lua
index da002f8a4..4721f9541 100644
--- a/xmake/modules/private/service/sync_files.lua
+++ b/xmake/modules/private/service/sync_files.lua
@@ -24,7 +24,7 @@ import("private.service.config")
import("private.service.remote_build.client", {alias = "remote_build_client"})
function main()
- remote_build_client():sync()
+ remote_build_client():syncdir()
end