From 808827f6280766ce06920d6c0e8dcfe7cee8caf5 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Fri, 15 Feb 2019 15:45:54 -0700 Subject: [PATCH] WIP: Caputure output from tribits_ctest_update_commands.cmake (#278) I also added this to the notes files and refactored that a little to clean them up. --- .../ctest_driver/TribitsCTestDriverCore.cmake | 65 ++++++++++++++++--- .../tribits_ctest_update_commands.cmake | 27 ++++++-- ...ribits_ctest_update_commands_wrapper.cmake | 28 ++++++++ 3 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 tribits/ctest_driver/tribits_ctest_update_commands_wrapper.cmake diff --git a/tribits/ctest_driver/TribitsCTestDriverCore.cmake b/tribits/ctest_driver/TribitsCTestDriverCore.cmake index e3cf5e7fc..6ce8b5eeb 100644 --- a/tribits/ctest_driver/TribitsCTestDriverCore.cmake +++ b/tribits/ctest_driver/TribitsCTestDriverCore.cmake @@ -1014,6 +1014,20 @@ INCLUDE(${CMAKE_CURRENT_LIST_DIR}/TribitsCTestDriverCoreHelpers.cmake) # ``BUILD_DIR_NAME`` is expected to be set in each specific CTest -S # driver script. # +# .. _CTEST_NOTES_FILES: +# +# ``CTEST_NOTES_FILES`` +# +# Built-in CTest variable that specifies a set of files that will get +# uploaded to CDash as "notes files". This function will also add other +# files as well such as the ``CMakeCache.clean.txt`` file (cleaned-up +# version of the CMakeCache.txt file), the ``Updates.txt`` file (lists new +# git commits pulled in all the git repos since), the +# ``UpdateCommandsOutput.txt`` file (list of commands and their output +# which are run by the ``ctest_update()`` in the base git repo), and the +# ``${PROJECT_NAME}RepoVersion.txt`` file (gives version of all the git +# repos being tested). +# # .. _Specifying where the results go to CDash (TRIBITS_CTEST_DRIVER()): # # **Specifying where the results go to CDash (TRIBITS_CTEST_DRIVER()):** @@ -1751,6 +1765,9 @@ FUNCTION(TRIBITS_CTEST_DRIVER) SET(CREATE_VC_UPDATE_FILE FALSE) + SET(CTEST_UPDATE_COMMANDS_OUTPUT_FILE + "${CTEST_BINARY_DIRECTORY}/UpdateCommandsOutput.txt") + IF (CTEST_DO_UPDATES) SET(UPDATE_TYPE "git") @@ -1796,11 +1813,13 @@ FUNCTION(TRIBITS_CTEST_DRIVER) # Provide a custom command to do the update SET(CTEST_GIT_UPDATE_CUSTOM - "${CMAKE_COMMAND}" -DGIT_EXE=${GIT_EXE} - -DREMOTE_NAME=${${PROJECT_NAME}_GIT_REPOSITORY_REMOTE} - -DBRANCH=${${PROJECT_NAME}_BRANCH} - -DUNIT_TEST_MODE=${CTEST_DEPENDENCY_HANDLING_UNIT_TESTING} - -P ${THIS_CMAKE_CURRENT_LIST_DIR}/tribits_ctest_update_commands.cmake + "${CMAKE_COMMAND}" + -DGIT_EXE=${GIT_EXE} + -DREMOTE_NAME=${${PROJECT_NAME}_GIT_REPOSITORY_REMOTE} + -DBRANCH=${${PROJECT_NAME}_BRANCH} + -DUNIT_TEST_MODE=${CTEST_DEPENDENCY_HANDLING_UNIT_TESTING} + -DOUTPUT_FILE=${CTEST_UPDATE_COMMANDS_OUTPUT_FILE} + -P ${THIS_CMAKE_CURRENT_LIST_DIR}/tribits_ctest_update_commands_wrapper.cmake ) MESSAGE("CTEST_GIT_UPDATE_CUSTOM=${CTEST_GIT_UPDATE_CUSTOM}") @@ -1929,6 +1948,14 @@ FUNCTION(TRIBITS_CTEST_DRIVER) RETURN_VALUE CTEST_UPDATE_RETURN_VAL) MESSAGE("CTEST_UPDATE(...) returned '${CTEST_UPDATE_RETURN_VAL}' [ rtn >= 0: num files; rnt == -1: error ]") + # Print the output from the git commands called in ctest_update() + IF (EXISTS "${CTEST_UPDATE_COMMANDS_OUTPUT_FILE}") + FILE(READ "${CTEST_UPDATE_COMMANDS_OUTPUT_FILE}" CTEST_UPDATE_COMMANDS_OUTPUT_STR) + MESSAGE("\n------------------------------------------------------------------------") + MESSAGE("${CTEST_UPDATE_COMMANDS_OUTPUT_STR}") + MESSAGE("------------------------------------------------------------------------\n") + ENDIF() + TRIBITS_CLONE_OR_UPDATE_EXTRA_REPOS(${CTEST_UPDATE_RETURN_VAL} LOC_UPDATE_FAILED) IF (LOC_UPDATE_FAILED) SET(UPDATE_FAILED TRUE) @@ -2066,12 +2093,30 @@ FUNCTION(TRIBITS_CTEST_DRIVER) "\n***\n" ) - IF (EXISTS ${CTEST_BINARY_DIRECTORY}/Updates.txt) - SET(CTEST_NOTES_FILES_WO_CACHE - "${CTEST_BINARY_DIRECTORY}/Updates.txt;${CTEST_NOTES_FILES}") - ELSE() - SET(CTEST_NOTES_FILES_WO_CACHE "${CTEST_NOTES_FILES}") + # Set up a list of notes files that don't include the CMakeCache.clean.txt + # file which will change for every submit in the package-by-package modee. + + SET(CTEST_NOTES_FILES_WO_CACHE) + + SET(REPO_VERSION_FILE "${CTEST_BINARY_DIRECTORY}/${PROJECT_NAME}RepoVersion.txt") + IF (EXISTS "${REPO_VERSION_FILE}") + LIST(APPEND CTEST_NOTES_FILES_WO_CACHE "${REPO_VERSION_FILE}") + ENDIF() + + SET(MULTIREPO_GIT_UPDATES_FILE "${CTEST_BINARY_DIRECTORY}/Updates.txt" ) + IF (EXISTS "${MULTIREPO_GIT_UPDATES_FILE}") + LIST(APPEND CTEST_NOTES_FILES_WO_CACHE "${MULTIREPO_GIT_UPDATES_FILE}") + ENDIF() + + IF (EXISTS "${CTEST_UPDATE_COMMANDS_OUTPUT_FILE}") + LIST(APPEND CTEST_NOTES_FILES_WO_CACHE "${CTEST_UPDATE_COMMANDS_OUTPUT_FILE}" ) + ENDIF() + + # Tack on any notes files that the client might have set to the end of these + IF ("${CTEST_NOTES_FILES}") + LIST(APPEND CTEST_NOTES_FILES_WO_CACHE "${CTEST_NOTES_FILES}") ENDIF() + PRINT_VAR(CTEST_NOTES_FILES_WO_CACHE) # Note: We must only do the submit after we have decided if there are any diff --git a/tribits/ctest_driver/tribits_ctest_update_commands.cmake b/tribits/ctest_driver/tribits_ctest_update_commands.cmake index 856d9138c..263c18a0f 100644 --- a/tribits/ctest_driver/tribits_ctest_update_commands.cmake +++ b/tribits/ctest_driver/tribits_ctest_update_commands.cmake @@ -1,10 +1,24 @@ # -# ctest -P script to do and update of the base git repo. +# cmake -P script to do and update of the base git repo. # -# ToDo: Finish documentation +# Usage: +# +# cmake [arguments] -P tribits_ctest_update_commands.cmake +# +# where the -D= arguments are shown below. +# +# The list of commands in this script completely clean out a git repo and +# create a local branch with name ${BRANCH} tracking a remote branch ${BRANCH} +# in the remote repo ${REMOTE_NAME}. This is robust no matter what the +# current state of the local git repo. The built-in git commands used by +# ctest_update() are not robust to some use cases where these commands are. +# For example, the commands are robust to the situation where the local repo +# may be tracking a remote branch that may have been deleted in the remote +# repo. The default commands used in ctest_update() (at least as of CMake +# 3.12) crash in that case. # -message("cmake -P tribits_ctest_update_commands.cmake:") +message("\ncmake -P tribits_ctest_update_commands.cmake:") message("-- GIT_EXE=${GIT_EXE}") message("-- REMOTE_NAME=${REMOTE_NAME}") message("-- BRANCH=${BRANCH}") @@ -17,7 +31,7 @@ macro(execute_process_wrapper) message("\nRunning: execute_process(${ARGN})") if (NOT UNIT_TEST_MODE) execute_process(${ARGN} RESULT_VARIABLE RTN_CODE) - message("RESULT_VARIABLE=${RTN_CODE}") + message("RTN_CODE: ${RTN_CODE}") IF (NOT "${RTN_CODE}" STREQUAL "0") set(OVERALL_SUCCESS FALSE) set(ERROR_CODE ${RTN_CODE}) @@ -47,3 +61,8 @@ if (OVERALL_SUCCESS) else() message(FATAL_ERROR "Git Update FAILED!") endif() + +# NOTE: Above, you have to use separate execute_process() commands for each +# git command or you get git errors complaining about git commands running on +# top of each other. The execute_process() implementation must not ensure +# that one command is completely finished before the next one starts. diff --git a/tribits/ctest_driver/tribits_ctest_update_commands_wrapper.cmake b/tribits/ctest_driver/tribits_ctest_update_commands_wrapper.cmake new file mode 100644 index 000000000..02f0f9ce3 --- /dev/null +++ b/tribits/ctest_driver/tribits_ctest_update_commands_wrapper.cmake @@ -0,0 +1,28 @@ +# +# cmake -P script that calls tribits_ctest_update_commands.cmake and sends +# STDOUT to a file. +# +# This script is required if you want to capture the output from these +# commands to a file since this is called from ctest_update() which discards +# the output (and does not send it to CDash). +# + +message("\ncmake -P tribits_ctest_update_commands_wrapper.cmake:") +message("-- OUTPUT_FILE=${OUTPUT_FILE}\n") + +execute_process( + COMMAND "${CMAKE_COMMAND}" + -DGIT_EXE=${GIT_EXE} + -DREMOTE_NAME=${REMOTE_NAME} + -DBRANCH=${BRANCH} + -DUNIT_TEST_MODE=${UNIT_TEST_MODE} + -P ${CMAKE_CURRENT_LIST_DIR}/tribits_ctest_update_commands.cmake + OUTPUT_FILE "${OUTPUT_FILE}" + ERROR_FILE "${OUTPUT_FILE}" + RESULT_VARIABLE RTN_CODE + ) +message("\ntribits_ctest_update_commands_wrapper.cmake return: ${RTN_CODE}\n") + +if (NOT "${RTN_CODE}" STREQUAL "0") + message(FATAL_ERROR "Git Update FAILED!") +endif()