diff --git a/ament_clang_tidy/ament_clang_tidy/main.py b/ament_clang_tidy/ament_clang_tidy/main.py index 96bf0ca6e..cc30595b9 100755 --- a/ament_clang_tidy/ament_clang_tidy/main.py +++ b/ament_clang_tidy/ament_clang_tidy/main.py @@ -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): @@ -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) @@ -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: diff --git a/ament_clang_tidy/doc/index.rst b/ament_clang_tidy/doc/index.rst index 81fc2fc4d..9ed947434 100644 --- a/ament_clang_tidy/doc/index.rst +++ b/ament_clang_tidy/doc/index.rst @@ -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 ```` is a directory, it will be recursively searched for @@ -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? ----------------------------------------------------------------------------