<commit_before>
message(STATUS "cland-tools")

# Generates a compile_commands.json file containing the exact compiler calls for all translation units
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(COMPILE_COMMANDS_LINK "${CMAKE_SOURCE_DIR}/compile_commands.json")
set(COMPILE_COMMANDS_SRC "${CMAKE_BINARY_DIR}/compile_commands.json")
add_custom_command(
    OUTPUT ${COMPILE_COMMANDS_LINK}
    COMMAND ${CMAKE_COMMAND} -E create_symlink ${COMPILE_COMMANDS_SRC} ${COMPILE_COMMANDS_LINK}
    COMMENT "Symlink clang compile commands file into source folder"
)
add_custom_target(
    NAME symlink_compile_command
    COMMENT "Symlink ${COMPILE_COMMANDS_LINK}"
    DEPENDS ${COMPILE_COMMANDS_LINK}
)

set(CLANG_TIDY_BINARY_NAME
    NAMES clang-tidy clang-tidy-6.0)
find_program(CLANG_TIDY_BIN ${CLANG_TIDY_BINARY_NAME})

set(RUN_CLANG_TIDY_BINARY_NAME
    NAMES run-clang-tidy.py run-clang-tidy-6.0.py)
find_program(RUN_CLANG_TIDY_BIN ${RUN_CLANG_TIDY_BINARY_NAME})

if( NOT CLANG_TIDY_BIN STREQUAL "CLANG_TIDY_BIN-NOTFOUND"
    AND NOT RUN_CLANG_TIDY_BIN STREQUAL "RUN_CLANG_TIDY_BIN-NOTFOUND")
    # Get all .cpp files in navitia/source/ and remove everything
    # From utils and /third_party
    file(GLOB_RECURSE FILES_TO_SCAN "${CMAKE_SOURCE_DIR}/*.cpp")
    list(FILTER FILES_TO_SCAN EXCLUDE REGEX "(third_party|utils)")
    list(APPEND RUN_CLANG_TIDY_BIN_ARGS -clang-tidy-binary ${CLANG_TIDY_BIN} "${FILES_TO_SCAN}")

    add_custom_target(
        tidy
        COMMAND ${RUN_CLANG_TIDY_BIN} ${RUN_CLANG_TIDY_BIN_ARGS}
        COMMENT "running clang tidy -- ${CMAKE_SOURCE_DIR}"
        DEPENDS protobuf_files ${COMPILE_COMMANDS_LINK}
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    )

    add_custom_target(
        tidy_fix
        COMMAND ${RUN_CLANG_TIDY_BIN} -fix ${RUN_CLANG_TIDY_BIN_ARGS}
        COMMENT "running clang tidy -fix -- ${CMAKE_SOURCE_DIR}"
        DEPENDS protobuf_files ${COMPILE_COMMANDS_LINK}
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    )
    message(STATUS "found")
endif()

unset(missing_bin)<commit_msg>Add run-clang-tidy as possible binary name.<commit_after>
message(STATUS "cland-tools")

# Generates a compile_commands.json file containing the exact compiler calls for all translation units
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(COMPILE_COMMANDS_LINK "${CMAKE_SOURCE_DIR}/compile_commands.json")
set(COMPILE_COMMANDS_SRC "${CMAKE_BINARY_DIR}/compile_commands.json")
add_custom_command(
    OUTPUT ${COMPILE_COMMANDS_LINK}
    COMMAND ${CMAKE_COMMAND} -E create_symlink ${COMPILE_COMMANDS_SRC} ${COMPILE_COMMANDS_LINK}
    COMMENT "Symlink clang compile commands file into source folder"
)
add_custom_target(
    NAME symlink_compile_command
    COMMENT "Symlink ${COMPILE_COMMANDS_LINK}"
    DEPENDS ${COMPILE_COMMANDS_LINK}
)

set(CLANG_TIDY_BINARY_NAME
    NAMES clang-tidy clang-tidy-6.0)
find_program(CLANG_TIDY_BIN ${CLANG_TIDY_BINARY_NAME})

set(RUN_CLANG_TIDY_BINARY_NAME
    NAMES run-clang-tidy run-clang-tidy.py run-clang-tidy-6.0.py)
find_program(RUN_CLANG_TIDY_BIN ${RUN_CLANG_TIDY_BINARY_NAME})

if( NOT CLANG_TIDY_BIN STREQUAL "CLANG_TIDY_BIN-NOTFOUND"
    AND NOT RUN_CLANG_TIDY_BIN STREQUAL "RUN_CLANG_TIDY_BIN-NOTFOUND")
    # Get all .cpp files in navitia/source/ and remove everything
    # From utils and /third_party
    file(GLOB_RECURSE FILES_TO_SCAN "${CMAKE_SOURCE_DIR}/*.cpp")
    list(FILTER FILES_TO_SCAN EXCLUDE REGEX "(third_party|utils)")
    list(APPEND RUN_CLANG_TIDY_BIN_ARGS -clang-tidy-binary ${CLANG_TIDY_BIN} "${FILES_TO_SCAN}")

    add_custom_target(
        tidy
        COMMAND ${RUN_CLANG_TIDY_BIN} ${RUN_CLANG_TIDY_BIN_ARGS}
        COMMENT "running clang tidy -- ${CMAKE_SOURCE_DIR}"
        DEPENDS protobuf_files ${COMPILE_COMMANDS_LINK}
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    )

    add_custom_target(
        tidy_fix
        COMMAND ${RUN_CLANG_TIDY_BIN} -fix ${RUN_CLANG_TIDY_BIN_ARGS}
        COMMENT "running clang tidy -fix -- ${CMAKE_SOURCE_DIR}"
        DEPENDS protobuf_files ${COMPILE_COMMANDS_LINK}
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    )
    message(STATUS "found")
endif()

unset(missing_bin)
{'fraction_non_alphanumeric': 0.08817099829973281, 'fraction_numerical': 0.0019431624969638087, 'mean_word_length': 4.9681159420289855, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4218042', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1587, 'n_words': 269}