summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-02-21 14:51:33 +0800
committerGitHub <[email protected]>2023-02-21 14:51:33 +0800
commit6b91893e33b58d09fdd2f530962c42f516f382d6 (patch)
treed45f6dd8b71b30942a8dcf438d3f6a3c0cb0d741
parenteec6de9e8b6456aa13b588ecce47af07fcfba965 (diff)
parent77c0a9dcfbbad5e72b3b59b02ebdf8f00a3141ac (diff)
Merge pull request #3402 from xmake-io/check
Improve check
-rw-r--r--xmake/actions/build/check.lua (renamed from xmake/rules/utils/check_targets/checker.lua)39
-rw-r--r--xmake/actions/build/main.lua30
-rw-r--r--xmake/modules/private/check/checker.lua27
-rw-r--r--xmake/modules/private/check/checkers/api/api_checker.lua2
-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.lua6
-rw-r--r--xmake/rules/cuda/xmake.lua3
-rw-r--r--xmake/rules/objc++/xmake.lua3
-rw-r--r--xmake/rules/swift/xmake.lua2
-rw-r--r--xmake/rules/utils/check_licenses/xmake.lua24
-rw-r--r--xmake/rules/utils/check_targets/xmake.lua25
-rw-r--r--xmake/rules/vala/xmake.lua7
12 files changed, 105 insertions, 102 deletions
diff --git a/xmake/rules/utils/check_targets/checker.lua b/xmake/actions/build/check.lua
index e4fa31ce7..e26e4f0d0 100644
--- a/xmake/rules/utils/check_targets/checker.lua
+++ b/xmake/actions/build/check.lua
@@ -18,16 +18,22 @@
-- @file check_targets.lua
--
+-- imports
+import("core.base.option")
+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)
@@ -38,13 +44,32 @@ function _show(str, opt)
end
end
-function check_target(target)
+function main(targetname, opt)
+ opt = opt or {}
+
+ -- get targets
+ local targets = {}
+ if targetname then
+ table.insert(targets, project.target(targetname))
+ else
+ for _, target in pairs(project.targets()) do
+ if target:is_enabled() then
+ local group = target:get("group")
+ if (target:is_default() and not group_pattern) or option.get("all") or (group_pattern and group and group:match(group_pattern)) then
+ table.insert(targets, target)
+ end
+ end
+ end
+ end
+
+ -- do check
local checkers = checker.checkers()
for name, info in table.orderpairs(checkers) do
- -- just do some faster checkers
- if info.timely then
- import("private.check.checkers." .. name, {anonymous = true})({
- target = target, show = _show})
+ if (info.build and opt.build) or (info.build_failure and opt.build_failure) then
+ local check = import("private.check.checkers." .. name, {anonymous = true})
+ for _, target in ipairs(targets) do
+ check({target = target, show = _show})
+ end
end
end
end
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index 27b2419da..31a63b1d1 100644
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -32,6 +32,7 @@ import("build")
import("build_files")
import("cleaner")
import("statistics")
+import("check", {alias = "check_targets"})
import("private.cache.build_cache")
import("private.service.remote_build.action", {alias = "remote_build_action"})
@@ -109,6 +110,25 @@ function _do_build(targetname, group_pattern)
end
end
+-- on exit
+function _on_exit(ok, errors)
+
+ -- since we call it in both os.atexit and catch block,
+ -- we need to avoid duplicate execution.
+ local handled = false
+ local exited = _g.exited
+ if not exited then
+ exited = true
+ handled = true
+ _g.exited = exited
+ end
+
+ -- we just handle the build failure
+ if handled and not ok then
+ check_targets(targetname, {build_failure = true})
+ end
+end
+
-- main
function main()
@@ -144,10 +164,16 @@ function main()
-- clean up temporary files once a day
cleaner.cleanup()
+ -- register exit callbacks
+ os.atexit(_on_exit)
+
try
{
function ()
+ -- do check
+ check_targets(targetname, {build = true})
+
-- do rules before building
_do_project_rules("build_before")
@@ -163,6 +189,10 @@ function main()
{
function (errors)
+ -- maybe it's unreachable when building fails, so we need also os.atexit()
+ -- @see https://github.com/xmake-io/xmake/issues/3401
+ _on_exit(false, errors)
+
-- do rules after building
_do_project_rules("build_after", {errors = errors})
diff --git a/xmake/modules/private/check/checker.lua b/xmake/modules/private/check/checker.lua
index 9396f825f..eb48a2029 100644
--- a/xmake/modules/private/check/checker.lua
+++ b/xmake/modules/private/check/checker.lua
@@ -28,31 +28,32 @@ function checkers()
checkers = {
-- target api checkers
["api.target.version"] = {description = "Check version configuration in target."},
- ["api.target.kind"] = {description = "Check kind configuration in target.", timely = true},
- ["api.target.strip"] = {description = "Check strip configuration in target.", timely = true},
- ["api.target.optimize"] = {description = "Check optimize configuration in target.", timely = true},
- ["api.target.symbols"] = {description = "Check symbols configuration in target.", timely = true},
- ["api.target.fpmodels"] = {description = "Check fpmodels configuration in target.", timely = true},
- ["api.target.warnings"] = {description = "Check warnings configuration in target.", timely = true},
- ["api.target.languages"] = {description = "Check languages configuration in target.", timely = true},
- ["api.target.vectorexts"] = {description = "Check vectorexts configuration in target.", timely = true},
- ["api.target.exceptions"] = {description = "Check exceptions configuration in target.", timely = true},
+ ["api.target.kind"] = {description = "Check kind configuration in target.", build = true},
+ ["api.target.strip"] = {description = "Check strip configuration in target.", build = true},
+ ["api.target.optimize"] = {description = "Check optimize configuration in target.", build = true},
+ ["api.target.symbols"] = {description = "Check symbols configuration in target.", build = true},
+ ["api.target.fpmodels"] = {description = "Check fpmodels configuration in target.", build = true},
+ ["api.target.warnings"] = {description = "Check warnings configuration in target.", build = true},
+ ["api.target.languages"] = {description = "Check languages configuration in target.", build = true},
+ ["api.target.vectorexts"] = {description = "Check vectorexts configuration in target.", build = true},
+ ["api.target.exceptions"] = {description = "Check exceptions configuration in target.", build = true},
["api.target.packages"] = {description = "Check packages configuration in target."},
["api.target.files"] = {description = "Check files configuration in target."},
["api.target.headerfiles"] = {description = "Check header files configuration in target."},
["api.target.installfiles"] = {description = "Check install files configuration in target."},
["api.target.configfiles"] = {description = "Check config files configuration in target."},
- ["api.target.linkdirs"] = {description = "Check linkdirs configuration in target.", timely = true},
- ["api.target.includedirs"] = {description = "Check includedirs configuration in target.", timely = true},
- ["api.target.frameworkdirs"] = {description = "Check frameworkdirs configuration in target.", timely = true},
+ ["api.target.linkdirs"] = {description = "Check linkdirs configuration in target.", build = true},
+ ["api.target.includedirs"] = {description = "Check includedirs configuration in target.", build = true},
+ ["api.target.frameworkdirs"] = {description = "Check frameworkdirs configuration in target.", build = true},
["api.target.cflags"] = {description = "Check c compiler flags configuration in target."},
["api.target.cxflags"] = {description = "Check c/c++ compiler flags configuration in target."},
["api.target.cxxflags"] = {description = "Check c++ compiler flags configuration in target."},
["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.", build = true},
-- cuda checkers
- ["cuda.devlink"] = {description = "Check devlink for targets."},
+ ["cuda.devlink"] = {description = "Check devlink for targets.", build_failure = true},
-- clang tidy checker
["clang.tidy"] = {description = "Check project code using clang-tidy.", showstats = false}
}
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 3d160ab65..19c943e77 100644
--- a/xmake/rules/c++/xmake.lua
+++ b/xmake/rules/c++/xmake.lua
@@ -52,12 +52,6 @@ rule("c++")
-- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled
add_deps("utils.symbols.extract")
- -- check targets
- add_deps("utils.check.targets")
-
- -- check licenses
- add_deps("utils.check.licenses")
-
-- add platform rules
add_deps("platform.wasm")
add_deps("platform.windows")
diff --git a/xmake/rules/cuda/xmake.lua b/xmake/rules/cuda/xmake.lua
index d46784169..543df54b8 100644
--- a/xmake/rules/cuda/xmake.lua
+++ b/xmake/rules/cuda/xmake.lua
@@ -33,6 +33,3 @@ rule("cuda")
-- inherit links and linkdirs of all dependent targets by default
add_deps("utils.inherit.links")
- -- check targets
- add_deps("utils.check.targets")
-
diff --git a/xmake/rules/objc++/xmake.lua b/xmake/rules/objc++/xmake.lua
index 65ba757b8..447c12176 100644
--- a/xmake/rules/objc++/xmake.lua
+++ b/xmake/rules/objc++/xmake.lua
@@ -63,6 +63,3 @@ rule("objc++")
-- we attempt to extract symbols to the independent file and
-- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled
add_deps("utils.symbols.extract")
-
- -- check targets
- add_deps("utils.check.targets")
diff --git a/xmake/rules/swift/xmake.lua b/xmake/rules/swift/xmake.lua
index 4a44fcb13..5ebd919c9 100644
--- a/xmake/rules/swift/xmake.lua
+++ b/xmake/rules/swift/xmake.lua
@@ -32,5 +32,3 @@ rule("swift")
-- support `add_files("src/*.o")` to merge object files to target
add_deps("utils.merge.object")
- -- check targets
- add_deps("utils.check.targets")
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/utils/check_targets/xmake.lua b/xmake/rules/utils/check_targets/xmake.lua
deleted file mode 100644
index 35f58bc37..000000000
--- a/xmake/rules/utils/check_targets/xmake.lua
+++ /dev/null
@@ -1,25 +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
---
-
-rule("utils.check.targets")
- before_build(function (target)
- import("checker").check_target(target)
- end)
-
diff --git a/xmake/rules/vala/xmake.lua b/xmake/rules/vala/xmake.lua
index 8f1431fca..a4b3f4b1e 100644
--- a/xmake/rules/vala/xmake.lua
+++ b/xmake/rules/vala/xmake.lua
@@ -165,10 +165,3 @@ rule("vala")
-- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled
add_deps("utils.symbols.extract")
- -- check targets
- add_deps("utils.check.targets")
-
- -- check licenses
- add_deps("utils.check.licenses")
-
-