Skip to content

Commit 545f4d9

Browse files
authored
[libc] Remove recursion in get_object_files_for_test to improve build time. (#72351)
1 parent 27e6e4a commit 545f4d9

File tree

1 file changed

+47
-36
lines changed

1 file changed

+47
-36
lines changed

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,59 @@
1515
function(get_object_files_for_test result skipped_entrypoints_list)
1616
set(object_files "")
1717
set(skipped_list "")
18-
foreach(dep IN LISTS ARGN)
19-
if (NOT TARGET ${dep})
20-
# Skip any tests whose dependencies have not been defined.
21-
list(APPEND skipped_list ${dep})
22-
continue()
23-
endif()
24-
get_target_property(dep_type ${dep} "TARGET_TYPE")
25-
if(NOT dep_type)
26-
# Target for which TARGET_TYPE property is not set do not
27-
# provide any object files.
28-
continue()
29-
endif()
18+
set(checked_list "")
19+
set(unchecked_list "${ARGN}")
20+
list(REMOVE_DUPLICATES unchecked_list)
21+
list(LENGTH unchecked_list length)
3022

31-
if(${dep_type} STREQUAL ${OBJECT_LIBRARY_TARGET_TYPE})
32-
get_target_property(dep_object_files ${dep} "OBJECT_FILES")
33-
if(dep_object_files)
34-
list(APPEND object_files ${dep_object_files})
35-
endif()
36-
elseif(${dep_type} STREQUAL ${ENTRYPOINT_OBJ_TARGET_TYPE})
37-
get_target_property(is_skipped ${dep} "SKIPPED")
38-
if(is_skipped)
23+
while(length)
24+
set(indirect_list "")
25+
26+
foreach(dep IN LISTS unchecked_list)
27+
if (NOT TARGET ${dep})
28+
# Skip tests with undefined dependencies.
3929
list(APPEND skipped_list ${dep})
4030
continue()
4131
endif()
42-
get_target_property(object_file_raw ${dep} "OBJECT_FILE_RAW")
43-
if(object_file_raw)
44-
list(APPEND object_files ${object_file_raw})
32+
get_target_property(dep_type ${dep} "TARGET_TYPE")
33+
if(NOT dep_type)
34+
# Skip tests with no object dependencies.
35+
continue()
4536
endif()
46-
elseif(${dep_type} STREQUAL ${ENTRYPOINT_OBJ_VENDOR_TARGET_TYPE})
47-
# We skip tests for all externally implemented entrypoints.
48-
list(APPEND skipped_list ${dep})
49-
continue()
50-
endif()
5137

52-
get_target_property(indirect_deps ${dep} "DEPS")
53-
get_object_files_for_test(
54-
indirect_objfiles indirect_skipped_list ${indirect_deps})
55-
list(APPEND object_files ${indirect_objfiles})
56-
if(indirect_skipped_list)
57-
list(APPEND skipped_list ${indirect_skipped_list})
58-
endif()
59-
endforeach(dep)
38+
if(${dep_type} STREQUAL ${OBJECT_LIBRARY_TARGET_TYPE})
39+
get_target_property(dep_object_files ${dep} "OBJECT_FILES")
40+
if(dep_object_files)
41+
list(APPEND object_files ${dep_object_files})
42+
endif()
43+
elseif(${dep_type} STREQUAL ${ENTRYPOINT_OBJ_TARGET_TYPE})
44+
get_target_property(is_skipped ${dep} "SKIPPED")
45+
if(is_skipped)
46+
list(APPEND skipped_list ${dep})
47+
continue()
48+
endif()
49+
get_target_property(object_file_raw ${dep} "OBJECT_FILE_RAW")
50+
if(object_file_raw)
51+
list(APPEND object_files ${object_file_raw})
52+
endif()
53+
elseif(${dep_type} STREQUAL ${ENTRYPOINT_OBJ_VENDOR_TARGET_TYPE})
54+
# Skip tests for externally implemented entrypoints.
55+
list(APPEND skipped_list ${dep})
56+
continue()
57+
endif()
58+
59+
get_target_property(indirect_deps ${dep} "DEPS")
60+
list(APPEND indirect_list "${indirect_deps}")
61+
endforeach(dep)
62+
63+
# Only add new indirect dependencies to check.
64+
list(APPEND checked_list "${unchecked_list}")
65+
list(REMOVE_DUPLICATES indirect_list)
66+
list(REMOVE_ITEM indirect_list checked_list)
67+
set(unchecked_list "${indirect_list}")
68+
list(LENGTH unchecked_list length)
69+
endwhile()
70+
6071
list(REMOVE_DUPLICATES object_files)
6172
set(${result} ${object_files} PARENT_SCOPE)
6273
list(REMOVE_DUPLICATES skipped_list)

0 commit comments

Comments
 (0)