SERVER-106576 vscode clang tidy falls back to direct clang tidy command for headers (#37632)

GitOrigin-RevId: 7805f38151c1bfb70ccdc1881b33cc5ce9c2a789
This commit is contained in:
Daniel Moody 2025-06-23 15:41:04 -05:00 committed by MongoDB Bot
parent ee4b5de6cf
commit b21709bde4
1 changed files with 27 additions and 14 deletions

View File

@ -96,10 +96,11 @@ def main():
with open(".mongo_checks_module_path") as f: with open(".mongo_checks_module_path") as f:
checks_so = f.read().strip() checks_so = f.read().strip()
if os.path.isfile(checks_so): if checks_so and os.path.isfile(checks_so):
clang_tidy_cmd += [f"-load={checks_so}"] clang_tidy_cmd += [f"-load={checks_so}"]
else: else:
print("ERROR: failed to find mongo tidy checks, run `bazel build compiledb'") print("ERROR: failed to find mongo tidy checks, run `bazel build compiledb'")
sys.exit(1)
files_to_check = [] files_to_check = []
other_args = [] other_args = []
@ -142,10 +143,17 @@ def main():
except ValueError: except ValueError:
pass pass
break break
# found a cpp file entry with exact compile args, cache it
if compile_args:
cfg_dir = pathlib.Path().home() / ".cltcache" cfg_dir = pathlib.Path().home() / ".cltcache"
cfg_dir.mkdir(parents=True, exist_ok=True) cfg_dir.mkdir(parents=True, exist_ok=True)
with open(cfg_dir / "cltcache.cfg", "w") as f:
f.write(CLTCONFIG % executable) conf_file = cfg_dir / "cltcache.cfg"
new_content = CLTCONFIG % executable
if not conf_file.exists() or conf_file.read_text() != new_content:
conf_file.write_text(new_content)
full_cmd = ( full_cmd = (
[sys.executable, cltcache_path] [sys.executable, cltcache_path]
@ -157,6 +165,11 @@ def main():
) )
proc = subprocess.run(full_cmd, capture_output=True) proc = subprocess.run(full_cmd, capture_output=True)
# probably a header, skip caching and let clang-tidy do its thing:
else:
proc = subprocess.run(clang_tidy_cmd + files_to_check + other_args, capture_output=True)
sys.stdout.buffer.write(proc.stdout) sys.stdout.buffer.write(proc.stdout)
sys.stderr.buffer.write(proc.stderr) sys.stderr.buffer.write(proc.stderr)
return proc.returncode return proc.returncode