Skip to content

Commit

Permalink
Merge pull request #4879 from xmake-io/envs
Browse files Browse the repository at this point in the history
Improve package envs
  • Loading branch information
waruqi committed Mar 26, 2024
2 parents 45aadcc + f17d017 commit bcc939b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
3 changes: 3 additions & 0 deletions xmake/core/package/package.lua
Expand Up @@ -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"}
Expand Down
45 changes: 38 additions & 7 deletions xmake/modules/private/action/require/impl/actions/install.lua
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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})
Expand Down

0 comments on commit bcc939b

Please sign in to comment.