summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-15 09:15:28 +0800
committerruki <[email protected]>2022-05-15 09:15:28 +0800
commit998db83357fed76073b8ccd77c68d82db5b52946 (patch)
treecb41302e9a5da2d09444d974b7e40e92cd5d7b40
parent129b240a59eb5ecdb5b5288c03997a7eb07aa47b (diff)
send object file
-rw-r--r--xmake/modules/private/service/distcc_build/client_session.lua5
-rw-r--r--xmake/modules/private/service/distcc_build/server.lua6
-rw-r--r--xmake/modules/private/service/distcc_build/server_session.lua31
3 files changed, 36 insertions, 6 deletions
diff --git a/xmake/modules/private/service/distcc_build/client_session.lua b/xmake/modules/private/service/distcc_build/client_session.lua
index 01aaf8b6f..e01772859 100644
--- a/xmake/modules/private/service/distcc_build/client_session.lua
+++ b/xmake/modules/private/service/distcc_build/client_session.lua
@@ -120,7 +120,8 @@ function client_session:_gcc_iorunv(program, argv, opt)
local stream = self:stream()
if stream:send_msg(message.new_compile(self:id(), opt.toolname, flags, path.filename(sourcefile), {token = self:token()})) and
stream:send_file(cppfile, {compress = os.filesize(cppfile) > 4096}) and stream:flush() then
- if stream:recv_file(objectfile) then
+ local recv = stream:recv_file(objectfile)
+ if recv ~= nil then
local msg = stream:recv_msg()
if msg then
if msg:success() then
@@ -129,6 +130,8 @@ function client_session:_gcc_iorunv(program, argv, opt)
errors = msg:errors()
end
end
+ else
+ errors = "recv object file failed!"
end
end
os.tryrm(cppfile)
diff --git a/xmake/modules/private/service/distcc_build/server.lua b/xmake/modules/private/service/distcc_build/server.lua
index c67fecef7..a7d253982 100644
--- a/xmake/modules/private/service/distcc_build/server.lua
+++ b/xmake/modules/private/service/distcc_build/server.lua
@@ -87,7 +87,11 @@ function distcc_build_server:_on_handle(stream, msg)
else
assert(session:is_connected(), "session has not been connected!")
if msg:is_compile() then
- session:compile(respmsg)
+ local ok, errors = session:compile(respmsg)
+ if not ok then
+ session_errs = errors
+ return false
+ end
end
end
return true
diff --git a/xmake/modules/private/service/distcc_build/server_session.lua b/xmake/modules/private/service/distcc_build/server_session.lua
index 6347393e4..218771e03 100644
--- a/xmake/modules/private/service/distcc_build/server_session.lua
+++ b/xmake/modules/private/service/distcc_build/server_session.lua
@@ -83,8 +83,9 @@ end
function server_session:compile(respmsg)
-- recv source file
+ local body = respmsg:body()
local stream = self:stream()
- local sourcename = respmsg.sourcename
+ local sourcename = body.sourcename
local sourcedir = path.join(self:workdir(), (hash.uuid4():gsub("-", "")))
local sourcefile = path.join(sourcedir, sourcename)
local objectfile = sourcefile .. ".o"
@@ -93,16 +94,38 @@ function server_session:compile(respmsg)
end
-- do compile
- -- TODO
+ local errors
+ local ok = try
+ {
+ function ()
+ local flags = body.flags
+ local compiler = body.compiler
+ os.vrunv(compiler, table.join(flags, "-o", objectfile, sourcefile))
+ return os.isfile(objectfile)
+ end,
+ catch
+ {
+ function (errs)
+ errors = tostring(errs)
+ end
+ }
+ }
-- send object file
- if not stream:send_emptydata() then
- raise("send %s failed!", objectfile)
+ if ok then
+ if not stream:send_file(objectfile, {compress = os.filesize(objectfile) > 4096}) then
+ raise("send %s failed!", objectfile)
+ end
+ else
+ if not stream:send_emptydata() then
+ raise("send empty data failed!")
+ end
end
-- remove files
os.tryrm(sourcefile)
os.tryrm(objectfile)
+ return ok, errors
end
-- set stream