Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve package envs #4879

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions xmake/core/package/package.lua
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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