diff options
| author | ruki <[email protected]> | 2026-07-02 14:53:50 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-07-02 14:53:50 +0800 |
| commit | 88a9ac094fe5491c82fd887fafd434c9ea74f042 (patch) | |
| tree | dc642420a9cb51b09c4a7e66c7188c22384587d9 | |
| parent | 5cb46ce73332d1cb361b1869e92441d24a017469 (diff) | |
| parent | f9c82cd72ce0dfb2cb88790a1cd7d9fb49d916c4 (diff) | |
Merge pull request #7630 from xmake-io/toolset
Add toolset api checker in target
| -rw-r--r-- | xmake/core/project/target.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/private/check/checker.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/private/check/checkers/api/api_checker.lua | 44 | ||||
| -rw-r--r-- | xmake/modules/private/check/checkers/api/target/toolset.lua | 35 |
4 files changed, 70 insertions, 14 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..0625d2cfa 100644 --- a/xmake/modules/private/check/checkers/api/api_checker.lua +++ b/xmake/modules/private/check/checkers/api/api_checker.lua @@ -123,6 +123,18 @@ function _show(apiname, value, instance, opt) probable_value = probable_value}) end +-- report the invalid value on the given instance +function _report(instance, apiname, value, level, opt) + local reported = _show(apiname, value, instance, { + show = opt.show, + showstr = opt.showstr, + valueset = opt.valueset, + level = level}) + if reported then + checker.update_stats(level) + end +end + -- check instance function _check_instance(instance, apiname, valueset, level, opt) local instance_valueset = valueset @@ -133,26 +145,30 @@ 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"}, so we report it on the key + -- @see https://github.com/xmake-io/xmake/pull/7597 + if opt.keyvalues then + if opt.check then + for key, value in pairs(table.wrap(values)) do + local ok, errors = opt.check(instance, key, value) + if not ok then + _report(instance, apiname, key, level, {show = opt.show, showstr = errors}) + end + end + end + return + end + for _, value in ipairs(values) do if opt.check then local ok, errors = opt.check(instance, value) if not ok then - local reported = _show(apiname, value, instance, { - show = opt.show, - showstr = errors, - level = level}) - if reported then - checker.update_stats(level) - end + _report(instance, apiname, value, level, {show = opt.show, showstr = errors}) end elseif not instance_valueset:has(value) then - local reported = _show(apiname, value, instance, { - show = opt.show, - valueset = instance_valueset, - level = level}) - if reported then - checker.update_stats(level) - end + _report(instance, apiname, value, level, {show = opt.show, valueset = instance_valueset}) end end end 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 |
