Skip to content

Commit

Permalink
Merge pull request #1693 from DARMA-tasking/1692-dont-error-with-no-git
Browse files Browse the repository at this point in the history
#1692: do not error in build if git folder is not available
  • Loading branch information
lifflander authored and cz4rs committed Mar 4, 2022
2 parents a2eb852 + 2ff27b9 commit 8bfefd2
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 102 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
42 changes: 27 additions & 15 deletions cmake/build_git_info.cmake
Original file line number Diff line number Diff line change
@@ -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}"
Expand All @@ -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}
)

Expand Down
6 changes: 3 additions & 3 deletions cmake/load_doxygen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 7 additions & 4 deletions cmake/run-git.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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}\"")
Expand All @@ -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}\"")
Expand All @@ -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}\"")
Expand Down
3 changes: 3 additions & 0 deletions src/vt/configs/generated/vt_git_revision.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@

#include <string>

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;
Expand Down
48 changes: 24 additions & 24 deletions src/vt/runtime/runtime_banner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)));
}
Expand Down
6 changes: 6 additions & 0 deletions vt_git_revision.cc.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@

#include <string>

#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;
Expand Down
55 changes: 0 additions & 55 deletions vt_git_revision.h

This file was deleted.

0 comments on commit 8bfefd2

Please sign in to comment.