From fd9d954313ef8867286f321c4499ff98709e10ed Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Thu, 3 Mar 2022 09:55:22 -0800 Subject: [PATCH 1/3] #1692: make build script not error out when running cmake if .git folder is not available --- cmake/build_git_info.cmake | 42 ++++++++++++++++++++++++-------------- cmake/run-git.cmake | 11 ++++++---- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/cmake/build_git_info.cmake b/cmake/build_git_info.cmake index 15689502af..8d47e28479 100644 --- a/cmake/build_git_info.cmake +++ b/cmake/build_git_info.cmake @@ -1,4 +1,7 @@ find_package(Git REQUIRED) + +set(GIT_DIR) +set(HEAD_FILE) execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --git-dir WORKING_DIRECTORY "${PROJECT_BASE_DIR}" @@ -8,26 +11,35 @@ execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --git-dir REL_GIT_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) if (NOT res EQUAL 0) - message(FATAL_ERROR "git invocation failed") -endif() - -get_filename_component(GIT_DIR ${REL_GIT_DIR} ABSOLUTE BASE_DIR ${PROJECT_BASE_DIR}) -message(STATUS "Git DIR: ${GIT_DIR}") -if (NOT GIT_DIR) - message(FATAL_ERROR "not a git directory") + message(STATUS "git invocation failed, git info cannot be obtained") +else() + get_filename_component(GIT_DIR ${REL_GIT_DIR} ABSOLUTE BASE_DIR ${PROJECT_BASE_DIR}) + message(STATUS "Git DIR: ${GIT_DIR}") + if (NOT GIT_DIR) + message(STATUS "no git directory present") + else() + if(NOT EXISTS "${GIT_DIR}/HEAD") + message(STATUS "no such file: \"${GIT_DIR}/HEAD\"") + else() + set(HEAD_FILE "${GIT_DIR}/HEAD") + message(STATUS "Git HEAD file: \"${HEAD_FILE}\"") + endif() + endif() endif() -if(NOT EXISTS "${GIT_DIR}/HEAD") - message(FATAL_ERROR "no such file: \"${GIT_DIR}/HEAD\"") -endif() -set(HEAD_FILE "${GIT_DIR}/HEAD") - -message(STATUS "Git HEAD file: \"${HEAD_FILE}\"") - set(VT_GIT_CONFIG_FILE "${PROJECT_BIN_DIR}/src/vt/configs/generated/vt_git_revision.cc") add_custom_command( OUTPUT ${VT_GIT_CONFIG_FILE} - COMMAND ${CMAKE_COMMAND} -DIN_FILE=${PROJECT_BASE_DIR}/vt_git_revision.cc.in -DOUT_FILE=${VT_GIT_CONFIG_FILE} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DGIT_DIR=${GIT_DIR} -DHEAD_FILE=${HEAD_FILE} -P ${CMAKE_CURRENT_LIST_DIR}/run-git.cmake + COMMAND ${CMAKE_COMMAND} + -DIN_FILE=${PROJECT_BASE_DIR}/vt_git_revision.cc.in + -DOUT_FILE=${VT_GIT_CONFIG_FILE} + -DGIT_EXECUTABLE=${GIT_EXECUTABLE} + -DGIT_DIR=${GIT_DIR} + -DHEAD_FILE=${HEAD_FILE} + -DPROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR} + -DPROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR} + -DPROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH} + -P ${CMAKE_CURRENT_LIST_DIR}/run-git.cmake DEPENDS ${GIT_DIR} ) diff --git a/cmake/run-git.cmake b/cmake/run-git.cmake index feb6528767..73c341e0fb 100644 --- a/cmake/run-git.cmake +++ b/cmake/run-git.cmake @@ -14,7 +14,10 @@ message(STATUS "Reading head file ${HEAD_FILE}") message(STATUS "Using git executable at \"${GIT_EXECUTABLE}\"") -get_filename_component(ROOT_DIR ${GIT_DIR} DIRECTORY) +set(ROOT_DIR) +if (GIT_DIR) + get_filename_component(ROOT_DIR ${GIT_DIR} DIRECTORY) +endif() set(GIT_SHA1) @@ -39,7 +42,7 @@ execute_process(COMMAND GIT_SHA1 OUTPUT_STRIP_TRAILING_WHITESPACE) if(NOT res EQUAL 0) - message(FATAL_ERROR "could not get the git sha1") + message(STATUS "could not get the git sha1") endif() message(STATUS "GIT_SHA1: \"${GIT_SHA1}\"") @@ -57,7 +60,7 @@ execute_process(COMMAND GIT_EXACT_TAG OUTPUT_STRIP_TRAILING_WHITESPACE) if(NOT res EQUAL 0) - message(FATAL_ERROR "could not get the exact git tag") + message(STATUS "could not get the exact git tag") endif() message(STATUS "GIT_EXACT_TAG: \"${GIT_EXACT_TAG}\"") @@ -75,7 +78,7 @@ execute_process(COMMAND GIT_DESCRIPTION OUTPUT_STRIP_TRAILING_WHITESPACE) if(NOT res EQUAL 0) - message(FATAL_ERROR "could not get the description") + message(STATUS "could not get the description") endif() message(STATUS "GIT_DESCRIPTION: \"${GIT_DESCRIPTION}\"") From 139c1265c1c2b4587e24d6f54da1fca28161e11b Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Thu, 3 Mar 2022 09:55:56 -0800 Subject: [PATCH 2/3] #1692: remove vt_git_revision.h from root directory because it's not actually used; a copy in the src folder is used instead --- vt_git_revision.h | 55 ----------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 vt_git_revision.h diff --git a/vt_git_revision.h b/vt_git_revision.h deleted file mode 100644 index 086d6b8abf..0000000000 --- a/vt_git_revision.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -//@HEADER -// ***************************************************************************** -// -// vt_git_revision.h -// DARMA/vt => Virtual Transport -// -// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC -// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. -// Government retains certain rights in this software. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * Neither the name of the copyright holder nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -// Questions? Contact darma@sandia.gov -// -// ***************************************************************************** -//@HEADER -*/ - -#if !defined VT_CONFIG_GIT_REVISION_H -#define VT_CONFIG_GIT_REVISION_H - -#include - -extern std::string const vt_git_sha1; -extern std::string const vt_git_exact_tag; -extern std::string const vt_git_refspec; -extern std::string const vt_git_description; -extern std::string const vt_git_clean_status; - -#endif /*VT_CONFIG_GIT_REVISION_H*/ From 144de3b5d8eeea5453729cda72cf470ac9a8331d Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Thu, 3 Mar 2022 09:56:50 -0800 Subject: [PATCH 3/3] #1692: cmake: make version consistent and only modified in one place (the VERSION file). This also allows us to print out the version in the banner, which is useful if not git info is available --- CMakeLists.txt | 5 ++- cmake/load_doxygen.cmake | 6 +-- src/vt/configs/generated/vt_git_revision.h | 3 ++ src/vt/runtime/runtime_banner.cc | 48 +++++++++++----------- vt_git_revision.cc.in | 6 +++ 5 files changed, 40 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd6d37e24d..04fd094cab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.17 FATAL_ERROR) -project(vt VERSION 1.1.0) + +file(READ "VERSION" _vt_version_str) +string(STRIP "${_vt_version_str}" _vt_version_str) +project(vt VERSION ${_vt_version_str}) # To generate output file with compilation errors and warnings # CMake generator needs to be known diff --git a/cmake/load_doxygen.cmake b/cmake/load_doxygen.cmake index 81849cd175..616dcdf7cd 100644 --- a/cmake/load_doxygen.cmake +++ b/cmake/load_doxygen.cmake @@ -10,9 +10,9 @@ if (${vt_doxygen_enabled}) set(doxygen_out ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) set(DOXYGEN_PROJECT_NAME "vt") - set(VERSION_MAJOR "1") - set(VERSION_MINOR "0") - set(VERSION_PATCH "0") + set(VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") + set(VERSION_MINOR "${PROJECT_VERSION_MINOR}") + set(VERSION_PATCH "${PROJECT_VERSION_PATCH}") set(DOXYGEN_INPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/") set(DOXYGEN_CHECKPOINT_SHARED_DOCS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib/checkpoint/docs/shared") set(DOXYGEN_CHECKPOINT_EXAMPLE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib/checkpoint/examples") diff --git a/src/vt/configs/generated/vt_git_revision.h b/src/vt/configs/generated/vt_git_revision.h index a2595f2bc6..f84d6b54af 100644 --- a/src/vt/configs/generated/vt_git_revision.h +++ b/src/vt/configs/generated/vt_git_revision.h @@ -46,6 +46,9 @@ #include +extern int const vt_version_major; +extern int const vt_version_minor; +extern int const vt_version_patch; extern std::string const vt_git_sha1; extern std::string const vt_git_exact_tag; extern std::string const vt_git_refspec; diff --git a/src/vt/runtime/runtime_banner.cc b/src/vt/runtime/runtime_banner.cc index c59f24b1bd..f5f9e09c18 100644 --- a/src/vt/runtime/runtime_banner.cc +++ b/src/vt/runtime/runtime_banner.cc @@ -164,7 +164,7 @@ void Runtime::printStartupBanner() { #endif std::string dirty = ""; - if (strncmp(vt_git_clean_status.c_str(), "DIRTY", 5) == 0) { + if (vt_git_clean_status == "DIRTY") { dirty = red + std::string("*dirty*") + reset; } @@ -174,29 +174,29 @@ void Runtime::printStartupBanner() { auto const version = std::to_string(std::get<0>(version_tuple)); auto const subversion = std::to_string(std::get<1>(version_tuple)); - auto f1 = fmt::format("{} {}{}\n", reg(init), reg(mode), emph(mode_type + thd)); - auto f2a = fmt::format("{}Program: {} ({})\n", green, - emph(getAppConfig()->prog_name), emph(getAppConfig()->argv_prog_name)); - auto f2b = fmt::format("{}Running on: {}\n", green, emph(all_node)); - auto f3 = fmt::format("{}Machine Hostname: {}\n", green, emph(hostname)); - auto f3a = fmt::format("{}MPI Version: {}.{}\n", green, emph(version), emph(subversion)); - auto f3b = fmt::format("{}MPI Max tag: {}\n", green, emph(max_tag_str)); - - auto f4 = fmt::format("{}Build SHA: {}\n", green, emph(vt_git_sha1)); - auto f5 = fmt::format("{}Build Ref: {}\n", green, emph(vt_git_refspec)); - auto f6 = fmt::format("{}Description: {} {}\n", green, emph(vt_git_description), dirty); - auto f7 = fmt::format("{}Compile-time Features Enabled:{}\n", green, reset); - - fmt::print("{}{}{}", vt_pre, f1, reset); - fmt::print("{}{}{}", vt_pre, f2a, reset); - fmt::print("{}{}{}", vt_pre, f2b, reset); - fmt::print("{}{}{}", vt_pre, f3, reset); - fmt::print("{}{}{}", vt_pre, f3a, reset); - fmt::print("{}{}{}", vt_pre, f3b, reset); - fmt::print("{}{}{}", vt_pre, f4, reset); - fmt::print("{}{}{}", vt_pre, f5, reset); - fmt::print("{}{}{}", vt_pre, f6, reset); - fmt::print("{}{}{}", vt_pre, f7, reset); + auto vt_version_string = fmt::format("{}.{}.{}", vt_version_major, vt_version_minor, vt_version_patch); + std::array< std::string, 11 > info_lines = { + fmt::format("{}Version: {}\n", green, emph(vt_version_string)), + + fmt::format("{} {}{}\n", reg(init), reg(mode), emph(mode_type + thd)), + fmt::format("{}Program: {} ({})\n", green, + emph(getAppConfig()->prog_name), emph(getAppConfig()->argv_prog_name)), + fmt::format("{}Running on: {}\n", green, emph(all_node)), + fmt::format("{}Machine Hostname: {}\n", green, emph(hostname)), + fmt::format("{}MPI Version: {}.{}\n", green, emph(version), emph(subversion)), + fmt::format("{}MPI Max tag: {}\n", green, emph(max_tag_str)), + + fmt::format("{}Build SHA: {}\n", green, emph(vt_git_sha1)), + fmt::format("{}Build Ref: {}\n", green, emph(vt_git_refspec)), + fmt::format("{}Description: {} {}\n", green, emph(vt_git_description), dirty), + fmt::format("{}Compile-time Features Enabled:{}\n", green, reset) + }; + + for (auto &&line: info_lines) + { + fmt::print("{}{}{}", vt_pre, line, reset); + } + for (size_t i = 0; i < features.size(); i++) { fmt::print("{}\t{}\n", vt_pre, emph(features.at(i))); } diff --git a/vt_git_revision.cc.in b/vt_git_revision.cc.in index 300c991267..e5516088a3 100644 --- a/vt_git_revision.cc.in +++ b/vt_git_revision.cc.in @@ -45,12 +45,18 @@ #include +#define VT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ +#define VT_VERSION_MINOR @PROJECT_VERSION_MINOR@ +#define VT_VERSION_PATCH @PROJECT_VERSION_PATCH@ #define VT_GIT_SHA1 "@GIT_SHA1@" #define VT_GIT_EXACT_TAG "@GIT_EXACT_TAG@" #define VT_GIT_REFSPEC "@GIT_REFSPEC@" #define VT_GIT_DESCRIPTION "@GIT_DESCRIPTION@" #define VT_GIT_CLEAN_STATUS "@GIT_CLEAN_STATUS@" +int const vt_version_major = VT_VERSION_MAJOR; +int const vt_version_minor = VT_VERSION_MINOR; +int const vt_version_patch = VT_VERSION_PATCH; std::string const vt_git_sha1 = VT_GIT_SHA1; std::string const vt_git_exact_tag = VT_GIT_EXACT_TAG; std::string const vt_git_refspec = VT_GIT_REFSPEC;