summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode_defaults/linux-virtual-workstation.code-workspace2
-rwxr-xr-xbuildscripts/clang_tidy.py10
-rwxr-xr-xbuildscripts/clang_tidy_vscode.py26
3 files changed, 32 insertions, 6 deletions
diff --git a/.vscode_defaults/linux-virtual-workstation.code-workspace b/.vscode_defaults/linux-virtual-workstation.code-workspace
index ad921e35247..57a124e5694 100644
--- a/.vscode_defaults/linux-virtual-workstation.code-workspace
+++ b/.vscode_defaults/linux-virtual-workstation.code-workspace
@@ -12,7 +12,7 @@
],
"clangd.checkUpdates": true,
"clang-format.executable": "/opt/mongodbtoolchain/v3/bin/clang-format",
- "clang-tidy.executable": "/opt/mongodbtoolchain/v4/bin/clang-tidy",
+ "clang-tidy.executable": "buildscripts/clang_tidy_vscode.py",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
diff --git a/buildscripts/clang_tidy.py b/buildscripts/clang_tidy.py
index 9bcd0ae993c..b62c1be7fe0 100755
--- a/buildscripts/clang_tidy.py
+++ b/buildscripts/clang_tidy.py
@@ -15,11 +15,12 @@ from typing import Any, Dict, List, Optional, Tuple
import multiprocessing
from pathlib import Path
from concurrent import futures
-from simple_report import Result, Report, put_report, try_combine_reports, make_report
+from simple_report import put_report, try_combine_reports, make_report
import yaml
+from clang_tidy_vscode import CHECKS_SO
-def _clang_tidy_executor(clang_tidy_filename: str, clang_tidy_binary: str,
+def _clang_tidy_executor(clang_tidy_filename: Path, clang_tidy_binary: str,
clang_tidy_cfg: Dict[str, Any], output_dir: str, show_stdout: bool,
mongo_check_module: str = '') -> Tuple[str, Optional[str]]:
@@ -139,8 +140,7 @@ def main():
help="clang tidy log from evergreen")
parser.add_argument("--disable-reporting", action='store_true', default=False,
help="Disable generating the report file for evergreen perf.send")
- parser.add_argument("-m", "--check-module", type=str,
- default="build/install/lib/libmongo_tidy_checks.so",
+ parser.add_argument("-m", "--check-module", type=str, default=CHECKS_SO,
help="Path to load the custom mongo checks module.")
# TODO: Is there someway to get this without hardcoding this much
parser.add_argument("-y", "--clang-tidy-toolchain", type=str, default="v4")
@@ -178,7 +178,7 @@ def main():
print(f"Could not find config file: {args.clang_tidy_cfg}")
sys.exit(1)
- files_to_tidy = list()
+ files_to_tidy: List[Path] = list()
files_to_parse = list()
for file_doc in compile_commands:
# A few special cases of files to ignore
diff --git a/buildscripts/clang_tidy_vscode.py b/buildscripts/clang_tidy_vscode.py
new file mode 100755
index 00000000000..5182584bc0a
--- /dev/null
+++ b/buildscripts/clang_tidy_vscode.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+"""Wraps clang tidy to include our custom checks."""
+
+# TODO: if https://github.com/notskm/vscode-clang-tidy/pull/77#issuecomment-1422910143 is resolved then this script can be removed
+
+import subprocess
+import sys
+import os
+
+CHECKS_SO = "build/install/lib/libmongo_tidy_checks.so"
+
+
+def main():
+ clang_tidy_args = ["/opt/mongodbtoolchain/v4/bin/clang-tidy"]
+ if os.path.isfile(CHECKS_SO):
+ clang_tidy_args += [f"-load={CHECKS_SO}"]
+ clang_tidy_args += sys.argv[1:]
+ proc = subprocess.run(clang_tidy_args, capture_output=True)
+ # Write to output buffer here because that is how to copy directly from stdin to stdout without making assumptions about encoding
+ sys.stdout.buffer.write(proc.stdout)
+ sys.stderr.buffer.write(proc.stderr)
+ return proc.returncode
+
+
+if __name__ == "__main__":
+ sys.exit(main())