Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy: Add clang-tidy executable path argument #494

Open
wants to merge 5 commits into
base: humble
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions ament_clang_tidy/ament_clang_tidy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ def main(argv=sys.argv[1:]):
parser.add_argument(
'--xunit-file',
help='Generate a xunit compliant XML file')
parser.add_argumet(
'--clang-tidy-path-exe',
default=None,
dest='clang_tidy_path',
help='Path to Clang Tidy executable')
args = parser.parse_args(argv)

if args.config_file is not None and not os.path.exists(args.config_file):
Expand Down Expand Up @@ -115,7 +120,10 @@ def main(argv=sys.argv[1:]):
'clang-tidy-11',
'clang-tidy-6.0',
]
clang_tidy_bin = find_executable(bin_names)
if args.clang_tidy_path:
clang_tidy_bin = args.clang_tidy_path if check_executable(args.clang_tidy_path) else None
else:
clang_tidy_bin = find_executable(bin_names)
if not clang_tidy_bin:
print('Could not find %s executable' %
' / '.join(["'%s'" % n for n in bin_names]), file=sys.stderr)
Expand Down Expand Up @@ -268,11 +276,15 @@ def find_executable(file_names):
for file_name in file_names:
for path in paths:
file_path = os.path.join(path, file_name)
if os.path.isfile(file_path) and os.access(file_path, os.X_OK):
if check_executable(file_path):
return file_path
return None


def check_executable(exec_path):
return os.path.isfile(exec_path) and os.access(exec_path, os.X_OK)


def get_compilation_db_files(paths):
files = []
for path in paths:
Expand Down
4 changes: 4 additions & 0 deletions ament_clang_tidy/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ have already been installed. ``compile_commands.json`` files should have already
[--system-headers] [--jobs N]
[--packages-select [PKG_NAME [PKG_NAME ...]]]
[--xunit-file XUNIT_FILE]
[--clang-tidy-path-exe CLANG_TIDY_PATH_EXE]
[paths [paths ...]]

If ``<paths>`` is a directory, it will be recursively searched for
Expand Down Expand Up @@ -59,6 +60,9 @@ to just those generated by specific ROS packages.
The ``--xunit-file`` option will generate a xunit compliant XML file when
supplied with a file name.

The ``--clang-tidy-path-exe`` option allows you to set the path of the
clang-tidy executalbe.

How to run the check from within a CMake ament package as part of the tests?
----------------------------------------------------------------------------

Expand Down