Skip to content

Commit

Permalink
Use pathlib for clang_tidy_binary and args list for version
Browse files Browse the repository at this point in the history
This fixes getting the version on windows because the forward slashes are not properly interpreted in `subprocess.run` in shell mode.
  • Loading branch information
bwrsandman committed Jan 11, 2024
1 parent e78c0b1 commit e2610c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
16 changes: 10 additions & 6 deletions post/clang_tidy_review/clang_tidy_review/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ class PRReview(TypedDict):


def build_clang_tidy_warnings(
line_filter, build_dir, clang_tidy_checks, clang_tidy_binary, config_file, files
line_filter,
build_dir,
clang_tidy_checks,
clang_tidy_binary: pathlib.Path,
config_file,
files,
) -> None:
"""Run clang-tidy on the given files and save output into FIXES_FILE"""

Expand Down Expand Up @@ -88,12 +93,11 @@ def build_clang_tidy_warnings(
print(f"Took: {end - start}")


def clang_tidy_version(clang_tidy_binary: str):
def clang_tidy_version(clang_tidy_binary: pathlib.Path):
try:
version_out = subprocess.run(
f"{clang_tidy_binary} --version",
[clang_tidy_binary, "--version"],
capture_output=True,
shell=True,
check=True,
text=True,
).stdout
Expand All @@ -111,7 +115,7 @@ def clang_tidy_version(clang_tidy_binary: str):


def config_file_or_checks(
clang_tidy_binary: str, clang_tidy_checks: str, config_file: str
clang_tidy_binary: pathlib.Path, clang_tidy_checks: str, config_file: str
):
version = clang_tidy_version(clang_tidy_binary)

Expand Down Expand Up @@ -739,7 +743,7 @@ def create_review(
pull_request: PullRequest,
build_dir: str,
clang_tidy_checks: str,
clang_tidy_binary: str,
clang_tidy_binary: pathlib.Path,
config_file: str,
include: List[str],
exclude: List[str],
Expand Down
3 changes: 2 additions & 1 deletion post/clang_tidy_review/clang_tidy_review/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import argparse
import os
import pathlib
import re
import subprocess

Expand Down Expand Up @@ -34,7 +35,7 @@ def main():
parser.add_argument("--repo", help="Repo name in form 'owner/repo'")
parser.add_argument("--pr", help="PR number", type=int)
parser.add_argument(
"--clang_tidy_binary", help="clang-tidy binary", default="clang-tidy-14"
"--clang_tidy_binary", help="clang-tidy binary", default="clang-tidy-14", type=pathlib.Path
)
parser.add_argument(
"--build_dir", help="Directory with compile_commands.json", default="."
Expand Down

0 comments on commit e2610c9

Please sign in to comment.