summaryrefslogtreecommitdiff
path: root/xmake/plugins
diff options
context:
space:
mode:
authorruki <[email protected]>2023-02-02 00:58:03 +0800
committerruki <[email protected]>2023-02-02 00:58:03 +0800
commit1a14178101b25cddbdee751f382b7bd9a5b15088 (patch)
treef4641c1000e938901f2e9094a7d7411f8ff247ea /xmake/plugins
parentb128cb98313b95b65f1d5bd2028831861ca80e13 (diff)
fix xmake format
Diffstat (limited to 'xmake/plugins')
-rw-r--r--xmake/plugins/check/checkers/clang/tidy.lua49
-rw-r--r--xmake/plugins/format/main.lua7
-rw-r--r--xmake/plugins/format/xmake.lua11
3 files changed, 43 insertions, 24 deletions
diff --git a/xmake/plugins/check/checkers/clang/tidy.lua b/xmake/plugins/check/checkers/clang/tidy.lua
index cde175bb8..7ff6ed854 100644
--- a/xmake/plugins/check/checkers/clang/tidy.lua
+++ b/xmake/plugins/check/checkers/clang/tidy.lua
@@ -30,21 +30,26 @@ import("private.action.require.impl.install_packages")
-- the clang.tidy options
local options = {
- {"l", "list", "k", nil, "Show the clang-tidy checks list."},
+ {"l", "list", "k", nil, "Show the clang-tidy checks list."},
{'j', "jobs", "kv", tostring(os.default_njob()),
- "Set the number of parallel check jobs."},
- {nil, "checks", "kv", nil, "Set the given checks.",
- "e.g.",
- " - xmake check clang.tidy --checks=\"*\""},
- {nil, "target", "v", nil, "Check the sourcefiles of the given target.",
- ".e.g",
- " - xmake check clang.tidy",
- " - xmake check clang.tidy [target]"}
+ "Set the number of parallel check jobs."},
+ {nil, "configfile", "kv", nil, "Specify the path of .clang-tidy or custom config file"},
+ {nil, "checks", "kv", nil, "Set the given checks.",
+ "e.g.",
+ " - xmake check clang.tidy --checks=\"*\""},
+ {'f', "files", "v", nil, "Set files path with pattern",
+ "e.g.",
+ " - xmake check clang.tidy -f src/main.c",
+ " - xmake check clang.tidy -f 'src/*.c" .. path.envsep() .. "src/**.cpp'"},
+ {nil, "target", "v", nil, "Check the sourcefiles of the given target.",
+ ".e.g",
+ " - xmake check clang.tidy",
+ " - xmake check clang.tidy [target]"}
}
-- show checks list
function _show_list(clang_tidy)
- os.execv(clang_tidy, {"-list-checks"})
+ os.execv(clang_tidy, {"--list-checks"})
end
-- add sourcefiles in target
@@ -57,12 +62,15 @@ function _check_sourcefile(clang_tidy, sourcefile, opt)
opt = opt or {}
local argv = {}
if opt.checks then
- table.insert(argv, "-checks=" .. opt.checks)
+ table.insert(argv, "--checks=" .. opt.checks)
end
if opt.compdbfile then
table.insert(argv, "-p")
table.insert(argv, opt.compdbfile)
end
+ if opt.configfile then
+ table.insert(argv, "--config-file=" .. opt.configfile)
+ end
table.insert(argv, sourcefile)
os.execv(clang_tidy, argv)
end
@@ -83,12 +91,21 @@ function _check(clang_tidy, opt)
-- get sourcefiles
local sourcefiles = {}
- local targetname = opt.target
- if targetname then
- _add_target_files(sourcefiles, project.target(targetname))
+ if opt.files then
+ local files = path.splitenv(opt.files)
+ for _, file in ipairs(files) do
+ for _, filepath in ipairs(os.files(file)) do
+ table.insert(sourcefiles, filepath)
+ end
+ end
else
- for _, target in ipairs(project.ordertargets()) do
- _add_target_files(sourcefiles, target)
+ local targetname = opt.target
+ if targetname then
+ _add_target_files(sourcefiles, project.target(targetname))
+ else
+ for _, target in ipairs(project.ordertargets()) do
+ _add_target_files(sourcefiles, target)
+ end
end
end
diff --git a/xmake/plugins/format/main.lua b/xmake/plugins/format/main.lua
index 9a119aec3..328bcb394 100644
--- a/xmake/plugins/format/main.lua
+++ b/xmake/plugins/format/main.lua
@@ -73,10 +73,9 @@ function main()
-- set file to format
if option.get("files") then
- -- list of files/path to format
- local files = option.get("file"):split(" ")
+ local files = path.splitenv(option.get("files"))
for _, f in ipairs(files) do
- local p = path.join(project, f)
+ local p = path.join(projectdir, f)
for _, filepath in ipairs(os.files(p)) do
table.insert(argv, filepath)
end
@@ -97,7 +96,7 @@ function main()
-- format files
os.vrunv(clang_format.program, argv, {curdir = projectdir})
- cprint("${color.success}formatting complete")
+ cprint("${color.success}format ok!")
-- done
os.setenvs(oldenvs)
diff --git a/xmake/plugins/format/xmake.lua b/xmake/plugins/format/xmake.lua
index d3a00039f..ed2bf3d65 100644
--- a/xmake/plugins/format/xmake.lua
+++ b/xmake/plugins/format/xmake.lua
@@ -25,10 +25,13 @@ task("format")
usage = "xmake format [options] [arguments]",
description = "Format the current project.",
options = {
- {'s', "style", "kv", nil, "Set the path of .clang-format file, a coding style"..
- "(LLVM, Google, Chromium, Mozilla, WebKit) or key value string" },
- {nil, "create", "k", nil, "Create a .clang-format file from a coding style" },
- {'f', "files", "v", nil, "Set file path or glob pattern"}
+ {'s', "style", "kv", nil, "Set the path of .clang-format file, a coding style",
+ values = {"LLVM", "Google", "Chromium", "Mozilla", "WebKit"}},
+ {nil, "create", "k", nil, "Create a .clang-format file from a coding style"},
+ {'f', "files", "v", nil, "Set files path with pattern",
+ "e.g.",
+ " - xmake format -f src/main.c",
+ " - xmake format -f 'src/*.c" .. path.envsep() .. "src/**.cpp'"}
}
}