summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-01-15 23:08:59 +0800
committerruki <[email protected]>2026-01-15 23:08:59 +0800
commitb861a8bae087e0324ed77133b3e283a2c8dd1cc8 (patch)
tree2d736332feae1663f72efd7b81f7ef3e40e81564
parentb8c02f4d81b0aceb976401f3ce20605f4ee775cb (diff)
improve to find clang-tidy
-rw-r--r--xmake/modules/private/check/checkers/clang/tidy.lua51
1 files changed, 32 insertions, 19 deletions
diff --git a/xmake/modules/private/check/checkers/clang/tidy.lua b/xmake/modules/private/check/checkers/clang/tidy.lua
index a77b3e946..9e0da0e2b 100644
--- a/xmake/modules/private/check/checkers/clang/tidy.lua
+++ b/xmake/modules/private/check/checkers/clang/tidy.lua
@@ -237,22 +237,11 @@ function _check(clang_tidy, opt)
_check_sourcefiles(clang_tidy, sourcefiles, opt)
end
-function main(argv)
-
- -- parse arguments
- local args = option.parse(argv or {}, options, "Use clang-tidy to check project code."
- , ""
- , "Usage: xmake check clang.tidy [options]")
-
- -- save option context
- option.save()
-
- -- set verbose and diagnosis if specified
- if args.verbose then
- option.set("verbose", true)
- end
- if args.diagnosis then
- option.set("diagnosis", true)
+-- get clang-tidy
+function _get_clang_tidy()
+ local clang_tidy = find_tool("clang-tidy")
+ if clang_tidy then
+ return clang_tidy
end
-- enter the environments of llvm
@@ -260,7 +249,7 @@ function main(argv)
-- find clang-tidy
local packages = {}
- local clang_tidy = find_tool("clang-tidy", {version = true})
+ local clang_tidy = find_tool("clang-tidy")
if not clang_tidy then
table.join2(packages, install_packages("llvm"))
end
@@ -272,8 +261,33 @@ function main(argv)
-- we need to force detect and flush detect cache after loading all environments
if not clang_tidy then
- clang_tidy = find_tool("clang-tidy", {force = true, version = true})
+ clang_tidy = find_tool("clang-tidy", {force = true})
+ end
+
+ os.setenvs(oldenvs)
+ return clang_tidy
+end
+
+function main(argv)
+
+ -- parse arguments
+ local args = option.parse(argv or {}, options, "Use clang-tidy to check project code."
+ , ""
+ , "Usage: xmake check clang.tidy [options]")
+
+ -- save option context
+ option.save()
+
+ -- set verbose and diagnosis if specified
+ if args.verbose then
+ option.set("verbose", true)
+ end
+ if args.diagnosis then
+ option.set("diagnosis", true)
end
+
+ -- find clang-tidy
+ local clang_tidy = _get_clang_tidy()
assert(clang_tidy, "clang-tidy not found!")
-- list checks
@@ -284,7 +298,6 @@ function main(argv)
else
_check(clang_tidy, args)
end
- os.setenvs(oldenvs)
-- restore option context
option.restore()