Skip to content

Commit

Permalink
AMREX_RELEASE_NUMBER (#2448)
Browse files Browse the repository at this point in the history
Add a new macro `AMREX_RELEASE_NUMBER`.  It is a six digits number.  The
first two are for the year, and the next two are for the month.  The last
two are usually 00, unless a patch other than the monthly release is
released.  If the AMReX source is a git version that's not the release
version, the last release number will be used.

For git version obtained with git --describe, we define something like

    #define AMREX_GIT_VERSION "21.10-65-gfbb2edc95551-dirty"
    #define AMREX_RELEASE_NUMBER 211000

For git version obtained from the CHANGES file, we define something like

    #define AMREX_GIT_VERSION "21.10"
    #define AMREX_RELEASE_NUMBER 211000

or

    #define AMREX_GIT_VERSION "21.10.1"
    #define AMREX_RELEASE_NUMBER 2110001

or

    #define AMREX_GIT_VERSION "21.10.11"
    #define AMREX_RELEASE_NUMBER 211011
  • Loading branch information
WeiqunZhang authored Dec 1, 2021
1 parent 1d50bfc commit ef9a37d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Tools/CMake/AMReXConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ set(AMReX_BUILD_TYPE @CMAKE_BUILD_TYPE@)
#
set(AMReX_GIT_VERSION \"@AMREX_GIT_VERSION@\")

#
# Release number
#
set(AMReX_RELEASE_NUMBER @AMREX_RELEASE_NUMBER@)

#
# AMReX CMake modules PATH
#
Expand Down
3 changes: 3 additions & 0 deletions Tools/CMake/AMReXSetDefines.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ include(AMReXGenerateConfigHeader) # provides add_amrex_defines
# Git version
add_amrex_define( "AMREX_GIT_VERSION=\"${AMREX_GIT_VERSION}\"" NO_LEGACY )

# Release number
add_amrex_define( "AMREX_RELEASE_NUMBER=${AMREX_RELEASE_NUMBER}" NO_LEGACY )

# XSDK mode
add_amrex_define( AMREX_XSDK NO_LEGACY IF USE_XSDK_DEFAULTS )

Expand Down
29 changes: 27 additions & 2 deletions Tools/CMake/AMReXUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# FUNCTION: get_amrex_version
#
# Retrieves AMReX version info and sets internal cache variables
# AMREX_GIT_VERSION and AMREX_PKG_VERSION
# AMREX_GIT_VERSION, AMREX_RELEASE_NUMBER, and AMREX_PKG_VERSION
#
#
function (get_amrex_version)
Expand All @@ -30,7 +30,11 @@ function (get_amrex_version)
list(GET ALL_VERSIONS 0 _tmp)
string(REPLACE "#" "" _tmp "${_tmp}")
string(STRIP "${_tmp}" _tmp )
set(_tmp "${_tmp}.0")
string(SUBSTRING "{_tmp}" 5 -1 _tmp2)
if (NOT _tmp2) # don't want to add `.0` if it is already something like 21.10.2
set(_tmp "${_tmp}.0")
endif ()
unset(_tmp2)
endif ()

set( AMREX_GIT_VERSION "${_tmp}" CACHE INTERNAL "" )
Expand All @@ -48,6 +52,27 @@ function (get_amrex_version)
set( AMREX_PKG_VERSION "${_pkg_version}" CACHE INTERNAL "" )
unset(_pkg_version)

if (AMREX_GIT_VERSION)
string(FIND "${AMREX_GIT_VERSION}" "-" _idx)
string(SUBSTRING "${AMREX_GIT_VERSION}" 0 "${_idx}" _rel_number )
string(REPLACE "." "" _rel_number "${_rel_number}")
string(SUBSTRING "${_rel_number}" 0 4 _rel_yymm)
string(SUBSTRING "${_rel_number}" 4 2 _rel_patch)
string(LENGTH "${_rel_patch}" _rel_patch_len)
if (_rel_patch_len EQUAL 0)
string(PREPEND _rel_patch "00")
elseif (_rel_patch_len EQUAL 1)
string(PREPEND _rel_patch "00")
endif ()
string(CONCAT _rel_number "${_rel_yymm}" "${_rel_patch}")
unset(_rel_yymm)
unset(_rel_patch)
unset(_rel_patch_len)
endif ()

set( AMREX_RELEASE_NUMBER "${_rel_number}" CACHE INTERNAL "" )
unset(_rel_number)

endfunction ()


Expand Down
1 change: 1 addition & 0 deletions Tools/CMake/AMReX_Config.H.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef AMREX_CONFIG_H_
#define AMREX_CONFIG_H_
#cmakedefine AMREX_GIT_VERSION @AMREX_GIT_VERSION@
#cmakedefine AMREX_RELEASE_NUMBER @AMREX_RELEASE_NUMBER@
#cmakedefine AMREX_XSDK
#cmakedefine AMREX_DEBUG
#cmakedefine AMREX_PROFILING
Expand Down
25 changes: 25 additions & 0 deletions Tools/GNUMake/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,31 @@ ifndef AMREX_GIT_VERSION
endif
DEFINES += -DAMREX_GIT_VERSION=\"$(AMREX_GIT_VERSION)\"

ifeq ($(findstring ., $(AMREX_GIT_VERSION)), .)
amrex_release_string := $(AMREX_GIT_VERSION)
else
# AMREX_GIT_VERSION obtained from a shallow clone does not have the release version
amrex_release_string := $(shell grep -o -m 1 -E "[0-9]{2}\.[0-9]{2}(\.[0-9]+)?" $(AMREX_HOME)/CHANGES)
endif
amrex_release_words := $(subst ., ,$(firstword $(subst -, ,$(amrex_release_string))))
amrex_release_numwords := $(words $(amrex_release_words))
ifneq ($(amrex_release_numwords),2)
ifneq ($(amrex_release_numwords),3)
amrex_release_numwords := 3
amrex_release_words := 00 00 00
endif
endif
amrex_release_yy := $(word 1, $(amrex_release_words))
amrex_release_mm := $(word 2, $(amrex_release_words))
ifeq ($(amrex_release_numwords),2)
AMREX_RELEASE_NUMBER := $(amrex_release_yy)$(amrex_release_mm)00
else
amrex_release_patch := $(shell printf '%02d' $(word 3, $(amrex_release_words)) | cut -c-2)
AMREX_RELEASE_NUMBER := $(amrex_release_yy)$(amrex_release_mm)$(amrex_release_patch)
endif
DEFINES += -DAMREX_RELEASE_NUMBER=$(AMREX_RELEASE_NUMBER)


FORTLINK = UNDERSCORE

FORT_CPP = cpp -E -traditional-cpp -P
Expand Down

0 comments on commit ef9a37d

Please sign in to comment.