summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-08-17 23:01:23 +0800
committerruki <[email protected]>2023-08-17 23:01:23 +0800
commit0175f30b0a2da6b6985aa2c30029af821dd81f0b (patch)
treea802cbbecb2ae65a330daf933e8ab0b22ce22401
parentbeafb2d5cfca0a3d52479312b6b92ca651f4959d (diff)
improve tools.xmake to pass deps #3952
-rw-r--r--xmake/modules/package/tools/xmake.lua50
1 files changed, 44 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"