mongo/buildscripts/tests/test_compiledb_output_format.py
Daniel Moody 7fbd72d6f0 SERVER-117726 move compiledb generation into the bazel graph (#49797)
GitOrigin-RevId: ed2b1096fd0a6b1eea8405df897756feda930f5d
2026-03-17 19:33:55 +00:00

43 lines
1.5 KiB
Python

import sys
import unittest
sys.path.append(".")
from bazel.wrapper_hook.compiledb import _build_final_compile_command_entry
class CompiledbOutputFormatTest(unittest.TestCase):
def test_final_entry_omits_non_standard_target_key(self):
def rewrite_exec_path(path, out_root_str, external_root_str):
if path.startswith("bazel-out/"):
return out_root_str + "/" + path[len("bazel-out/") :]
return path
entry = {
"file": "bazel-out/k8/bin/src/mongo/base/error_codes.cpp",
"arguments": ["clang++", "-c", "src/mongo/base/error_codes.cpp"],
"output": "bazel-out/k8/bin/src/mongo/base/error_codes.cpp.o",
"target": "//src/mongo/base:error_codes",
}
formatted_entry = _build_final_compile_command_entry(
entry=entry,
arguments=entry["arguments"],
repo_root_resolved="/repo",
rewrite_exec_path=rewrite_exec_path,
out_root_str="/real/bazel-out",
external_root_str="/real/external",
)
assert formatted_entry == {
"file": "/real/bazel-out/k8/bin/src/mongo/base/error_codes.cpp",
"arguments": ["clang++", "-c", "src/mongo/base/error_codes.cpp"],
"directory": "/repo",
"output": "/real/bazel-out/k8/bin/src/mongo/base/error_codes.cpp.o",
}
assert "target" not in formatted_entry
if __name__ == "__main__":
unittest.main()