Ignore:
Timestamp:
Jan 13, 2025, 4:52:20 PM (6 months ago)
Author:
jbclement
Message:

COMMON:
The compilation generates a Fortran subroutine to track compilation and version (SVN or Git) details through the executable file. Put the argument 'version' as an option when executing the code to display these information and create a file "version_diff.txt" containing the diff result.
It can work with every program but it has been implemented only for: 'gcm', 'parallel gcm', 'pem', '1D Mars PCM', 'Mars newstart', 'Mars start2archive' and '1D Generic PCM'.
JBC

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.COMMON/makelmdz_fcm

    r3499 r3574  
    7878########################################################################
    7979
     80# Get the compilation command
     81compilation_command="$(basename $0) $@"
     82
     83# Parse arguments and capture options
    8084while (($# > 0))
    8185  do
     
    120124 exec                      : executable to build
    121125fin
    122           exit;;
     126      exit;;
    123127
    124128      "-d")
    125           dim=$2 ; shift ; shift ;;
     129      dim=$2 ; shift ; shift ;;
    126130
    127131      "-p")
    128           physique="$2" ;  shift ; shift ;;
     132      physique="$2" ;  shift ; shift ;;
    129133
    130134      "-s")
    131           scatterers=$2 ; shift ; shift ;;
     135      scatterers=$2 ; shift ; shift ;;
    132136
    133137      "-b")
    134           bands=$2 ; shift ; shift ;;
     138      bands=$2 ; shift ; shift ;;
    135139
    136140      "-g")
    137           grille="$2" ; shift ; shift ;;
     141      grille="$2" ; shift ; shift ;;
    138142
    139143      "-c")
    140           couple="$2" ; shift ; shift ;;
     144      couple="$2" ; shift ; shift ;;
    141145
    142146      "-prod")
    143           compil_mod="prod" ; shift ;;
     147      compil_mod="prod" ; shift ;;
    144148
    145149      "-dev")
    146           compil_mod="dev" ; shift ;;
     150      compil_mod="dev" ; shift ;;
    147151
    148152      "-debug")
    149           compil_mod="debug" ; shift ;;
     153      compil_mod="debug" ; shift ;;
    150154
    151155      "-io")
    152           io="$2" ; shift ; shift ;;
     156      io="$2" ; shift ; shift ;;
    153157
    154158      "-v")
    155           veget="$2" ; shift ; shift ;;
     159      veget="$2" ; shift ; shift ;;
    156160
    157161      "-sisvat")
    158           sisvat="$2" ; shift ; shift ;;
     162      sisvat="$2" ; shift ; shift ;;
    159163
    160164      "-rrtm")
    161           rrtm="$2" ; shift ; shift ;;
     165      rrtm="$2" ; shift ; shift ;;
    162166
    163167      "-dust")
    164           dust="$2" ; shift ; shift ;;
     168      dust="$2" ; shift ; shift ;;
    165169
    166170      "-strataer")
    167           strataer="$2" ; shift ; shift ;;
     171      strataer="$2" ; shift ; shift ;;
    168172
    169173      "-chimie")
    170           chimie="$2" ; shift ; shift ;;
     174      chimie="$2" ; shift ; shift ;;
    171175
    172176      "-parallel")
    173           parallel="$2" ; shift ; shift ;;
     177      parallel="$2" ; shift ; shift ;;
    174178
    175179      "-include")
    176           INCLUDE_DIR="$INCLUDE_DIR -I$2" ; shift ; shift ;;
     180      INCLUDE_DIR="$INCLUDE_DIR -I$2" ; shift ; shift ;;
    177181
    178182      "-cpp")
    179           CPP_KEY="$CPP_KEY $2" ; shift ; shift ;;
     183      CPP_KEY="$CPP_KEY $2" ; shift ; shift ;;
    180184
    181185      "-adjnt")
    182           echo "not operational ... work to be done here ";exit 1
    183           opt_dep="$opt_dep adjnt" ; adjnt="-ladjnt -ldyn3d "
    184           optim="$optim -Dadj" ; shift ;;
     186      echo "not operational ... work to be done here ";exit 1
     187      opt_dep="$opt_dep adjnt" ; adjnt="-ladjnt -ldyn3d "
     188      optim="$optim -Dadj" ; shift ;;
    185189
    186190      "-cosp")
     
    191195
    192196      "-filtre")
    193           filtre=$2 ; shift ; shift ;;
     197      filtre=$2 ; shift ; shift ;;
    194198
    195199      "-link")
    196           LIB="$LIB $2" ; shift ; shift ;;
     200      LIB="$LIB $2" ; shift ; shift ;;
    197201
    198202      "-fcm_path")
    199           fcm_path=$2 ; shift ; shift ;;
     203      fcm_path=$2 ; shift ; shift ;;
    200204
    201205      "-ext_src")
    202           EXT_SRC=$2 ; shift ; shift ;;
     206      EXT_SRC=$2 ; shift ; shift ;;
    203207
    204208      "-j")
    205           job=$2 ; shift ; shift ;;
     209      job=$2 ; shift ; shift ;;
    206210
    207211      "-full")
    208           full="-full" ; shift ;;
     212      full="-full" ; shift ;;
    209213
    210214      "-libphy")
    211           libphy="true" ; shift ;;
     215      libphy="true" ; shift ;;
    212216
    213217      "-arch")
    214           arch=$2 ; arch_defined="TRUE" ; shift ; shift ;;
     218      arch=$2 ; arch_defined="TRUE" ; shift ; shift ;;
    215219
    216220      "-arch_path")
    217           arch_path=$2 ; arch_path_defined="TRUE"; shift ; shift ;;
     221      arch_path=$2 ; arch_path_defined="TRUE"; shift ; shift ;;
    218222
    219223      *)
    220           code="$1" ; shift ;;
     224      code="$1" ; shift ;;
    221225  esac
    222226done
     
    333337    if [[ "$couple" == "MPI1" ]]
    334338    then
    335         CPP_KEY="$CPP_KEY CPP_COUPLE"
    336         export OASIS_INCDIR=$LMDGCM/../../prism/X64/build/lib/psmile.MPI1
    337         export OASIS_LIBDIR=$LMDGCM/../../prism/X64/lib
    338         INCLUDE_DIR="$INCLUDE_DIR -I${OASIS_INCDIR}"
    339         LIB="$LIB -L${OASIS_LIBDIR} ${OASIS_LIB}"
     339    CPP_KEY="$CPP_KEY CPP_COUPLE"
     340    export OASIS_INCDIR=$LMDGCM/../../prism/X64/build/lib/psmile.MPI1
     341    export OASIS_LIBDIR=$LMDGCM/../../prism/X64/lib
     342    INCLUDE_DIR="$INCLUDE_DIR -I${OASIS_INCDIR}"
     343    LIB="$LIB -L${OASIS_LIBDIR} ${OASIS_LIB}"
    340344    else
    341         CPP_KEY="$CPP_KEY CPP_COUPLE CPP_OMCT"
    342         INCLUDE_DIR="$INCLUDE_DIR -I${OASIS_INCDIR}"
    343         LIB="$LIB -L${OASIS_LIBDIR} ${OASIS_LIB}"
     345    CPP_KEY="$CPP_KEY CPP_COUPLE CPP_OMCT"
     346    INCLUDE_DIR="$INCLUDE_DIR -I${OASIS_INCDIR}"
     347    LIB="$LIB -L${OASIS_LIBDIR} ${OASIS_LIB}"
    344348    fi
    345349fi
     
    588592  fi
    589593fi
     594
     595
     596########################################################################
     597# Generation of a Fortran subroutine to track compilation and version
     598# details through the executable file
     599########################################################################
     600
     601# Path and name of the generated file
     602info_file="$LIBFGCM/misc/version_info.F90"
     603
     604# Path and name of the file containing the difference result
     605diff_file="version_diff.txt"
     606
     607# Get the current date
     608current_date=$(date)
     609
     610# Determine version control system (SVN, Git or none)
     611if command -v svn > /dev/null && svn info > /dev/null 2>&1; then
     612    vcs="svn"
     613    vcs_info=$(svn info $LMDGCM/..)
     614    vcs_diff=$(svn diff $LMDGCM/..)
     615elif command -v git > /dev/null && git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
     616    vcs="git"
     617    vcs_info=$(git log -1 --pretty=format:"%H%n%an%n%ad%n%s" $LMDGCM/..)
     618    vcs_diff=$(git diff $LMDGCM/..)
     619else
     620    vcs="none"
     621fi
     622
     623# Function to escape the simple quotation sign
     624escape_signs() {
     625    echo "$1" | sed "s/'/''/g"
     626}
     627
     628# Generate the Fortran subroutine
     629cat << EOF > "$info_file"
     630!***********************************************************************
     631! File generated automatically at compilation
     632!
     633! DESCRIPTION:
     634!    The subroutine 'print_version_info' prints compilation details, the
     635!    version control information (SVN or Git) and the diff result if
     636!    applicable.
     637!
     638! PARAMETERS:
     639!    None.
     640!
     641! USAGE:
     642!    Put the argument 'version' as an option when executing the code to
     643!    display compilation and version details. It is useful for tracking
     644!    code builds through the executable file.
     645!***********************************************************************
     646
     647MODULE version_info_mod
     648
     649!=======================================================================
     650contains
     651!=======================================================================
     652
     653SUBROUTINE print_version_info()
     654
     655    write(*,*) '=== Compilation details ==='
     656    write(*,*) 'Date: ${current_date}'
     657    write(*,*) 'Command: ${compilation_command}'
     658    write(*,*)
     659EOF
     660
     661if [ "$vcs" == "svn" ]; then # SVN info
     662    echo "    write(*,*) '===== SVN Information ====='" >> "$info_file"
     663    while IFS= read -r line; do
     664        echo "    write(*,*) '${line//\"/\\\"}'" >> "$info_file"
     665    done <<< "$vcs_info"
     666    echo "    write(*,*)" >> "$info_file"
     667    echo "    write(*,*) '======== SVN Diff ========='" >> "$info_file"
     668    echo "    write(*,*) 'Writing SVN diff to file: ${diff_file}'" >> "$info_file"
     669    echo "    open(unit = 1,file = \"${diff_file}\",status = 'replace')" >> "$info_file"
     670    while IFS= read -r line; do
     671        escaped_line=$(escape_signs "$line")
     672        echo "    write(1,*) '${escaped_line//\"/\\\"}'" >> "$info_file"
     673    done <<< "$vcs_diff"
     674    echo "    close(1)" >> "$info_file"
     675
     676
     677elif [ "$vcs" == "git" ]; then # Git info
     678    echo "    write(*,*) '===== Git Information ====='" >> "$info_file"
     679    while IFS= read -r line; do
     680        echo "    write(*,*) \"${line//\"/\\\"}\"" >> "$info_file"
     681    done <<< "$vcs_info"
     682    echo "    write(*,*)" >> "$info_file"
     683    echo "    write(*,*) '======== Git Diff ========='" >> "$info_file"
     684    echo "    write(*,*) 'Writing Git diff to file: ${diff_file}'" >> "$info_file"
     685    while IFS= read -r line; do
     686        escaped_line=$(escape_signs "$line")
     687        echo "    write(1,*) '${escaped_line//\"/\\\"}'" >> "$info_file"
     688    done <<< "$vcs_diff"
     689    echo "    close(1)" >> "$info_file"
     690else # Non-versioned code
     691    echo "    write(*,*) 'No version control information available.'" >> "$info_file"
     692fi
     693    echo "    write(*,*) '==========================='" >> "$info_file"
     694
     695cat << EOF >> "$info_file"
     696
     697END SUBROUTINE print_version_info
     698
     699END MODULE version_info_mod
     700EOF
     701
     702# Termination message
     703echo "'$info_file' has been successfully generated."
    590704
    591705
Note: See TracChangeset for help on using the changeset viewer.