summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-03-26 23:33:53 +0800
committerruki <[email protected]>2024-03-26 23:33:53 +0800
commitf17d01706c2b9b5db840ebaa4e9c8abf4e748064 (patch)
tree196e3751f607343463edcbaaecf1dcd9bb863ce7
parentf1769ddf69ff053809b37b103a91a37231369994 (diff)
improve envs
-rw-r--r--xmake/core/package/package.lua17
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua45
2 files changed, 38 insertions, 24 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index c3cba4407..4fbfa635a 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -985,23 +985,6 @@ function _instance:_rawenvs()
envs.PATH = {"bin"}
end
- -- add compiler runtime library directory to $PATH
- -- @see https://github.com/xmake-io/xmake-repo/pull/3606
- if is_host("windows") and self:is_plat("windows", "mingw") then -- bin/*.dll for windows
- local toolchains = self:toolchains()
- if not toolchains then
- local platform_inst = platform.load(self:plat(), self:arch())
- toolchains = platform_inst:toolchains()
- for _, toolchain_inst in ipairs(toolchains) do
- local runenvs = toolchain_inst:runenvs()
- if runenvs then
- envs.PATH = envs.PATH or {}
- table.join2(envs.PATH, runenvs.PATH)
- end
- end
- end
- end
-
-- add LD_LIBRARY_PATH to load *.so directory
if os.host() ~= "windows" and self:is_plat(os.host()) and self:is_arch(os.arch()) then
envs.LD_LIBRARY_PATH = {"lib"}
diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua
index 6d903885a..2aad2ed2a 100644
--- a/xmake/modules/private/action/require/impl/actions/install.lua
+++ b/xmake/modules/private/action/require/impl/actions/install.lua
@@ -23,6 +23,7 @@ import("core.base.option")
import("core.base.tty")
import("core.package.package", {alias = "core_package"})
import("core.project.target")
+import("core.platform.platform")
import("lib.detect.find_file")
import("private.action.require.impl.actions.test")
import("private.action.require.impl.actions.patch_sources")
@@ -315,6 +316,41 @@ function _leave_workdir(package, oldir)
_clear_sourcedir(package)
end
+-- enter package install environments
+function _enter_package_installenvs(package)
+ for _, dep in ipairs(package:orderdeps()) do
+ dep:envs_enter()
+ end
+end
+
+-- enter package test environments
+function _enter_package_testenvs(package)
+
+ -- add compiler runtime library directory to $PATH
+ -- @see https://github.com/xmake-io/xmake-repo/pull/3606
+ if is_host("windows") and package:is_plat("windows", "mingw") then -- bin/*.dll for windows
+ local toolchains = package:toolchains()
+ if not toolchains then
+ local platform_inst = platform.load(package:plat(), package:arch())
+ toolchains = platform_inst:toolchains()
+ for _, toolchain_inst in ipairs(toolchains) do
+ local runenvs = toolchain_inst:runenvs()
+ if runenvs and runenvs.PATH then
+ local envs = {PATH = runenvs.PATH}
+ os.addenvs(envs)
+ end
+ end
+ end
+ end
+
+ -- enter package environments
+ for _, dep in ipairs(package:orderdeps()) do
+ dep:envs_enter()
+ end
+ package:envs_enter()
+end
+
+
function main(package)
-- enter working directory
@@ -356,9 +392,7 @@ function main(package)
patch_sources(package)
-- enter the environments of all package dependencies
- for _, dep in ipairs(package:orderdeps()) do
- dep:envs_enter()
- end
+ _enter_package_installenvs(package)
-- check package toolchains
_check_package_toolchains(package)
@@ -384,10 +418,7 @@ function main(package)
end
-- enter the package environments
- for _, dep in ipairs(package:orderdeps()) do
- dep:envs_enter()
- end
- package:envs_enter()
+ _enter_package_testenvs(package)
-- fetch package and force to flush the cache
local fetchinfo = package:fetch({force = true})