diff options
| author | ruki <[email protected]> | 2022-04-15 22:36:10 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-15 22:36:10 +0800 |
| commit | abee3747fe8a4673e6d5a2d53f78bf98847b8d07 (patch) | |
| tree | af2b011f29074bf8d8b736fc48913fafb0ce30ae | |
| parent | 0db2b97ec84fb3d003b0e07ef7c731531268c083 (diff) | |
improve service env
| -rw-r--r-- | xmake/modules/private/service/remote_build/client.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/private/service/remote_build/environment.lua | 61 | ||||
| -rw-r--r-- | xmake/modules/private/service/start_service.lua | 4 |
3 files changed, 65 insertions, 4 deletions
diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua index 3a80f2faa..3fbd58c7d 100644 --- a/xmake/modules/private/service/remote_build/client.lua +++ b/xmake/modules/private/service/remote_build/client.lua @@ -29,7 +29,7 @@ import("private.service.config") import("private.service.message") import("private.service.client") import("private.service.stream", {alias = "socket_stream"}) -import("private.action.require.impl.packagenv") +import("private.service.remote_build.environment") -- define module local remote_build_client = remote_build_client or client() @@ -54,7 +54,7 @@ function remote_build_client:init() end -- enter git environment - packagenv.enter("git") + environment.enter() end -- get class diff --git a/xmake/modules/private/service/remote_build/environment.lua b/xmake/modules/private/service/remote_build/environment.lua new file mode 100644 index 000000000..d273679a7 --- /dev/null +++ b/xmake/modules/private/service/remote_build/environment.lua @@ -0,0 +1,61 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file environment.lua +-- + +-- imports +import("lib.detect.find_tool") +import("private.action.require.impl.packagenv") +import("private.action.require.impl.install_packages") + +-- enter environment +-- +-- ensure that we can find some basic tools: git, ... +-- +-- If these tools not exist, we will install it first. +-- +function enter() + + -- enter the environments of git + _g._OLDENVS = packagenv.enter("git") + + -- git not found? install it first + local packages = {} + local git = find_tool("git") + if not git then + table.join2(packages, install_packages("git")) + end + + -- enter the environments of installed packages + for _, instance in ipairs(packages) do + instance:envs_enter() + end + + -- we need force to detect and flush detect cache after loading all environments + if not git then + find_tool("git", {force = true}) + end +end + +-- leave environment +function leave() + local oldenvs = _g._OLDENVS + if oldenvs then + os.setenvs(oldenvs) + end +end diff --git a/xmake/modules/private/service/start_service.lua b/xmake/modules/private/service/start_service.lua index 0488ba705..07ec76c8e 100644 --- a/xmake/modules/private/service/start_service.lua +++ b/xmake/modules/private/service/start_service.lua @@ -22,11 +22,11 @@ import("core.base.option") import("private.service.config") import("private.service.service") -import("private.action.require.impl.packagenv") +import("private.service.remote_build.environment") function main(opt) opt = opt or {} - packagenv.enter("git") + environment.enter() if opt.daemon then local argv = {"lua"} if option.get("verbose") then |
