summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-06-30 23:12:29 +0800
committerruki <[email protected]>2026-06-30 13:21:13 +0800
commitfd5810a06f8aab1f5fa11ce52eb1f006fba9025b (patch)
tree5b386cd0aef2f2970841fb3d6e028fdc4bfb334a
parent5cb46ce73332d1cb361b1869e92441d24a017469 (diff)
add add_toolset checker
-rw-r--r--xmake/core/project/target.lua4
-rw-r--r--xmake/modules/private/check/checker.lua1
-rw-r--r--xmake/modules/private/check/checkers/api/api_checker.lua23
-rw-r--r--xmake/modules/private/check/checkers/api/target/toolset.lua35
4 files changed, 63 insertions, 0 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 03891563b..cc5df14d4 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -2787,6 +2787,10 @@ function _instance:tool(toolkind)
before_get = function()
-- get program from set_toolset
local program = self:get("toolset." .. toolkind)
+ if program and type(program) ~= "string" then
+ os.raise("set_toolset(\"%s\", \"%s\") in target(%s), please set only one tool for each tool kind.",
+ toolkind, table.concat(table.wrap(program), "\", \""), self:fullname())
+ end
-- get program from `xmake f --cc`
if not program and not self:get("toolchains") then
diff --git a/xmake/modules/private/check/checker.lua b/xmake/modules/private/check/checker.lua
index 083c5b9c9..5e5ea7aca 100644
--- a/xmake/modules/private/check/checker.lua
+++ b/xmake/modules/private/check/checker.lua
@@ -57,6 +57,7 @@ function checkers()
["api.target.ldflags"] = {description = "Check binary linker flags configuration in target."},
["api.target.shflags"] = {description = "Check shared library linker flags configuration in target."},
["api.target.license"] = {description = "Check license in target and packages.", build = true},
+ ["api.target.toolset"] = {description = "Check toolset configuration in target."},
-- cuda checkers
["cuda.devlink"] = {description = "Check devlink for targets.", build_failure = true},
-- clang tidy checker
diff --git a/xmake/modules/private/check/checkers/api/api_checker.lua b/xmake/modules/private/check/checkers/api/api_checker.lua
index 10e3942ac..c52547183 100644
--- a/xmake/modules/private/check/checkers/api/api_checker.lua
+++ b/xmake/modules/private/check/checkers/api/api_checker.lua
@@ -133,6 +133,29 @@ function _check_instance(instance, apiname, valueset, level, opt)
end
end
local values = instance:get(apiname)
+
+ -- check the keyvalues api, e.g. set_toolset("cxx", "clang")
+ -- the values is a dictionary, e.g. {cxx = "clang"}
+ -- @see https://github.com/xmake-io/xmake/pull/7597
+ if opt.keyvalues then
+ for key, value in pairs(table.wrap(values)) do
+ if opt.check then
+ local ok, errors = opt.check(instance, key, value)
+ if not ok then
+ -- we report it on the key, because the sourceinfo is saved on the key
+ local reported = _show(apiname, key, instance, {
+ show = opt.show,
+ showstr = errors,
+ level = level})
+ if reported then
+ checker.update_stats(level)
+ end
+ end
+ end
+ end
+ return
+ end
+
for _, value in ipairs(values) do
if opt.check then
local ok, errors = opt.check(instance, value)
diff --git a/xmake/modules/private/check/checkers/api/target/toolset.lua b/xmake/modules/private/check/checkers/api/target/toolset.lua
new file mode 100644
index 000000000..2c2befdc7
--- /dev/null
+++ b/xmake/modules/private/check/checkers/api/target/toolset.lua
@@ -0,0 +1,35 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file toolset.lua
+--
+
+-- imports
+import(".api_checker")
+
+function main(opt)
+ opt = opt or {}
+ -- we only support one tool for each tool kind, e.g. set_toolset("cxx", "clang")
+ -- @see https://github.com/xmake-io/xmake/pull/7597
+ api_checker.check_targets("toolset", table.join(opt, {keyvalues = true, check = function(target, toolkind, program)
+ if type(program) ~= "string" then
+ return false, string.format("set_toolset(\"%s\", \"%s\") in target(%s), please set only one tool for each tool kind.",
+ toolkind, table.concat(table.wrap(program), "\", \""), target:fullname())
+ end
+ return true
+ end, level = "error"}))
+end