From 577977955fd9da341100486fcb13a79a657e374b Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Tue, 24 Sep 2024 12:23:22 +0600 Subject: [PATCH 01/25] single source of truth for version identifier --- CMakeLists.txt | 25 +++++++++++++++++++++---- pyproject.toml | 5 ++++- tools/version.txt | 1 + 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 tools/version.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f4cc1b527b..4d95527a42d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,28 @@ cmake_minimum_required(VERSION 3.16 FATAL_ERROR) project(openmc C CXX) -# Set version numbers -set(OPENMC_VERSION_MAJOR 0) -set(OPENMC_VERSION_MINOR 15) -set(OPENMC_VERSION_RELEASE 1) +# Read the version information from version.txt +file(READ "tools/version.txt" VERSION_STRING) + +# Strip any whitespace +string(STRIP "${VERSION_STRING}" VERSION_STRING) + +# Match version format and capture the main version part +if(VERSION_STRING MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)(-[^ ]+)?$") + set(VERSION_NO_SUFFIX "${CMAKE_MATCH_1}") +else() + message(FATAL_ERROR "Invalid version format in version.txt: ${VERSION_STRING}") +endif() + +# Set OpenMC version +string(REPLACE "." ";" VERSION_LIST "${VERSION_NO_SUFFIX}") +list(GET VERSION_LIST 0 OPENMC_VERSION_MAJOR) +list(GET VERSION_LIST 1 OPENMC_VERSION_MINOR) +list(GET VERSION_LIST 2 OPENMC_VERSION_RELEASE) set(OPENMC_VERSION ${OPENMC_VERSION_MAJOR}.${OPENMC_VERSION_MINOR}.${OPENMC_VERSION_RELEASE}) +message(STATUS "OpenMC version: ${OPENMC_VERSION}") + +# Generate version.h configure_file(include/openmc/version.h.in "${CMAKE_BINARY_DIR}/include/openmc/version.h" @ONLY) # Setup output directories diff --git a/pyproject.toml b/pyproject.toml index 39aa261c1b4..083b4654bb3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ authors = [ {name = "The OpenMC Development Team", email = "openmc@anl.gov"}, ] description = "OpenMC" -version = "0.15.1-dev" +dynamic = ["version"] requires-python = ">=3.10" license = {file = "LICENSE"} classifiers = [ @@ -58,6 +58,9 @@ Documentation = "https://docs.openmc.org" Repository = "https://github.com/openmc-dev/openmc" Issues = "https://github.com/openmc-dev/openmc/issues" +[tool.setuptools.dynamic] +version = {file = "tools/version.txt"} + [tool.setuptools.packages.find] include = ['openmc*', 'scripts*'] exclude = ['tests*'] diff --git a/tools/version.txt b/tools/version.txt new file mode 100644 index 00000000000..bf222ecb47b --- /dev/null +++ b/tools/version.txt @@ -0,0 +1 @@ +1.15.1-dev \ No newline at end of file From 104dfb012c348a1b8303a04bad0b79ebf9989a70 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Fri, 27 Sep 2024 21:31:22 +0600 Subject: [PATCH 02/25] Follow PyPA compliant --- CMakeLists.txt | 2 +- tools/version.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d95527a42d..efd2a252885 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ file(READ "tools/version.txt" VERSION_STRING) string(STRIP "${VERSION_STRING}" VERSION_STRING) # Match version format and capture the main version part -if(VERSION_STRING MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)(-[^ ]+)?$") +if(VERSION_STRING MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)([-\\.]dev[0-9]*)?$") set(VERSION_NO_SUFFIX "${CMAKE_MATCH_1}") else() message(FATAL_ERROR "Invalid version format in version.txt: ${VERSION_STRING}") diff --git a/tools/version.txt b/tools/version.txt index bf222ecb47b..74365f62820 100644 --- a/tools/version.txt +++ b/tools/version.txt @@ -1 +1 @@ -1.15.1-dev \ No newline at end of file +1.15.1.dev1 \ No newline at end of file From cb849ee360db6105654d378478fe2c5413053ba1 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Fri, 27 Sep 2024 21:38:08 +0600 Subject: [PATCH 03/25] move version file to root-level --- CMakeLists.txt | 2 +- pyproject.toml | 2 +- tools/version.txt | 1 - version.txt | 1 + 4 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 tools/version.txt create mode 100644 version.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index efd2a252885..99b2efcab1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16 FATAL_ERROR) project(openmc C CXX) # Read the version information from version.txt -file(READ "tools/version.txt" VERSION_STRING) +file(READ "version.txt" VERSION_STRING) # Strip any whitespace string(STRIP "${VERSION_STRING}" VERSION_STRING) diff --git a/pyproject.toml b/pyproject.toml index 083b4654bb3..24dec8271a4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,7 @@ Repository = "https://github.com/openmc-dev/openmc" Issues = "https://github.com/openmc-dev/openmc/issues" [tool.setuptools.dynamic] -version = {file = "tools/version.txt"} +version = {file = "version.txt"} [tool.setuptools.packages.find] include = ['openmc*', 'scripts*'] diff --git a/tools/version.txt b/tools/version.txt deleted file mode 100644 index 74365f62820..00000000000 --- a/tools/version.txt +++ /dev/null @@ -1 +0,0 @@ -1.15.1.dev1 \ No newline at end of file diff --git a/version.txt b/version.txt new file mode 100644 index 00000000000..53013ddb21f --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.15.1.dev1 \ No newline at end of file From 0ce318c6f787c5d42e10d6497e9c422b21368ffb Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Fri, 27 Sep 2024 22:01:52 +0600 Subject: [PATCH 04/25] add get_version_info function --- docs/source/conf.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 726269f0b7c..3276b5c8652 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -68,10 +68,26 @@ # |version| and |release|, also used in various other places throughout the # built documents. # -# The short X.Y version. -version = "0.15" -# The full version, including alpha/beta/rc tags. -release = "0.15.1-dev" +def get_version_info(): + """Read the version information from version.txt""" + version_file = os.path.join(os.path.dirname(__file__), '..', '..', 'version.txt') + with open(version_file, 'r') as f: + version_string = f.read().strip() + + # Check for the presence of a development suffix (e.g., -dev or .dev) + if version_string.endswith(('-dev', '.dev')): + version_parts = version_string.split('-')[0].split('.') + release = version_string + else: + version_parts = version_string.split('.') + release = version_string + + version = ".".join(version_parts[:2]) # The short X.Y version. + + return version, release + +# Get version and release from version.txt +version, release = get_version_info() # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. From 23b93e34de3685021fb5cf54faced5703b6850a0 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Wed, 16 Oct 2024 21:50:44 +0600 Subject: [PATCH 05/25] add export config --- .git_archival.txt | 3 +++ .gitattributes | 1 + 2 files changed, 4 insertions(+) create mode 100644 .git_archival.txt create mode 100644 .gitattributes diff --git a/.git_archival.txt b/.git_archival.txt new file mode 100644 index 00000000000..b423033f9ea --- /dev/null +++ b/.git_archival.txt @@ -0,0 +1,3 @@ +node: $Format:%H$ +node-date: $Format:%cI$ +describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000000..82bf71c1c5b --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +.git_archival.txt export-subst \ No newline at end of file From 31e369292e629c4dde9d0b50af2d818139d01b9a Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Wed, 16 Oct 2024 22:18:16 +0600 Subject: [PATCH 06/25] remove version file --- CMakeLists.txt | 37 +++++++++++++++++++++++++++++-------- docs/source/conf.py | 28 ++++++++-------------------- pyproject.toml | 7 +++---- version.txt | 1 - 4 files changed, 40 insertions(+), 33 deletions(-) delete mode 100644 version.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c8760d89ff..77722962ad4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,38 @@ cmake_minimum_required(VERSION 3.16 FATAL_ERROR) project(openmc C CXX) -# Read the version information from version.txt -file(READ "version.txt" VERSION_STRING) - -# Strip any whitespace -string(STRIP "${VERSION_STRING}" VERSION_STRING) +# Try to get the version from git describe +if(EXISTS "${CMAKE_SOURCE_DIR}/.git") + execute_process( + COMMAND git describe --tags --match "*[0-9]*" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE VERSION_STRING + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +else() + set(GIT_ARCHIVAL_FILE "${CMAKE_SOURCE_DIR}/.git_archival.txt") + if(EXISTS "${GIT_ARCHIVAL_FILE}") + file(READ "${GIT_ARCHIVAL_FILE}" GIT_ARCHIVAL_CONTENT) + + # Extract the describe-name line + string(REGEX MATCH "describe-name: ([^\\n]+)" VERSION_STRING "${GIT_ARCHIVAL_CONTENT}") + + # If a match is found, extract the actual version + if(VERSION_STRING MATCHES "describe-name: (.*)") + set(VERSION_STRING "${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "Could not extract version from .git_archival.txt") + endif() + else() + message(FATAL_ERROR "Neither git describe nor .git_archival.txt is available for versioning.") + endif() +endif() -# Match version format and capture the main version part +# Ensure the version string matches a standard format if(VERSION_STRING MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)([-\\.]dev[0-9]*)?$") - set(VERSION_NO_SUFFIX "${CMAKE_MATCH_1}") + set(VERSION_NO_SUFFIX "${CMAKE_MATCH_1}") else() - message(FATAL_ERROR "Invalid version format in version.txt: ${VERSION_STRING}") + message(FATAL_ERROR "Invalid version format: ${VERSION_STRING}") endif() # Set OpenMC version diff --git a/docs/source/conf.py b/docs/source/conf.py index 3276b5c8652..5ec4677480c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -68,26 +68,14 @@ # |version| and |release|, also used in various other places throughout the # built documents. # -def get_version_info(): - """Read the version information from version.txt""" - version_file = os.path.join(os.path.dirname(__file__), '..', '..', 'version.txt') - with open(version_file, 'r') as f: - version_string = f.read().strip() - - # Check for the presence of a development suffix (e.g., -dev or .dev) - if version_string.endswith(('-dev', '.dev')): - version_parts = version_string.split('-')[0].split('.') - release = version_string - else: - version_parts = version_string.split('.') - release = version_string - - version = ".".join(version_parts[:2]) # The short X.Y version. - - return version, release - -# Get version and release from version.txt -version, release = get_version_info() + +import openmc + +# The short X.Y version. +version = ".".join(openmc.__version__.split('.')[:2]) + +# The full version, including alpha/beta/rc tags. +release = openmc.__version__ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/pyproject.toml b/pyproject.toml index 24dec8271a4..4250172d078 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools", "wheel"] +requires = ["setuptools", "setuptools-scm", "wheel"] build-backend = "setuptools.build_meta" [project] @@ -58,9 +58,6 @@ Documentation = "https://docs.openmc.org" Repository = "https://github.com/openmc-dev/openmc" Issues = "https://github.com/openmc-dev/openmc/issues" -[tool.setuptools.dynamic] -version = {file = "version.txt"} - [tool.setuptools.packages.find] include = ['openmc*', 'scripts*'] exclude = ['tests*'] @@ -70,6 +67,8 @@ exclude = ['tests*'] "openmc.data" = ["*.txt", "*.DAT", "*.json", "*.h5"] "openmc.lib" = ["libopenmc.dylib", "libopenmc.so"] +[tool.setuptools_scm] + [project.scripts] openmc-ace-to-hdf5 = "scripts.openmc_ace_to_hdf5:main" openmc-plot-mesh-tally = "scripts.openmc_plot_mesh_tally:main" diff --git a/version.txt b/version.txt deleted file mode 100644 index 53013ddb21f..00000000000 --- a/version.txt +++ /dev/null @@ -1 +0,0 @@ -0.15.1.dev1 \ No newline at end of file From d6be0ff6a8673f30b8fba842f4bf797792a39906 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Wed, 16 Oct 2024 22:28:46 +0600 Subject: [PATCH 07/25] Ensure the version string matches a standard format --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77722962ad4..21a36f3b83d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(openmc C CXX) # Try to get the version from git describe if(EXISTS "${CMAKE_SOURCE_DIR}/.git") execute_process( - COMMAND git describe --tags --match "*[0-9]*" + COMMAND git describe --tags --match "*[0-9]*" --dirty WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE @@ -29,7 +29,7 @@ else() endif() # Ensure the version string matches a standard format -if(VERSION_STRING MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)([-\\.]dev[0-9]*)?$") +if(VERSION_STRING MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)([-].*)?") set(VERSION_NO_SUFFIX "${CMAKE_MATCH_1}") else() message(FATAL_ERROR "Invalid version format: ${VERSION_STRING}") From 8bc99cdaaf74b1ee675d93318cba74f299a49039 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Wed, 16 Oct 2024 23:08:12 +0600 Subject: [PATCH 08/25] set fetch depth to zero --- .github/workflows/ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5973c3cd48d..8c599081323 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,8 +87,11 @@ jobs: RDMAV_FORK_SAFE: 1 steps: - - uses: actions/checkout@v4 - + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: From 521940629917d1cab68a364b4c897b90571094ef Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Sun, 12 Jan 2025 11:25:46 +0600 Subject: [PATCH 09/25] add hash --- .git_archival.txt | 1 + CMakeLists.txt | 26 ++++++++++++++++++++++++++ include/openmc/version.h.in | 3 ++- src/output.cpp | 6 +++--- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/.git_archival.txt b/.git_archival.txt index b423033f9ea..eb7c3675b2d 100644 --- a/.git_archival.txt +++ b/.git_archival.txt @@ -1,3 +1,4 @@ node: $Format:%H$ +short-node: $Format:%h$ node-date: $Format:%cI$ describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 21a36f3b83d..24ff538a739 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,12 +3,21 @@ project(openmc C CXX) # Try to get the version from git describe if(EXISTS "${CMAKE_SOURCE_DIR}/.git") + # Extract the tag execute_process( COMMAND git describe --tags --match "*[0-9]*" --dirty WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE ) + + # Extract the abbreviated hash + execute_process( + COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE ABBREVIATED_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) else() set(GIT_ARCHIVAL_FILE "${CMAKE_SOURCE_DIR}/.git_archival.txt") if(EXISTS "${GIT_ARCHIVAL_FILE}") @@ -23,6 +32,16 @@ else() else() message(FATAL_ERROR "Could not extract version from .git_archival.txt") endif() + + # Extract the abbreviated hash + string(REGEX MATCH "short-node: ([a-f0-9]+)" ABBREVIATED_HASH "${GIT_ARCHIVAL_CONTENT}") + + # If a abbreviated hash is found, use it + if(ABBREVIATED_HASH MATCHES "short-node: ([a-f0-9]+)") + set(ABBREVIATED_HASH "${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "Could not extract abbreviated hash from .git_archival.txt") + endif() else() message(FATAL_ERROR "Neither git describe nor .git_archival.txt is available for versioning.") endif() @@ -31,6 +50,11 @@ endif() # Ensure the version string matches a standard format if(VERSION_STRING MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)([-].*)?") set(VERSION_NO_SUFFIX "${CMAKE_MATCH_1}") + if(VERSION_STRING MATCHES "-.*") + set(VERSION_DEV_SUFFIX "true") + else() + set(VERSION_DEV_SUFFIX "false") + endif() else() message(FATAL_ERROR "Invalid version format: ${VERSION_STRING}") endif() @@ -42,6 +66,8 @@ list(GET VERSION_LIST 1 OPENMC_VERSION_MINOR) list(GET VERSION_LIST 2 OPENMC_VERSION_RELEASE) set(OPENMC_VERSION ${OPENMC_VERSION_MAJOR}.${OPENMC_VERSION_MINOR}.${OPENMC_VERSION_RELEASE}) message(STATUS "OpenMC version: ${OPENMC_VERSION}") +message(STATUS "OpenMC development version: ${VERSION_DEV_SUFFIX}") +message(STATUS "OpenMC version hash: ${ABBREVIATED_HASH}") # Generate version.h configure_file(include/openmc/version.h.in "${CMAKE_BINARY_DIR}/include/openmc/version.h" @ONLY) diff --git a/include/openmc/version.h.in b/include/openmc/version.h.in index e1c2b0541a5..aa153d06894 100644 --- a/include/openmc/version.h.in +++ b/include/openmc/version.h.in @@ -10,7 +10,8 @@ namespace openmc { constexpr int VERSION_MAJOR {@OPENMC_VERSION_MAJOR@}; constexpr int VERSION_MINOR {@OPENMC_VERSION_MINOR@}; constexpr int VERSION_RELEASE {@OPENMC_VERSION_RELEASE@}; -constexpr bool VERSION_DEV {true}; +constexpr bool VERSION_DEV {@VERSION_DEV_SUFFIX@}; +constexpr const char* VERSION_HASH = "@ABBREVIATED_HASH@"; constexpr std::array VERSION {VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE}; // clang-format on diff --git a/src/output.cpp b/src/output.cpp index a430fe9a6c6..a8306ff3cc9 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -75,10 +75,10 @@ void title() // Write version information fmt::print( " | The OpenMC Monte Carlo Code\n" - " Copyright | 2011-2024 MIT, UChicago Argonne LLC, and contributors\n" + " Copyright | 2011-2025 MIT, UChicago Argonne LLC, and contributors\n" " License | https://docs.openmc.org/en/latest/license.html\n" - " Version | {}.{}.{}{}\n", - VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE, VERSION_DEV ? "-dev" : ""); + " Version | {}.{}.{}{} ({})\n", + VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE, VERSION_DEV ? "-dev" : "", VERSION_HASH); #ifdef GIT_SHA1 fmt::print(" Git SHA1 | {}\n", GIT_SHA1); #endif From d4b37cf641bb92dc68583aaa14605818ec31cc47 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Sun, 12 Jan 2025 11:32:29 +0600 Subject: [PATCH 10/25] Add more log --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 24ff538a739..c323a71433c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project(openmc C CXX) # Try to get the version from git describe if(EXISTS "${CMAKE_SOURCE_DIR}/.git") + message(STATUS "Using git describe for versioning") # Extract the tag execute_process( COMMAND git describe --tags --match "*[0-9]*" --dirty @@ -19,6 +20,7 @@ if(EXISTS "${CMAKE_SOURCE_DIR}/.git") OUTPUT_STRIP_TRAILING_WHITESPACE ) else() + message(STATUS "Using .git_archival.txt for versioning") set(GIT_ARCHIVAL_FILE "${CMAKE_SOURCE_DIR}/.git_archival.txt") if(EXISTS "${GIT_ARCHIVAL_FILE}") file(READ "${GIT_ARCHIVAL_FILE}" GIT_ARCHIVAL_CONTENT) From 160bf43d7376bac5106e6579421aae9921eea9a4 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Sun, 12 Jan 2025 11:41:59 +0600 Subject: [PATCH 11/25] clang format --- src/output.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/output.cpp b/src/output.cpp index a8306ff3cc9..6df902a4e65 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -78,7 +78,8 @@ void title() " Copyright | 2011-2025 MIT, UChicago Argonne LLC, and contributors\n" " License | https://docs.openmc.org/en/latest/license.html\n" " Version | {}.{}.{}{} ({})\n", - VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE, VERSION_DEV ? "-dev" : "", VERSION_HASH); + VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE, VERSION_DEV ? "-dev" : "", + VERSION_HASH); #ifdef GIT_SHA1 fmt::print(" Git SHA1 | {}\n", GIT_SHA1); #endif From 2b47355f24dabcc1110d5c892839097e911b6675 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Sun, 12 Jan 2025 16:14:42 +0600 Subject: [PATCH 12/25] Find git at the beginning --- .git_archival.txt | 5 ++--- CMakeLists.txt | 45 ++++++++++++++----------------------- include/openmc/version.h.in | 4 ++-- src/output.cpp | 19 ++++++---------- 4 files changed, 28 insertions(+), 45 deletions(-) diff --git a/.git_archival.txt b/.git_archival.txt index eb7c3675b2d..f2f118c0d67 100644 --- a/.git_archival.txt +++ b/.git_archival.txt @@ -1,4 +1,3 @@ -node: $Format:%H$ -short-node: $Format:%h$ -node-date: $Format:%cI$ +commit: $Format:%H$ +commit-date: $Format:%cI$ describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index c323a71433c..d2b3fbd30e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,11 @@ cmake_minimum_required(VERSION 3.16 FATAL_ERROR) project(openmc C CXX) +# Find git +find_package(Git) + # Try to get the version from git describe -if(EXISTS "${CMAKE_SOURCE_DIR}/.git") +if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND GIT_FOUND) message(STATUS "Using git describe for versioning") # Extract the tag execute_process( @@ -12,11 +15,11 @@ if(EXISTS "${CMAKE_SOURCE_DIR}/.git") OUTPUT_STRIP_TRAILING_WHITESPACE ) - # Extract the abbreviated hash + # Extract the commit hash execute_process( - COMMAND git rev-parse --short HEAD + COMMAND git rev-parse HEAD WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE ABBREVIATED_HASH + OUTPUT_VARIABLE COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE ) else() @@ -35,14 +38,14 @@ else() message(FATAL_ERROR "Could not extract version from .git_archival.txt") endif() - # Extract the abbreviated hash - string(REGEX MATCH "short-node: ([a-f0-9]+)" ABBREVIATED_HASH "${GIT_ARCHIVAL_CONTENT}") + # Extract the commit hash + string(REGEX MATCH "commit: ([a-f0-9]+)" COMMIT_HASH "${GIT_ARCHIVAL_CONTENT}") - # If a abbreviated hash is found, use it - if(ABBREVIATED_HASH MATCHES "short-node: ([a-f0-9]+)") - set(ABBREVIATED_HASH "${CMAKE_MATCH_1}") + # If a commit hash is found, use it + if(COMMIT_HASH MATCHES "commit: ([a-f0-9]+)") + set(COMMIT_HASH "${CMAKE_MATCH_1}") else() - message(FATAL_ERROR "Could not extract abbreviated hash from .git_archival.txt") + message(FATAL_ERROR "Could not extract commit hash from .git_archival.txt") endif() else() message(FATAL_ERROR "Neither git describe nor .git_archival.txt is available for versioning.") @@ -53,9 +56,9 @@ endif() if(VERSION_STRING MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)([-].*)?") set(VERSION_NO_SUFFIX "${CMAKE_MATCH_1}") if(VERSION_STRING MATCHES "-.*") - set(VERSION_DEV_SUFFIX "true") + set(VERSION_DEV "true") else() - set(VERSION_DEV_SUFFIX "false") + set(VERSION_DEV "false") endif() else() message(FATAL_ERROR "Invalid version format: ${VERSION_STRING}") @@ -68,8 +71,8 @@ list(GET VERSION_LIST 1 OPENMC_VERSION_MINOR) list(GET VERSION_LIST 2 OPENMC_VERSION_RELEASE) set(OPENMC_VERSION ${OPENMC_VERSION_MAJOR}.${OPENMC_VERSION_MINOR}.${OPENMC_VERSION_RELEASE}) message(STATUS "OpenMC version: ${OPENMC_VERSION}") -message(STATUS "OpenMC development version: ${VERSION_DEV_SUFFIX}") -message(STATUS "OpenMC version hash: ${ABBREVIATED_HASH}") +message(STATUS "OpenMC development version: ${VERSION_DEV}") +message(STATUS "OpenMC commit hash: ${COMMIT_HASH}") # Generate version.h configure_file(include/openmc/version.h.in "${CMAKE_BINARY_DIR}/include/openmc/version.h" @ONLY) @@ -287,8 +290,6 @@ endif() #=============================================================================== # Update git submodules as needed #=============================================================================== - -find_package(Git) if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") option(GIT_SUBMODULE "Check submodules during build" ON) if(GIT_SUBMODULE) @@ -550,18 +551,6 @@ if (OPENMC_USE_MPI) target_compile_definitions(libopenmc PUBLIC -DOPENMC_MPI) endif() -# Set git SHA1 hash as a compile definition -if(GIT_FOUND) - execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - RESULT_VARIABLE GIT_SHA1_SUCCESS - OUTPUT_VARIABLE GIT_SHA1 - ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) - if(GIT_SHA1_SUCCESS EQUAL 0) - target_compile_definitions(libopenmc PRIVATE -DGIT_SHA1="${GIT_SHA1}") - endif() -endif() - # target_link_libraries treats any arguments starting with - but not -l as # linker flags. Thus, we can pass both linker flags and libraries together. target_link_libraries(libopenmc ${ldflags} ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES} diff --git a/include/openmc/version.h.in b/include/openmc/version.h.in index aa153d06894..2a8e045be3f 100644 --- a/include/openmc/version.h.in +++ b/include/openmc/version.h.in @@ -10,8 +10,8 @@ namespace openmc { constexpr int VERSION_MAJOR {@OPENMC_VERSION_MAJOR@}; constexpr int VERSION_MINOR {@OPENMC_VERSION_MINOR@}; constexpr int VERSION_RELEASE {@OPENMC_VERSION_RELEASE@}; -constexpr bool VERSION_DEV {@VERSION_DEV_SUFFIX@}; -constexpr const char* VERSION_HASH = "@ABBREVIATED_HASH@"; +constexpr bool VERSION_DEV {@VERSION_DEV@}; +constexpr const char* COMMIT_HASH = "@COMMIT_HASH@"; constexpr std::array VERSION {VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE}; // clang-format on diff --git a/src/output.cpp b/src/output.cpp index 6df902a4e65..267c73a85c4 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -77,12 +77,9 @@ void title() " | The OpenMC Monte Carlo Code\n" " Copyright | 2011-2025 MIT, UChicago Argonne LLC, and contributors\n" " License | https://docs.openmc.org/en/latest/license.html\n" - " Version | {}.{}.{}{} ({})\n", - VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE, VERSION_DEV ? "-dev" : "", - VERSION_HASH); -#ifdef GIT_SHA1 - fmt::print(" Git SHA1 | {}\n", GIT_SHA1); -#endif + " Version | {}.{}.{}{}\n", + VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE, VERSION_DEV ? "-dev" : ""); + fmt::print(" Commit Hash | {}\n", COMMIT_HASH); // Write the date and time fmt::print(" Date/Time | {}\n", time_stamp()); @@ -292,12 +289,10 @@ void print_usage() void print_version() { if (mpi::master) { - fmt::print("OpenMC version {}.{}.{}\n", VERSION_MAJOR, VERSION_MINOR, - VERSION_RELEASE); -#ifdef GIT_SHA1 - fmt::print("Git SHA1: {}\n", GIT_SHA1); -#endif - fmt::print("Copyright (c) 2011-2024 MIT, UChicago Argonne LLC, and " + fmt::print("OpenMC version {}.{}.{}{}\n", VERSION_MAJOR, VERSION_MINOR, + VERSION_RELEASE, VERSION_DEV ? "-dev" : ""); + fmt::print("Commit hash: {}\n", COMMIT_HASH); + fmt::print("Copyright (c) 2011-2025 MIT, UChicago Argonne LLC, and " "contributors\nMIT/X license at " "\n"); } From 923f84a39edfe8a6287a5cc764bab8ccc4eebc53 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Sun, 19 Jan 2025 23:09:48 +0600 Subject: [PATCH 13/25] add VERSION_COMMIT_COUNT --- CMakeLists.txt | 67 ++++++++++++++++++++++--------------- include/openmc/version.h.in | 3 +- src/mcpl_interface.cpp | 4 +-- src/output.cpp | 13 +++---- 4 files changed, 51 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2b3fbd30e0..f992f3c4f70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,20 +8,20 @@ find_package(Git) if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND GIT_FOUND) message(STATUS "Using git describe for versioning") # Extract the tag - execute_process( - COMMAND git describe --tags --match "*[0-9]*" --dirty - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE VERSION_STRING - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - # Extract the commit hash - execute_process( - COMMAND git rev-parse HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE COMMIT_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE - ) + execute_process( + COMMAND git describe --tags --match "*[0-9]*" --dirty + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE VERSION_STRING + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + # Extract the commit hash + execute_process( + COMMAND git rev-parse HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE VERSION_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) else() message(STATUS "Using .git_archival.txt for versioning") set(GIT_ARCHIVAL_FILE "${CMAKE_SOURCE_DIR}/.git_archival.txt") @@ -39,29 +39,40 @@ else() endif() # Extract the commit hash - string(REGEX MATCH "commit: ([a-f0-9]+)" COMMIT_HASH "${GIT_ARCHIVAL_CONTENT}") + string(REGEX MATCH "commit: ([a-f0-9]+)" VERSION_COMMIT_HASH "${GIT_ARCHIVAL_CONTENT}") # If a commit hash is found, use it - if(COMMIT_HASH MATCHES "commit: ([a-f0-9]+)") - set(COMMIT_HASH "${CMAKE_MATCH_1}") + if(VERSION_COMMIT_HASH MATCHES "commit: ([a-f0-9]+)") + set(VERSION_COMMIT_HASH "${CMAKE_MATCH_1}") else() - message(FATAL_ERROR "Could not extract commit hash from .git_archival.txt") + message(VERSION_COMMIT_HASH "Could not extract commit hash from .git_archival.txt") endif() else() message(FATAL_ERROR "Neither git describe nor .git_archival.txt is available for versioning.") endif() endif() -# Ensure the version string matches a standard format -if(VERSION_STRING MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)([-].*)?") - set(VERSION_NO_SUFFIX "${CMAKE_MATCH_1}") - if(VERSION_STRING MATCHES "-.*") +# Ensure the version string matches the standard format +# Step 1: Match and extract the base version (major.minor.release) +if(VERSION_STRING MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)") + set(VERSION_NO_SUFFIX "${CMAKE_MATCH_1}") +else() + message(FATAL_ERROR "Invalid version format: Missing base version in ${VERSION_STRING}") +endif() + +# Step 2: Check for commit count +if(VERSION_STRING MATCHES "-([0-9]+)-g([0-9a-f]+)") set(VERSION_DEV "true") - else() + set(VERSION_COMMIT_COUNT "${CMAKE_MATCH_1}") +else() set(VERSION_DEV "false") - endif() +endif() + +# Step 3: Check for dirty state +if(VERSION_STRING MATCHES "-dirty") + set(VERSION_DIRTY "true") else() - message(FATAL_ERROR "Invalid version format: ${VERSION_STRING}") + set(VERSION_DIRTY "false") endif() # Set OpenMC version @@ -71,8 +82,10 @@ list(GET VERSION_LIST 1 OPENMC_VERSION_MINOR) list(GET VERSION_LIST 2 OPENMC_VERSION_RELEASE) set(OPENMC_VERSION ${OPENMC_VERSION_MAJOR}.${OPENMC_VERSION_MINOR}.${OPENMC_VERSION_RELEASE}) message(STATUS "OpenMC version: ${OPENMC_VERSION}") -message(STATUS "OpenMC development version: ${VERSION_DEV}") -message(STATUS "OpenMC commit hash: ${COMMIT_HASH}") +message(STATUS "OpenMC dev state: ${VERSION_DEV}") +message(STATUS "OpenMC commit count: ${VERSION_COMMIT_COUNT}") +message(STATUS "OpenMC commit hash: ${VERSION_COMMIT_HASH}") +message(STATUS "OpenMC dirty state: ${VERSION_DIRTY}") # Generate version.h configure_file(include/openmc/version.h.in "${CMAKE_BINARY_DIR}/include/openmc/version.h" @ONLY) diff --git a/include/openmc/version.h.in b/include/openmc/version.h.in index 2a8e045be3f..d9142b69fa7 100644 --- a/include/openmc/version.h.in +++ b/include/openmc/version.h.in @@ -11,7 +11,8 @@ constexpr int VERSION_MAJOR {@OPENMC_VERSION_MAJOR@}; constexpr int VERSION_MINOR {@OPENMC_VERSION_MINOR@}; constexpr int VERSION_RELEASE {@OPENMC_VERSION_RELEASE@}; constexpr bool VERSION_DEV {@VERSION_DEV@}; -constexpr const char* COMMIT_HASH = "@COMMIT_HASH@"; +constexpr const char* VERSION_COMMIT_COUNT = "@VERSION_COMMIT_COUNT@"; +constexpr const char* VERSION_COMMIT_HASH = "@VERSION_COMMIT_HASH@"; constexpr std::array VERSION {VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE}; // clang-format on diff --git a/src/mcpl_interface.cpp b/src/mcpl_interface.cpp index 5c3df026ce5..5a1cd26ad3e 100644 --- a/src/mcpl_interface.cpp +++ b/src/mcpl_interface.cpp @@ -207,8 +207,8 @@ void write_mcpl_source_point(const char* filename, if (mpi::master) { file_id = mcpl_create_outfile(filename_.c_str()); if (VERSION_DEV) { - line = fmt::format("OpenMC {0}.{1}.{2}-development", VERSION_MAJOR, - VERSION_MINOR, VERSION_RELEASE); + line = fmt::format("OpenMC {0}.{1}.{2}-dev{3}", VERSION_MAJOR, + VERSION_MINOR, VERSION_RELEASE, VERSION_COMMIT_COUNT); } else { line = fmt::format( "OpenMC {0}.{1}.{2}", VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE); diff --git a/src/output.cpp b/src/output.cpp index 267c73a85c4..42c983a13c7 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -77,9 +77,10 @@ void title() " | The OpenMC Monte Carlo Code\n" " Copyright | 2011-2025 MIT, UChicago Argonne LLC, and contributors\n" " License | https://docs.openmc.org/en/latest/license.html\n" - " Version | {}.{}.{}{}\n", - VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE, VERSION_DEV ? "-dev" : ""); - fmt::print(" Commit Hash | {}\n", COMMIT_HASH); + " Version | {}.{}.{}{}{}\n", + VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE, VERSION_DEV ? "-dev" : "", + VERSION_COMMIT_COUNT); + fmt::print(" Commit Hash | {}\n", VERSION_COMMIT_HASH); // Write the date and time fmt::print(" Date/Time | {}\n", time_stamp()); @@ -289,9 +290,9 @@ void print_usage() void print_version() { if (mpi::master) { - fmt::print("OpenMC version {}.{}.{}{}\n", VERSION_MAJOR, VERSION_MINOR, - VERSION_RELEASE, VERSION_DEV ? "-dev" : ""); - fmt::print("Commit hash: {}\n", COMMIT_HASH); + fmt::print("OpenMC version {}.{}.{}{}{}\n", VERSION_MAJOR, VERSION_MINOR, + VERSION_RELEASE, VERSION_DEV ? "-dev" : "", VERSION_COMMIT_COUNT); + fmt::print("Commit hash: {}\n", VERSION_COMMIT_HASH); fmt::print("Copyright (c) 2011-2025 MIT, UChicago Argonne LLC, and " "contributors\nMIT/X license at " "\n"); From 07c65a3023479876899bc4c86eb0e51d718447a2 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Thu, 23 Jan 2025 19:04:48 +0600 Subject: [PATCH 14/25] Increment release number for dev versions --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f992f3c4f70..abcff5bb5bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,11 @@ string(REPLACE "." ";" VERSION_LIST "${VERSION_NO_SUFFIX}") list(GET VERSION_LIST 0 OPENMC_VERSION_MAJOR) list(GET VERSION_LIST 1 OPENMC_VERSION_MINOR) list(GET VERSION_LIST 2 OPENMC_VERSION_RELEASE) + +# Increment release number for dev versions +if(VERSION_DEV) + math(EXPR OPENMC_VERSION_RELEASE "${OPENMC_VERSION_RELEASE} + 1") +endif() set(OPENMC_VERSION ${OPENMC_VERSION_MAJOR}.${OPENMC_VERSION_MINOR}.${OPENMC_VERSION_RELEASE}) message(STATUS "OpenMC version: ${OPENMC_VERSION}") message(STATUS "OpenMC dev state: ${VERSION_DEV}") From 21594d6fc213ee28013a848be8fc0b629a415559 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Mon, 27 Jan 2025 01:35:20 +0600 Subject: [PATCH 15/25] Move versioning to a separate file, as suggested by @gonuke --- CMakeLists.txt | 100 ++-------------------- cmake/Modules/GetVersionFromGit.cmake | 117 ++++++++++++++++++++++++++ include/openmc/version.h.in | 12 +-- 3 files changed, 132 insertions(+), 97 deletions(-) create mode 100644 cmake/Modules/GetVersionFromGit.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index abcff5bb5bb..4e8e77019f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,96 +1,17 @@ cmake_minimum_required(VERSION 3.16 FATAL_ERROR) project(openmc C CXX) -# Find git -find_package(Git) - -# Try to get the version from git describe -if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND GIT_FOUND) - message(STATUS "Using git describe for versioning") - # Extract the tag - execute_process( - COMMAND git describe --tags --match "*[0-9]*" --dirty - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE VERSION_STRING - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - # Extract the commit hash - execute_process( - COMMAND git rev-parse HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE VERSION_COMMIT_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE - ) -else() - message(STATUS "Using .git_archival.txt for versioning") - set(GIT_ARCHIVAL_FILE "${CMAKE_SOURCE_DIR}/.git_archival.txt") - if(EXISTS "${GIT_ARCHIVAL_FILE}") - file(READ "${GIT_ARCHIVAL_FILE}" GIT_ARCHIVAL_CONTENT) - - # Extract the describe-name line - string(REGEX MATCH "describe-name: ([^\\n]+)" VERSION_STRING "${GIT_ARCHIVAL_CONTENT}") - - # If a match is found, extract the actual version - if(VERSION_STRING MATCHES "describe-name: (.*)") - set(VERSION_STRING "${CMAKE_MATCH_1}") - else() - message(FATAL_ERROR "Could not extract version from .git_archival.txt") - endif() - - # Extract the commit hash - string(REGEX MATCH "commit: ([a-f0-9]+)" VERSION_COMMIT_HASH "${GIT_ARCHIVAL_CONTENT}") - - # If a commit hash is found, use it - if(VERSION_COMMIT_HASH MATCHES "commit: ([a-f0-9]+)") - set(VERSION_COMMIT_HASH "${CMAKE_MATCH_1}") - else() - message(VERSION_COMMIT_HASH "Could not extract commit hash from .git_archival.txt") - endif() - else() - message(FATAL_ERROR "Neither git describe nor .git_archival.txt is available for versioning.") - endif() -endif() - -# Ensure the version string matches the standard format -# Step 1: Match and extract the base version (major.minor.release) -if(VERSION_STRING MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)") - set(VERSION_NO_SUFFIX "${CMAKE_MATCH_1}") -else() - message(FATAL_ERROR "Invalid version format: Missing base version in ${VERSION_STRING}") -endif() - -# Step 2: Check for commit count -if(VERSION_STRING MATCHES "-([0-9]+)-g([0-9a-f]+)") - set(VERSION_DEV "true") - set(VERSION_COMMIT_COUNT "${CMAKE_MATCH_1}") -else() - set(VERSION_DEV "false") -endif() +# Set module path +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) -# Step 3: Check for dirty state -if(VERSION_STRING MATCHES "-dirty") - set(VERSION_DIRTY "true") -else() - set(VERSION_DIRTY "false") -endif() +include(GetVersionFromGit) -# Set OpenMC version -string(REPLACE "." ";" VERSION_LIST "${VERSION_NO_SUFFIX}") -list(GET VERSION_LIST 0 OPENMC_VERSION_MAJOR) -list(GET VERSION_LIST 1 OPENMC_VERSION_MINOR) -list(GET VERSION_LIST 2 OPENMC_VERSION_RELEASE) - -# Increment release number for dev versions -if(VERSION_DEV) - math(EXPR OPENMC_VERSION_RELEASE "${OPENMC_VERSION_RELEASE} + 1") -endif() -set(OPENMC_VERSION ${OPENMC_VERSION_MAJOR}.${OPENMC_VERSION_MINOR}.${OPENMC_VERSION_RELEASE}) -message(STATUS "OpenMC version: ${OPENMC_VERSION}") -message(STATUS "OpenMC dev state: ${VERSION_DEV}") -message(STATUS "OpenMC commit count: ${VERSION_COMMIT_COUNT}") -message(STATUS "OpenMC commit hash: ${VERSION_COMMIT_HASH}") -message(STATUS "OpenMC dirty state: ${VERSION_DIRTY}") +# Output version information +message(STATUS "OpenMC version: ${PROJECT_VERSION}") +message(STATUS "OpenMC dev state: ${PROJECT_DEV_STATE}") +message(STATUS "OpenMC commit hash: ${PROJECT_COMMIT_HASH}") +message(STATUS "OpenMC commit count: ${PROJECT_COMMIT_COUNT}") +message(STATUS "OpenMC dirty state: ${PROJECT_DIRTY_STATE}") # Generate version.h configure_file(include/openmc/version.h.in "${CMAKE_BINARY_DIR}/include/openmc/version.h" @ONLY) @@ -100,9 +21,6 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -# Set module path -set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) - # Enable correct usage of CXX_EXTENSIONS if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.22) cmake_policy(SET CMP0128 NEW) diff --git a/cmake/Modules/GetVersionFromGit.cmake b/cmake/Modules/GetVersionFromGit.cmake new file mode 100644 index 00000000000..445344597ad --- /dev/null +++ b/cmake/Modules/GetVersionFromGit.cmake @@ -0,0 +1,117 @@ +# GetVersionFromGit.cmake +# Standalone script to retrieve versioning information from Git or .git_archival.txt. +# Customizable for any project by setting variables before including this file. + +# Configurable variables (set these in your main CMakeLists.txt if needed): +# - VERSION_PREFIX: Prefix for version tags (default: "v"). +# - VERSION_SURFIX: Suffix for version tags (default: "[~+-]([a-zA-Z0-9]+)"). +# - VERSION_REGEX: Regex to extract version (default: "[0-9]+\\.[0-9]+\\.[0-9]+"). +# - ARCHIVAL_FILE: Path to .git_archival.txt (default: "${CMAKE_SOURCE_DIR}/.git_archival.txt"). + +set(VERSION_PREFIX "v" CACHE STRING "Prefix used in version tags") +set(VERSION_SURFIX "[~+-]([a-zA-Z0-9]+)" CACHE STRING "Suffix used in version tags") +set(VERSION_REGEX "?([0-9]+\\.[0-9]+\\.[0-9]+)" CACHE STRING "Regex for extracting version") +set(ARCHIVAL_FILE "${CMAKE_SOURCE_DIR}/.git_archival.txt" CACHE STRING "Path to .git_archival.txt") + + +set(VERSION_REGEX_WITH_PREFIX "^${VERSION_PREFIX}${VERSION_REGEX}") + +# Ensure Git is available +find_package(Git REQUIRED) + +# Attempt to retrieve version from Git +if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND GIT_FOUND) + message(STATUS "Using git describe for versioning") + + # Extract the version string + execute_process( + COMMAND git describe --tags --dirty + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE VERSION_STRING + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + # Extract the commit hash + execute_process( + COMMAND git rev-parse HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +else() + message(STATUS "Using archival file for versioning: ${ARCHIVAL_FILE}") + if(EXISTS "${ARCHIVAL_FILE}") + file(READ "${ARCHIVAL_FILE}" ARCHIVAL_CONTENT) + + # Extract the describe-name line + string(REGEX MATCH "describe-name: ([^\\n]+)" VERSION_STRING "${ARCHIVAL_CONTENT}") + if(VERSION_STRING MATCHES "describe-name: (.*)") + set(VERSION_STRING "${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "Could not extract version from ${ARCHIVAL_FILE}") + endif() + + # Extract the commit hash + string(REGEX MATCH "commit: ([a-f0-9]+)" COMMIT_HASH "${ARCHIVAL_CONTENT}") + if(COMMIT_HASH MATCHES "commit: ([a-f0-9]+)") + set(COMMIT_HASH "${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "Could not extract commit hash from ${ARCHIVAL_FILE}") + endif() + else() + message(FATAL_ERROR "Neither git describe nor ${ARCHIVAL_FILE} is available for versioning.") + endif() +endif() + +# Ensure version string format +if(VERSION_STRING MATCHES "${VERSION_REGEX_WITH_PREFIX}") + set(VERSION_NO_SUFFIX "${CMAKE_MATCH_1}") +else() + message(FATAL_ERROR "Invalid version format: Missing base version in ${VERSION_STRING}") +endif() + +# Check for development state +if(VERSION_STRING MATCHES "-([0-9]+)-g([0-9a-f]+)") + set(DEV_STATE "true") + set(COMMIT_COUNT "${CMAKE_MATCH_1}") + string(REGEX REPLACE "-([0-9]+)-g([0-9a-f]+)" "" VERSION_WITHOUT_META "${VERSION_STRING}") +else() + set(DEV_STATE "false") + set(VERSION_WITHOUT_META "${VERSION_STRING}") +endif() + +# Check for dirty state +if(VERSION_STRING MATCHES "-dirty") + set(DIRTY_STATE "true") +else() + set(DIRTY_STATE "false") +endif() + +# Check for extra version +if(VERSION_WITHOUT_META MATCHES "${VERSION_SURFIX}") + set(VERSION_EXTRA "${CMAKE_MATCH_1}") +else() + set(VERSION_EXTRA "") +endif() + +# Split and set version components +string(REPLACE "." ";" VERSION_LIST "${VERSION_NO_SUFFIX}") +list(GET VERSION_LIST 0 VERSION_MAJOR) +list(GET VERSION_LIST 1 VERSION_MINOR) +list(GET VERSION_LIST 2 VERSION_PATCH) + +# Increment patch number for dev versions +if(DEV_STATE) + math(EXPR VERSION_PATCH "${VERSION_PATCH} + 1") +endif() + +# Export variables +set(PROJECT_VERSION_MAJOR "${VERSION_MAJOR}") +set(PROJECT_VERSION_MINOR "${VERSION_MINOR}") +set(PROJECT_VERSION_PATCH "${VERSION_PATCH}") +set(PROJECT_VERSION_EXTRA "${VERSION_EXTRA}") +set(PROJECT_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") +set(PROJECT_COMMIT_HASH "${COMMIT_HASH}") +set(PROJECT_DIRTY_STATE "${DIRTY_STATE}") +set(PROJECT_DEV_STATE "${DEV_STATE}") +set(PROJECT_COMMIT_COUNT "${COMMIT_COUNT}") diff --git a/include/openmc/version.h.in b/include/openmc/version.h.in index d9142b69fa7..24e361c9dff 100644 --- a/include/openmc/version.h.in +++ b/include/openmc/version.h.in @@ -7,12 +7,12 @@ namespace openmc { // OpenMC major, minor, and release numbers // clang-format off -constexpr int VERSION_MAJOR {@OPENMC_VERSION_MAJOR@}; -constexpr int VERSION_MINOR {@OPENMC_VERSION_MINOR@}; -constexpr int VERSION_RELEASE {@OPENMC_VERSION_RELEASE@}; -constexpr bool VERSION_DEV {@VERSION_DEV@}; -constexpr const char* VERSION_COMMIT_COUNT = "@VERSION_COMMIT_COUNT@"; -constexpr const char* VERSION_COMMIT_HASH = "@VERSION_COMMIT_HASH@"; +constexpr int VERSION_MAJOR {@PROJECT_VERSION_MAJOR@}; +constexpr int VERSION_MINOR {@PROJECT_VERSION_MINOR@}; +constexpr int VERSION_RELEASE {@PROJECT_VERSION_PATCH@}; +constexpr bool VERSION_DEV {@PROJECT_DEV_STATE@}; +constexpr const char* VERSION_COMMIT_COUNT = "@PROJECT_COMMIT_COUNT@"; +constexpr const char* VERSION_COMMIT_HASH = "@PROJECT_COMMIT_HASH@"; constexpr std::array VERSION {VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE}; // clang-format on From 14e678f25f34ad813b07cc7a2a7dd94131ecaaf1 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Mon, 27 Jan 2025 01:41:24 +0600 Subject: [PATCH 16/25] add more info --- cmake/Modules/GetVersionFromGit.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/GetVersionFromGit.cmake b/cmake/Modules/GetVersionFromGit.cmake index 445344597ad..f71894bf7fd 100644 --- a/cmake/Modules/GetVersionFromGit.cmake +++ b/cmake/Modules/GetVersionFromGit.cmake @@ -5,9 +5,11 @@ # Configurable variables (set these in your main CMakeLists.txt if needed): # - VERSION_PREFIX: Prefix for version tags (default: "v"). # - VERSION_SURFIX: Suffix for version tags (default: "[~+-]([a-zA-Z0-9]+)"). -# - VERSION_REGEX: Regex to extract version (default: "[0-9]+\\.[0-9]+\\.[0-9]+"). +# - VERSION_REGEX: Regex to extract version (default: "(?[0-9]+\\.[0-9]+\\.[0-9]+)"). # - ARCHIVAL_FILE: Path to .git_archival.txt (default: "${CMAKE_SOURCE_DIR}/.git_archival.txt"). +# Default Format Example: 1.2.3 v1.2.3 v1.2.3-rc1 + set(VERSION_PREFIX "v" CACHE STRING "Prefix used in version tags") set(VERSION_SURFIX "[~+-]([a-zA-Z0-9]+)" CACHE STRING "Suffix used in version tags") set(VERSION_REGEX "?([0-9]+\\.[0-9]+\\.[0-9]+)" CACHE STRING "Regex for extracting version") From dc28e2a76c69aa8bd014e85f4a913a236c9de826 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Mon, 27 Jan 2025 20:27:46 +0600 Subject: [PATCH 17/25] Update cmake/Modules/GetVersionFromGit.cmake Co-authored-by: Paul Wilson --- cmake/Modules/GetVersionFromGit.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/GetVersionFromGit.cmake b/cmake/Modules/GetVersionFromGit.cmake index f71894bf7fd..b7ebf058805 100644 --- a/cmake/Modules/GetVersionFromGit.cmake +++ b/cmake/Modules/GetVersionFromGit.cmake @@ -11,7 +11,7 @@ # Default Format Example: 1.2.3 v1.2.3 v1.2.3-rc1 set(VERSION_PREFIX "v" CACHE STRING "Prefix used in version tags") -set(VERSION_SURFIX "[~+-]([a-zA-Z0-9]+)" CACHE STRING "Suffix used in version tags") +set(VERSION_SUFFIX "[~+-]([a-zA-Z0-9]+)" CACHE STRING "Suffix used in version tags") set(VERSION_REGEX "?([0-9]+\\.[0-9]+\\.[0-9]+)" CACHE STRING "Regex for extracting version") set(ARCHIVAL_FILE "${CMAKE_SOURCE_DIR}/.git_archival.txt" CACHE STRING "Path to .git_archival.txt") From e2a64d79be1d39f693809d73899b2b1be89223c5 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Mon, 27 Jan 2025 20:27:56 +0600 Subject: [PATCH 18/25] Update cmake/Modules/GetVersionFromGit.cmake Co-authored-by: Paul Wilson --- cmake/Modules/GetVersionFromGit.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/GetVersionFromGit.cmake b/cmake/Modules/GetVersionFromGit.cmake index b7ebf058805..f412ac7bed2 100644 --- a/cmake/Modules/GetVersionFromGit.cmake +++ b/cmake/Modules/GetVersionFromGit.cmake @@ -90,7 +90,7 @@ else() endif() # Check for extra version -if(VERSION_WITHOUT_META MATCHES "${VERSION_SURFIX}") +if(VERSION_WITHOUT_META MATCHES "${VERSION_SUFFIX}") set(VERSION_EXTRA "${CMAKE_MATCH_1}") else() set(VERSION_EXTRA "") From 1603dc545da94ed9414c2b03bcf5faef33b2c826 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Tue, 28 Jan 2025 00:05:19 +0600 Subject: [PATCH 19/25] add more variables --- cmake/Modules/GetVersionFromGit.cmake | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cmake/Modules/GetVersionFromGit.cmake b/cmake/Modules/GetVersionFromGit.cmake index f412ac7bed2..10ec11d6651 100644 --- a/cmake/Modules/GetVersionFromGit.cmake +++ b/cmake/Modules/GetVersionFromGit.cmake @@ -2,20 +2,26 @@ # Standalone script to retrieve versioning information from Git or .git_archival.txt. # Customizable for any project by setting variables before including this file. -# Configurable variables (set these in your main CMakeLists.txt if needed): +# Configurable variables: # - VERSION_PREFIX: Prefix for version tags (default: "v"). # - VERSION_SURFIX: Suffix for version tags (default: "[~+-]([a-zA-Z0-9]+)"). # - VERSION_REGEX: Regex to extract version (default: "(?[0-9]+\\.[0-9]+\\.[0-9]+)"). # - ARCHIVAL_FILE: Path to .git_archival.txt (default: "${CMAKE_SOURCE_DIR}/.git_archival.txt"). +# - DESCRIBE_NAME_KEY: Key for describe name in .git_archival.txt (default: "describe-name: "). +# - COMMIT_HASH_KEY: Key for commit hash in .git_archival.txt (default: "commit: "). -# Default Format Example: 1.2.3 v1.2.3 v1.2.3-rc1 +# Default Format Example: +# 1.2.3 v1.2.3 v1.2.3-rc1 set(VERSION_PREFIX "v" CACHE STRING "Prefix used in version tags") set(VERSION_SUFFIX "[~+-]([a-zA-Z0-9]+)" CACHE STRING "Suffix used in version tags") set(VERSION_REGEX "?([0-9]+\\.[0-9]+\\.[0-9]+)" CACHE STRING "Regex for extracting version") set(ARCHIVAL_FILE "${CMAKE_SOURCE_DIR}/.git_archival.txt" CACHE STRING "Path to .git_archival.txt") +set(DESCRIBE_NAME_KEY "describe-name: " CACHE STRING "Key for describe name in .git_archival.txt") +set(COMMIT_HASH_KEY "commit: " CACHE STRING "Key for commit hash in .git_archival.txt") +# Combine prefix and regex set(VERSION_REGEX_WITH_PREFIX "^${VERSION_PREFIX}${VERSION_REGEX}") # Ensure Git is available @@ -46,16 +52,16 @@ else() file(READ "${ARCHIVAL_FILE}" ARCHIVAL_CONTENT) # Extract the describe-name line - string(REGEX MATCH "describe-name: ([^\\n]+)" VERSION_STRING "${ARCHIVAL_CONTENT}") - if(VERSION_STRING MATCHES "describe-name: (.*)") + string(REGEX MATCH "${DESCRIBE_NAME_KEY}([^\\n]+)" VERSION_STRING "${ARCHIVAL_CONTENT}") + if(VERSION_STRING MATCHES "${DESCRIBE_NAME_KEY}(.*)") set(VERSION_STRING "${CMAKE_MATCH_1}") else() message(FATAL_ERROR "Could not extract version from ${ARCHIVAL_FILE}") endif() # Extract the commit hash - string(REGEX MATCH "commit: ([a-f0-9]+)" COMMIT_HASH "${ARCHIVAL_CONTENT}") - if(COMMIT_HASH MATCHES "commit: ([a-f0-9]+)") + string(REGEX MATCH "${COMMIT_HASH_KEY}([a-f0-9]+)" COMMIT_HASH "${ARCHIVAL_CONTENT}") + if(COMMIT_HASH MATCHES "${COMMIT_HASH_KEY}([a-f0-9]+)") set(COMMIT_HASH "${CMAKE_MATCH_1}") else() message(FATAL_ERROR "Could not extract commit hash from ${ARCHIVAL_FILE}") @@ -116,4 +122,4 @@ set(PROJECT_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") set(PROJECT_COMMIT_HASH "${COMMIT_HASH}") set(PROJECT_DIRTY_STATE "${DIRTY_STATE}") set(PROJECT_DEV_STATE "${DEV_STATE}") -set(PROJECT_COMMIT_COUNT "${COMMIT_COUNT}") +set(PROJECT_COMMIT_COUNT "${COMMIT_COUNT}") \ No newline at end of file From 9dc344e66a84338c0e626b6901db4546ceed8071 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Wed, 29 Jan 2025 19:37:50 +0600 Subject: [PATCH 20/25] Update cmake/Modules/GetVersionFromGit.cmake Co-authored-by: Paul Wilson --- cmake/Modules/GetVersionFromGit.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/GetVersionFromGit.cmake b/cmake/Modules/GetVersionFromGit.cmake index 10ec11d6651..14927c5191f 100644 --- a/cmake/Modules/GetVersionFromGit.cmake +++ b/cmake/Modules/GetVersionFromGit.cmake @@ -4,7 +4,7 @@ # Configurable variables: # - VERSION_PREFIX: Prefix for version tags (default: "v"). -# - VERSION_SURFIX: Suffix for version tags (default: "[~+-]([a-zA-Z0-9]+)"). +# - VERSION_SUFFIX: Suffix for version tags (default: "[~+-]([a-zA-Z0-9]+)"). # - VERSION_REGEX: Regex to extract version (default: "(?[0-9]+\\.[0-9]+\\.[0-9]+)"). # - ARCHIVAL_FILE: Path to .git_archival.txt (default: "${CMAKE_SOURCE_DIR}/.git_archival.txt"). # - DESCRIBE_NAME_KEY: Key for describe name in .git_archival.txt (default: "describe-name: "). From a2942f621dc0411c567362308730adf82c180b88 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 20 Feb 2025 13:26:33 -0600 Subject: [PATCH 21/25] Don't use PROJECT_ variable names --- CMakeLists.txt | 10 +++++----- cmake/Modules/GetVersionFromGit.cmake | 24 ++++++++++++------------ include/openmc/version.h.in | 12 ++++++------ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 030c64200ff..26b6eb5d369 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,11 +7,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) include(GetVersionFromGit) # Output version information -message(STATUS "OpenMC version: ${PROJECT_VERSION}") -message(STATUS "OpenMC dev state: ${PROJECT_DEV_STATE}") -message(STATUS "OpenMC commit hash: ${PROJECT_COMMIT_HASH}") -message(STATUS "OpenMC commit count: ${PROJECT_COMMIT_COUNT}") -message(STATUS "OpenMC dirty state: ${PROJECT_DIRTY_STATE}") +message(STATUS "OpenMC version: ${OPENMC_VERSION}") +message(STATUS "OpenMC dev state: ${OPENMC_DEV_STATE}") +message(STATUS "OpenMC commit hash: ${OPENMC_COMMIT_HASH}") +message(STATUS "OpenMC commit count: ${OPENMC_COMMIT_COUNT}") +message(STATUS "OpenMC dirty state: ${OPENMC_DIRTY_STATE}") # Generate version.h configure_file(include/openmc/version.h.in "${CMAKE_BINARY_DIR}/include/openmc/version.h" @ONLY) diff --git a/cmake/Modules/GetVersionFromGit.cmake b/cmake/Modules/GetVersionFromGit.cmake index 14927c5191f..4d5b6ec7d32 100644 --- a/cmake/Modules/GetVersionFromGit.cmake +++ b/cmake/Modules/GetVersionFromGit.cmake @@ -10,8 +10,8 @@ # - DESCRIBE_NAME_KEY: Key for describe name in .git_archival.txt (default: "describe-name: "). # - COMMIT_HASH_KEY: Key for commit hash in .git_archival.txt (default: "commit: "). -# Default Format Example: -# 1.2.3 v1.2.3 v1.2.3-rc1 +# Default Format Example: +# 1.2.3 v1.2.3 v1.2.3-rc1 set(VERSION_PREFIX "v" CACHE STRING "Prefix used in version tags") set(VERSION_SUFFIX "[~+-]([a-zA-Z0-9]+)" CACHE STRING "Suffix used in version tags") @@ -30,7 +30,7 @@ find_package(Git REQUIRED) # Attempt to retrieve version from Git if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND GIT_FOUND) message(STATUS "Using git describe for versioning") - + # Extract the version string execute_process( COMMAND git describe --tags --dirty @@ -114,12 +114,12 @@ if(DEV_STATE) endif() # Export variables -set(PROJECT_VERSION_MAJOR "${VERSION_MAJOR}") -set(PROJECT_VERSION_MINOR "${VERSION_MINOR}") -set(PROJECT_VERSION_PATCH "${VERSION_PATCH}") -set(PROJECT_VERSION_EXTRA "${VERSION_EXTRA}") -set(PROJECT_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") -set(PROJECT_COMMIT_HASH "${COMMIT_HASH}") -set(PROJECT_DIRTY_STATE "${DIRTY_STATE}") -set(PROJECT_DEV_STATE "${DEV_STATE}") -set(PROJECT_COMMIT_COUNT "${COMMIT_COUNT}") \ No newline at end of file +set(OPENMC_VERSION_MAJOR "${VERSION_MAJOR}") +set(OPENMC_VERSION_MINOR "${VERSION_MINOR}") +set(OPENMC_VERSION_PATCH "${VERSION_PATCH}") +set(OPENMC_VERSION_EXTRA "${VERSION_EXTRA}") +set(OPENMC_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") +set(OPENMC_COMMIT_HASH "${COMMIT_HASH}") +set(OPENMC_DIRTY_STATE "${DIRTY_STATE}") +set(OPENMC_DEV_STATE "${DEV_STATE}") +set(OPENMC_COMMIT_COUNT "${COMMIT_COUNT}") diff --git a/include/openmc/version.h.in b/include/openmc/version.h.in index 24e361c9dff..6dfc7c7dd67 100644 --- a/include/openmc/version.h.in +++ b/include/openmc/version.h.in @@ -7,12 +7,12 @@ namespace openmc { // OpenMC major, minor, and release numbers // clang-format off -constexpr int VERSION_MAJOR {@PROJECT_VERSION_MAJOR@}; -constexpr int VERSION_MINOR {@PROJECT_VERSION_MINOR@}; -constexpr int VERSION_RELEASE {@PROJECT_VERSION_PATCH@}; -constexpr bool VERSION_DEV {@PROJECT_DEV_STATE@}; -constexpr const char* VERSION_COMMIT_COUNT = "@PROJECT_COMMIT_COUNT@"; -constexpr const char* VERSION_COMMIT_HASH = "@PROJECT_COMMIT_HASH@"; +constexpr int VERSION_MAJOR {@OPENMC_VERSION_MAJOR@}; +constexpr int VERSION_MINOR {@OPENMC_VERSION_MINOR@}; +constexpr int VERSION_RELEASE {@OPENMC_VERSION_PATCH@}; +constexpr bool VERSION_DEV {@OPENMC_DEV_STATE@}; +constexpr const char* VERSION_COMMIT_COUNT = "@OPENMC_COMMIT_COUNT@"; +constexpr const char* VERSION_COMMIT_HASH = "@OPENMC_COMMIT_HASH@"; constexpr std::array VERSION {VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE}; // clang-format on From 727a0ae710f2fc07d734f5fd47df959f0edac06c Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 20 Feb 2025 13:42:41 -0600 Subject: [PATCH 22/25] Get rid of unused variables --- CMakeLists.txt | 1 - cmake/Modules/GetVersionFromGit.cmake | 16 ---------------- 2 files changed, 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 26b6eb5d369..7f8ea669b6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,6 @@ message(STATUS "OpenMC version: ${OPENMC_VERSION}") message(STATUS "OpenMC dev state: ${OPENMC_DEV_STATE}") message(STATUS "OpenMC commit hash: ${OPENMC_COMMIT_HASH}") message(STATUS "OpenMC commit count: ${OPENMC_COMMIT_COUNT}") -message(STATUS "OpenMC dirty state: ${OPENMC_DIRTY_STATE}") # Generate version.h configure_file(include/openmc/version.h.in "${CMAKE_BINARY_DIR}/include/openmc/version.h" @ONLY) diff --git a/cmake/Modules/GetVersionFromGit.cmake b/cmake/Modules/GetVersionFromGit.cmake index 4d5b6ec7d32..d4e9b6ebddf 100644 --- a/cmake/Modules/GetVersionFromGit.cmake +++ b/cmake/Modules/GetVersionFromGit.cmake @@ -88,20 +88,6 @@ else() set(VERSION_WITHOUT_META "${VERSION_STRING}") endif() -# Check for dirty state -if(VERSION_STRING MATCHES "-dirty") - set(DIRTY_STATE "true") -else() - set(DIRTY_STATE "false") -endif() - -# Check for extra version -if(VERSION_WITHOUT_META MATCHES "${VERSION_SUFFIX}") - set(VERSION_EXTRA "${CMAKE_MATCH_1}") -else() - set(VERSION_EXTRA "") -endif() - # Split and set version components string(REPLACE "." ";" VERSION_LIST "${VERSION_NO_SUFFIX}") list(GET VERSION_LIST 0 VERSION_MAJOR) @@ -117,9 +103,7 @@ endif() set(OPENMC_VERSION_MAJOR "${VERSION_MAJOR}") set(OPENMC_VERSION_MINOR "${VERSION_MINOR}") set(OPENMC_VERSION_PATCH "${VERSION_PATCH}") -set(OPENMC_VERSION_EXTRA "${VERSION_EXTRA}") set(OPENMC_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") set(OPENMC_COMMIT_HASH "${COMMIT_HASH}") -set(OPENMC_DIRTY_STATE "${DIRTY_STATE}") set(OPENMC_DEV_STATE "${DEV_STATE}") set(OPENMC_COMMIT_COUNT "${COMMIT_COUNT}") From 8440b2c92434147a5c560749798eb7be1d99d175 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 20 Feb 2025 13:42:57 -0600 Subject: [PATCH 23/25] Fix fetch-depth --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d5df71f388..cd5909936ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,8 +90,8 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 - + fetch-depth: 2 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: From 8ddcb065aac4bc7af7843f933990a4d59fc137c6 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 20 Feb 2025 13:48:54 -0600 Subject: [PATCH 24/25] Set fetch-depth to 0 as before --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd5909936ba..7fe3e1557b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,7 +90,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 2 + fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 From ece247ada700ff6be1704a4360f042ccd40c8e3a Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 21 Feb 2025 11:24:02 -0600 Subject: [PATCH 25/25] Update cmake/Modules/GetVersionFromGit.cmake Co-authored-by: Ahnaf Tahmid Chowdhury --- cmake/Modules/GetVersionFromGit.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/GetVersionFromGit.cmake b/cmake/Modules/GetVersionFromGit.cmake index d4e9b6ebddf..ee6bac827e3 100644 --- a/cmake/Modules/GetVersionFromGit.cmake +++ b/cmake/Modules/GetVersionFromGit.cmake @@ -24,8 +24,8 @@ set(COMMIT_HASH_KEY "commit: " CACHE STRING "Key for commit hash in .git_archiva # Combine prefix and regex set(VERSION_REGEX_WITH_PREFIX "^${VERSION_PREFIX}${VERSION_REGEX}") -# Ensure Git is available -find_package(Git REQUIRED) +# Find Git +find_package(Git) # Attempt to retrieve version from Git if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND GIT_FOUND)