diff --git a/.gitignore b/.gitignore index 02650eccfd..7bf426e527 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ Makefile !developer_tests/time_manager/Makefile !developer_tests/mpi_utilities/tests/Makefile build_templates/mkmf.template +build_templates/version_mod.f90 dart_log.* mkmf.template input.nml.*default diff --git a/assimilation_code/programs/preprocess/path_names_preprocess b/assimilation_code/programs/preprocess/path_names_preprocess index 55156d5ce3..7ac864b932 100644 --- a/assimilation_code/programs/preprocess/path_names_preprocess +++ b/assimilation_code/programs/preprocess/path_names_preprocess @@ -3,5 +3,5 @@ assimilation_code/modules/utilities/parse_args_mod.f90 assimilation_code/modules/utilities/time_manager_mod.f90 assimilation_code/modules/utilities/types_mod.f90 assimilation_code/modules/utilities/utilities_mod.f90 -build_templates/version_mod.F90 +build_templates/version_mod.f90 assimilation_code/programs/preprocess/preprocess.f90 diff --git a/build_templates/buildconvfunctions.sh b/build_templates/buildconvfunctions.sh index 56d14c2428..07e9f98c17 100644 --- a/build_templates/buildconvfunctions.sh +++ b/build_templates/buildconvfunctions.sh @@ -35,7 +35,6 @@ mpisrc="null_mpi" m="" LIBRARIES="" EXTRA="" -version_def="" source "$DART"/build_templates/buildpreprocess.sh dartversion @@ -117,7 +116,7 @@ local misc="$DART/models/utilities/ \ $DART/assimilation_code/modules/observations/obs_sequence_mod.f90 \ $DART/assimilation_code/modules/observations/forward_operator_mod.f90 \ $DART/observations/obs_converters/utilities/obs_utilities_mod.f90 \ - $DART/build_templates/version_mod.F90" + $DART/build_templates/version_mod.f90" local obserrsrc=$DART/observations/obs_converters/obs_error/$OBS_ERROR"_obs_err_mod.f90" # remove null/mpi from list @@ -192,7 +191,7 @@ else mkmf_libs="" fi - $DART/build_templates/mkmf -c $version_def -a $DART -x $m $mkmf_libs -p $(basename $1) \ + $DART/build_templates/mkmf -a $DART -x $m $mkmf_libs -p $(basename $1) \ $EXTRA \ $convsrc \ $program \ diff --git a/build_templates/buildfunctions.sh b/build_templates/buildfunctions.sh index fa94e0d9ce..5bebb4b582 100644 --- a/build_templates/buildfunctions.sh +++ b/build_templates/buildfunctions.sh @@ -34,7 +34,6 @@ EXTRA="" EXCLUDE="" TEST="" dev_test=0 -version_def="" declare -a programs declare -a serial_programs @@ -156,7 +155,7 @@ local misc="$DART/models/utilities/ \ $DART/assimilation_code/modules/observations/obs_kind_mod.f90 \ $DART/assimilation_code/modules/observations/obs_sequence_mod.f90 \ $DART/assimilation_code/modules/observations/forward_operator_mod.f90 \ - $DART/build_templates/version_mod.F90" + $DART/build_templates/version_mod.f90" # The quantity_mod.f90 files are in assimilation_code/modules/observations # so adding individual files from assimilation_code/modules/observations @@ -242,7 +241,7 @@ else devlibs=$DART/developer_tests/contrib/fortran-testanything fi - $DART/build_templates/mkmf -c $version_def -x -a $DART $m -p $1 \ + $DART/build_templates/mkmf -x -a $DART $m -p $1 \ $dartsrc \ $EXTRA \ $devlibs \ @@ -255,7 +254,7 @@ fi #------------------------- function buildlib() { findsrc -$DART/build_templates/mkmf -c $version_def -x -a $DART $m -p $1 \ +$DART/build_templates/mkmf -x -a $DART $m -p $1 \ $dartsrc \ $EXTRA } @@ -266,7 +265,7 @@ $DART/build_templates/mkmf -c $version_def -x -a $DART $m -p $1 \ # program name #------------------------- function modelbuild() { - $DART/build_templates/mkmf -c $version_def -x -a $DART $m -p $(basename $1) $DART/models/$MODEL/$1.f90 \ + $DART/build_templates/mkmf -x -a $DART $m -p $(basename $1) $DART/models/$MODEL/$1.f90 \ $EXTRA \ $dartsrc } diff --git a/build_templates/buildpreprocess.sh b/build_templates/buildpreprocess.sh index 4116e67034..425793ed69 100644 --- a/build_templates/buildpreprocess.sh +++ b/build_templates/buildpreprocess.sh @@ -5,27 +5,80 @@ # http://www.image.ucar.edu/DAReS/DART/DART_download #------------------------- -# Build and run preprocess -# Arguements: +# Generate build_templates/version_mod.f90 with the version from git describe. +# Arguments: # none # Globals: # DART - root of DART #------------------------- function dartversion() { -local git_version +local git_version out tmp +git_version="" if command -v git >/dev/null 2>&1 && [ -e "$DART/.git" ]; then - git_version=$(cd "$DART" && git describe --tags --dirty --always 2>/dev/null || echo "version_unknown") -else - git_version="version_unknown" + git_version=$(cd "$DART" && git describe --tags --dirty --always 2>/dev/null) || git_version="" fi -# preprocessor definition for DART version -version_def="-DDART_VERSION=\"'$git_version'\"" +# The version becomes a Fortran character literal. +# Restrict it to characters that cannot break out of the quotes and cap length to 64 characters +git_version=$(printf '%s' "$git_version" | LC_ALL=C tr -c 'A-Za-z0-9._+-' '_' | cut -c1-64) +git_version="${git_version:-unknown}" + +out="$DART/build_templates/version_mod.f90" +tmp="$out.$$" + +cat > "$tmp" << EOF +! DART software - Copyright UCAR. This open source software is provided +! by UCAR, "as is", without charge, subject to all terms of use at +! http://www.image.ucar.edu/DAReS/DART/DART_download + +!> Module to provide version information for DART programs +!> +!> Generated at build time by dartversion() in +!> \$DART/build_templates/buildpreprocess.sh - do not edit, do not commit. + +module version_mod + +implicit none +private + +character(len=*), parameter :: dart_version_string = & + '$git_version' + +public :: get_dart_version + +contains + +! Return DART version in string +function get_dart_version() result(version) + +character(len=len(dart_version_string)) :: version + +version = dart_version_string + +end function get_dart_version + +end module version_mod +EOF + +# leave the file alone if the version has not changed, so make does not +# rebuild everything that uses version_mod on every build +if cmp -s "$tmp" "$out" ; then + \rm -f -- "$tmp" +else + mv -f -- "$tmp" "$out" +fi } +#------------------------- +# Build and run preprocess +# Arguements: +# none +# Globals: +# DART - root of DART +#------------------------- function buildpreprocess() { local pp_dir=$DART/assimilation_code/programs/preprocess @@ -45,7 +98,7 @@ fi # build preprocess, link, run cd $pp_dir - $DART/build_templates/mkmf -c $version_def -x -p $pp_dir/preprocess \ + $DART/build_templates/mkmf -x -p $pp_dir/preprocess \ -a $DART $pp_dir/path_names_preprocess cd - ln -s $pp_dir/preprocess . diff --git a/build_templates/version_mod.F90 b/build_templates/version_mod.F90 deleted file mode 100644 index 8865223649..0000000000 --- a/build_templates/version_mod.F90 +++ /dev/null @@ -1,38 +0,0 @@ -! DART software - Copyright UCAR. This open source software is provided -! by UCAR, "as is", without charge, subject to all terms of use at -! http://www.image.ucar.edu/DAReS/DART/DART_download - -!> Module to provide version information for DART programs -!> -!> This module stores the version information that is captured at build time -!> from git describe and provides a function to access it. - -module version_mod - -implicit none -private - -! Assign a preprocessor variable for the version, which we'll get using git -#ifndef DART_VERSION -#define DART_VERSION 'unknown' -#endif - -character(len=*), parameter :: dart_version_string = DART_VERSION - -public :: get_dart_version - -contains - -! Return DART version in string -function get_dart_version() result(version) - -character(len=len(dart_version_string)) :: version - -version = dart_version_string - -end function get_dart_version - - -end module version_mod - - diff --git a/developer_tests/build_everything/run_all_quickbuilds.sh b/developer_tests/build_everything/run_all_quickbuilds.sh index 2df673b94f..5a50b541d4 100755 --- a/developer_tests/build_everything/run_all_quickbuilds.sh +++ b/developer_tests/build_everything/run_all_quickbuilds.sh @@ -62,8 +62,10 @@ esac cp build_templates/$mkmf_template build_templates/mkmf.template -# Build preprocess once +# Build preprocess once, and get dart_version pp_dir=$DART/assimilation_code/programs/preprocess +source "$DART"/build_templates/buildpreprocess.sh +dartversion cd $pp_dir $DART/build_templates/mkmf -x -p $pp_dir/preprocess \ -a $DART $pp_dir/path_names_preprocess