diff options
| author | ruki <[email protected]> | 2022-04-26 00:51:42 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-26 00:51:42 +0800 |
| commit | abc5735b2659094a2e6ce89437f0cacdf18bedbf (patch) | |
| tree | 650c966bc47771d2229c48f12c44b53d0a7e253e /xmake/modules | |
| parent | 564876e408be47c73644fb9a060790c71f45e8f6 (diff) | |
improve service
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/private/service/remote_build/client.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/private/service/remote_build/server.lua | 19 | ||||
| -rw-r--r-- | xmake/modules/private/service/remote_build/session.lua | 51 |
3 files changed, 65 insertions, 9 deletions
diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua index dd335f272..bdd0ee1f0 100644 --- a/xmake/modules/private/service/remote_build/client.lua +++ b/xmake/modules/private/service/remote_build/client.lua @@ -456,6 +456,10 @@ end -- is connected? we cannot depend on client:init when run action function is_connected() + -- the current process is in service? we cannot enable it + if os.getenv("XMAKE_IN_SERVICE") then + return false + end local projectdir = os.projectdir() local projectfile = os.projectfile() if projectfile and os.isfile(projectfile) and projectdir then diff --git a/xmake/modules/private/service/remote_build/server.lua b/xmake/modules/private/service/remote_build/server.lua index 15b017b36..085dc1e42 100644 --- a/xmake/modules/private/service/remote_build/server.lua +++ b/xmake/modules/private/service/remote_build/server.lua @@ -70,14 +70,17 @@ function remote_build_server:_on_handle(stream, msg) elseif msg:is_disconnect() then session:close() self._SESSIONS[session_id] = nil - elseif msg:is_diff() then - session:diff(respmsg) - elseif msg:is_sync() then - session:sync(respmsg) - elseif msg:is_clean() then - session:clean() - elseif msg:is_runcmd() then - session:runcmd(respmsg) + else + assert(session:is_connected(), "session has not been connected!") + if msg:is_diff() then + session:diff(respmsg) + elseif msg:is_sync() then + session:sync(respmsg) + elseif msg:is_clean() then + session:clean() + elseif msg:is_runcmd() then + session:runcmd(respmsg) + end end return true end, diff --git a/xmake/modules/private/service/remote_build/session.lua b/xmake/modules/private/service/remote_build/session.lua index 9f81809e6..80a26f65c 100644 --- a/xmake/modules/private/service/remote_build/session.lua +++ b/xmake/modules/private/service/remote_build/session.lua @@ -47,11 +47,31 @@ end -- open session function session:open() + if self:is_connected() then + return + end + + -- ensure source directory self:_ensure_sourcedir() + + -- update status + local status = self:status() + status.connected = true + status.session_id = self:id() + self:status_save() end -- close session function session:close() + if not self:is_connected() then + return + end + + -- update status + local status = self:status() + status.connected = false + status.session_id = self:id() + self:status_save() end -- set stream @@ -184,7 +204,7 @@ function session:runcmd(respmsg) scheduler.co_start(self._read_pipe, self, stdout_rpipeopt) -- run program - os.execv(program, argv, {curdir = self:sourcedir(), stdout = stdout_wpipe, stdin = stdin_rpipe}) + os.execv(program, argv, {curdir = self:sourcedir(), stdout = stdout_wpipe, stdin = stdin_rpipe, envs = {XMAKE_IN_SERVICE = "true"}}) -- stop it stdin_wpipeopt.stop = true @@ -203,6 +223,35 @@ function session:workdir() return path.join(workdir, "sessons", self:id()) end +-- is connected? +function session:is_connected() + return self:status().connected +end + +-- get the status +function session: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 session:status_save() + io.save(self:statusfile(), self:status()) +end + +-- get status file +function session:statusfile() + return path.join(self:workdir(), "status.txt") +end + -- get sourcedir directory function session:sourcedir() return path.join(self:workdir(), "source") |
