cmake: Replace recursive globbing with explicit globbing in folders
What changed, and why it matters
This commit changes how Bitcoin Core's test files are copied into the build directory during compilation. It replaces a broad 'grab everything recursively' approach with explicit lists of file types per folder. There is no security vulnerability here; it is a build-system cleanup that makes the test setup more predictable and avoids accidentally linking unexpected files.
No security action required. Review as normal build-system maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors test/CMakeLists.txt to replace GLOB_RECURSE with per-directory GLOB calls that explicitly enumerate expected extensions (.py, .json, .csv, .html). It also removes the creation of the unused util/ directory link. The change is purely build hygiene: it reduces non-determinism in what gets symlinked/copied into the build tree and prevents stray files from being picked up by the test runner’s symlink farm.
Changed components
test/CMakeLists.txtInspect captured patch +62 / −18
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 515c24f9..ed7ab201 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -32,21 +32,65 @@ endfunction()
create_test_config()
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/functional)
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/functional/data)
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/functional/mocks)
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/functional/test_framework)
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/functional/test_framework/crypto)
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fuzz)
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/util)
-
-file(GLOB_RECURSE functional_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} functional/*)
-foreach(script ${functional_tests} fuzz/test_runner.py)
- if(CMAKE_HOST_WIN32)
- set(symlink)
- else()
- set(symlink SYMBOLIC)
- endif()
- file(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/${script} ${CMAKE_CURRENT_BINARY_DIR}/${script} COPY_ON_ERROR ${symlink})
-endforeach()
-unset(functional_tests)
+
+function(create_test_directory_links)
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/functional)
+ file(GLOB functional
+ LIST_DIRECTORIES FALSE
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ functional/*.html
+ functional/*.py
+ )
+
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/functional/data)
+ file(GLOB functional_data
+ LIST_DIRECTORIES FALSE
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ functional/data/*.json
+ functional/data/*.py
+ )
+
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/functional/mocks)
+ file(GLOB functional_mocks
+ LIST_DIRECTORIES FALSE
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ functional/mocks/*.py
+ )
+
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/functional/test_framework)
+ file(GLOB functional_test_framework
+ LIST_DIRECTORIES FALSE
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ functional/test_framework/*.csv
+ functional/test_framework/*.py
+ )
+
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/functional/test_framework/crypto)
+ file(GLOB functional_test_framework_crypto
+ LIST_DIRECTORIES FALSE
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ functional/test_framework/crypto/*.csv
+ functional/test_framework/crypto/*.py
+ )
+
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fuzz)
+ set(files_to_link
+ ${functional}
+ ${functional_data}
+ ${functional_mocks}
+ ${functional_test_framework}
+ ${functional_test_framework_crypto}
+ fuzz/test_runner.py
+ )
+
+ foreach(f IN LISTS files_to_link)
+ if(CMAKE_HOST_WIN32)
+ set(symlink)
+ else()
+ set(symlink SYMBOLIC)
+ endif()
+ file(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/${f} ${CMAKE_CURRENT_BINARY_DIR}/${f} COPY_ON_ERROR ${symlink})
+ endforeach()
+endfunction()
+
+create_test_directory_links()
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.