# HG changeset patch # User Loïc Guilloux # Date 2023-12-05 14:37:53 # Node ID 62b1dfcb422f6e60f94f91e5b136b24194d7db2a # Parent a65eee5f1368457e8f05729ab8247bad72557f89 Change: [CMake] Use explicit list for regression (#11541) diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -454,8 +454,9 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8) add_definitions(-DPOINTER_IS_64BIT) endif() -include(CreateRegression) -create_regression() +enable_testing() + +add_subdirectory(regression) if(APPLE OR WIN32) find_package(Pandoc) diff --git a/cmake/CreateRegression.cmake b/cmake/CreateRegression.cmake --- a/cmake/CreateRegression.cmake +++ b/cmake/CreateRegression.cmake @@ -3,20 +3,15 @@ # 'ctest'. The first is prefered, as it is more verbose, and takes care of # dependencies correctly. # -# create_regression() +# create_regression(file1 ...) # macro(create_regression) - # Find all the files in the regression folder; they need to be copied to the - # build folder before we can run the regression - file(GLOB_RECURSE REGRESSION_SOURCE_FILES ${CMAKE_SOURCE_DIR}/regression/*) + set(REGRESSION_SOURCE_FILES ${ARGN}) + foreach(REGRESSION_SOURCE_FILE IN LISTS REGRESSION_SOURCE_FILES) string(REPLACE "${CMAKE_SOURCE_DIR}/regression/" "" REGRESSION_SOURCE_FILE_NAME "${REGRESSION_SOURCE_FILE}") string(CONCAT REGRESSION_BINARY_FILE "${CMAKE_BINARY_DIR}/ai/" "${REGRESSION_SOURCE_FILE_NAME}") - if("${REGRESSION_SOURCE_FILE_NAME}" STREQUAL "regression.cfg") - continue() - endif() - add_custom_command(OUTPUT ${REGRESSION_BINARY_FILE} COMMAND ${CMAKE_COMMAND} -E copy ${REGRESSION_SOURCE_FILE} @@ -28,59 +23,36 @@ macro(create_regression) list(APPEND REGRESSION_BINARY_FILES ${REGRESSION_BINARY_FILE}) endforeach() - # Copy the regression configuration in a special folder, so all autogenerated - # folders end up in the same place after running regression. - add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/regression/regression.cfg - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_SOURCE_DIR}/regression/regression.cfg - ${CMAKE_BINARY_DIR}/regression/regression.cfg - MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/regression/regression.cfg - COMMENT "Copying ${REGRESSION_SOURCE_FILE_NAME} regression file" - ) - list(APPEND REGRESSION_BINARY_FILES ${CMAKE_BINARY_DIR}/regression/regression.cfg) + get_filename_component(REGRESSION_TEST_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME) - # Create a new target which copies all regression files - add_custom_target(regression_files - ALL # this is needed because 'make test' doesn't resolve dependencies, and otherwise this is never executed + # Create a new target which copies regression files + add_custom_target(regression_${REGRESSION_TEST_NAME}_files DEPENDS ${REGRESSION_BINARY_FILES} ) - enable_testing() + add_dependencies(regression_files regression_${REGRESSION_TEST_NAME}_files) - # Find all the tests we have, and create a target for them - file(GLOB REGRESSION_TESTS ${CMAKE_SOURCE_DIR}/regression/*) - foreach(REGRESSION_TEST IN LISTS REGRESSION_TESTS) - get_filename_component(REGRESSION_TEST_NAME "${REGRESSION_TEST}" NAME) - - if("${REGRESSION_TEST_NAME}" STREQUAL "regression.cfg") - continue() - endif() + add_custom_target(regression_${REGRESSION_TEST_NAME} + COMMAND ${CMAKE_COMMAND} + -DOPENTTD_EXECUTABLE=$ + -DEDITBIN_EXECUTABLE=${EDITBIN_EXECUTABLE} + -DREGRESSION_TEST=${REGRESSION_TEST_NAME} + -P "${CMAKE_SOURCE_DIR}/cmake/scripts/Regression.cmake" + DEPENDS openttd regression_${REGRESSION_TEST_NAME}_files + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Running regression test ${REGRESSION_TEST_NAME}" + ) - add_custom_target(regression_${REGRESSION_TEST_NAME} - COMMAND ${CMAKE_COMMAND} - -DOPENTTD_EXECUTABLE=$ - -DEDITBIN_EXECUTABLE=${EDITBIN_EXECUTABLE} - -DREGRESSION_TEST=${REGRESSION_TEST_NAME} - -P "${CMAKE_SOURCE_DIR}/cmake/scripts/Regression.cmake" - DEPENDS openttd regression_files - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMENT "Running regression test ${REGRESSION_TEST_NAME}" - ) + # Also make sure that 'make test' runs the regression + add_test(NAME regression_${REGRESSION_TEST_NAME} + COMMAND ${CMAKE_COMMAND} + -DOPENTTD_EXECUTABLE=$ + -DEDITBIN_EXECUTABLE=${EDITBIN_EXECUTABLE} + -DREGRESSION_TEST=${REGRESSION_TEST_NAME} + -P "${CMAKE_SOURCE_DIR}/cmake/scripts/Regression.cmake" + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) - # Also make sure that 'make test' runs the regression - add_test(NAME regression_${REGRESSION_TEST_NAME} - COMMAND ${CMAKE_COMMAND} - -DOPENTTD_EXECUTABLE=$ - -DEDITBIN_EXECUTABLE=${EDITBIN_EXECUTABLE} - -DREGRESSION_TEST=${REGRESSION_TEST_NAME} - -P "${CMAKE_SOURCE_DIR}/cmake/scripts/Regression.cmake" - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) - - list(APPEND REGRESSION_TARGETS regression_${REGRESSION_TEST_NAME}) - endforeach() - - # Create a new target which runs the regression - add_custom_target(regression - DEPENDS ${REGRESSION_TARGETS}) + add_dependencies(regression regression_${REGRESSION_TEST_NAME}) endmacro() diff --git a/regression/CMakeLists.txt b/regression/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/regression/CMakeLists.txt @@ -0,0 +1,24 @@ + # Copy the regression configuration in a special folder, so all autogenerated + # folders end up in the same place after running regression. + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/regression.cfg + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/regression.cfg + ${CMAKE_CURRENT_BINARY_DIR}/regression.cfg + MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/regression.cfg + COMMENT "Copying regression.cfg regression file" + ) + + # Create a new target which copies all regression files + # Subdirectory targets will add themselves as dependencies + add_custom_target(regression_files + ALL # this is needed because 'make test' doesn't resolve dependencies, and otherwise this is never executed + DEPENDS + ${CMAKE_BINARY_DIR}/regression/regression.cfg + ) + + # Create a new target which runs the regression + # Subdirectory targets will add themselves as dependencies + add_custom_target(regression) + + add_subdirectory(regression) + add_subdirectory(stationlist) diff --git a/regression/regression/CMakeLists.txt b/regression/regression/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/regression/regression/CMakeLists.txt @@ -0,0 +1,8 @@ +include(CreateRegression) +create_regression( + ${CMAKE_CURRENT_SOURCE_DIR}/info.nut + ${CMAKE_CURRENT_SOURCE_DIR}/main.nut + ${CMAKE_CURRENT_SOURCE_DIR}/require.nut + ${CMAKE_CURRENT_SOURCE_DIR}/result.txt + ${CMAKE_CURRENT_SOURCE_DIR}/test.sav +) diff --git a/regression/stationlist/CMakeLists.txt b/regression/stationlist/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/regression/stationlist/CMakeLists.txt @@ -0,0 +1,7 @@ +include(CreateRegression) +create_regression( + ${CMAKE_CURRENT_SOURCE_DIR}/info.nut + ${CMAKE_CURRENT_SOURCE_DIR}/main.nut + ${CMAKE_CURRENT_SOURCE_DIR}/result.txt + ${CMAKE_CURRENT_SOURCE_DIR}/test.sav +)