Skip to content

Commit

Permalink
build: add descriptive warning about version
Browse files Browse the repository at this point in the history
Problem: flux-sched's version comes from `git describe`, which is
passed to CMake. CMake validates versions using a regex in
`CMake/Source/cmProjectCommand.cxx`. When this is an invalid
version, flux-sched can't build. This often happens in CI, forks,
or stripped-down user environments, and often happens to new
contributors.

Solution: Validate the version before passing to CMake. If the
version is invalid, throw a descriptive warning with some
suggestions.

Fixes #1291
  • Loading branch information
wihobbs committed Sep 6, 2024
1 parent 8d8941d commit 2a2abcd
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ else()
endif()
message(STATUS "VER ${FLUX_SCHED_VER}")
string(REGEX REPLACE "-.*$" "" FLUX_SCHED_VER_NOGIT "${FLUX_SCHED_VER}")
# I took this regex from the CMake source code. If the version fails to
# match it, CMake will error out. We can help the end-user get past this
# with a few tips.
string(REGEX MATCH "(^([0-9]+(\.[0-9]+(\.[0-9]+(\.[0-9]+)?)?)?)?$)" CHECK_FLUX_SCHED_VER "${FLUX_SCHED_VER_NOGIT}")
string(LENGTH "${CHECK_FLUX_SCHED_VER}" LENGTH_FLUX_SCHED_VER)
if (LENGTH_FLUX_SCHED_VER STREQUAL "0")
message(WARNING
"CMake may generate an error that says \"VERSION \"${FLUX_SCHED_VER}\" format invalid.\"\n"
"If this happens, try the following:\n"
" 1. If you are running in a CI environment, run `git fetch tags`\n"
" before building. Versions in flux-sched are derived from \n"
" `git describe` which uses the most recent tag.\n"
" 2. If you are running in a fork of the main repository, try\n"
" `git push --tags` to make sure tags are synchronized in \n"
" your fork.\n"
" 3. If you are running outside of a repo (such as in a buildfarm),\n"
" add a file to the source directory called flux-sched.ver and\n"
" place a valid version string in that file."
)
endif()
project(flux-sched VERSION ${FLUX_SCHED_VER_NOGIT} LANGUAGES CXX C)
message(STATUS "Building flux-sched version ${FLUX_SCHED_VER}")

Expand Down

0 comments on commit 2a2abcd

Please sign in to comment.