summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-12 23:51:22 +0800
committerruki <[email protected]>2022-05-12 23:51:22 +0800
commit9287baf136e9c347da35d27cd7c6c1c1c54b89a2 (patch)
tree5df72e07f30a956dfa4eade00a52b57234b6ce2b
parent9442ba64fb5eb2e272a45c850376e4296ebfb761 (diff)
improve distcc config
-rw-r--r--xmake/modules/private/service/client.lua36
-rw-r--r--xmake/modules/private/service/config.lua8
-rw-r--r--xmake/modules/private/service/distcc_build/client.lua37
-rw-r--r--xmake/modules/private/service/remote_build/client.lua25
4 files changed, 72 insertions, 34 deletions
diff --git a/xmake/modules/private/service/client.lua b/xmake/modules/private/service/client.lua
index 5a91ab1e8..437a10f8a 100644
--- a/xmake/modules/private/service/client.lua
+++ b/xmake/modules/private/service/client.lua
@@ -30,40 +30,26 @@ local client = client or object()
function client:init()
end
--- set the given client address
-function client:address_set(address)
+-- parse host address
+function client:address_parse(address)
+ local addr, port, user
local splitinfo = address:split(':', {plain = true})
if #splitinfo == 2 then
- self._ADDR = splitinfo[1]
- self._PORT = splitinfo[2]
+ addr = splitinfo[1]
+ port = splitinfo[2]
else
- self._ADDR = "127.0.0.1"
- self._PORT = splitinfo[1]
+ addr = "127.0.0.1"
+ port = splitinfo[1]
end
- local addr = self._ADDR
if addr and addr:find("@", 1, true) then
splitinfo = addr:split('@', {plain = true})
if #splitinfo == 2 then
- self._USER = splitinfo[1]
- self._ADDR = splitinfo[2]
+ user = splitinfo[1]
+ addr = splitinfo[2]
end
end
- assert(self._ADDR and self._PORT, "invalid client address!")
-end
-
--- get user name
-function client:user()
- return self._USER
-end
-
--- get the ip address
-function client:addr()
- return self._ADDR
-end
-
--- get the address port
-function client:port()
- return self._PORT
+ assert(addr and port, "invalid client address!")
+ return addr, port, user
end
-- get class
diff --git a/xmake/modules/private/service/config.lua b/xmake/modules/private/service/config.lua
index 9301ab818..fff082234 100644
--- a/xmake/modules/private/service/config.lua
+++ b/xmake/modules/private/service/config.lua
@@ -65,11 +65,9 @@ function _generate_configfile()
workdir = path.join(servicedir, "distcc_build"),
},
client = {
- -- without authorization: "127.0.0.1:9691"
- -- with user authorization: "[email protected]:9691"
- connect = "127.0.0.1:9692",
- -- with token authorization
- token = token
+ hosts = {
+ {connect = "127.0.0.1:9692", token = token}
+ }
}
}
diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua
index b2456e4e0..4e7f14e48 100644
--- a/xmake/modules/private/service/distcc_build/client.lua
+++ b/xmake/modules/private/service/distcc_build/client.lua
@@ -39,9 +39,9 @@ local super = distcc_build_client:class()
function distcc_build_client:init()
super.init(self)
- -- init address
- local address = assert(config.get("distcc_build.client.connect"), "config(distcc_build.client.connect): not found!")
- super.address_set(self, address)
+ -- init hosts
+ local hosts = assert(config.get("distcc_build.client.hosts"), "config(distcc_build.client.hosts): not found!")
+ self:hosts_set(hosts)
-- get project directory
local projectdir = os.projectdir()
@@ -59,6 +59,36 @@ function distcc_build_client:class()
return distcc_build_client
end
+-- get the client hosts
+function distcc_build_client:hosts()
+ return self._HOSTS
+end
+
+-- set the client hosts
+function distcc_build_client:hosts_set(hosts)
+ local hostinfos = {}
+ for _, host in ipairs(hosts) do
+ local hostinfo = {}
+ local address = assert(host.connect, "connect address not found in hosts configuration!")
+ local addr, port, user = self:address_parse(address)
+ hostinfo.addr = addr
+ hostinfo.port = port
+ hostinfo.user = user
+ hostinfo.token = host.token
+ table.insert(hostinfos, hostinfo)
+ end
+ self._HOSTS = hostinfos
+end
+
+-- connect to the distcc server
+function distcc_build_client:connect()
+end
+
+-- disconnect server
+function distcc_build_client:disconnect()
+end
+
+--[[
-- connect to the distcc server
function distcc_build_client:connect()
if self:is_connected() then
@@ -162,6 +192,7 @@ function distcc_build_client:disconnect()
status.connected = not ok
self:status_save()
end
+]]
-- is connected?
function distcc_build_client:is_connected()
diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua
index 6e2ddd279..66c7c2791 100644
--- a/xmake/modules/private/service/remote_build/client.lua
+++ b/xmake/modules/private/service/remote_build/client.lua
@@ -42,7 +42,7 @@ function remote_build_client:init()
-- init address
local address = assert(config.get("remote_build.client.connect"), "config(remote_build.client.connect): not found!")
- super.address_set(self, address)
+ self:address_set(address)
-- get project directory
local projectdir = os.projectdir()
@@ -365,6 +365,29 @@ function remote_build_client:session_id()
return self:status().session_id or hash.uuid():split("-", {plain = true})[1]:lower()
end
+-- set the given client address
+function remote_build_client:address_set(address)
+ local addr, port, user = self:address_parse(address)
+ self._ADDR = addr
+ self._PORT = port
+ self._USER = user
+end
+
+-- get user name
+function remote_build_client:user()
+ return self._USER
+end
+
+-- get the ip address
+function remote_build_client:addr()
+ return self._ADDR
+end
+
+-- get the address port
+function remote_build_client:port()
+ return self._PORT
+end
+
-- get filesync
function remote_build_client:_filesync()
return self._FILESYNC