diff options
| author | ruki <[email protected]> | 2023-02-21 23:21:48 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-02-21 23:21:48 +0800 |
| commit | d4a354d714f69c598945f91557f7a6eec2334161 (patch) | |
| tree | d9fab1e184b8b207648d6f11808ea6e1ffd68a7f | |
| parent | b39a55d547a5c80298626cb46ff9e338d4729e10 (diff) | |
improve license checker
| -rw-r--r-- | xmake/actions/build/check.lua | 7 | ||||
| -rw-r--r-- | xmake/modules/private/check/checker.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/private/check/checkers/api/api_checker.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/private/check/checkers/api/target/license.lua (renamed from xmake/rules/utils/check_licenses/check_licenses.lua) | 39 | ||||
| -rw-r--r-- | xmake/rules/c++/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/rules/utils/check_licenses/xmake.lua | 24 | ||||
| -rw-r--r-- | xmake/rules/vala/xmake.lua | 4 |
7 files changed, 35 insertions, 45 deletions
diff --git a/xmake/actions/build/check.lua b/xmake/actions/build/check.lua index 5907ae5b0..6bbb45b8a 100644 --- a/xmake/actions/build/check.lua +++ b/xmake/actions/build/check.lua @@ -24,13 +24,16 @@ import("core.project.project") import("private.check.checker") function _show(str, opt) + opt = opt or {} _g.showed = _g.showed or {} local showed = _g.showed local infostr - if str then + if str and opt.sourcetips then infostr = string.format("%s${clear}: %s", opt.sourcetips, str) - else + elseif opt.sourcetips and opt.apiname and opt.value ~= nil then infostr = string.format("%s${clear}: unknown %s value '%s'", opt.sourcetips, opt.apiname, opt.value) + elseif str then + infostr = string.format("${clear}: %s", str) end if opt.probable_value then infostr = string.format("%s, it may be '%s'", infostr, opt.probable_value) diff --git a/xmake/modules/private/check/checker.lua b/xmake/modules/private/check/checker.lua index 9396f825f..5ddcc9fdc 100644 --- a/xmake/modules/private/check/checker.lua +++ b/xmake/modules/private/check/checker.lua @@ -51,6 +51,7 @@ function checkers() ["api.target.asflags"] = {description = "Check assembler flags configuration in target."}, ["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.", timely = true}, -- cuda checkers ["cuda.devlink"] = {description = "Check devlink for targets."}, -- 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 79e4809bd..10b63d19c 100644 --- a/xmake/modules/private/check/checkers/api/api_checker.lua +++ b/xmake/modules/private/check/checkers/api/api_checker.lua @@ -22,7 +22,7 @@ import("core.base.option") import("core.base.hashset") import("core.project.project") -import("..checker") +import("private.check.checker") -- get the most probable value function _get_most_probable_value(value, valueset) diff --git a/xmake/rules/utils/check_licenses/check_licenses.lua b/xmake/modules/private/check/checkers/api/target/license.lua index 628cae09a..4de6fc53e 100644 --- a/xmake/rules/utils/check_licenses/check_licenses.lua +++ b/xmake/modules/private/check/checkers/api/target/license.lua @@ -19,10 +19,18 @@ -- -- imports +import("core.project.project") import("core.base.license") +import("private.check.checker") + +-- show info +function _show(str) + cprint("${color.warning}${text.warning}${clear}: %s", str) +end -- check licenses -function _check_licenses_for_package(target, package) +function _check_licenses_for_package(target, package, opt) + opt = opt or {} local target_license = target:license() local package_license = package:license() local package_kind = package:has_shared() and "shared" @@ -30,10 +38,12 @@ function _check_licenses_for_package(target, package) if not ok then errors = errors or "you can use set_license()/set_policy() to modify/disable license" if target_license then - wprint("license(%s) of target(%s) is not compatible with license(%s) of package(%s)\n%s!", target_license, target:name(), package_license, package:name(), errors) + errors = string.format("license(%s) of target(%s) is not compatible with license(%s) of package(%s)\n%s!", target_license, target:name(), package_license, package:name(), errors) else - wprint("target(%s) maybe is not compatible with license(%s) of package(%s), \n%s!", target:name(), package_license, package:name(), errors) + errors = string.format("target(%s) maybe is not compatible with license(%s) of package(%s), \n%s!", target:name(), package_license, package:name(), errors) end + (opt.show or _show)(errors) + checker.update_stats("warning") end end @@ -41,17 +51,24 @@ end -- -- @see https://github.com/xmake-io/xmake/issues/1016 -- -function _check_licenses_for_packages(target) - for _, pkg in ipairs(target:orderpkgs()) do - if pkg:license() then - _check_licenses_for_package(target, pkg) +function _check_licenses_for_target(target, opt) + if target:policy("check.target_package_licenses") then + for _, pkg in ipairs(target:orderpkgs()) do + if pkg:license() then + _check_licenses_for_package(target, pkg, opt) + end end end end --- main entry -function main(target) - if target:policy("check.target_package_licenses") then - _check_licenses_for_packages(target) +function main(opt) + opt = opt or {} + local target = opt.target + if target then + _check_licenses_for_target(target, opt) + else + for _, target in pairs(project.targets()) do + _check_licenses_for_target(target, opt) + end end end diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua index bc67941d9..19c943e77 100644 --- a/xmake/rules/c++/xmake.lua +++ b/xmake/rules/c++/xmake.lua @@ -52,9 +52,6 @@ rule("c++") -- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled add_deps("utils.symbols.extract") - -- check licenses - add_deps("utils.check.licenses") - -- add platform rules add_deps("platform.wasm") add_deps("platform.windows") diff --git a/xmake/rules/utils/check_licenses/xmake.lua b/xmake/rules/utils/check_licenses/xmake.lua deleted file mode 100644 index 46fe6db0c..000000000 --- a/xmake/rules/utils/check_licenses/xmake.lua +++ /dev/null @@ -1,24 +0,0 @@ ---!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, TBOOX Open Source Group. --- --- @author ruki --- @file xmake.lua --- - --- define rule: utils.check.licenses -rule("utils.check.licenses") - before_build("check_licenses") - diff --git a/xmake/rules/vala/xmake.lua b/xmake/rules/vala/xmake.lua index c71effd05..a4b3f4b1e 100644 --- a/xmake/rules/vala/xmake.lua +++ b/xmake/rules/vala/xmake.lua @@ -165,7 +165,3 @@ rule("vala") -- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled add_deps("utils.symbols.extract") - -- check licenses - add_deps("utils.check.licenses") - - |
