summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-10-16 22:47:57 +0800
committerruki <[email protected]>2025-10-16 22:47:57 +0800
commitfa1e44cc4ee14fdc3e6e82546c995e888c56d460 (patch)
treee9af38a6875b3920e1e53e336831dd57e8ea7183
parent7529874021cda55b9199d07c17922f97e969e272 (diff)
add requirestr in toolchain
-rw-r--r--xmake/core/project/project.lua7
-rw-r--r--xmake/core/tool/toolchain.lua66
2 files changed, 45 insertions, 28 deletions
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 5af05c21f..8b94cbff7 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -1207,9 +1207,14 @@ end
-- get the given toolchain
function project.toolchain(name, opt)
opt = opt or {}
- local toolchain_name = toolchain.parsename(name) -- we need to ignore `@packagename`
+ local parseinfo = toolchain.parsename(name) -- we need to ignore `@packagename`
+ local toolchain_name = parseinfo.name
local info = project._toolchains()[toolchain_name]
if info == nil and opt.namespace then
+ local requirestr = parseinfo.requirestr
+ if requirestr then
+ toolchain_name = toolchain_name .. "[" .. requirestr .. "]"
+ end
info = project._toolchains()[opt.namespace .. "::" .. toolchain_name]
end
if info then
diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua
index cf89e7234..57b2f5073 100644
--- a/xmake/core/tool/toolchain.lua
+++ b/xmake/core/tool/toolchain.lua
@@ -40,8 +40,11 @@ local sandbox = require("sandbox/sandbox")
local sandbox_module = require("sandbox/modules/import/core/sandbox/module")
-- new an instance
-function _instance.new(name, info, cachekey, is_builtin, configs)
- local instance = table.inherit(_instance)
+function _instance.new(name, info, opt)
+ opt = opt or {}
+ local cachekey = opt.cachekey
+ local configs = opt.configs
+ local instance = table.inherit(_instance)
local parts = name:split("::", {plain = true})
instance._NAME = parts[#parts]
table.remove(parts)
@@ -49,7 +52,8 @@ function _instance.new(name, info, cachekey, is_builtin, configs)
instance._NAMESPACE = table.concat(parts, "::")
end
instance._INFO = info
- instance._IS_BUILTIN = is_builtin
+ instance._REQUIRESTR = opt.requirestr
+ instance._IS_BUILTIN = opt.is_builtin
instance._CACHE = toolchain._localcache()
instance._CACHEKEY = cachekey
local toolchain_configs = instance._CACHE:get(cachekey)
@@ -86,7 +90,12 @@ end
-- get the full name
function _instance:fullname()
local namespace = self:namespace()
- return namespace and namespace .. "::" .. self:name() or self:name()
+ local name = self:name()
+ local requirestr = self._REQUIRESTR
+ if requirestr then
+ name = name .. "[" .. requirestr .. "]"
+ end
+ return namespace and namespace .. "::" .. name or name
end
-- get toolchain platform
@@ -615,33 +624,34 @@ function toolchain.parsename(name)
if packages == "" then
packages = nil
end
- local configs
+ local requireconfs, requirestr
if toolchain_name then
local toolchain_name_raw, configs_str = toolchain_name:match("(.-)%[(.*)%]")
if toolchain_name_raw and configs_str then
configs_str = configs_str:gsub("%[(.*)%]", function (w)
return w:replace(",", ":")
end)
+ requirestr = configs_str
toolchain_name = toolchain_name_raw
local splitinfo = configs_str:split(",", {plain = true})
for _, v in ipairs(splitinfo) do
local parts = v:split("=", {plain = true})
local k = parts[1]
v = parts[2]
- configs = configs or {}
+ requireconfs = requireconfs or {}
if v then
if v:find(":", 1 ,true) then
- configs[k] = v:split(":", {plain = true})
+ requireconfs[k] = v:split(":", {plain = true})
else
- configs[k] = option.boolean(v)
+ requireconfs[k] = option.boolean(v)
end
else
- configs[k] = true
+ requireconfs[k] = true
end
end
end
end
- return toolchain_name or packages, packages, configs
+ return {name = toolchain_name or packages, packages = packages, requireconfs = requireconfs, requirestr = requirestr}
end
-- get toolchain apis
@@ -697,16 +707,16 @@ end
-- load toolchain
function toolchain.load(name, opt)
-
- -- get toolchain name and packages
opt = opt or {}
- local packages, configs
- name, packages, configs = toolchain.parsename(name)
+
+ -- parse toolchain name
+ local parseinfo = toolchain.parsename(name)
+ name = parseinfo.name
-- init configs
- configs = configs or {}
+ local configs = parseinfo.requireconfs or {}
table.join2(configs, opt)
- configs.packages = opt.packages or packages
+ configs.packages = opt.packages or parseinfo.packages
configs.plat = opt.plat or config.get("plat") or os.host()
configs.arch = opt.arch or config.get("arch") or os.arch()
@@ -747,30 +757,31 @@ function toolchain.load(name, opt)
return nil, errors
end
- -- check the toolchain name
- local result = results[name]
- if not result then
+ -- get toolchain info
+ local info = results[name]
+ if not info then
return nil, string.format("the toolchain %s not found!", name)
end
-- save instance to the cache
- instance = _instance.new(name, result, cachekey, true, configs)
+ instance = _instance.new(name, info, {cachekey = cachekey,
+ is_builtin = true, configs = configs, requirestr = parseinfo.requirestr})
cache:set(cachekey, instance)
return instance
end
-- load toolchain from the give toolchain info
function toolchain.load_withinfo(name, info, opt)
-
- -- get toolchain name and packages
opt = opt or {}
- local packages, configs
- name, packages, configs = toolchain.parsename(name)
+
+ -- parse toolchain name
+ local parseinfo = toolchain.parsename(name)
+ name = parseinfo.name
-- init configs
- configs = configs or {}
+ local configs = parseinfo.requireconfs or {}
table.join2(configs, opt)
- configs.packages = opt.packages or packages
+ configs.packages = opt.packages or parseinfo.packages
configs.plat = opt.plat or config.get("plat") or os.host()
configs.arch = opt.arch or config.get("arch") or os.arch()
@@ -785,7 +796,8 @@ function toolchain.load_withinfo(name, info, opt)
end
-- save instance to the cache
- instance = _instance.new(name, info, cachekey, false, configs)
+ instance = _instance.new(name, info, {cachekey = cachekey,
+ is_builtin = false, configs = configs, requirestr = parseinfo.requirestr})
cache:set(cachekey, instance)
return instance
end