summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-08-17 21:08:55 +0800
committerGitHub <[email protected]>2023-08-17 21:08:55 +0800
commitbfd46b7d46241d14f9fbe44c2460b86daea3f827 (patch)
tree398d6a65ec6d1da5acbb24d2f7c33c955ec7e91c
parentbeafb2d5cfca0a3d52479312b6b92ca651f4959d (diff)
parentf5f742820467d797376e0843711e3119a7d31212 (diff)
Merge pull request #4088 from xmake-io/package
improve tools.xmake to pass deps #3952
-rw-r--r--xmake/modules/package/tools/xmake.lua50
-rw-r--r--xmake/modules/private/action/require/impl/package.lua5
2 files changed, 49 insertions, 6 deletions
diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua
index 0594d0f6b..0b0812b7e 100644
--- a/xmake/modules/package/tools/xmake.lua
+++ b/xmake/modules/package/tools/xmake.lua
@@ -325,9 +325,8 @@ function _get_package_requireinfo(packagename)
end
-- get package toolchains envs
-function _get_package_toolchains_envs(package, opt)
+function _get_package_toolchains_envs(envs, package, opt)
opt = opt or {}
- local envs = {}
local toolchains = package:config("toolchains")
if toolchains then
@@ -358,9 +357,7 @@ function _get_package_toolchains_envs(package, opt)
end
rcfile:print("add_toolchains(\"%s\")", table.concat(table.wrap(toolchains), '", "'))
rcfile:close()
- envs.XMAKE_RCFILES = {}
table.insert(envs.XMAKE_RCFILES, rcfile_path)
- table.join2(envs.XMAKE_RCFILES, os.getenv("XMAKE_RCFILES"))
-- pass custom toolchains definition in project
for _, toolchain_inst in ipairs(toolchains_custom) do
@@ -379,12 +376,53 @@ function _get_package_toolchains_envs(package, opt)
end
end
end
- return envs
+end
+
+-- get require paths
+function _get_package_requirepaths(requirepaths, package, dep, rootpath)
+ for _, plaindep in ipairs(package:plaindeps()) do
+ local subpath = table.join(rootpath, plaindep:name())
+ if plaindep == dep then
+ table.insert(requirepaths, table.concat(subpath, "."))
+ else
+ _get_package_requirepaths(requirepaths, plaindep, dep, subpath)
+ end
+ end
+end
+
+-- get package depconfs envs
+-- @see https://github.com/xmake-io/xmake/issues/3952
+function _get_package_depconfs_envs(envs, package, opt)
+ local requireconfs = {}
+ for _, dep in ipairs(package:librarydeps()) do
+ local requireinfo = dep:requireinfo()
+ if requireinfo and (requireinfo.override or (requireinfo.configs and #requireinfo.configs > 0)) then
+ local requirepaths = {}
+ _get_package_requirepaths(requirepaths, package, dep, {})
+ if #requirepaths > 0 then
+ table.insert(requireconfs, {requirepaths = requirepaths, requireinfo = requireinfo})
+ end
+ end
+ end
+ if #requireconfs > 0 then
+ local rcfile_path = os.tmpfile() .. ".lua"
+ local rcfile = io.open(rcfile_path, 'w')
+ for _, requireconf in ipairs(requireconfs) do
+ for _, requirepath in ipairs(requireconf.requirepaths) do
+ rcfile:print("add_requireconfs(\"%s\", %s)", requirepath, string.serialize(requireconf.requireinfo, {strip = true, indent = false}))
+ end
+ end
+ rcfile:close()
+ table.insert(envs.XMAKE_RCFILES, rcfile_path)
+ end
end
-- get the build environments
function buildenvs(package, opt)
- local envs = _get_package_toolchains_envs(package, opt)
+ local envs = {XMAKE_RCFILES = {}}
+ table.join2(envs.XMAKE_RCFILES, os.getenv("XMAKE_RCFILES"))
+ _get_package_toolchains_envs(envs, package, opt)
+ _get_package_depconfs_envs(envs, package, opt)
-- we should avoid using $XMAKE_CONFIGDIR outside to cause conflicts
envs.XMAKE_CONFIGDIR = os.curdir()
envs.XMAKE_IN_XREPO = "1"
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index c35f37174..9f2683fe5 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -831,6 +831,11 @@ function _load_package(packagename, requireinfo, opt)
if requireinfo.is_toplevel and not package_cached:is_toplevel() then
package_cached:requireinfo().is_toplevel = true
end
+ -- mark this cached package.requireinfo as override
+ -- @see https://github.com/xmake-io/xmake/issues/4078
+ if requireinfo.override then
+ package_cached:requireinfo().override = true
+ end
return package_cached
end