diff options
| author | ruki <[email protected]> | 2026-02-09 22:55:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-02-09 22:55:06 +0800 |
| commit | 8d33fc825ba7d93e06bcada9dec24366c557b4ac (patch) | |
| tree | 89ae6b07b169494307208b95be009c2368334960 /xmake/modules | |
| parent | f9fc4cd7f3f96be6bf0f3ae20633cd4c8b378b2f (diff) | |
improve remote build config
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/private/service/remote_build/client.lua | 103 |
1 files changed, 98 insertions, 5 deletions
diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua index c951740e2..26e03014b 100644 --- a/xmake/modules/private/service/remote_build/client.lua +++ b/xmake/modules/private/service/remote_build/client.lua @@ -41,9 +41,8 @@ local super = remote_build_client:class() function remote_build_client:init() super.init(self) - -- init address - local address = assert(config.get("remote_build.connect"), "config(remote_build.connect): not found!") - self:address_set(address) + -- init host + self:_init_host() -- get project directory local projectdir = os.projectdir() @@ -80,7 +79,7 @@ function remote_build_client:connect() end -- Do we need user authorization? - local token = config.get("remote_build.token") + local token = self:token() if not token and self:user() then -- get user password @@ -92,6 +91,9 @@ function remote_build_client:connect() -- compute user authorization token = base64.encode(self:user() .. ":" .. pass) token = hash.md5(bytes(token)) + + -- update the computed token + self:token_set(token) end -- do connect @@ -397,7 +399,12 @@ end -- get user token function remote_build_client:token() - return self:status().token + return self._TOKEN or self:status().token +end + +-- set user token +function remote_build_client:token_set(token) + self._TOKEN = token end -- get the session id, only for unique project @@ -405,6 +412,92 @@ function remote_build_client:session_id() return self:status().session_id or hash.uuid(option.get("session")):split("-", {plain = true})[1]:lower() end +-- init host address and token +-- +-- Supported configuration formats: +-- +-- New format (multiple hosts): +-- remote_build = { +-- hosts = { +-- { +-- name = "windows", +-- connect = "10.5.139.8:9691", +-- token = "0e052f8c7153a6111d5a418e514020ee" +-- }, +-- { +-- name = "linux", +-- connect = "192.168.1.100:9691", +-- token = "abc123def456" +-- } +-- } +-- } +-- +-- Old format (single host, backward compatible): +-- remote_build = { +-- connect = "10.5.139.8:9691", +-- token = "0e052f8c7153a6111d5a418e514020ee" +-- } +-- +-- Usage: +-- xmake service --connect --host=windows # connect by name +-- xmake service --connect --host=10.5.139.8:9691 # connect by address +-- xmake service --connect # use default host +function remote_build_client:_init_host() + local remote_build_config = config.get("remote_build") or {} + local address + local token + + -- support new hosts format + if remote_build_config.hosts then + local host_name = option.get("host") + if host_name then + -- find host by name or address + for _, host in ipairs(remote_build_config.hosts) do + local host_ip, host_port = host.connect:split(":", {plain = true}) + + -- match by name + if host.name == host_name then + address = host.connect + token = host.token + break + -- match by full address + elseif host.connect == host_name then + address = host.connect + token = host.token + break + -- match by IP only (when user doesn't specify port) + elseif host_ip == host_name and not host_name:find(":", 1, true) then + address = host.connect + token = host.token + break + end + end + if not address then + raise("host '%s' not found in configuration!", host_name) + end + else + -- use first host as default + if #remote_build_config.hosts > 0 then + address = remote_build_config.hosts[1].connect + token = remote_build_config.hosts[1].token + end + end + -- support old format for backward compatibility + elseif remote_build_config.connect then + address = remote_build_config.connect + token = remote_build_config.token + end + + if not address then + raise("config(remote_build.connect) or config(remote_build.hosts) not found!") + end + + self:address_set(address) + if token then + self:token_set(token) + end +end + -- set the given client address function remote_build_client:address_set(address) local addr, port, user = self:address_parse(address) |
