diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fdb39eb08bc6e8c8578cdc018ac68c0e5e3917cc..55473002ec9894f0552fd848e487d9e7b28f7f75 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -221,12 +221,6 @@ FileLicenceCheck: - if [[ -n $RAW_DATA_PATH ]]; then - echo "export RAW_DATA_PATH=$RAW_DATA_PATH" >> Dart.cfg - fi - # Need to encapsulate the command to add GEO_HASH_CHANGE flag in Dart.cfg probably due to a long-standing - # feature/bug of gitlab shell runners w/ cmd result assignment when the return value is 0 - # see https://gitlab.com/gitlab-org/gitlab-runner/-/issues/1779 and 3897 - - if [[ -n $CHECK_GEO_HASH_CHANGE ]]; then - - scripts/check-geo-hash-changes.sh $CI_MERGE_REQUEST_PROJECT_URL $CI_MERGE_REQUEST_TARGET_BRANCH_NAME - - fi - echo "export BUILDDIR=$PWD/build" >> Dart.cfg - echo "export SOURCEDIR=$PWD" >> Dart.cfg - if [[ -n $EXTRA_PATH ]]; then diff --git a/cmake/modules/CbmMacros.cmake b/cmake/modules/CbmMacros.cmake index da1ae38832db9022ecf258ce0ebe18976f81ff53..d8653109b35bb310b8c16881e822d055d5f0f137 100644 --- a/cmake/modules/CbmMacros.cmake +++ b/cmake/modules/CbmMacros.cmake @@ -10,6 +10,17 @@ Macro(Remove_Trailing_Slash _variable) EndIf() EndMacro() +# Remove trailing character from a string, store resulting string in _ret_val +Function(Strip_Trailing_Char _string _char) + string(FIND ${_string} ${_char} _pos_last_slash REVERSE) + string(LENGTH ${_string} _length) + Math(EXPR _last_pos ${_pos_last_slash}+1) + If(${_last_pos} EQUAL ${_length}) + string(SUBSTRING ${_string} 0 ${_pos_last_slash} _string) + EndIf() + Set(_ret_val ${_string} PARENT_SCOPE) # Functions work in their own scope +EndFunction() + Macro(FairRootVersion) Execute_Process(COMMAND ${FAIRROOTPATH}/bin/fairroot-config --version diff --git a/external/InstallGeometry.cmake b/external/InstallGeometry.cmake index 8aceb6d3de07d03ddafe806dd7819b898e7429bd..03ecae96c3e9b124dbd5c1ae179ec70a49fa951d 100644 --- a/external/InstallGeometry.cmake +++ b/external/InstallGeometry.cmake @@ -8,3 +8,39 @@ download_project_if_needed(PROJECT Geometry_source SOURCE_DIR ${CMAKE_SOURCE_DIR}/geometry TEST_FILE media.geo ) +If(DEFINED ENV{CHECK_GEO_HASH_CHANGE} AND DEFINED ENV{CI_MERGE_REQUEST_PROJECT_URL}) + Message( STATUS "Checking geo setup changes against $ENV{CI_MERGE_REQUEST_PROJECT_URL} " + "$ENV{CI_MERGE_REQUEST_TARGET_BRANCH_NAME}") + execute_process(COMMAND "${CBMROOT_SOURCE_DIR}/scripts/check-geo-hash-changes.sh" + $ENV{CI_MERGE_REQUEST_PROJECT_URL} + $ENV{CI_MERGE_REQUEST_TARGET_BRANCH_NAME} + WORKING_DIRECTORY ${CBMROOT_SOURCE_DIR} + OUTPUT_VARIABLE checks_std_out) + + ##### Strip trailing new line in output + Strip_Trailing_Char(${checks_std_out} "\n") + Set( checks_std_out ${_ret_val} ) + ##### + + # Transform output lines into list items + string(REPLACE "\n" ";" found_checks_exports ${checks_std_out}) + + # Loop on lines, find those with the pattern "CMAKE_EXPORT XXXXX=YYYYY" and use to set CMAKE variables + foreach(_LINE IN LISTS found_checks_exports) + if (_LINE MATCHES "CMAKE_EXPORT (.*)$") + string(REGEX MATCHALL "\ (.*)$" _PAIR ${_LINE}) # Cut out the token, lead space left -_-' + string(SUBSTRING ${_PAIR} 1 -1 _PAIR) # Remove leading space + if (_PAIR MATCHES "^([^:]+)=(.*)$") + #### Replace temporary : with ; to make it a CMAKE list (used to avoid CMAKE errors in previous commands) + Strip_Trailing_Char(${CMAKE_MATCH_2} ":") + Set( CMAKE_MATCH_2 ${_ret_val} ) + string(REPLACE ":" ";" CMAKE_MATCH_2 ${CMAKE_MATCH_2}) + #### + # Message( STATUS "Setting: ${CMAKE_MATCH_1} to ${CMAKE_MATCH_2}") + set("${CMAKE_MATCH_1}" ${CMAKE_MATCH_2} PARENT_SCOPE) # Need parent scope to share it out of "add_subdirectory" + else() + message(FATAL_ERROR "Invalid export pair: ${_PAIR}") + endif() + endif() + endforeach() +endIf() diff --git a/macro/geometry/CMakeLists.txt b/macro/geometry/CMakeLists.txt index de20dac5c9438fe0e50983a444ee1863b0a10836..e4dc12cda8b1e1350d81c921f861aa3769a8d344 100644 --- a/macro/geometry/CMakeLists.txt +++ b/macro/geometry/CMakeLists.txt @@ -34,19 +34,24 @@ SET( CHECK_SETUPS FALSE ) If(${CBM_TEST_MODEL} MATCHES Nightly OR ${CBM_TEST_MODEL} MATCHES Weekly) SET( CHECK_SETUPS TRUE ) Message( STATUS "Enabling tests on geometry setups consistency (materials and overlaps) for Nightly/Weekly build") -elseIf(DEFINED ENV{GEO_HASH_CHANGE}) - set(GEO_HASH_CHANGE $ENV{GEO_HASH_CHANGE}) - If(GEO_HASH_CHANGE) - SET( CHECK_SETUPS TRUE ) - Message( STATUS "Change in geo repo hash => Enabling tests on geometry setups consistency (materials and overlaps)") +elseIf(${GEO_SETUPS_CHANGE}) + SET( CHECK_SETUPS TRUE ) + # Use list of modified setups from script by default, but keep option for "full check" w/ only GEO_SETUPS_CHANGE=1 + If(DEFINED CHANGED_SETUPS) + SET(setup_files ${CHANGED_SETUPS}) endIf() + Message( STATUS "Change in geo repo hash => Enabling tests on geometry setups consistency (materials and overlaps)") + # Message( STATUS "Change in geo repo hash => Found following setups to test: ${setup_files}") +else() + Message( STATUS "No checks booked over geo setups") endIf() -If(CHECK_SETUPS) +If(${CHECK_SETUPS} AND setup_files) ForEach(setup IN LISTS setup_files) - string(REPLACE ${CBMROOT_SOURCE_DIR}/geometry/setup/setup_ "" setup ${setup}) + string(REPLACE setup/setup_ "" setup ${setup}) + string(REPLACE ${CBMROOT_SOURCE_DIR}/geometry/ "" setup ${setup}) # Needed only with "all setups list" string(REPLACE .C "" setup ${setup}) - # Message("Test: found setup tag ${setup}") + Message("Change in geo repo hash => Found following setups to test: ${setup}") # --- Test setup materials # --- Check that materials in a loaded geometry (1 evt tra run) match corresponding single det geo files, diff --git a/scripts/check-geo-hash-changes.sh b/scripts/check-geo-hash-changes.sh index c9b104eafd3356ca3e67dd88f12a35dec95a4f6a..d8c55badbf449cd37c486d50f04faa321b73ef21 100755 --- a/scripts/check-geo-hash-changes.sh +++ b/scripts/check-geo-hash-changes.sh @@ -1,10 +1,17 @@ +#!/bin/bash # Copyright (C) 2023 Facility for Antiproton and Ion Research in Europe, Darmstadt # SPDX-License-Identifier: GPL-3.0-only # First commited by Pierre-Alain Loizeau -# This script will check if the Geometry repository installation script (externals) hold any modification relative to -# the "upstream" repository. -# The result is stored as an export to the variable GEO_HASH_CHANGE in the Dart.cfg file +# This script will check if the Geometry repository installation script (externals) holds any modification relative to +# the "upstream" repository leading to modifications of the setup files. +# If it is the case, it will check if the hash was changed. +# If the hash was changed, it will check if setup files were modifed between the old and new hash values. +# +# The result of the check is echoed with a custom pattern to be extracted by CMAKE into the variable GEO_HASH_CHANGE +# The eventual list (; sep) of modified setups is similarly echoed for the variable CHANGED_SETUPS +# The custom pattern extracted in the `geometry/InstallGeometry.cmake` file is +# CMAKE_EXPORT <VAR_NAME>=<VAR_VAL or <VAR_VAL_LIST_1:VAR_VAL_LIST_2:...:> # # upstream is used here in the CBM workflow and CBM CI meaning # => designating the target branch of an MR or the official master branch @@ -24,7 +31,7 @@ if [[ $# -ne 2 ]]; then echo "Examples: " echo "./scripts/check-geo-hash-changes.sh https://git.cbm.gsi.de/computing/cbmroot.git master # https without login" echo "./scripts/check-geo-hash-changes.sh git@git.cbm.gsi.de:computing/cbmroot.git master # ssh with key login" - echo "./scripts/check-geo-hash-changes.sh $CI_MERGE_REQUEST_PROJECT_URL $CI_MERGE_REQUEST_TARGET_BRANCH_NAME # MR CI" + echo "./scripts/check-geo-hash-changes.sh \$CI_MERGE_REQUEST_PROJECT_URL \$CI_MERGE_REQUEST_TARGET_BRANCH_NAME #MR CI" exit -1 fi @@ -42,15 +49,42 @@ if [ $? -eq 0 ]; then fi fi -scripts/connect_upstream_repo.sh $1 -git fetch upstream +scripts/connect_upstream_repo.sh $1 &> build/geo_check_connect_upstream_repo.log # Store logs in case of failure +git fetch upstream &> build/geo_check_fetch_upstream_repo.log # Store logs in case of failure BASE_COMMIT=upstream/$2 +CMAKE_FILE=external/InstallGeometry.cmake -GEO_HASH_CHANGE=`git diff --name-only $BASE_COMMIT | grep external/InstallGeometry.cmake | wc -l` -echo "export GEO_HASH_CHANGE=$GEO_HASH_CHANGE" >> Dart.cfg -if [[ $GEO_HASH_CHANGE -eq 0 ]]; then +GEO_SETUPS_CHANGE=`git diff --name-only $BASE_COMMIT | grep ${CMAKE_FILE} | wc -l` +if [[ $GEO_SETUPS_CHANGE -eq 0 ]]; then echo "No changes found to Geometry repository install script" else - echo "Changes found to Geometry repository install script, assuming hash was bumped or target repo/branch changed" + echo "Changes found to Geometry repository install script, checking if hash was bumped" + OLD_HASH=`git diff ${BASE_COMMIT} ${CMAKE_FILE} | grep '\-set' | grep -Po 'GEOMETRY_VERSION \s*\K\S*' | tr -d '()'` + NEW_HASH=`git diff ${BASE_COMMIT} ${CMAKE_FILE} | grep '\+set' | grep -Po 'GEOMETRY_VERSION \s*\K\S*' | tr -d '()'` + + if [[ -n ${OLD_HASH} && -n ${NEW_HASH} ]]; then + echo "Hash bumped, checking if some setup files were modified" + echo "Old hash: ${OLD_HASH}" + echo "New hash: ${NEW_HASH}" + + PWD_ORIG=`pwd` + cd geometry + git fetch origin + # Use : as temporary separator to avoid troubles with CMAKE strings/lists processing built-in functions + CHANGED_SETUPS=`git diff --name-only ${OLD_HASH} ${NEW_HASH} | grep setup | tr '\n' ':'` + cd ${PWD_ORIG} + if [[ -n ${CHANGED_SETUPS} ]]; then + echo "Some setups files were found to have been modified" + echo "Changed setups:" + echo "CMAKE_EXPORT CHANGED_SETUPS=$CHANGED_SETUPS" # Only way to pass values from script to parent cmake + else + echo "No setup found to have been modified" + GEO_SETUPS_CHANGE=0 + fi + else + echo "Hashes were not changed, modifications are in other part of cmake file" + GEO_SETUPS_CHANGE=0 + fi fi +echo "CMAKE_EXPORT GEO_SETUPS_CHANGE=$GEO_SETUPS_CHANGE" # Only way to pass values from script to parent cmake