SERVER-114073 Dont lint .vim directories and fix stdout on linter (#44147)

GitOrigin-RevId: 3afefa10ce7fc832d10b9ae7dad9e40266c79c44
This commit is contained in:
Andrew Bradshaw 2025-11-19 14:24:55 -08:00 committed by MongoDB Bot
parent 3b08fd485a
commit 23f4a8dbf1
3 changed files with 61 additions and 19 deletions

View File

@ -105,6 +105,13 @@ class LintRunner:
"src/mongo/util/processinfo_solaris.cpp",
}
exempted_subpaths = [
# Skip files in bazel_rules_mongo, since it has its own Bazel repo
"bazel_rules_mongo",
# vim creates temporary c++ files that aren't part of the tree
"/.vim/",
]
typed_files_in_targets = [line for line in files_with_targets if line.endswith(f".{ext}")]
print(f"Checking that all {type_name} files have BUILD.bazel targets...")
@ -129,11 +136,8 @@ class LintRunner:
new_list = []
for file in all_typed_files:
if file not in typed_files_in_targets_set and file not in exempt_list:
if "bazel_rules_mongo" in file:
# Skip files in bazel_rules_mongo, since it has its own Bazel repo
continue
new_list.append(file)
if not any(subpath in file for subpath in exempted_subpaths):
new_list.append(file)
if len(new_list) != 0:
print(f"Found {type_name} files without BUILD.bazel definitions:")
@ -408,7 +412,7 @@ def run_rules_lint(bazel_bin: str, args: List[str]):
)
# Actually run the lint itself
subprocess.run([bazel_bin, "build"] + args, check=True)
subprocess.run([bazel_bin, "build"] + args, check=True, stdout=sys.stdout, stderr=sys.stderr)
# Parse out the reports from the build events
filter_expr = '.namedSetOfFiles | values | .files[] | select(.name | endswith($ext)) | ((.pathPrefix | join("/")) + "/" + .name)'

View File

@ -13,6 +13,7 @@ sys.stdout = sys.stderr
from bazel.wrapper_hook.install_modules import install_modules
from bazel.wrapper_hook.wrapper_debug import wrapper_debug
from bazel.wrapper_hook.wrapper_util import get_terminal_stream
wrapper_debug(f"wrapper hook script is using {sys.executable}")
@ -41,10 +42,7 @@ def _fmt_duration(seconds: float) -> str:
def _info(msg: str, printer=print, stream=None):
from bazel.wrapper_hook.wrapper_util import get_terminal_stream
term_err = get_terminal_stream("MONGO_WRAPPER_STDERR_FD")
# Save current stdout/stderr
old_stdout = sys.stdout
old_stderr = sys.stderr
@ -63,6 +61,24 @@ def _info(msg: str, printer=print, stream=None):
sys.stderr = old_stderr
def run_with_terminal_output(func, *args, **kwargs):
term_err = get_terminal_stream("MONGO_WRAPPER_STDERR_FD")
sys.stdout = None
# Save current stdout/stderr
old_stdout = sys.stdout
old_stderr = sys.stderr
try:
sys.stdout = term_err
sys.stderr = term_err
return func(*args, **kwargs)
finally:
# Restore original stdout/stderr to whatever wrapper has
sys.stdout = old_stdout
sys.stderr = old_stderr
def main():
install_modules(sys.argv[1], sys.argv[1:])
@ -127,7 +143,8 @@ def main():
check_resource()
try:
args = test_runner_interface(
args = run_with_terminal_output(
test_runner_interface,
sys.argv[1:],
autocomplete_query=os.environ.get("MONGO_AUTOCOMPLETE_QUERY") == "1",
enterprise=enterprise,

View File

@ -9,6 +9,8 @@ from bazel.wrapper_hook.wrapper_debug import wrapper_debug
_UNKNOWN = "Unknown"
_REPO_ROOT = str(pathlib.Path(__file__).parent.parent.parent)
_EXISTING_TERMINAL_STDOUT = None
_EXISTING_TERMINAL_STDERR = None
def get_terminal_stream(fd_env_var: str):
@ -17,30 +19,49 @@ def get_terminal_stream(fd_env_var: str):
if not fd_str:
return None
global _EXISTING_TERMINAL_STDOUT, _EXISTING_TERMINAL_STDERR
if _EXISTING_TERMINAL_STDOUT:
return _EXISTING_TERMINAL_STDOUT
if _EXISTING_TERMINAL_STDERR:
return _EXISTING_TERMINAL_STDERR
# Handle Windows CON device
if fd_str == "CON":
# On Windows, open CON device for console output
# Use the appropriate stream based on the variable name
if "STDOUT" in fd_env_var:
try:
return open("CON", "w", buffering=1)
except (OSError, IOError):
_EXISTING_TERMINAL_STDOUT = open("CON", "w", buffering=1)
return _EXISTING_TERMINAL_STDOUT
except (OSError, IOError) as e:
print(e)
return None
elif "STDERR" in fd_env_var:
try:
return open("CON", "w", buffering=1)
except (OSError, IOError):
_EXISTING_TERMINAL_STDERR = open("CON", "w", buffering=1)
return _EXISTING_TERMINAL_STDERR
except (OSError, IOError) as e:
print(e)
return None
return None
# Handle Unix file descriptors
if fd_str.isdigit():
fd = int(fd_str)
try:
return os.fdopen(fd, "w", buffering=1)
except (OSError, ValueError):
return None
if "STDOUT" in fd_env_var:
try:
_EXISTING_TERMINAL_STDOUT = os.fdopen(fd, "w", buffering=1)
return _EXISTING_TERMINAL_STDOUT
except (OSError, ValueError) as e:
print(e)
return None
elif "STDERR" in fd_env_var:
try:
_EXISTING_TERMINAL_STDERR = os.fdopen(fd, "w", buffering=1)
return _EXISTING_TERMINAL_STDERR
except (OSError, ValueError) as e:
print(e)
return None
return None