Skip to content

Commit 7e80d17

Browse files
committed
Fix clang tidy error with long path names
1 parent bb18c61 commit 7e80d17

File tree

7 files changed

+38
-19
lines changed

7 files changed

+38
-19
lines changed

share/rocmcmakebuildtools/cmake/ROCMClangTidy.cmake

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -192,24 +192,26 @@ function(rocm_clang_tidy_check TARGET)
192192
add_custom_target(tidy-target-${TARGET})
193193
foreach(SOURCE ${SOURCES})
194194
if(NOT "${SOURCE}" MATCHES "(h|hpp|hxx)$")
195-
string(MAKE_C_IDENTIFIER "${SOURCE}" tidy_file)
195+
get_filename_component(SRC_ABS ${SOURCE} ABSOLUTE)
196+
string(FIND ${SRC_ABS} ${CMAKE_CURRENT_BINARY_DIR} BINARY_IDX)
197+
if(BINARY_IDX EQUAL -1)
198+
set(tidy_file_prefix "s")
199+
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
200+
else()
201+
set(tidy_file_prefix "b")
202+
set(ROOT_DIR ${CMAKE_CURRENT_BINARY_DIR})
203+
endif()
204+
get_filename_component(SRC_PATH ${SRC_ABS} DIRECTORY)
205+
file(RELATIVE_PATH REL_PATH ${ROOT_DIR} ${SRC_PATH})
206+
get_filename_component(BASE_SOURCE_NAME ${SOURCE} NAME_WE)
207+
if(REL_PATH)
208+
set(BASE_SOURCE ${REL_PATH}/${BASE_SOURCE_NAME})
209+
else()
210+
set(BASE_SOURCE ${BASE_SOURCE_NAME})
211+
endif()
212+
string(MAKE_C_IDENTIFIER "${tidy_file_prefix}/${BASE_SOURCE}" tidy_file)
196213
set(tidy_target tidy-target-${TARGET}-${tidy_file})
197214
if(CLANG_TIDY_CACHE_SIZE GREATER 0)
198-
get_filename_component(SRC_ABS ${SOURCE} ABSOLUTE)
199-
string(FIND ${SRC_ABS} ${CMAKE_CURRENT_BINARY_DIR} BINARY_IDX)
200-
if(BINARY_IDX EQUAL -1)
201-
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
202-
else()
203-
set(ROOT_DIR ${CMAKE_CURRENT_BINARY_DIR})
204-
endif()
205-
get_filename_component(SRC_PATH ${SRC_ABS} DIRECTORY)
206-
file(RELATIVE_PATH REL_PATH ${ROOT_DIR} ${SRC_PATH})
207-
get_filename_component(BASE_SOURCE_NAME ${SOURCE} NAME_WE)
208-
if(REL_PATH)
209-
set(BASE_SOURCE ${REL_PATH}/${BASE_SOURCE_NAME})
210-
else()
211-
set(BASE_SOURCE ${BASE_SOURCE_NAME})
212-
endif()
213215
file(
214216
WRITE ${CMAKE_CURRENT_BINARY_DIR}/${tidy_target}.cmake
215217
"

test/analyze/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ rocm_enable_cppcheck(
4040
threadsafety
4141
)
4242

43+
# Workaround clangTooling issue: https://github.com/llvm/llvm-project/issues/100909
44+
add_compile_options(-Wno-unused-command-line-argument)
45+
4346
rocm_setup_version(VERSION 1.0.0)
4447

45-
configure_file(simple2.cpp.in simple2.cpp)
48+
configure_file(simple2.cpp.in simple.cpp)
49+
configure_file(simple_with_a_ridiculously_long_filename_in_order_to_test_long_filenames_in_clang_tidy_cmake.cpp.in simple_with_a_ridiculously_long_filename_in_order_to_test_long_filenames_in_clang_tidy_cmake.cpp)
4650

47-
add_library(simple simple.cpp ${CMAKE_CURRENT_BINARY_DIR}/simple2.cpp)
51+
add_library(simple simple.cpp ${CMAKE_CURRENT_BINARY_DIR}/simple_with_a_ridiculously_long_filename_in_order_to_test_long_filenames_in_clang_tidy_cmake.cpp ${CMAKE_CURRENT_BINARY_DIR}/simple.cpp)
4852
rocm_install_targets(TARGETS simple INCLUDE include)
4953

5054

test/analyze/include/simple.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#define GUARD_SIMPLE_H
88

99
void simple();
10+
void simple2();
11+
void simple_long();
1012

1113

1214
#endif

test/analyze/simple.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (C) 2017 Advanced Micro Devices, Inc.
33
******************************************************************************/
44

5+
#include <simple.h>
56

67
void simple()
78
{}

test/analyze/simple2.cpp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (C) 2020 Advanced Micro Devices, Inc.
33
******************************************************************************/
44

5+
#include <simple.h>
56

67
void simple2()
78
{}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2017 Advanced Micro Devices, Inc.
3+
******************************************************************************/
4+
5+
#include <simple.h>
6+
7+
void simple_long()
8+
{}

test/test.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ function(configure_dir DIR)
107107
cmake_parse_arguments(PARSE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
108108

109109
string(RANDOM BUILD_RAND)
110-
set(BUILD_DIR ${BUILDS_DIR}/${BUILD_RAND})
110+
set(BUILD_DIR ${BUILDS_DIR}/${BUILD_RAND}/longer_pathname_so_that_rpms_can_support_packaging_the_debug_info_for_all_os_profiles/src/out/some-os-version/version/build/rocm-cmake/build)
111+
# set(BUILD_DIR ${BUILDS_DIR}/${BUILD_RAND})
111112
if(NOT EXISTS ${BUILD_DIR})
112113
file(MAKE_DIRECTORY ${BUILD_DIR})
113114
endif()

0 commit comments

Comments
 (0)