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 | |
| parent | f9fc4cd7f3f96be6bf0f3ae20633cd4c8b378b2f (diff) | |
improve remote build config
| -rw-r--r-- | xmake/actions/service/xmake.lua | 9 | ||||
| -rw-r--r-- | xmake/modules/private/service/remote_build/client.lua | 103 |
2 files changed, 106 insertions, 6 deletions
diff --git a/xmake/actions/service/xmake.lua b/xmake/actions/service/xmake.lua index ed6772749..b292a73a2 100644 --- a/xmake/actions/service/xmake.lua +++ b/xmake/actions/service/xmake.lua @@ -38,7 +38,9 @@ task("service") " - xmake service --connect", " - xmake service --connect --remote", " - xmake service --connect --distcc", - " - xmake service --connect --remote --distcc" }, + " - xmake service --connect --remote --distcc", + " - xmake service --connect --host=windows", + " - xmake service --connect --host=10.5.139.8:9691" }, {nil, "session" , "kv", nil,"Connect with the given session name, it will generate a session id via name.", "e.g.", " -- xmake service --connect --ccache --session=foo" }, @@ -68,6 +70,11 @@ task("service") {nil, "gen-token", "k", nil, "Generate a new token in the server.", "e.g.", " - xmake service --gen-token" }, + {nil, "host", "kv", nil, "Connect to the specific host by name or address.", + "e.g.", + " - xmake service --connect --host=windows", + " - xmake service --connect --host=10.5.139.8:9691", + " - xmake service --connect --host=10.5.139.8" }, {nil, "logs", "k", nil, "Show service logs if the daemon service has been started." }, {nil, "status", "k", nil, "Show service status if the daemon service has been started." }, {nil, "values", "vs", nil, "The values list for pull/.. options." } 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) |
