Skip to content

Commit

Permalink
review comments:
Browse files Browse the repository at this point in the history
- fail if DEVEL_TOOLS=ON, but no git
- cmake fixes

Co-authored-by: Tobias Ribizel <[email protected]>
  • Loading branch information
MarcelKoch and upsj committed Nov 13, 2023
1 parent 6b94de8 commit 5a585e0
Showing 1 changed file with 25 additions and 49 deletions.
74 changes: 25 additions & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -354,58 +354,34 @@ if(GINKGO_BUILD_BENCHMARKS)
endif()

if(GINKGO_DEVEL_TOOLS)
function(enable_format_check)
macro(message_git_warning)
message(WARNING "No viable Git setup found, but GINKGO_DEVEL_TOOLS=ON is set. "
"It is recommended to enable this option only with the intention of "
"adding changes to Ginkgo via Git.")
endmacro()

find_package(Git QUIET)
if(NOT GIT_FOUND)
message_git_warning()
return()
endif()

execute_process(COMMAND ${GIT_EXECUTABLE} "rev-parse" "--git-dir"
WORKING_DIRECTORY ${Ginkgo_SOURCE_DIR}
RESULT_VARIABLE GINKGO_IS_GIT_DIR_ERROR)
if(${GINKGO_IS_GIT_DIR_ERROR})
message_git_warning()
return()
endif()

find_program(PRE_COMMIT pre-commit)
if(${PRE_COMMIT} STREQUAL "PRE_COMMIT-NOTFOUND")
message(FATAL_ERROR "The pre-commit command was not found. It is necessary if you want to commit changes to Ginkgo. "
"If that is not the case, set GINKGO_DEVEL_TOOLS=OFF. "
"Otherwise install pre-commit via pipx (or pip) using:\n"
" pipx install pre-commit")
endif()

execute_process(COMMAND "${PRE_COMMIT}" "install"
WORKING_DIRECTORY ${Ginkgo_SOURCE_DIR}
RESULT_VARIABLE pre-commit-result
OUTPUT_VARIABLE pre-commit-output
ERROR_VARIABLE pre-commit-error)
if(${pre-commit-result})
message(FATAL_ERROR
"Failed to install the git hooks via pre-commit. Please check the error message:\n"
"${pre-commit-output}\n${pre-commit-error}")
endif()
find_program(PRE_COMMIT pre-commit)
if(NOT ${PRE_COMMIT})
message(FATAL_ERROR "The pre-commit command was not found. It is necessary if you want to commit changes to Ginkgo. "
"If that is not the case, set GINKGO_DEVEL_TOOLS=OFF. "
"Otherwise install pre-commit via pipx (or pip) using:\n"
" pipx install pre-commit")
endif()

add_custom_target(format
COMMAND bash -c "pre-commit run"
WORKING_DIRECTORY ${Ginkgo_SOURCE_DIR}
VERBATIM)
execute_process(COMMAND "${PRE_COMMIT}" "install"
WORKING_DIRECTORY ${Ginkgo_SOURCE_DIR}
RESULT_VARIABLE pre-commit-result
OUTPUT_VARIABLE pre-commit-output
ERROR_VARIABLE pre-commit-error)
if(${pre-commit-result})
message(FATAL_ERROR
"Failed to install the git hooks via pre-commit. Please check the error message:\n"
"${pre-commit-output}\n${pre-commit-error}")
endif()

add_custom_target(add_license
COMMAND ${Ginkgo_SOURCE_DIR}/dev_tools/scripts/add_license.sh
WORKING_DIRECTORY ${Ginkgo_SOURCE_DIR})
add_dependencies(format add_license)
endfunction()
add_custom_target(format
COMMAND bash -c "${PRE_COMMIT} run"
WORKING_DIRECTORY ${Ginkgo_SOURCE_DIR}
VERBATIM)

enable_format_check()
add_custom_target(add_license
COMMAND ${Ginkgo_SOURCE_DIR}/dev_tools/scripts/add_license.sh
WORKING_DIRECTORY ${Ginkgo_SOURCE_DIR})
add_dependencies(format add_license)
endif()

# MacOS needs to install bash, gnu-sed, findutils and coreutils
Expand Down

0 comments on commit 5a585e0

Please sign in to comment.