diff options
| author | Stehsaer <[email protected]> | 2025-09-28 10:51:31 +0800 |
|---|---|---|
| committer | Stehsaer <[email protected]> | 2025-09-28 10:51:31 +0800 |
| commit | 782df6e3a9a9cabb7fba741ea52b86d32549a73c (patch) | |
| tree | 16b545d300aa702821b552296b3ffda8109168a9 /xmake/plugins/format/main.lua | |
| parent | b0dedad75dd17c98361c2723be98bbd8d8b1d975 (diff) | |
fix: removed hard-coded filters, use rule-based filter
Diffstat (limited to 'xmake/plugins/format/main.lua')
| -rw-r--r-- | xmake/plugins/format/main.lua | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/xmake/plugins/format/main.lua b/xmake/plugins/format/main.lua index 733b9b59f..efc825c2a 100644 --- a/xmake/plugins/format/main.lua +++ b/xmake/plugins/format/main.lua @@ -106,6 +106,13 @@ function _get_targets(targetname, group_pattern) return targets end +-- tell if the source batch is a c/c++/objc/objc++/cuda source batch +function _source_batch_should_format(sourcebatch) + local rulename = sourcebatch.rulename + local matched_rules = {"c.build", "c++.build", "cuda.build", "objc.build", "objc++.build"} + return table.contains(matched_rules, rulename) +end + -- main function main() @@ -190,13 +197,12 @@ function main() end end else - -- Default source file filter when not specifying "--files" option - -- **.c, **.cc, **.cxx, **.cpp - local source_filepatterns = _get_file_patterns("**.c" .. path.envsep() .. "**.cc" .. path.envsep() .. "**.cxx" .. path.envsep() .. "**.cpp") for _, target in ipairs(targets) do - for _, source in ipairs(target:sourcefiles()) do - if _match_sourcefiles(source, source_filepatterns) then - table.insert(argv, path.join(projectdir, source)) + for _, sourcebatch in pairs(target:sourcebatches()) do + if _source_batch_should_format(sourcebatch) then + for _, source in ipairs(sourcebatch.sourcefiles) do + table.insert(argv, path.join(projectdir, source)) + end end end for _, header in ipairs(target:headerfiles()) do |
