summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-03-26 18:46:26 +0800
committerGitHub <[email protected]>2024-03-26 18:46:26 +0800
commitbcc939b303b638e6ac789237b444ef040e2d2c31 (patch)
tree6b7a7ee26a1d86de94902cf68c8769c190173537
parent45aadcc5974de9b7d40dd2641e7bd335db8fb2e3 (diff)
parentf17d01706c2b9b5db840ebaa4e9c8abf4e748064 (diff)
Merge pull request #4879 from xmake-io/envs
Improve package envs
-rw-r--r--xmake/core/package/package.lua3
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua45
2 files changed, 41 insertions, 7 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index d1a082890..4fbfa635a 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -979,9 +979,12 @@ function _instance:_rawenvs()
local envs = self._RAWENVS
if not envs then
envs = {}
+
+ -- add bin PATH
if self:is_binary() or self:is_plat("windows", "mingw") then -- bin/*.dll for windows
envs.PATH = {"bin"}
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})