diff options
| author | ruki <[email protected]> | 2024-12-25 17:01:51 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-12-25 17:01:51 +0800 |
| commit | b029e65edeb69f3ce0326a0a33c917a5080e6d7b (patch) | |
| tree | c1fbbc75a1465035a630658f6e6cd211f8d0d413 | |
| parent | c2d7c1d703c6716ae46fdfad46dc09ace18be559 (diff) | |
| parent | a548e1fe2e06378315fec592fb3f59b718e7d3ef (diff) | |
Merge pull request #5592 from xmake-io/tidy
improve clang-tidy to support multiple sourcefiles
| -rw-r--r-- | xmake/modules/private/check/checkers/clang/tidy.lua | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/xmake/modules/private/check/checkers/clang/tidy.lua b/xmake/modules/private/check/checkers/clang/tidy.lua index d047bc541..1c17110a5 100644 --- a/xmake/modules/private/check/checkers/clang/tidy.lua +++ b/xmake/modules/private/check/checkers/clang/tidy.lua @@ -21,6 +21,7 @@ -- imports import("core.base.option") import("core.base.task") +import("core.base.semver") import("core.project.config") import("core.project.project") import("lib.detect.find_tool") @@ -81,8 +82,8 @@ function _add_target_files(sourcefiles, target) end end --- check sourcefile -function _check_sourcefile(clang_tidy, sourcefile, opt) +-- check sourcefiles +function _check_sourcefiles(clang_tidy, sourcefiles, opt) opt = opt or {} local projectdir = project.directory() local argv = {} @@ -108,11 +109,35 @@ function _check_sourcefile(clang_tidy, sourcefile, opt) if opt.quiet then table.insert(argv, "--quiet") end - if not path.is_absolute(sourcefile) then - sourcefile = path.absolute(sourcefile, projectdir) + -- https://github.com/llvm/llvm-project/pull/120547 + if clang_tidy.version and semver.compare(clang_tidy.version, "19.1.6") > 0 and #sourcefiles > 32 then + for _, sourcefile in ipairs(sourcefiles) do + if not path.is_absolute(sourcefile) then + sourcefile = path.absolute(sourcefile, projectdir) + end + table.insert(argv, sourcefile) + end + local argsfile = os.tmpfile() .. ".args.txt" + io.writefile(argsfile, os.args(argv)) + argv = {"@" .. argsfile} + os.execv(clang_tidy.program, argv, {curdir = projectdir}) + os.rm(argsfile) + elseif #sourcefiles <= 32 then + for _, sourcefile in ipairs(sourcefiles) do + if not path.is_absolute(sourcefile) then + sourcefile = path.absolute(sourcefile, projectdir) + end + table.insert(argv, sourcefile) + end + os.execv(clang_tidy.program, argv, {curdir = projectdir}) + else + for _, sourcefile in ipairs(sourcefiles) do + if not path.is_absolute(sourcefile) then + sourcefile = path.absolute(sourcefile, projectdir) + end + os.execv(clang_tidy.program, table.join(argv, sourcefile), {curdir = projectdir}) + end end - table.insert(argv, sourcefile) - os.execv(clang_tidy, argv, {curdir = projectdir}) end -- do check @@ -164,15 +189,7 @@ function _check(clang_tidy, opt) end -- check files - local jobs = tonumber(opt.jobs or "1") - runjobs("check_files", function (index) - local sourcefile = sourcefiles[index] - if sourcefile then - _check_sourcefile(clang_tidy, sourcefile, opt) - end - end, {total = #sourcefiles, - comax = jobs, - isolate = true}) + _check_sourcefiles(clang_tidy, sourcefiles, opt) end function main(argv) @@ -187,7 +204,7 @@ function main(argv) -- find clang-tidy local packages = {} - local clang_tidy = find_tool("clang-tidy") + local clang_tidy = find_tool("clang-tidy", {version = true}) if not clang_tidy then table.join2(packages, install_packages("llvm")) end @@ -199,9 +216,10 @@ 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}) + clang_tidy = find_tool("clang-tidy", {force = true, version = true}) end assert(clang_tidy, "clang-tidy not found!") + print(clang_tidy) -- list checks if args.list then @@ -209,7 +227,7 @@ function main(argv) elseif args.create then _create_config(clang_tidy.program, args) else - _check(clang_tidy.program, args) + _check(clang_tidy, args) end os.setenvs(oldenvs) end |
