From 695591b3e9ff8978bbfe9b9f8e68e68186a5e32f Mon Sep 17 00:00:00 2001 From: Paul Bauer Date: Tue, 13 Oct 2020 07:32:55 +0000 Subject: [PATCH] Do not validate build for external source management If git was not found for builds not coming from a tarball, the source validation script would generate warnings due to the missing reference checksum file. Refs #2128 Change-Id: I7a0d0c164e19eb47446b26a039442b57e537375b --- ...=> gmxGenerateVersionInfoWithoutGit.cmake} | 90 +++++++++++-------- cmake/gmxVersionInfo.cmake | 2 +- 2 files changed, 52 insertions(+), 40 deletions(-) rename cmake/{gmxGenerateVersionInfoRelease.cmake => gmxGenerateVersionInfoWithoutGit.cmake} (55%) diff --git a/cmake/gmxGenerateVersionInfoRelease.cmake b/cmake/gmxGenerateVersionInfoWithoutGit.cmake similarity index 55% rename from cmake/gmxGenerateVersionInfoRelease.cmake rename to cmake/gmxGenerateVersionInfoWithoutGit.cmake index 2e3997ff0a..68b9c6fafa 100644 --- a/cmake/gmxGenerateVersionInfoRelease.cmake +++ b/cmake/gmxGenerateVersionInfoWithoutGit.cmake @@ -94,47 +94,59 @@ foreach(DIR ${DIRECTORIES_TO_CHECKSUM_LIST}) list(APPEND FULL_PATH_DIRECTORIES "${PROJECT_SOURCE_DIR}/${DIR}") endforeach() -# Prepare for checking source tree file hashes. -# To notify the user during compilation and at runtime that the build source -# has not been modified after unpacking the source tarball, the contents are hashed -# to be compared to a hash computed during the release process. If the hash matches -# all is fine and the user gets a message in the log file indicating that. -# If either the release hash file is missing, or if the hash does not match -# a different message is printed to indicate that the source has been changed -# compared to the version actually released. This is not needed in case a build -# is done in git, as we have the information there already. -# This is not done if the user has explicitly set an additional custom version string with -# -DGMX_VERSION_STRING_OF_FORK, as this indicates that they are knowing that a custom -# version of GROMACS is in use. -set(RELEASE_CHECKSUM_FILE "${PROJECT_SOURCE_DIR}/src/reference_checksum") -if(NOT VERSION_STRING_OF_FORK OR "${VERSION_STRING_OF_FORK}" STREQUAL "") - if(EXISTS ${RELEASE_CHECKSUM_FILE} AND PYTHON_EXECUTABLE) - file(READ ${RELEASE_CHECKSUM_FILE} GMX_RELEASE_SOURCE_FILE_CHECKSUM) - string(STRIP ${GMX_RELEASE_SOURCE_FILE_CHECKSUM} GMX_RELEASE_SOURCE_FILE_CHECKSUM) - set(CHECKSUM_RESULT_FILE "${CMAKE_CURRENT_BINARY_DIR}/computed_checksum") - execute_process(COMMAND ${PYTHON_EXECUTABLE} - ${PROJECT_SOURCE_DIR}/admin/createFileHash.py - -s ${FULL_PATH_DIRECTORIES} - -o ${CHECKSUM_RESULT_FILE} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - OUTPUT_QUIET) - file(READ ${CHECKSUM_RESULT_FILE} GMX_CURRENT_SOURCE_FILE_CHECKSUM) - string(STRIP ${GMX_CURRENT_SOURCE_FILE_CHECKSUM} GMX_CURRENT_SOURCE_FILE_CHECKSUM) - if(NOT ${GMX_RELEASE_SOURCE_FILE_CHECKSUM} STREQUAL ${GMX_CURRENT_SOURCE_FILE_CHECKSUM}) - set(GMX_VERSION_STRING_FULL "${GMX_VERSION_STRING_FULL}-MODIFIED") - message(STATUS "The source code for this GROMACS installation is different from the officially released version.") +# Change path depending on if this is a source distribution (e.g. release tarball) +# or just a source directory that is managed by something else, like an IDE. +# If the git executable isn't found by CMake, there will not be version info even +# if the .git folder is present and SOURCE_IS_GIT_REPOSITORY is true. +# Don't issue warnings in this case. +if (SOURCE_IS_SOURCE_DISTRIBUTION) + # Prepare for checking source tree file hashes. + # To notify the user during compilation and at runtime that the build source + # has not been modified after unpacking the source tarball, the contents are hashed + # to be compared to a hash computed during the release process. If the hash matches + # all is fine and the user gets a message in the log file indicating that. + # If either the release hash file is missing, or if the hash does not match + # a different message is printed to indicate that the source has been changed + # compared to the version actually released. This is not needed in case a build + # is done in git, as we have the information there already. + # This is not done if the user has explicitly set an additional custom version string with + # -DGMX_VERSION_STRING_OF_FORK, as this indicates that they are knowing that a custom + # version of GROMACS is in use. + set(RELEASE_CHECKSUM_FILE "${PROJECT_SOURCE_DIR}/src/reference_checksum") + if(NOT VERSION_STRING_OF_FORK OR "${VERSION_STRING_OF_FORK}" STREQUAL "") + if(EXISTS ${RELEASE_CHECKSUM_FILE} AND PYTHON_EXECUTABLE) + file(READ ${RELEASE_CHECKSUM_FILE} GMX_RELEASE_SOURCE_FILE_CHECKSUM) + string(STRIP ${GMX_RELEASE_SOURCE_FILE_CHECKSUM} GMX_RELEASE_SOURCE_FILE_CHECKSUM) + set(CHECKSUM_RESULT_FILE "${CMAKE_CURRENT_BINARY_DIR}/computed_checksum") + execute_process(COMMAND ${PYTHON_EXECUTABLE} + ${PROJECT_SOURCE_DIR}/admin/createFileHash.py + -s ${FULL_PATH_DIRECTORIES} + -o ${CHECKSUM_RESULT_FILE} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + OUTPUT_QUIET) + file(READ ${CHECKSUM_RESULT_FILE} GMX_CURRENT_SOURCE_FILE_CHECKSUM) + string(STRIP ${GMX_CURRENT_SOURCE_FILE_CHECKSUM} GMX_CURRENT_SOURCE_FILE_CHECKSUM) + if(NOT ${GMX_RELEASE_SOURCE_FILE_CHECKSUM} STREQUAL ${GMX_CURRENT_SOURCE_FILE_CHECKSUM}) + set(GMX_VERSION_STRING_FULL "${GMX_VERSION_STRING_FULL}-MODIFIED") + message(STATUS "The source code for this GROMACS installation is different from the officially released version.") + endif() + elseif(PYTHON_EXECUTABLE) + set(GMX_VERSION_STRING_FULL "${GMX_VERSION_STRING_FULL}-UNCHECKED") + set(GMX_RELEASE_SOURCE_FILE_CHECKSUM "NoChecksumFile") + set(GMX_CURRENT_SOURCE_FILE_CHECKSUM "NoChecksumFile") + message(WARNING "Could not valdiate the GROMACS source due to missing reference checksum file.") + else() + set(GMX_VERSION_STRING_FULL "${GMX_VERSION_STRING_FULL}-UNCHECKED") + set(GMX_RELEASE_SOURCE_FILE_CHECKSUM "NoPythonAvailable") + set(GMX_CURRENT_SOURCE_FILE_CHECKSUM "NoPythonAvailable") + message(STATUS "Could not calculate checksum of source files without Python") endif() - elseif(PYTHON_EXECUTABLE) - set(GMX_VERSION_STRING_FULL "${GMX_VERSION_STRING_FULL}-UNCHECKED") - set(GMX_RELEASE_SOURCE_FILE_CHECKSUM "NoChecksumFile") - set(GMX_CURRENT_SOURCE_FILE_CHECKSUM "NoChecksumFile") - message(WARNING "Could not valdiate the GROMACS source due to missing reference checksum file.") - else() - set(GMX_VERSION_STRING_FULL "${GMX_VERSION_STRING_FULL}-UNCHECKED") - set(GMX_RELEASE_SOURCE_FILE_CHECKSUM "NoPythonAvailable") - set(GMX_CURRENT_SOURCE_FILE_CHECKSUM "NoPythonAvailable") - message(STATUS "Could not calculate checksum of source files without Python") endif() +else() + set(GMX_VERSION_STRING_FULL "${GMX_VERSION_STRING_FULL}-UNCHECKED") + set(GMX_RELEASE_SOURCE_FILE_CHECKSUM "NotSourceDistribution") + set(GMX_CURRENT_SOURCE_FILE_CHECKSUM "NotSourceDistribution") + message(STATUS "Build without git or source information") endif() # Generate the output file. diff --git a/cmake/gmxVersionInfo.cmake b/cmake/gmxVersionInfo.cmake index 58f3ff6efc..5343f20a17 100644 --- a/cmake/gmxVersionInfo.cmake +++ b/cmake/gmxVersionInfo.cmake @@ -411,7 +411,7 @@ else() -D VERSION_CMAKEIN=${VERSION_INFO_CMAKEIN_FILE_PARTIAL} -D VERSION_OUT=${VERSION_INFO_CMAKE_FILE} -D VERSION_STRING_OF_FORK=${GMX_VERSION_STRING_OF_FORK} - -P ${CMAKE_CURRENT_LIST_DIR}/gmxGenerateVersionInfoRelease.cmake + -P ${CMAKE_CURRENT_LIST_DIR}/gmxGenerateVersionInfoWithoutGit.cmake WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMENT "Generating release version information") list(APPEND VERSION_INFO_DEPS release-version-info) -- 2.22.0