From 8a5f3b49cb80e56b346ebb8af336b487fa608464 Mon Sep 17 00:00:00 2001 From: William Hobbs Date: Sun, 8 Sep 2024 19:20:49 -0700 Subject: [PATCH] configure: add check for valid version Problem: autoconf will accept junk at configure time as a valid version, then go off and generate an invalid version.h file. This happens frequently with shallow clones, setups in CI, or other constrained user environments. It has caused new contributors a lot of confusion in the past. Solution: Like flux-framework/flux-sched#1291 suggested, reject invalid versions at configure time and provide appropriate suggestions to the user to remedy this. --- configure.ac | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/configure.ac b/configure.ac index d7d513fcb403..6911abc02bb3 100644 --- a/configure.ac +++ b/configure.ac @@ -36,6 +36,28 @@ AC_SUBST([AX_MAJOR_VERSION]) AC_SUBST([AX_MINOR_VERSION]) AC_SUBST([AX_POINT_VERSION]) +AC_MSG_CHECKING([whether version number is sane]) +AS_IF([printf "%d.%d.%d" ${AX_MAJOR_VERSION} ${AX_MINOR_VERSION} ${AX_POINT_VERSION} >/dev/null 2>&1], [ + AC_MSG_RESULT([yes]) +],[ + AC_MSG_RESULT([no]) + version_err_msg=" + VERSION ${VERSION} is invalid. + Try the following to remedy this: + + 1. Run \`git fetch --tags\` before building. Versions in + flux-core are derived from \`git describe\` which uses + the most recent tag. + 2. If you are running remote CI in a fork of the main repository, + try pushing the upstream tags to your fork with + \`git push --tags \` to make sure tags are + synchronized in your fork. + 3. Set the variable manually, with FLUX_VERSION= + in your environment. + " + AC_MSG_ERROR(["${version_err_msg}"]) +]) + ## # Initialize pkg-config for PKG_CHECK_MODULES to avoid conditional issues ##