From 10f7e2c79a783936203e9a7348b7e67cc7ec5e72 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 24 Jul 2024 21:13:57 +0200 Subject: [PATCH 01/29] tools/gitlog2version.sh: introduce new helper script to parse NUT structured version from Git (if available) [#1949] Signed-off-by: Jim Klimov --- tools/gitlog2version.sh | 98 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100755 tools/gitlog2version.sh diff --git a/tools/gitlog2version.sh b/tools/gitlog2version.sh new file mode 100755 index 0000000000..b6391d9751 --- /dev/null +++ b/tools/gitlog2version.sh @@ -0,0 +1,98 @@ +#!/bin/sh + +# Copyright (C) 2016-2024 by Jim Klimov +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +############################################################################ +# +# Helper script to determine the project version in a manner similar to +# what `git describe` produces, but with added numbers after the common +# triplet of semantically versioned numbers: X.Y.Z.T.B(-C-gHASH) +# * X: MAJOR - incompatible API changes +# * Y: MINOR - new features and/or API +# * Z: PATCH - small bug fixes +# * T: Commits on trunk since previous release tag +# * B: Commits on branch since nearest ancestor which is on trunk +# The optional suffix (only for commits which are not tags themselves) +# is provided by `git describe`: +# * C: Commits on branch since previous release tag +# * H: Git hash (prefixed by "g" character) of the described commit +# Note that historically NUT did not diligently follow the semver triplet, +# primarily because a snapshot of trunk is tested and released, and work +# moves on with the PATCH part (rarely MINOR one) incremented; no actual +# patches are released to some sustaining track of an older release lineage. +# There were large re-designs that got MAJOR up to 2, though. +# +############################################################################ +# Checked with bash 3 and 5, dash, ksh, zsh and even busybox sh; +# OpenIndiana, FreeBSD and OpenBSD sh. Not compatible with csh and tcsh. +# See some examples in https://github.com/networkupstools/nut/issues/1949 + +############################################################################ +# Numeric-only default version, for AC_INIT and similar consumers +# in case we build without a Git workspace (from tarball, etc.) +# By legacy convention, 3-digit "semver" was for NUT releases, and +# a nominal "semver.1" for any development snapshots afterwards. +[ -n "${DEFAULT_VERSION-}" ] || DEFAULT_VERSION='2.8.2.1' + +getver() ( + # NOTE: The chosen trunk branch must be up to date (may be "origin/master" + # or "upstream/master", etc.) for resulting version discovery to make sense. + [ x"${TRUNK-}" != x ] || TRUNK=master + + # How much of the known trunk history is in current HEAD? + # e.g. all of it when we are on that branch or PR made from its tip, + # some of it if looking at a historic snapshot, or nothing if looking + # at the tagged commit (it is the merge base for itself and any of + # its descendants): + BASE="`git merge-base HEAD "${TRUNK}"`" + + # By default, only annotated tags are considered + ALL_TAGS_ARG="" + if [ x"${ALL_TAGS-}" = xtrue ] ; then ALL_TAGS_ARG="--tags" ; fi + + DESC="`git describe $ALL_TAGS_ARG --match 'v[0-9]*.[0-9]*.[0-9]' --exclude '*-signed' --exclude '*rc*' --exclude '*alpha*' --exclude '*beta*' --exclude '*Windows*' --exclude '*IPM*' --always`" + # Old stripper (also for possible refspec parts like "tags/"): + # echo "${DESC}" | sed -e 's/^v\([0-9]\)/\1/' -e 's,^.*/,,' + + # Nearest (annotated by default) tag preceding the HEAD in history: + TAG="`echo "${DESC}" | sed 's/-[0-9][0-9]*-g[0-9a-fA-F][0-9a-fA-F]*$//'`" + + # Commit count since the tag and hash of the HEAD commit; + # empty e.g. when HEAD is the tagged commit: + SUFFIX="`echo "${DESC}" | sed 's/^.*\(-[0-9][0-9]*-g[0-9a-fA-F][0-9a-fA-F]*\)$/\1/'`" && [ x"${SUFFIX}" != x"${TAG}" ] || SUFFIX="" + + # 5-digit version, note we strip leading "v" from the expected TAG value + VER5="${TAG#v}.`git log --oneline "${TAG}..${BASE}" | wc -l | tr -d ' '`.`git log --oneline "${TRUNK}..HEAD" | wc -l | tr -d ' '`" + DESC5="${VER5}${SUFFIX}" + + # Strip trailing zeroes for trunk snapshots and releases + VER50="`echo "${VER5}" | sed -e 's/\.0$//' -e 's/\.0$//'`" + DESC50="${VER50}${SUFFIX}" + + # Debug + echo "DESC='${DESC}' => TAG='${TAG}' + SUFFIX='${SUFFIX}'; BASE='${BASE}' => VER5='${VER5}' => VER50='${VER50}' => DESC50='${DESC50}'" >&2 + + # echo "${DESC5}" + echo "${DESC50}" +) + +if (command -v git && git rev-parse --show-toplevel) >/dev/null 2>/dev/null ; then + getver + exit +fi + +echo "${DEFAULT_VERSION-}" From a3c82810a826b8907e4a88f67c2ba20c234dd1a7 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 24 Jul 2024 21:32:11 +0200 Subject: [PATCH 02/29] configure.ac, include/Makefile.am: use consistently the tools/gitlog2version.sh for version info [#1949] Signed-off-by: Jim Klimov --- configure.ac | 6 +++--- include/Makefile.am | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 4d149b3518..e1c0996a12 100644 --- a/configure.ac +++ b/configure.ac @@ -15,11 +15,11 @@ dnl the PDF documentation revision history via docs/docinfo.xml.in). dnl If the NUT codebase in this workspace is being developed and rebuilt dnl without reconfiguration, detailed version in the binaries will differ dnl (that one comes from the NUT_VERSION_MACRO from nut_version.h file). -(command -v git >/dev/null 2>/dev/null) \ -&& NUT_SOURCE_GITREV="`(git describe --tags --match 'v@<:@0-9@:>@*.@<:@0-9@:>@*.@<:@0-9@:>@' --exclude '*-signed' --exclude '*rc*' --exclude '*alpha*' --exclude '*beta*' 2>/dev/null || git describe --tags --exclude '*rc*' --exclude '*alpha*' --exclude '*beta*' --exclude '*Windows*' --exclude '*IPM*' 2>/dev/null ) | sed -e 's/^v\(@<:@0-9@:>@\)/\1/' -e 's,^.*/,,'`" \ -|| NUT_SOURCE_GITREV="" +dnl # Example: NUT_SOURCE_GITREV='2.8.2.695.1-696-g0e00f0777' +NUT_SOURCE_GITREV="`${srcdir}/tools/gitlog2version.sh`" dnl Gitrev-based build identifier which can be used for e.g. PyPI uploads: +dnl # Example: NUT_SOURCE_GITREV_NUMERIC='2.8.2.695.1.696' NUT_SOURCE_GITREV_NUMERIC="`echo "${NUT_SOURCE_GITREV}" | sed -e 's/^v//' -e 's/-g.*$//' -e 's/-/./g'`" dnl Note: except for experiments, do not pass this into config.h - use diff --git a/include/Makefile.am b/include/Makefile.am index 3113204671..3dee8c770f 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -32,7 +32,7 @@ MAINTAINERCLEANFILES = Makefile.in .dirstamp # (for builds not made from the tagged commit in a Git workspace) nut_version.h: @FORCE_NUT_VERSION@ - @GITREV="`git describe --tags --match 'v[0-9]*.[0-9]*.[0-9]' --exclude '*-signed' --exclude '*rc*' --exclude '*alpha*' --exclude '*beta*' 2>/dev/null | sed -e 's/^v\([0-9]\)/\1/' -e 's,^.*/,,'`" || GITREV=""; \ + @GITREV="`$(top_srcdir)/tools/gitlog2version.sh`" || GITREV=""; \ { echo '/* Autogenerated file. Do not change. */' ; \ echo '/* This file was generated by "make". */' ; \ if [ -z "$$GITREV" ]; then \ From 541ecad389b27cdd5318d873a7488e41bbe0b0db Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 24 Jul 2024 22:42:48 +0200 Subject: [PATCH 03/29] configure.ac: set PACKAGE_TARNAME and PACKAGE_URL [#1949] Signed-off-by: Jim Klimov --- configure.ac | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index e1c0996a12..a660e0c315 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ dnl +------------------------------------------------------------------+ dnl NUT version number is defined here, with a Git suffixed macro like dnl NUT_VERSION_MACRO "2.7.4-2838-gdfc3ac08" dnl in include/nut_version.h (generated by make) -AC_INIT([nut],[2.8.2.1],[https://github.com/networkupstools/nut/issues],[nut],[https://networkupstools.org/]) +AC_INIT([nut],[2.8.2.1],[https://github.com/networkupstools/nut/issues],[nut]) dnl See docs/maintainer-guide.txt about releases - updating the version dnl above is a small part of the consistent ritual! @@ -16,11 +16,15 @@ dnl If the NUT codebase in this workspace is being developed and rebuilt dnl without reconfiguration, detailed version in the binaries will differ dnl (that one comes from the NUT_VERSION_MACRO from nut_version.h file). dnl # Example: NUT_SOURCE_GITREV='2.8.2.695.1-696-g0e00f0777' -NUT_SOURCE_GITREV="`${srcdir}/tools/gitlog2version.sh`" +dnl Note: srcdir is only set after AC INIT above has completed. +NUT_SOURCE_GITREV="`${srcdir}/tools/gitlog2version.sh 2>/dev/null`" dnl Gitrev-based build identifier which can be used for e.g. PyPI uploads: dnl # Example: NUT_SOURCE_GITREV_NUMERIC='2.8.2.695.1.696' -NUT_SOURCE_GITREV_NUMERIC="`echo "${NUT_SOURCE_GITREV}" | sed -e 's/^v//' -e 's/-g.*$//' -e 's/-/./g'`" +dnl # NUT_SOURCE_GITREV_NUMERIC="`echo "${NUT_SOURCE_GITREV}" | sed -e 's/^v//' -e 's/-g.*$//' -e 's/-/./g'`" +dnl # Without the commit-count since tag (dash-separated part): +dnl # Example: NUT_SOURCE_GITREV_NUMERIC='2.8.2.695.1' +NUT_SOURCE_GITREV_NUMERIC="`echo "${NUT_SOURCE_GITREV}" | sed -e 's/^v//' -e 's/-g.*$//' -e 's/-@<:@0-9@:>@*$//'`" dnl Note: except for experiments, do not pass this into config.h - use dnl the NUT_VERSION_MACRO from nut_version.h instead. Developers may @@ -31,6 +35,15 @@ dnl ### AS_IF([test -n "${NUT_SOURCE_GITREV-}"], dnl ### [AC_DEFINE_UNQUOTED([NUT_SOURCE_GITREV], ["${NUT_SOURCE_GITREV}"], [NUT source revision when the build was configured])], dnl ### [AC_DEFINE([NUT_SOURCE_GITREV], [NULL], [NUT source revision when the build was configured: not detected])]) +dnl Clarify the project website URL - particularly historically frozen +dnl snapshots made for releases. +NUT_WEBSITE="https://networkupstools.org/" +AS_IF([test x"`echo "${NUT_SOURCE_GITREV_NUMERIC}" | sed 's,@<:@0-9@:>@*,,g'`" = x".."], [NUT_WEBSITE="${NUT_WEBSITE}historic/v${NUT_SOURCE_GITREV_NUMERIC}/index.html"]) + +PACKAGE_URL="${NUT_WEBSITE}" +m4_define([AC_PACKAGE_URL], m4_esyscmd(echo "${PACKAGE_URL}")) +AC_SUBST(PACKAGE_URL) + dnl Keep track of command-line options passed to this script: AC_MSG_CHECKING([for CONFIG_FLAGS]) CONFIG_FLAGS="" From 281db9cbd01cf2d4f4e2e98c5881bffa52f2ac5d Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 25 Jul 2024 16:24:35 +0200 Subject: [PATCH 04/29] tools/gitlog2version.sh: add WANT_VER query support, 3-digit SEMVER, and URL, and IS_RELEASE [#1949] Signed-off-by: Jim Klimov --- tools/gitlog2version.sh | 66 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/tools/gitlog2version.sh b/tools/gitlog2version.sh index b6391d9751..1062c81409 100755 --- a/tools/gitlog2version.sh +++ b/tools/gitlog2version.sh @@ -47,8 +47,9 @@ # By legacy convention, 3-digit "semver" was for NUT releases, and # a nominal "semver.1" for any development snapshots afterwards. [ -n "${DEFAULT_VERSION-}" ] || DEFAULT_VERSION='2.8.2.1' +NUT_WEBSITE="https://networkupstools.org/" -getver() ( +getver() { # NOTE: The chosen trunk branch must be up to date (may be "origin/master" # or "upstream/master", etc.) for resulting version discovery to make sense. [ x"${TRUNK-}" != x ] || TRUNK=master @@ -79,20 +80,73 @@ getver() ( VER5="${TAG#v}.`git log --oneline "${TAG}..${BASE}" | wc -l | tr -d ' '`.`git log --oneline "${TRUNK}..HEAD" | wc -l | tr -d ' '`" DESC5="${VER5}${SUFFIX}" - # Strip trailing zeroes for trunk snapshots and releases + # Strip up to two trailing zeroes for trunk snapshots and releases VER50="`echo "${VER5}" | sed -e 's/\.0$//' -e 's/\.0$//'`" DESC50="${VER50}${SUFFIX}" + # Leave exactly 3 components + SEMVER="`echo "${VER5}" | sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)\..*$/\1/'`" + # FIXME? Add ".0" up to 3 components? + # Debug echo "DESC='${DESC}' => TAG='${TAG}' + SUFFIX='${SUFFIX}'; BASE='${BASE}' => VER5='${VER5}' => VER50='${VER50}' => DESC50='${DESC50}'" >&2 - # echo "${DESC5}" - echo "${DESC50}" -) + case "${WANT_VER-}" in + "DESC5") echo "${DESC5}" ;; + "DESC50") echo "${DESC50}" ;; + "VER5") echo "${VER5}" ;; + "VER50") echo "${VER50}" ;; + "SEMVER") echo "${SEMVER}" ;; + "IS_RELEASE") [ x"${SEMVER}" = x"${VER50}" ] && echo true || echo false ;; + "TAG") echo "${TAG}" ;; + "SUFFIX") echo "${SUFFIX}" ;; + "BASE") echo "${BASE}" ;; + "URL") + if [ x"${SEMVER}" = x"${VER50}" ] ; then + echo "${NUT_WEBSITE}historic/v${SEMVER}/index.html" + else + echo "${NUT_WEBSITE}" + fi + ;; + *) echo "${DESC50}" ;; + esac +} if (command -v git && git rev-parse --show-toplevel) >/dev/null 2>/dev/null ; then getver exit fi -echo "${DEFAULT_VERSION-}" +DEFAULT_VERSION_DOTS="`echo "${DEFAULT_VERSION}" | sed 's/[^.]*//g' | tr -d '\n' | wc -c`" +DEFAULT_VERSION5_DOTS="${DEFAULT_VERSION_DOTS}" +DEFAULT_VERSION5="${DEFAULT_VERSION}" +while [ "${DEFAULT_VERSION5_DOTS}" -lt 4 ] ; do + DEFAULT_VERSION5="${DEFAULT_VERSION5}.0" + DEFAULT_VERSION5_DOTS="`expr $DEFAULT_VERSION5_DOTS + 1`" +done + +DEFAULT_VERSION3_DOTS="${DEFAULT_VERSION_DOTS}" +DEFAULT_VERSION3="${DEFAULT_VERSION}" +while [ "${DEFAULT_VERSION3_DOTS}" -lt 2 ] ; do + DEFAULT_VERSION3="${DEFAULT_VERSION3}.0" + DEFAULT_VERSION3_DOTS="`expr $DEFAULT_VERSION3_DOTS + 1`" +done +while [ "${DEFAULT_VERSION3_DOTS}" -gt 2 ] ; do + DEFAULT_VERSION3="`echo "${DEFAULT_VERSION3}" | sed 's,\.[0-9][0-9]*$,,'`" + DEFAULT_VERSION3_DOTS="`expr $DEFAULT_VERSION3_DOTS - 1`" +done + +if [ x"${DEFAULT_VERSION3}" = x"${DEFAULT_VERSION}" ] ; then + NUT_WEBSITE="${NUT_WEBSITE}historic/v${DEFAULT_VERSION3}/index.html" +fi + +case "${WANT_VER-}" in + "DESC5"|"VER5") echo "${DEFAULT_VERSION5}" ;; + "DESC50"|"VER50") echo "${DEFAULT_VERSION}" ;; + "SUFFIX"|"BASE") echo "" ;; + "SEMVER") echo "${DEFAULT_VERSION3}" ;; + "IS_RELEASE") [ x"${DEFAULT_VERSION3}" = x"${DEFAULT_VERSION}" ] && echo true || echo false ;; + "TAG") echo "v${DEFAULT_VERSION3}" ;; + "URL") echo "${NUT_WEBSITE}" ;; + *) echo "${DEFAULT_VERSION}" ;; +esac From 0271ae06769dfc5bf77f9c8036f4be1c014ff956 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 25 Jul 2024 16:48:11 +0200 Subject: [PATCH 05/29] tools/gitlog2version.sh: refactor to share more code; introduce PREFER_GIT toggle [#1949] Signed-off-by: Jim Klimov --- tools/gitlog2version.sh | 87 ++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 36 deletions(-) diff --git a/tools/gitlog2version.sh b/tools/gitlog2version.sh index 1062c81409..88f643c59e 100755 --- a/tools/gitlog2version.sh +++ b/tools/gitlog2version.sh @@ -47,9 +47,10 @@ # By legacy convention, 3-digit "semver" was for NUT releases, and # a nominal "semver.1" for any development snapshots afterwards. [ -n "${DEFAULT_VERSION-}" ] || DEFAULT_VERSION='2.8.2.1' -NUT_WEBSITE="https://networkupstools.org/" +[ -n "${NUT_WEBSITE-}" ] || NUT_WEBSITE="https://networkupstools.org/" +[ x"${PREFER_GIT-}" = xfalse ] || PREFER_GIT=true -getver() { +getver_git() { # NOTE: The chosen trunk branch must be up to date (may be "origin/master" # or "upstream/master", etc.) for resulting version discovery to make sense. [ x"${TRUNK-}" != x ] || TRUNK=master @@ -87,10 +88,47 @@ getver() { # Leave exactly 3 components SEMVER="`echo "${VER5}" | sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)\..*$/\1/'`" # FIXME? Add ".0" up to 3 components? +} + +getver_default() { + DEFAULT_VERSION_DOTS="`echo "${DEFAULT_VERSION}" | sed 's/[^.]*//g' | tr -d '\n' | wc -c`" + + # Ensure at least 4 dots (5 presumed-numeric components) + DEFAULT_VERSION5_DOTS="${DEFAULT_VERSION_DOTS}" + DEFAULT_VERSION5="${DEFAULT_VERSION}" + while [ "${DEFAULT_VERSION5_DOTS}" -lt 4 ] ; do + DEFAULT_VERSION5="${DEFAULT_VERSION5}.0" + DEFAULT_VERSION5_DOTS="`expr $DEFAULT_VERSION5_DOTS + 1`" + done + + # Truncate/extend to exactly 2 dots (3 presumed-numeric components) + DEFAULT_VERSION3_DOTS="${DEFAULT_VERSION_DOTS}" + DEFAULT_VERSION3="${DEFAULT_VERSION}" + while [ "${DEFAULT_VERSION3_DOTS}" -lt 2 ] ; do + DEFAULT_VERSION3="${DEFAULT_VERSION3}.0" + DEFAULT_VERSION3_DOTS="`expr $DEFAULT_VERSION3_DOTS + 1`" + done + while [ "${DEFAULT_VERSION3_DOTS}" -gt 2 ] ; do + DEFAULT_VERSION3="`echo "${DEFAULT_VERSION3}" | sed 's,\.[0-9][0-9]*$,,'`" + DEFAULT_VERSION3_DOTS="`expr $DEFAULT_VERSION3_DOTS - 1`" + done + + DESC5="${DEFAULT_VERSION5}" + DESC50="${DEFAULT_VERSION}" + VER5="${DEFAULT_VERSION5}" + VER50="${DEFAULT_VERSION}" + SUFFIX="" + BASE="" + SEMVER="${DEFAULT_VERSION3}" + TAG="v${DEFAULT_VERSION3}" +} +report_debug() { # Debug echo "DESC='${DESC}' => TAG='${TAG}' + SUFFIX='${SUFFIX}'; BASE='${BASE}' => VER5='${VER5}' => VER50='${VER50}' => DESC50='${DESC50}'" >&2 +} +report_output() { case "${WANT_VER-}" in "DESC5") echo "${DESC5}" ;; "DESC50") echo "${DESC50}" ;; @@ -102,6 +140,8 @@ getver() { "SUFFIX") echo "${SUFFIX}" ;; "BASE") echo "${BASE}" ;; "URL") + # Clarify the project website URL - particularly historically + # frozen snapshots made for releases if [ x"${SEMVER}" = x"${VER50}" ] ; then echo "${NUT_WEBSITE}historic/v${SEMVER}/index.html" else @@ -112,41 +152,16 @@ getver() { esac } -if (command -v git && git rev-parse --show-toplevel) >/dev/null 2>/dev/null ; then - getver - exit +DESC="" +if $PREFER_GIT ; then + if (command -v git && git rev-parse --show-toplevel) >/dev/null 2>/dev/null ; then + getver_git || DESC="" + fi fi -DEFAULT_VERSION_DOTS="`echo "${DEFAULT_VERSION}" | sed 's/[^.]*//g' | tr -d '\n' | wc -c`" -DEFAULT_VERSION5_DOTS="${DEFAULT_VERSION_DOTS}" -DEFAULT_VERSION5="${DEFAULT_VERSION}" -while [ "${DEFAULT_VERSION5_DOTS}" -lt 4 ] ; do - DEFAULT_VERSION5="${DEFAULT_VERSION5}.0" - DEFAULT_VERSION5_DOTS="`expr $DEFAULT_VERSION5_DOTS + 1`" -done - -DEFAULT_VERSION3_DOTS="${DEFAULT_VERSION_DOTS}" -DEFAULT_VERSION3="${DEFAULT_VERSION}" -while [ "${DEFAULT_VERSION3_DOTS}" -lt 2 ] ; do - DEFAULT_VERSION3="${DEFAULT_VERSION3}.0" - DEFAULT_VERSION3_DOTS="`expr $DEFAULT_VERSION3_DOTS + 1`" -done -while [ "${DEFAULT_VERSION3_DOTS}" -gt 2 ] ; do - DEFAULT_VERSION3="`echo "${DEFAULT_VERSION3}" | sed 's,\.[0-9][0-9]*$,,'`" - DEFAULT_VERSION3_DOTS="`expr $DEFAULT_VERSION3_DOTS - 1`" -done - -if [ x"${DEFAULT_VERSION3}" = x"${DEFAULT_VERSION}" ] ; then - NUT_WEBSITE="${NUT_WEBSITE}historic/v${DEFAULT_VERSION3}/index.html" +if [ x"$DESC" = x ]; then + getver_default fi -case "${WANT_VER-}" in - "DESC5"|"VER5") echo "${DEFAULT_VERSION5}" ;; - "DESC50"|"VER50") echo "${DEFAULT_VERSION}" ;; - "SUFFIX"|"BASE") echo "" ;; - "SEMVER") echo "${DEFAULT_VERSION3}" ;; - "IS_RELEASE") [ x"${DEFAULT_VERSION3}" = x"${DEFAULT_VERSION}" ] && echo true || echo false ;; - "TAG") echo "v${DEFAULT_VERSION3}" ;; - "URL") echo "${NUT_WEBSITE}" ;; - *) echo "${DEFAULT_VERSION}" ;; -esac +report_debug +report_output From a1cc10ab7c58154a85293e2cffd77d5593de888c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 25 Jul 2024 17:07:53 +0200 Subject: [PATCH 06/29] configure.ac: refactor to use tools/gitlog2version.sh directly in AC_INIT without hacks [#1949] Signed-off-by: Jim Klimov --- configure.ac | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index a660e0c315..cd71fbdf85 100644 --- a/configure.ac +++ b/configure.ac @@ -4,8 +4,19 @@ dnl +------------------------------------------------------------------+ dnl NUT version number is defined here, with a Git suffixed macro like dnl NUT_VERSION_MACRO "2.7.4-2838-gdfc3ac08" -dnl in include/nut_version.h (generated by make) -AC_INIT([nut],[2.8.2.1],[https://github.com/networkupstools/nut/issues],[nut]) +dnl defined separately in include/nut_version.h (generated by make) +dnl ...or not defined, for quicker rebuilds, depending on settings. +dnl Old hard-coded approach (mangled a bit): +dnl AC INIT([nut],[2.8.2.1],[https://github.com/networkupstools/nut/issues]) +dnl Note: srcdir is only set after AC INIT has completed, but $0 points +dnl to the generated configure script which is part of dist tarball and +dnl should be at source root too. +dnl Note: this gets evaluated (script called) a lot of times during autoconf +dnl but ends up as static strings in the generated configure script. +AC_INIT([nut], + [m4_esyscmd_s([WANT_VER=VER50 "`dirname "$0"`/tools/gitlog2version.sh" 2>/dev/null])], + [https://github.com/networkupstools/nut/issues],[nut], + [m4_esyscmd_s([WANT_VER=URL "`dirname "$0"`/tools/gitlog2version.sh" 2>/dev/null])]) dnl See docs/maintainer-guide.txt about releases - updating the version dnl above is a small part of the consistent ritual! @@ -16,8 +27,7 @@ dnl If the NUT codebase in this workspace is being developed and rebuilt dnl without reconfiguration, detailed version in the binaries will differ dnl (that one comes from the NUT_VERSION_MACRO from nut_version.h file). dnl # Example: NUT_SOURCE_GITREV='2.8.2.695.1-696-g0e00f0777' -dnl Note: srcdir is only set after AC INIT above has completed. -NUT_SOURCE_GITREV="`${srcdir}/tools/gitlog2version.sh 2>/dev/null`" +NUT_SOURCE_GITREV="`WANT_VER=DESC50 "${srcdir}/tools/gitlog2version.sh" 2>/dev/null`" dnl Gitrev-based build identifier which can be used for e.g. PyPI uploads: dnl # Example: NUT_SOURCE_GITREV_NUMERIC='2.8.2.695.1.696' @@ -35,15 +45,6 @@ dnl ### AS_IF([test -n "${NUT_SOURCE_GITREV-}"], dnl ### [AC_DEFINE_UNQUOTED([NUT_SOURCE_GITREV], ["${NUT_SOURCE_GITREV}"], [NUT source revision when the build was configured])], dnl ### [AC_DEFINE([NUT_SOURCE_GITREV], [NULL], [NUT source revision when the build was configured: not detected])]) -dnl Clarify the project website URL - particularly historically frozen -dnl snapshots made for releases. -NUT_WEBSITE="https://networkupstools.org/" -AS_IF([test x"`echo "${NUT_SOURCE_GITREV_NUMERIC}" | sed 's,@<:@0-9@:>@*,,g'`" = x".."], [NUT_WEBSITE="${NUT_WEBSITE}historic/v${NUT_SOURCE_GITREV_NUMERIC}/index.html"]) - -PACKAGE_URL="${NUT_WEBSITE}" -m4_define([AC_PACKAGE_URL], m4_esyscmd(echo "${PACKAGE_URL}")) -AC_SUBST(PACKAGE_URL) - dnl Keep track of command-line options passed to this script: AC_MSG_CHECKING([for CONFIG_FLAGS]) CONFIG_FLAGS="" From 21188e85c1f29e5b9a3bf2db05c581f1dabd78cd Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 25 Jul 2024 17:31:41 +0200 Subject: [PATCH 07/29] configure.ac: provide m4_esyscmd_s for builds with older autotools releases [#1949] Signed-off-by: Jim Klimov --- configure.ac | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/configure.ac b/configure.ac index cd71fbdf85..456155e357 100644 --- a/configure.ac +++ b/configure.ac @@ -2,6 +2,10 @@ dnl +------------------------------------------------------------------+ dnl | Network UPS Tools: configure.ac | dnl +------------------------------------------------------------------+ +dnl # Support for older autoconf without m4_esyscmd_s +m4_ifndef([m4_chomp_all], [m4_define([m4_chomp_all], [m4_format([[%.*s]], m4_bregexp(m4_translit([[$1]], [/], [/ ]), [/*$]), [$1])])]) +m4_ifndef([m4_esyscmd_s], [m4_define([m4_esyscmd_s], [m4_chomp_all(m4_esyscmd([$1]))])]) + dnl NUT version number is defined here, with a Git suffixed macro like dnl NUT_VERSION_MACRO "2.7.4-2838-gdfc3ac08" dnl defined separately in include/nut_version.h (generated by make) From d7eef9c1535656c040703151b49f2c9bc94c0349 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 25 Jul 2024 17:32:34 +0200 Subject: [PATCH 08/29] tools/gitlog2version.sh et al: add support for (taballed) VERSION_DEFAULT file [#1949] Signed-off-by: Jim Klimov --- .gitignore | 2 ++ Makefile.am | 9 +++++++++ autogen.sh | 2 ++ ci_build.sh | 4 ++-- tools/gitlog2version.sh | 43 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2dd9612364..db5d9cf882 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ /_install_pkgprotodir/ Makefile Makefile.in + ## Parent directory only /aclocal.m4 /ar-lib @@ -43,6 +44,7 @@ Makefile.in /README /TODO /UPGRADING +/VERSION_DEFAULT /install-sh /libtool /ltmain.sh diff --git a/Makefile.am b/Makefile.am index 6fef2550d9..c94e7d766e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -250,6 +250,15 @@ maintainer-asciidocs: check-NIT check-NIT-devel: +cd $(builddir)/tests/NIT && $(MAKE) $(AM_MAKEFLAGS) $@ +VERSION_DEFAULT: dummy-stamp + @abs_top_srcdir='$(abs_top_srcdir)' ; \ + abs_top_builddir='$(abs_top_builddir)' ; \ + export abs_top_srcdir ; export abs_top_builddir ; \ + WANT_VER=UPDATE_FILE '$(abs_top_srcdir)/tools/gitlog2version.sh' + +CLEANFILES += VERSION_DEFAULT.tmp +EXTRA_DIST += VERSION_DEFAULT + # This target adds syntax-checking for committed shell script files, # to avoid surprises and delays in finding fatal typos after packaging ### diff --git a/autogen.sh b/autogen.sh index 9d7d05e8c2..14afe2fae0 100755 --- a/autogen.sh +++ b/autogen.sh @@ -24,6 +24,8 @@ else DEBUG=false fi +WANT_VER=UPDATE_FILE "`dirname $0`"/tools/gitlog2version.sh + if [ -n "${PYTHON-}" ] ; then # May be a name/path of binary, or one with args - check both (command -v "$PYTHON") \ diff --git a/ci_build.sh b/ci_build.sh index ca111198cc..1b9ebd2a63 100755 --- a/ci_build.sh +++ b/ci_build.sh @@ -668,8 +668,8 @@ check_gitignore() { # and git diff; note that filenames starting with a dot should be # reported by `git status -- '*'` and not hidden. [ -n "${FILE_GLOB-}" ] || FILE_GLOB="'*'" - # Always filter these names away: - FILE_GLOB_EXCLUDE="':!.ci*.log*'" + # Always filter these names away; note: no extra quoting here: + FILE_GLOB_EXCLUDE=":!.ci*.log* :!VERSION_DEFAULT" [ -n "${GIT_ARGS-}" ] || GIT_ARGS='' # e.g. GIT_ARGS="--ignored" # Display contents of the diff? # (Helps copy-paste from CI logs to source to amend quickly) diff --git a/tools/gitlog2version.sh b/tools/gitlog2version.sh index 88f643c59e..1ba4de7268 100755 --- a/tools/gitlog2version.sh +++ b/tools/gitlog2version.sh @@ -41,12 +41,39 @@ # OpenIndiana, FreeBSD and OpenBSD sh. Not compatible with csh and tcsh. # See some examples in https://github.com/networkupstools/nut/issues/1949 +LANG=C +LC_ALL=C +TZ=UTC +export LANG LC_ALL TZ + +if [ x"${abs_top_srcdir}" = x ]; then + SCRIPT_DIR="`dirname "$0"`" + SCRIPT_DIR="`cd "${SCRIPT_DIR}" && pwd`" + abs_top_srcdir="${SCRIPT_DIR}/.." +fi +if [ x"${abs_top_builddir}" = x ]; then + abs_top_builddir="${abs_top_srcdir}" +fi + ############################################################################ # Numeric-only default version, for AC_INIT and similar consumers # in case we build without a Git workspace (from tarball, etc.) # By legacy convention, 3-digit "semver" was for NUT releases, and # a nominal "semver.1" for any development snapshots afterwards. + +# This file is absent in Git, but should be provided in tarballs. +# It may be re-generated by NUT autogen.sh script. +if [ -z "${DEFAULT_VERSION-}" -a -s "${abs_top_builddir}/VERSION_DEFAULT" ] ; then + . "${abs_top_builddir}/VERSION_DEFAULT" || exit +fi + +if [ -z "${DEFAULT_VERSION-}" -a -s "${abs_top_srcdir}/VERSION_DEFAULT" ] ; then + . "${abs_top_srcdir}/VERSION_DEFAULT" || exit +fi + +# Fallback default, to be updated only during release cycle [ -n "${DEFAULT_VERSION-}" ] || DEFAULT_VERSION='2.8.2.1' + [ -n "${NUT_WEBSITE-}" ] || NUT_WEBSITE="https://networkupstools.org/" [ x"${PREFER_GIT-}" = xfalse ] || PREFER_GIT=true @@ -148,6 +175,22 @@ report_output() { echo "${NUT_WEBSITE}" fi ;; + "UPDATE_FILE") + if [ x"${abs_top_builddir}" != x"${abs_top_srcdir}" ] \ + && [ -s "${abs_top_srcdir}/VERSION_DEFAULT" ] \ + && [ ! -s "${abs_top_builddir}/VERSION_DEFAULT" ] \ + ; then + cp -f "${abs_top_srcdir}/VERSION_DEFAULT" "${abs_top_builddir}/VERSION_DEFAULT" || exit + fi + + echo "DEFAULT_VERSION='${DESC50}'" > "${abs_top_builddir}/VERSION_DEFAULT.tmp" || exit + if cmp "${abs_top_builddir}/VERSION_DEFAULT.tmp" "${abs_top_builddir}/VERSION_DEFAULT" >/dev/null 2>/dev/null ; then + rm -f "${abs_top_builddir}/VERSION_DEFAULT.tmp" + else + mv -f "${abs_top_builddir}/VERSION_DEFAULT.tmp" "${abs_top_builddir}/VERSION_DEFAULT" || exit + fi + cat "${abs_top_builddir}/VERSION_DEFAULT" + ;; *) echo "${DESC50}" ;; esac } From 1b029e5a70da96c131d322d94c6b286c3ca8d075 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 25 Jul 2024 23:39:48 +0200 Subject: [PATCH 09/29] tools/Makefile.am: EXTRA_DIST the gitlog2version.sh helper [#1949] Signed-off-by: Jim Klimov --- tools/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/Makefile.am b/tools/Makefile.am index 5a5f9d6840..1321c3cf6a 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -25,7 +25,7 @@ SUBDIRS = . nut-scanner nutconf PYTHON = @PYTHON@ EXTRA_DIST = nut-usbinfo.pl nut-recorder.sh nut-ddl-dump.sh nut-dumpdiff.sh \ - gitlog2changelog.py.in nut-snmpinfo.py.in driver-list-format.sh + gitlog2changelog.py.in gitlog2version.sh nut-snmpinfo.py.in driver-list-format.sh # These files are generated for nut-scanner builds (and cleaned as any others), # and can change as respective SNMP/USB subdriver sources are iterated by a From 0955d6f437666e73425e7e6cd0533dc83c016de1 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 25 Jul 2024 23:53:58 +0200 Subject: [PATCH 10/29] NEWS.adoc, docs/nut.dict, UPGRADING.adoc: announce NUT development-friendly versioning scheme [#1949] Signed-off-by: Jim Klimov --- NEWS.adoc | 14 ++++++++++++++ UPGRADING.adoc | 10 ++++++++++ docs/nut.dict | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/NEWS.adoc b/NEWS.adoc index d3bd184fa1..adc0e84c5e 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -61,6 +61,20 @@ https://github.com/networkupstools/nut/milestone/11 bug is ancient, it took recent development to hit it as a practical regression. [issue #1904, issue #2484] + - development iterations of NUT should now identify with not only the semantic + version of a preceding release, but with git-derived information about the + amount of iterations that followed (if available): the three-number "semver" + would be seen on release snapshots, while other builds would expose the + added components: one with the amount of commits on the main development + trunk since the preceding release which are ancestors of the built code + base, and in case of feature development branches -- another component + with the amount of commits unique to this branch (which are not part of + the development trunk). This allows to produce more relevant (monotonously + growing) version identifiers for packages and similar artifacts, with more + meaningful upgrades via development snapshots, eventually. A copy of the + current version information would be embedded into "dist" archives as a + `VERSION_DEFAULT` file. [#1949] + - drivers, `upsd`, `upsmon`: reduce "scary noise" about failure to `fopen()` the PID file (which most of the time means that no previous instance of the daemon was running to potentially conflict with), especially useless diff --git a/UPGRADING.adoc b/UPGRADING.adoc index 908ce287e9..9af03874c7 100644 --- a/UPGRADING.adoc +++ b/UPGRADING.adoc @@ -26,6 +26,16 @@ Changes from 2.8.2 to 2.8.3 - PLANNED: Keep track of any further API clean-up? +- NUT development snapshots can now have more version components than the + standard semantic versioning triplet, optionally adding the amount of + commits on the development trunk since previous release, and the amount + of commits on a feature branch that are unique to it. Release artifacts + that have zeroes in both positions would have them stripped and still + have the standard "semver" exposed, but the development snapshots can + now be more reasonably upgraded with automated tooling. A copy of the + current version information would be embedded into "dist" archives as + a `VERSION_DEFAULT` file, so it can be used without git. [issue #1949] + - `usbhid-ups` subdriver `PowerCOM HID` subdriver sent UPS `shutdown` and `stayoff` commands in wrong byte order, at least for devices currently in the field. Driver now sends the commands in a way that satisfies new diff --git a/docs/nut.dict b/docs/nut.dict index 575264f3a8..0fd8a7a9c8 100644 --- a/docs/nut.dict +++ b/docs/nut.dict @@ -1,4 +1,4 @@ -personal_ws-1.1 en 3198 utf-8 +personal_ws-1.1 en 3199 utf-8 AAC AAS ABI @@ -2724,6 +2724,7 @@ securityLevel securityName sed selftest +semver sendback sendline sendmail From 13b2533a5bba8b8e274941f0031cb1a2f44f0646 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 25 Jul 2024 23:56:05 +0200 Subject: [PATCH 11/29] configure.ac: clarify further work possible about NUT versioning support [#1949] Signed-off-by: Jim Klimov --- configure.ac | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 456155e357..c38eba6633 100644 --- a/configure.ac +++ b/configure.ac @@ -16,7 +16,10 @@ dnl Note: srcdir is only set after AC INIT has completed, but $0 points dnl to the generated configure script which is part of dist tarball and dnl should be at source root too. dnl Note: this gets evaluated (script called) a lot of times during autoconf -dnl but ends up as static strings in the generated configure script. +dnl but ends up as static strings in the generated configure script. It may +dnl be beneficial to have a `version.m4` generated by `autogen.sh` and/or +dnl shipped in a tarball, allowing for a singular include into configure.ac +dnl See https://github.com/networkupstools/nut/issues/1949 for details. AC_INIT([nut], [m4_esyscmd_s([WANT_VER=VER50 "`dirname "$0"`/tools/gitlog2version.sh" 2>/dev/null])], [https://github.com/networkupstools/nut/issues],[nut], From 6504c2c6498f53092d0287e250d5f29dbb5b4244 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 00:10:39 +0200 Subject: [PATCH 12/29] configure.ac: introduce NUT_SOURCE_GITREV_IS_RELEASE and NUT_SOURCE_GITREV_SEMVER [#1949] Signed-off-by: Jim Klimov --- configure.ac | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index c38eba6633..ad46a8b09d 100644 --- a/configure.ac +++ b/configure.ac @@ -36,6 +36,16 @@ dnl (that one comes from the NUT_VERSION_MACRO from nut_version.h file). dnl # Example: NUT_SOURCE_GITREV='2.8.2.695.1-696-g0e00f0777' NUT_SOURCE_GITREV="`WANT_VER=DESC50 "${srcdir}/tools/gitlog2version.sh" 2>/dev/null`" +dnl A true/false (literally) response that can be used for prettier messages +dnl emitted by NUT code. +NUT_SOURCE_GITREV_IS_RELEASE="`WANT_VER=IS_RELEASE "${srcdir}/tools/gitlog2version.sh" 2>/dev/null`" +AS_IF([$NUT_SOURCE_GITREV_IS_RELEASE], [NUT_SOURCE_GITREV_DEVREL="release"], [NUT_SOURCE_GITREV_DEVREL="development iteration"]) + +dnl Semantic version of most-recent NUT release this code is derived from. +dnl It may equal the NUT_SOURCE_GITREV and NUT_SOURCE_GITREV_NUMERIC, but +dnl this situation is only expected if NUT_SOURCE_GITREV_IS_RELEASE==true. +NUT_SOURCE_GITREV_SEMVER="`WANT_VER=SEMVER "${srcdir}/tools/gitlog2version.sh" 2>/dev/null`" + dnl Gitrev-based build identifier which can be used for e.g. PyPI uploads: dnl # Example: NUT_SOURCE_GITREV_NUMERIC='2.8.2.695.1.696' dnl # NUT_SOURCE_GITREV_NUMERIC="`echo "${NUT_SOURCE_GITREV}" | sed -e 's/^v//' -e 's/-g.*$//' -e 's/-/./g'`" @@ -102,7 +112,10 @@ AC_CONFIG_SRCDIR(server/upsd.c) AC_CONFIG_MACRO_DIR([m4]) AS_IF([test x"${NUT_SOURCE_GITREV}" = x], [echo "Network UPS Tools version ${PACKAGE_VERSION}"], - [echo "Network UPS Tools version ${PACKAGE_VERSION} (${NUT_SOURCE_GITREV})"]) + [AS_IF([test x"${NUT_SOURCE_GITREV}" = x"${PACKAGE_VERSION}"], + [echo "Network UPS Tools version ${PACKAGE_VERSION} ${NUT_SOURCE_GITREV_DEVREL}"], + [echo "Network UPS Tools version ${PACKAGE_VERSION} (${NUT_SOURCE_GITREV}) ${NUT_SOURCE_GITREV_DEVREL}"]) + ]) AC_CANONICAL_TARGET NUT_CHECK_OS NUT_STASH_WARNINGS @@ -697,7 +710,10 @@ NUT_ARG_ENABLE([keep_nut_report_feature], AS_IF([test x"${NUT_SOURCE_GITREV}" = x], [NUT_REPORT([configured version], [${PACKAGE_VERSION}])], - [NUT_REPORT([configured version], [${PACKAGE_VERSION} (${NUT_SOURCE_GITREV})])]) + [AS_IF([test x"${NUT_SOURCE_GITREV}" = x"${PACKAGE_VERSION}"], + [NUT_REPORT([configured version], [${PACKAGE_VERSION} ${NUT_SOURCE_GITREV_DEVREL}])], + [NUT_REPORT([configured version], [${PACKAGE_VERSION} (${NUT_SOURCE_GITREV}) ${NUT_SOURCE_GITREV_DEVREL}])]) + ]) dnl Note: the compiler/pragma/attr methods below are custom for NUT codebase: NUT_COMPILER_FAMILY @@ -4705,6 +4721,8 @@ AC_SUBST(TREE_VERSION) AC_SUBST(NUT_NETVERSION) AC_SUBST(FORCE_NUT_VERSION) AC_SUBST(NUT_SOURCE_GITREV) +AC_SUBST(NUT_SOURCE_GITREV_IS_RELEASE) +AC_SUBST(NUT_SOURCE_GITREV_SEMVER) AC_SUBST(NUT_SOURCE_GITREV_NUMERIC) AC_SUBST(LIBSSL_CFLAGS) AC_SUBST(LIBSSL_LIBS) From 812b3f20ae2f3d4ff7c074e38b2fd5be6b9a159d Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 00:21:17 +0200 Subject: [PATCH 13/29] include/Makefile.am: nut_version.h: inject also NUT_VERSION_SEMVER_MACRO and NUT_VERSION_IS_RELEASE [#1949] Signed-off-by: Jim Klimov --- common/common.c | 5 ++++- include/Makefile.am | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/common/common.c b/common/common.c index 5acecd0118..b85ed9376b 100644 --- a/common/common.c +++ b/common/common.c @@ -62,7 +62,7 @@ static int upsnotify_report_verbosity = -1; /* the reason we define UPS_VERSION as a static string, rather than a macro, is to make dependency tracking easier (only common.o depends - on nut_version_macro.h), and also to prevent all sources from + on nut_version.h), and also to prevent all sources from having to be recompiled each time the version changes (they only need to be re-linked). */ #include "nut_version.h" @@ -2122,6 +2122,9 @@ void nut_report_config_flags(void) * in case of rebuilds while developers are locally iterating -- this * may be disabled for faster local iterations at a cost of a little lie). */ + /* FIXME: Make use of NUT_VERSION_SEMVER_MACRO and + * NUT_VERSION_IS_RELEASE ? "release" : "development iteration" + */ if (PACKAGE_VERSION && UPS_VERSION && (strlen(UPS_VERSION) < 12 || !strstr(UPS_VERSION, PACKAGE_VERSION)) ) { diff --git a/include/Makefile.am b/include/Makefile.am index 3dee8c770f..29e3267ed7 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -33,6 +33,8 @@ MAINTAINERCLEANFILES = Makefile.in .dirstamp nut_version.h: @FORCE_NUT_VERSION@ @GITREV="`$(top_srcdir)/tools/gitlog2version.sh`" || GITREV=""; \ + GITREV_IS_RELEASE="`WANT_VER=IS_RELEASE $(top_srcdir)/tools/gitlog2version.sh 2>/dev/null`" || GITREV_IS_RELEASE="false"; \ + GITREV_SEMVER="`WANT_VER=SEMVER $(top_srcdir)/tools/gitlog2version.sh 2>/dev/null`" || GITREV_SEMVER=""; \ { echo '/* Autogenerated file. Do not change. */' ; \ echo '/* This file was generated by "make". */' ; \ if [ -z "$$GITREV" ]; then \ @@ -45,9 +47,18 @@ nut_version.h: @FORCE_NUT_VERSION@ echo ' * building the newest tagged commit itself - then just the tag).'; \ echo ' */' ; \ fi ; \ + if [ -z "$$GITREV_SEMVER" ]; then \ + GITREV_SEMVER="@NUT_SOURCE_GITREV_SEMVER@"; \ + fi ; \ echo "#define NUT_VERSION_MACRO \"$$NUT_VERSION\"" ; \ + echo "#define NUT_VERSION_SEMVER_MACRO \"$$GITREV_SEMVER\"" ; \ + if $$GITREV_IS_RELEASE ; then \ + echo "#define NUT_VERSION_IS_RELEASE 1" ; \ + else \ + echo "#define NUT_VERSION_IS_RELEASE 0" ; \ + fi ; \ } > "$@.tmp" ; \ - echo "NUT_VERSION: \"$$NUT_VERSION\"" + echo "NUT_VERSION: \"$$NUT_VERSION\" NUT_VERSION_IS_RELEASE:$$GITREV_IS_RELEASE NUT_VERSION_SEMVER: \"$$GITREV_SEMVER\"" -test -f "$@" || cp "$@.tmp" "$@" -cmp -s "$@.tmp" "$@" || cp "$@.tmp" "$@" -rm -f "$@.tmp" From 9bd4b916f2581606854e6997daaf53075138078a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 00:38:33 +0200 Subject: [PATCH 14/29] tools/nut-scanner/nut-scanner.c: use NUT_VERSION_IS_RELEASE and NUT_VERSION_SEMVER_MACRO when printing version [#1949] Note this is a custom printer, separate from common.c Signed-off-by: Jim Klimov --- tools/nut-scanner/nut-scanner.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/nut-scanner/nut-scanner.c b/tools/nut-scanner/nut-scanner.c index fac8d4c2e0..27298180da 100644 --- a/tools/nut-scanner/nut-scanner.c +++ b/tools/nut-scanner/nut-scanner.c @@ -1543,7 +1543,12 @@ int main(int argc, char *argv[]) quiet = 1; break; case 'V': - printf("Network UPS Tools - %s\n", NUT_VERSION_MACRO); + printf("Network UPS Tools - %s %s%s%s\n", + NUT_VERSION_MACRO, + NUT_VERSION_IS_RELEASE ? "release" : "(development iteration after ", + NUT_VERSION_IS_RELEASE ? "" : NUT_VERSION_SEMVER_MACRO, + NUT_VERSION_IS_RELEASE ? "" : ")" + ); nut_report_config_flags(); exit(EXIT_SUCCESS); case 'a': From 1aabb49feb043f09516c580e320a4aec95c124de Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 00:48:43 +0200 Subject: [PATCH 15/29] common/common.c: convert nut_report_config_flags() to more definitive behavior with NUT_VERSION_IS_RELEASE flag and NUT_VERSION_SEMVER_MACRO string [#1949] Signed-off-by: Jim Klimov --- common/common.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/common/common.c b/common/common.c index b85ed9376b..3b0b9fbe67 100644 --- a/common/common.c +++ b/common/common.c @@ -2103,7 +2103,9 @@ void nut_report_config_flags(void) * Depending on amount of configuration tunables involved by a particular * build of NUT, the string can be quite long (over 1KB). */ +#if 0 const char *acinit_ver = NULL; +#endif /* Pass these as variables to avoid warning about never reaching one * of compiled codepaths: */ const char *compiler_ver = CC_VERSION; @@ -2113,6 +2115,7 @@ void nut_report_config_flags(void) if (nut_debug_level < 1) return; +#if 0 /* Only report git revision if NUT_VERSION_MACRO in nut_version.h aka * UPS_VERSION here is remarkably different from PACKAGE_VERSION from * configure.ac AC_INIT() -- which may be e.g. "2.8.0.1" although some @@ -2122,9 +2125,6 @@ void nut_report_config_flags(void) * in case of rebuilds while developers are locally iterating -- this * may be disabled for faster local iterations at a cost of a little lie). */ - /* FIXME: Make use of NUT_VERSION_SEMVER_MACRO and - * NUT_VERSION_IS_RELEASE ? "release" : "development iteration" - */ if (PACKAGE_VERSION && UPS_VERSION && (strlen(UPS_VERSION) < 12 || !strstr(UPS_VERSION, PACKAGE_VERSION)) ) { @@ -2133,7 +2133,14 @@ void nut_report_config_flags(void) * especially embedders, tend to place their product IDs here), * or if PACKAGE_VERSION *is NOT* a substring of it: */ acinit_ver = PACKAGE_VERSION; +/* + // Triplet that was printed below: + (acinit_ver ? " (release/snapshot of " : ""), + (acinit_ver ? acinit_ver : ""), + (acinit_ver ? ")" : ""), +*/ } +#endif /* NOTE: If changing wording here, keep in sync with configure.ac logic * looking for CONFIG_FLAGS_DEPLOYED via "configured with flags:" string! @@ -2155,9 +2162,9 @@ void nut_report_config_flags(void) difftime(now.tv_sec, upslog_start.tv_sec), (long)(now.tv_usec - upslog_start.tv_usec), UPS_VERSION, - (acinit_ver ? " (release/snapshot of " : ""), - (acinit_ver ? acinit_ver : ""), - (acinit_ver ? ")" : ""), + NUT_VERSION_IS_RELEASE ? " release" : " (development iteration after ", + NUT_VERSION_IS_RELEASE ? "" : NUT_VERSION_SEMVER_MACRO, + NUT_VERSION_IS_RELEASE ? "" : ")", (compiler_ver && *compiler_ver != '\0' ? " built with " : ""), (compiler_ver && *compiler_ver != '\0' ? compiler_ver : ""), (compiler_ver && *compiler_ver != '\0' ? " and" : ""), @@ -2174,9 +2181,9 @@ void nut_report_config_flags(void) if (xbit_test(upslog_flags, UPSLOG_SYSLOG)) syslog(LOG_DEBUG, "Network UPS Tools version %s%s%s%s%s%s%s %s%s", UPS_VERSION, - (acinit_ver ? " (release/snapshot of " : ""), - (acinit_ver ? acinit_ver : ""), - (acinit_ver ? ")" : ""), + NUT_VERSION_IS_RELEASE ? " release" : " (development iteration after ", + NUT_VERSION_IS_RELEASE ? "" : NUT_VERSION_SEMVER_MACRO, + NUT_VERSION_IS_RELEASE ? "" : ")", (compiler_ver && *compiler_ver != '\0' ? " built with " : ""), (compiler_ver && *compiler_ver != '\0' ? compiler_ver : ""), (compiler_ver && *compiler_ver != '\0' ? " and" : ""), From 045b3a767a7c37658ae40cda226b40405c74f3f5 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 01:54:22 +0200 Subject: [PATCH 16/29] ci_build.sh: check_gitignore(): define FILE_GLOB_EXCLUDE differently [#1949] Signed-off-by: Jim Klimov --- ci_build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci_build.sh b/ci_build.sh index 1b9ebd2a63..a92676cbe4 100755 --- a/ci_build.sh +++ b/ci_build.sh @@ -668,8 +668,8 @@ check_gitignore() { # and git diff; note that filenames starting with a dot should be # reported by `git status -- '*'` and not hidden. [ -n "${FILE_GLOB-}" ] || FILE_GLOB="'*'" - # Always filter these names away; note: no extra quoting here: - FILE_GLOB_EXCLUDE=":!.ci*.log* :!VERSION_DEFAULT" + # Always filter these names away: + FILE_GLOB_EXCLUDE="':!.ci*.log*' ':!VERSION_DEFAULT'" [ -n "${GIT_ARGS-}" ] || GIT_ARGS='' # e.g. GIT_ARGS="--ignored" # Display contents of the diff? # (Helps copy-paste from CI logs to source to amend quickly) From 8739f4844b7df3e3b582c56b9022958562a819d0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 07:09:04 +0000 Subject: [PATCH 17/29] tools/gitlog2version.sh: provide a fallback for older git which does not know how to --exclude [#1949] Signed-off-by: Jim Klimov --- tools/gitlog2version.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/gitlog2version.sh b/tools/gitlog2version.sh index 1ba4de7268..10bd0ee54e 100755 --- a/tools/gitlog2version.sh +++ b/tools/gitlog2version.sh @@ -93,9 +93,16 @@ getver_git() { ALL_TAGS_ARG="" if [ x"${ALL_TAGS-}" = xtrue ] ; then ALL_TAGS_ARG="--tags" ; fi - DESC="`git describe $ALL_TAGS_ARG --match 'v[0-9]*.[0-9]*.[0-9]' --exclude '*-signed' --exclude '*rc*' --exclude '*alpha*' --exclude '*beta*' --exclude '*Windows*' --exclude '*IPM*' --always`" + # Praises to old gits and the new, who may --exclude: + # NOTE: "--always" should not be needed in NUT repos, + # but may help other projects who accept such scheme: + # it tells git to return a commit hash if no tag is matched. + DESC="`git describe $ALL_TAGS_ARG --match 'v[0-9]*.[0-9]*.[0-9]' --exclude '*-signed' --exclude '*rc*' --exclude '*alpha*' --exclude '*beta*' --exclude '*Windows*' --exclude '*IPM*' --always 2>/dev/null`" \ + && [ -n "${DESC}" ] \ + || DESC="`git describe $ALL_TAGS_ARG | grep -Ev '(rc|-signed|alpha|beta|Windows|IPM)' | grep -E 'v[0-9]*.[0-9]*.[0-9]'`" # Old stripper (also for possible refspec parts like "tags/"): # echo "${DESC}" | sed -e 's/^v\([0-9]\)/\1/' -e 's,^.*/,,' + if [ x"${DESC}" = x ] ; then echo "$0: FAILED to 'git describe' this codebase" >&2 ; return ; fi # Nearest (annotated by default) tag preceding the HEAD in history: TAG="`echo "${DESC}" | sed 's/-[0-9][0-9]*-g[0-9a-fA-F][0-9a-fA-F]*$//'`" From 6b339650586c8dd772cfb1c499aa5f61ed352b67 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 07:15:31 +0000 Subject: [PATCH 18/29] configure.ac: update comment about AC_INIT complaints for m4_esyscmd_s() [#1949] Signed-off-by: Jim Klimov --- configure.ac | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure.ac b/configure.ac index ad46a8b09d..e0ff8c4559 100644 --- a/configure.ac +++ b/configure.ac @@ -20,6 +20,9 @@ dnl but ends up as static strings in the generated configure script. It may dnl be beneficial to have a `version.m4` generated by `autogen.sh` and/or dnl shipped in a tarball, allowing for a singular include into configure.ac dnl See https://github.com/networkupstools/nut/issues/1949 for details. +dnl Oddly, autoconf-2.69 on CentOS 7 both complains that AC INIT argument +dnl is not a literal, and does contain expected values in the generated +dnl script and include/config.h. A "pure" m4 solution would be quieter. AC_INIT([nut], [m4_esyscmd_s([WANT_VER=VER50 "`dirname "$0"`/tools/gitlog2version.sh" 2>/dev/null])], [https://github.com/networkupstools/nut/issues],[nut], From fe141bfbbee79ad5a769c90c0e91de502da56e83 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 07:21:20 +0000 Subject: [PATCH 19/29] autogen.sh: update comment about AC_INIT complaints for m4_esyscmd_s() [#1949] Signed-off-by: Jim Klimov --- autogen.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/autogen.sh b/autogen.sh index 14afe2fae0..6b07d3d39a 100755 --- a/autogen.sh +++ b/autogen.sh @@ -167,6 +167,13 @@ fi >&2 [ -f NEWS ] || { echo "Please see NEWS.adoc for actual contents" > NEWS; } [ -f README ] || { echo "Please see README.adoc for actual contents" > README; } +echo "----------------------------------------------------------------------" +echo "Please note that on some systems the routine below can complain that " +echo " > configure.ac: warning: AC_INIT: not a literal: m4_esyscmd_s(...)" +echo "but still does the right thing about PACKAGE_VERSION and PACKAGE_URL settings." +echo "Please post an issue in NUT bug tracker with platform details if it does not." +echo "----------------------------------------------------------------------" + echo "Calling autoreconf..." AUTOTOOL_RES=0 if $DEBUG ; then From 20b1a15b677f02800c710c783b98b90148a76184 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 07:47:19 +0000 Subject: [PATCH 20/29] common/common.c: hush compiler warnings about unreachable code paths with NUT_VERSION_IS_RELEASE macro decisions [#1949] Signed-off-by: Jim Klimov --- common/common.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/common/common.c b/common/common.c index 3b0b9fbe67..24c2433ba4 100644 --- a/common/common.c +++ b/common/common.c @@ -2157,6 +2157,20 @@ void nut_report_config_flags(void) now.tv_sec -= 1; } +#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE +#pragma GCC diagnostic push +#endif +#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE +#pragma GCC diagnostic ignored "-Wunreachable-code" +#endif +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunreachable-code" +#endif + /* NOTE: Some compilers deduce that macro-based decisions about + * NUT_VERSION_IS_RELEASE make one of codepaths unreachable in + * a particular build. So we pragmatically handwave this away. + */ if (xbit_test(upslog_flags, UPSLOG_STDERR)) { fprintf(stderr, "%4.0f.%06ld\t[D1] Network UPS Tools version %s%s%s%s%s%s%s %s%s\n", difftime(now.tv_sec, upslog_start.tv_sec), @@ -2178,7 +2192,7 @@ void nut_report_config_flags(void) /* NOTE: May be ignored or truncated by receiver if that syslog server * (and/or OS sender) does not accept messages of such length */ - if (xbit_test(upslog_flags, UPSLOG_SYSLOG)) + if (xbit_test(upslog_flags, UPSLOG_SYSLOG)) { syslog(LOG_DEBUG, "Network UPS Tools version %s%s%s%s%s%s%s %s%s", UPS_VERSION, NUT_VERSION_IS_RELEASE ? " release" : " (development iteration after ", @@ -2190,6 +2204,13 @@ void nut_report_config_flags(void) (config_flags && *config_flags != '\0' ? "configured with flags: " : "configured all by default guesswork"), (config_flags && *config_flags != '\0' ? config_flags : "") ); + } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif +#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE +#pragma GCC diagnostic pop +#endif } static void vupslog(int priority, const char *fmt, va_list va, int use_strerror) From c097d46d8d5c4001291eb1a59bb9a576b285ac08 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 07:49:20 +0000 Subject: [PATCH 21/29] tools/nut-scanner/nut-scanner.c: hush compiler warnings about unreachable code paths with NUT_VERSION_IS_RELEASE macro decisions [#1949] Signed-off-by: Jim Klimov --- tools/nut-scanner/nut-scanner.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/nut-scanner/nut-scanner.c b/tools/nut-scanner/nut-scanner.c index 27298180da..a3d785f5a4 100644 --- a/tools/nut-scanner/nut-scanner.c +++ b/tools/nut-scanner/nut-scanner.c @@ -1543,12 +1543,32 @@ int main(int argc, char *argv[]) quiet = 1; break; case 'V': +#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE +#pragma GCC diagnostic push +#endif +#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE +#pragma GCC diagnostic ignored "-Wunreachable-code" +#endif +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunreachable-code" +#endif + /* NOTE: Some compilers deduce that macro-based decisions about + * NUT_VERSION_IS_RELEASE make one of codepaths unreachable in + * a particular build. So we pragmatically handwave this away. + */ printf("Network UPS Tools - %s %s%s%s\n", NUT_VERSION_MACRO, NUT_VERSION_IS_RELEASE ? "release" : "(development iteration after ", NUT_VERSION_IS_RELEASE ? "" : NUT_VERSION_SEMVER_MACRO, NUT_VERSION_IS_RELEASE ? "" : ")" ); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif +#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE +#pragma GCC diagnostic pop +#endif nut_report_config_flags(); exit(EXIT_SUCCESS); case 'a': From 9b135c5227127ad4da4d1aa7fc240d24c2062557 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 08:00:17 +0000 Subject: [PATCH 22/29] tools/gitlog2version.sh: only PREFER_GIT blindly if abs_top_srcdir is a git workspace [#1949] Signed-off-by: Jim Klimov --- tools/gitlog2version.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/gitlog2version.sh b/tools/gitlog2version.sh index 10bd0ee54e..d1a5b59098 100755 --- a/tools/gitlog2version.sh +++ b/tools/gitlog2version.sh @@ -62,20 +62,29 @@ fi # a nominal "semver.1" for any development snapshots afterwards. # This file is absent in Git, but should be provided in tarballs. -# It may be re-generated by NUT autogen.sh script. +# It may be re-generated by NUT autogen.sh script forcibly, but is +# otherwise preferred if present and NUT source dir is not a git +# workspace itself (e.g. when we build from release tarballs in +# a git-tracked repository of distro recipes, do not use that +# distro's own versions for NUT). if [ -z "${DEFAULT_VERSION-}" -a -s "${abs_top_builddir}/VERSION_DEFAULT" ] ; then . "${abs_top_builddir}/VERSION_DEFAULT" || exit + [ x"${PREFER_GIT-}" = xtrue ] || { [ -e "${abs_top_srcdir}/.git" ] || PREFER_GIT=false ; } fi if [ -z "${DEFAULT_VERSION-}" -a -s "${abs_top_srcdir}/VERSION_DEFAULT" ] ; then . "${abs_top_srcdir}/VERSION_DEFAULT" || exit + [ x"${PREFER_GIT-}" = xtrue ] || { [ -e "${abs_top_srcdir}/.git" ] || PREFER_GIT=false ; } fi # Fallback default, to be updated only during release cycle [ -n "${DEFAULT_VERSION-}" ] || DEFAULT_VERSION='2.8.2.1' +# Default website paths, extended for historic sub-sites for a release [ -n "${NUT_WEBSITE-}" ] || NUT_WEBSITE="https://networkupstools.org/" -[ x"${PREFER_GIT-}" = xfalse ] || PREFER_GIT=true + +# Must be "true" or "false" exactly, interpreted as such below: +[ x"${PREFER_GIT-}" = xfalse ] || { [ -e "${abs_top_srcdir}/.git" ] && PREFER_GIT=true || PREFER_GIT=false ; } getver_git() { # NOTE: The chosen trunk branch must be up to date (may be "origin/master" From 34e7c3acbde60771e87adaecbb9d8313320d3a1a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 27 Jul 2024 07:38:00 +0200 Subject: [PATCH 23/29] configure.ac: drop square brackets around macro in AC_INIT [#1949] Per suggestion from https://github.com/NixOS/nix/issues/5832 Signed-off-by: Jim Klimov --- autogen.sh | 1 + configure.ac | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/autogen.sh b/autogen.sh index 6b07d3d39a..212cacc1f0 100755 --- a/autogen.sh +++ b/autogen.sh @@ -171,6 +171,7 @@ echo "----------------------------------------------------------------------" echo "Please note that on some systems the routine below can complain that " echo " > configure.ac: warning: AC_INIT: not a literal: m4_esyscmd_s(...)" echo "but still does the right thing about PACKAGE_VERSION and PACKAGE_URL settings." +echo "Check if your distro provides an 'autoconf-archive' package anf if it helps." echo "Please post an issue in NUT bug tracker with platform details if it does not." echo "----------------------------------------------------------------------" diff --git a/configure.ac b/configure.ac index e0ff8c4559..1ec2eba9e4 100644 --- a/configure.ac +++ b/configure.ac @@ -24,9 +24,9 @@ dnl Oddly, autoconf-2.69 on CentOS 7 both complains that AC INIT argument dnl is not a literal, and does contain expected values in the generated dnl script and include/config.h. A "pure" m4 solution would be quieter. AC_INIT([nut], - [m4_esyscmd_s([WANT_VER=VER50 "`dirname "$0"`/tools/gitlog2version.sh" 2>/dev/null])], + m4_esyscmd_s([WANT_VER=VER50 "`dirname "$0"`/tools/gitlog2version.sh" 2>/dev/null]), [https://github.com/networkupstools/nut/issues],[nut], - [m4_esyscmd_s([WANT_VER=URL "`dirname "$0"`/tools/gitlog2version.sh" 2>/dev/null])]) + m4_esyscmd_s([WANT_VER=URL "`dirname "$0"`/tools/gitlog2version.sh" 2>/dev/null])) dnl See docs/maintainer-guide.txt about releases - updating the version dnl above is a small part of the consistent ritual! From 32662987f54228dec068a5d0a39f766b41cb041a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 27 Jul 2024 07:42:00 +0200 Subject: [PATCH 24/29] autogen.sh: kill obsolete nut_version.h during regen [#1949] Signed-off-by: Jim Klimov --- autogen.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/autogen.sh b/autogen.sh index 212cacc1f0..adf5ceafc5 100755 --- a/autogen.sh +++ b/autogen.sh @@ -167,6 +167,10 @@ fi >&2 [ -f NEWS ] || { echo "Please see NEWS.adoc for actual contents" > NEWS; } [ -f README ] || { echo "Please see README.adoc for actual contents" > README; } +# Try to serve a fresh one at least when we remake from scratch like this +# Note to not do it forcefully during `configure` or rebuild +rm -f include/nut_version.h || true + echo "----------------------------------------------------------------------" echo "Please note that on some systems the routine below can complain that " echo " > configure.ac: warning: AC_INIT: not a literal: m4_esyscmd_s(...)" From 221320c1308ad774ce047c0994b0573bc6d35824 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 27 Jul 2024 08:28:47 +0200 Subject: [PATCH 25/29] docs/config-prereqs.txt: kudos to Termux Signed-off-by: Jim Klimov --- docs/config-prereqs.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/config-prereqs.txt b/docs/config-prereqs.txt index 939f542cf6..f52fea02f9 100644 --- a/docs/config-prereqs.txt +++ b/docs/config-prereqs.txt @@ -133,6 +133,20 @@ actual package source versions on both Debian 8 "Jessie" and Debian 11 "Buster"). ====== +[NOTE] +.FUN NOTE +====== +For development on the road (or a native ARM build) you can use the +link:https://termux.dev/en/[Termux] project on Android. It provides +a sufficiently Debian-like operating environment for all intents and +purposes, but you may have to use their `pkg` wrapper instead of `apt` +tooling directly. + +You would need at least a couple of gigabytes available on the internal +phone storage though, especially if using `ccache` or setting up cross +builds. +====== + Debian-like package installations commonly start with an update of metadata about recently published package revisions: From 46f3c2500b7714037562992564318b0f94231a23 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 27 Jul 2024 08:53:45 +0200 Subject: [PATCH 26/29] tools/gitlog2version.sh et al: change configurable vars to NUT_VERSION_* namespace [#1949] Signed-off-by: Jim Klimov --- Makefile.am | 2 +- autogen.sh | 2 +- configure.ac | 10 +++--- include/Makefile.am | 4 +-- tools/gitlog2version.sh | 68 +++++++++++++++++++++-------------------- 5 files changed, 44 insertions(+), 42 deletions(-) diff --git a/Makefile.am b/Makefile.am index c94e7d766e..82c6e67c26 100644 --- a/Makefile.am +++ b/Makefile.am @@ -254,7 +254,7 @@ VERSION_DEFAULT: dummy-stamp @abs_top_srcdir='$(abs_top_srcdir)' ; \ abs_top_builddir='$(abs_top_builddir)' ; \ export abs_top_srcdir ; export abs_top_builddir ; \ - WANT_VER=UPDATE_FILE '$(abs_top_srcdir)/tools/gitlog2version.sh' + NUT_VERSION_QUERY=UPDATE_FILE '$(abs_top_srcdir)/tools/gitlog2version.sh' CLEANFILES += VERSION_DEFAULT.tmp EXTRA_DIST += VERSION_DEFAULT diff --git a/autogen.sh b/autogen.sh index adf5ceafc5..f59d93e886 100755 --- a/autogen.sh +++ b/autogen.sh @@ -24,7 +24,7 @@ else DEBUG=false fi -WANT_VER=UPDATE_FILE "`dirname $0`"/tools/gitlog2version.sh +NUT_VERSION_QUERY=UPDATE_FILE "`dirname $0`"/tools/gitlog2version.sh if [ -n "${PYTHON-}" ] ; then # May be a name/path of binary, or one with args - check both diff --git a/configure.ac b/configure.ac index 1ec2eba9e4..88876d323e 100644 --- a/configure.ac +++ b/configure.ac @@ -24,9 +24,9 @@ dnl Oddly, autoconf-2.69 on CentOS 7 both complains that AC INIT argument dnl is not a literal, and does contain expected values in the generated dnl script and include/config.h. A "pure" m4 solution would be quieter. AC_INIT([nut], - m4_esyscmd_s([WANT_VER=VER50 "`dirname "$0"`/tools/gitlog2version.sh" 2>/dev/null]), + m4_esyscmd_s([NUT_VERSION_QUERY=VER50 "`dirname "$0"`/tools/gitlog2version.sh" 2>/dev/null]), [https://github.com/networkupstools/nut/issues],[nut], - m4_esyscmd_s([WANT_VER=URL "`dirname "$0"`/tools/gitlog2version.sh" 2>/dev/null])) + m4_esyscmd_s([NUT_VERSION_QUERY=URL "`dirname "$0"`/tools/gitlog2version.sh" 2>/dev/null])) dnl See docs/maintainer-guide.txt about releases - updating the version dnl above is a small part of the consistent ritual! @@ -37,17 +37,17 @@ dnl If the NUT codebase in this workspace is being developed and rebuilt dnl without reconfiguration, detailed version in the binaries will differ dnl (that one comes from the NUT_VERSION_MACRO from nut_version.h file). dnl # Example: NUT_SOURCE_GITREV='2.8.2.695.1-696-g0e00f0777' -NUT_SOURCE_GITREV="`WANT_VER=DESC50 "${srcdir}/tools/gitlog2version.sh" 2>/dev/null`" +NUT_SOURCE_GITREV="`NUT_VERSION_QUERY=DESC50 "${srcdir}/tools/gitlog2version.sh" 2>/dev/null`" dnl A true/false (literally) response that can be used for prettier messages dnl emitted by NUT code. -NUT_SOURCE_GITREV_IS_RELEASE="`WANT_VER=IS_RELEASE "${srcdir}/tools/gitlog2version.sh" 2>/dev/null`" +NUT_SOURCE_GITREV_IS_RELEASE="`NUT_VERSION_QUERY=IS_RELEASE "${srcdir}/tools/gitlog2version.sh" 2>/dev/null`" AS_IF([$NUT_SOURCE_GITREV_IS_RELEASE], [NUT_SOURCE_GITREV_DEVREL="release"], [NUT_SOURCE_GITREV_DEVREL="development iteration"]) dnl Semantic version of most-recent NUT release this code is derived from. dnl It may equal the NUT_SOURCE_GITREV and NUT_SOURCE_GITREV_NUMERIC, but dnl this situation is only expected if NUT_SOURCE_GITREV_IS_RELEASE==true. -NUT_SOURCE_GITREV_SEMVER="`WANT_VER=SEMVER "${srcdir}/tools/gitlog2version.sh" 2>/dev/null`" +NUT_SOURCE_GITREV_SEMVER="`NUT_VERSION_QUERY=SEMVER "${srcdir}/tools/gitlog2version.sh" 2>/dev/null`" dnl Gitrev-based build identifier which can be used for e.g. PyPI uploads: dnl # Example: NUT_SOURCE_GITREV_NUMERIC='2.8.2.695.1.696' diff --git a/include/Makefile.am b/include/Makefile.am index 29e3267ed7..cb13105ac5 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -33,8 +33,8 @@ MAINTAINERCLEANFILES = Makefile.in .dirstamp nut_version.h: @FORCE_NUT_VERSION@ @GITREV="`$(top_srcdir)/tools/gitlog2version.sh`" || GITREV=""; \ - GITREV_IS_RELEASE="`WANT_VER=IS_RELEASE $(top_srcdir)/tools/gitlog2version.sh 2>/dev/null`" || GITREV_IS_RELEASE="false"; \ - GITREV_SEMVER="`WANT_VER=SEMVER $(top_srcdir)/tools/gitlog2version.sh 2>/dev/null`" || GITREV_SEMVER=""; \ + GITREV_IS_RELEASE="`NUT_VERSION_QUERY=IS_RELEASE $(top_srcdir)/tools/gitlog2version.sh 2>/dev/null`" || GITREV_IS_RELEASE="false"; \ + GITREV_SEMVER="`NUT_VERSION_QUERY=SEMVER $(top_srcdir)/tools/gitlog2version.sh 2>/dev/null`" || GITREV_SEMVER=""; \ { echo '/* Autogenerated file. Do not change. */' ; \ echo '/* This file was generated by "make". */' ; \ if [ -z "$$GITREV" ]; then \ diff --git a/tools/gitlog2version.sh b/tools/gitlog2version.sh index d1a5b59098..c9371c8cfa 100755 --- a/tools/gitlog2version.sh +++ b/tools/gitlog2version.sh @@ -18,6 +18,8 @@ # ############################################################################ # +# For setup check NUT_VERSION* in script source. +# # Helper script to determine the project version in a manner similar to # what `git describe` produces, but with added numbers after the common # triplet of semantically versioned numbers: X.Y.Z.T.B(-C-gHASH) @@ -67,40 +69,40 @@ fi # workspace itself (e.g. when we build from release tarballs in # a git-tracked repository of distro recipes, do not use that # distro's own versions for NUT). -if [ -z "${DEFAULT_VERSION-}" -a -s "${abs_top_builddir}/VERSION_DEFAULT" ] ; then +if [ -z "${NUT_VERSION_DEFAULT-}" -a -s "${abs_top_builddir}/VERSION_DEFAULT" ] ; then . "${abs_top_builddir}/VERSION_DEFAULT" || exit - [ x"${PREFER_GIT-}" = xtrue ] || { [ -e "${abs_top_srcdir}/.git" ] || PREFER_GIT=false ; } + [ x"${NUT_VERSION_PREFER_GIT-}" = xtrue ] || { [ -e "${abs_top_srcdir}/.git" ] || NUT_VERSION_PREFER_GIT=false ; } fi -if [ -z "${DEFAULT_VERSION-}" -a -s "${abs_top_srcdir}/VERSION_DEFAULT" ] ; then +if [ -z "${NUT_VERSION_DEFAULT-}" -a -s "${abs_top_srcdir}/VERSION_DEFAULT" ] ; then . "${abs_top_srcdir}/VERSION_DEFAULT" || exit - [ x"${PREFER_GIT-}" = xtrue ] || { [ -e "${abs_top_srcdir}/.git" ] || PREFER_GIT=false ; } + [ x"${NUT_VERSION_PREFER_GIT-}" = xtrue ] || { [ -e "${abs_top_srcdir}/.git" ] || NUT_VERSION_PREFER_GIT=false ; } fi # Fallback default, to be updated only during release cycle -[ -n "${DEFAULT_VERSION-}" ] || DEFAULT_VERSION='2.8.2.1' +[ -n "${NUT_VERSION_DEFAULT-}" ] || NUT_VERSION_DEFAULT='2.8.2.1' # Default website paths, extended for historic sub-sites for a release [ -n "${NUT_WEBSITE-}" ] || NUT_WEBSITE="https://networkupstools.org/" # Must be "true" or "false" exactly, interpreted as such below: -[ x"${PREFER_GIT-}" = xfalse ] || { [ -e "${abs_top_srcdir}/.git" ] && PREFER_GIT=true || PREFER_GIT=false ; } +[ x"${NUT_VERSION_PREFER_GIT-}" = xfalse ] || { [ -e "${abs_top_srcdir}/.git" ] && NUT_VERSION_PREFER_GIT=true || NUT_VERSION_PREFER_GIT=false ; } getver_git() { # NOTE: The chosen trunk branch must be up to date (may be "origin/master" # or "upstream/master", etc.) for resulting version discovery to make sense. - [ x"${TRUNK-}" != x ] || TRUNK=master + [ x"${NUT_VERSION_GIT_TRUNK-}" != x ] || NUT_VERSION_GIT_TRUNK=master # How much of the known trunk history is in current HEAD? # e.g. all of it when we are on that branch or PR made from its tip, # some of it if looking at a historic snapshot, or nothing if looking # at the tagged commit (it is the merge base for itself and any of # its descendants): - BASE="`git merge-base HEAD "${TRUNK}"`" + BASE="`git merge-base HEAD "${NUT_VERSION_GIT_TRUNK}"`" # By default, only annotated tags are considered ALL_TAGS_ARG="" - if [ x"${ALL_TAGS-}" = xtrue ] ; then ALL_TAGS_ARG="--tags" ; fi + if [ x"${NUT_VERSION_GIT_ALL_TAGS-}" = xtrue ] ; then ALL_TAGS_ARG="--tags" ; fi # Praises to old gits and the new, who may --exclude: # NOTE: "--always" should not be needed in NUT repos, @@ -121,7 +123,7 @@ getver_git() { SUFFIX="`echo "${DESC}" | sed 's/^.*\(-[0-9][0-9]*-g[0-9a-fA-F][0-9a-fA-F]*\)$/\1/'`" && [ x"${SUFFIX}" != x"${TAG}" ] || SUFFIX="" # 5-digit version, note we strip leading "v" from the expected TAG value - VER5="${TAG#v}.`git log --oneline "${TAG}..${BASE}" | wc -l | tr -d ' '`.`git log --oneline "${TRUNK}..HEAD" | wc -l | tr -d ' '`" + VER5="${TAG#v}.`git log --oneline "${TAG}..${BASE}" | wc -l | tr -d ' '`.`git log --oneline "${NUT_VERSION_GIT_TRUNK}..HEAD" | wc -l | tr -d ' '`" DESC5="${VER5}${SUFFIX}" # Strip up to two trailing zeroes for trunk snapshots and releases @@ -134,36 +136,36 @@ getver_git() { } getver_default() { - DEFAULT_VERSION_DOTS="`echo "${DEFAULT_VERSION}" | sed 's/[^.]*//g' | tr -d '\n' | wc -c`" + NUT_VERSION_DEFAULT_DOTS="`echo "${NUT_VERSION_DEFAULT}" | sed 's/[^.]*//g' | tr -d '\n' | wc -c`" # Ensure at least 4 dots (5 presumed-numeric components) - DEFAULT_VERSION5_DOTS="${DEFAULT_VERSION_DOTS}" - DEFAULT_VERSION5="${DEFAULT_VERSION}" - while [ "${DEFAULT_VERSION5_DOTS}" -lt 4 ] ; do - DEFAULT_VERSION5="${DEFAULT_VERSION5}.0" - DEFAULT_VERSION5_DOTS="`expr $DEFAULT_VERSION5_DOTS + 1`" + NUT_VERSION_DEFAULT5_DOTS="${NUT_VERSION_DEFAULT_DOTS}" + NUT_VERSION_DEFAULT5="${NUT_VERSION_DEFAULT}" + while [ "${NUT_VERSION_DEFAULT5_DOTS}" -lt 4 ] ; do + NUT_VERSION_DEFAULT5="${NUT_VERSION_DEFAULT5}.0" + NUT_VERSION_DEFAULT5_DOTS="`expr $NUT_VERSION_DEFAULT5_DOTS + 1`" done # Truncate/extend to exactly 2 dots (3 presumed-numeric components) - DEFAULT_VERSION3_DOTS="${DEFAULT_VERSION_DOTS}" - DEFAULT_VERSION3="${DEFAULT_VERSION}" - while [ "${DEFAULT_VERSION3_DOTS}" -lt 2 ] ; do - DEFAULT_VERSION3="${DEFAULT_VERSION3}.0" - DEFAULT_VERSION3_DOTS="`expr $DEFAULT_VERSION3_DOTS + 1`" + NUT_VERSION_DEFAULT3_DOTS="${NUT_VERSION_DEFAULT_DOTS}" + NUT_VERSION_DEFAULT3="${NUT_VERSION_DEFAULT}" + while [ "${NUT_VERSION_DEFAULT3_DOTS}" -lt 2 ] ; do + NUT_VERSION_DEFAULT3="${NUT_VERSION_DEFAULT3}.0" + NUT_VERSION_DEFAULT3_DOTS="`expr $NUT_VERSION_DEFAULT3_DOTS + 1`" done - while [ "${DEFAULT_VERSION3_DOTS}" -gt 2 ] ; do - DEFAULT_VERSION3="`echo "${DEFAULT_VERSION3}" | sed 's,\.[0-9][0-9]*$,,'`" - DEFAULT_VERSION3_DOTS="`expr $DEFAULT_VERSION3_DOTS - 1`" + while [ "${NUT_VERSION_DEFAULT3_DOTS}" -gt 2 ] ; do + NUT_VERSION_DEFAULT3="`echo "${NUT_VERSION_DEFAULT3}" | sed 's,\.[0-9][0-9]*$,,'`" + NUT_VERSION_DEFAULT3_DOTS="`expr $NUT_VERSION_DEFAULT3_DOTS - 1`" done - DESC5="${DEFAULT_VERSION5}" - DESC50="${DEFAULT_VERSION}" - VER5="${DEFAULT_VERSION5}" - VER50="${DEFAULT_VERSION}" + DESC5="${NUT_VERSION_DEFAULT5}" + DESC50="${NUT_VERSION_DEFAULT}" + VER5="${NUT_VERSION_DEFAULT5}" + VER50="${NUT_VERSION_DEFAULT}" SUFFIX="" BASE="" - SEMVER="${DEFAULT_VERSION3}" - TAG="v${DEFAULT_VERSION3}" + SEMVER="${NUT_VERSION_DEFAULT3}" + TAG="v${NUT_VERSION_DEFAULT3}" } report_debug() { @@ -172,7 +174,7 @@ report_debug() { } report_output() { - case "${WANT_VER-}" in + case "${NUT_VERSION_QUERY-}" in "DESC5") echo "${DESC5}" ;; "DESC50") echo "${DESC50}" ;; "VER5") echo "${VER5}" ;; @@ -199,7 +201,7 @@ report_output() { cp -f "${abs_top_srcdir}/VERSION_DEFAULT" "${abs_top_builddir}/VERSION_DEFAULT" || exit fi - echo "DEFAULT_VERSION='${DESC50}'" > "${abs_top_builddir}/VERSION_DEFAULT.tmp" || exit + echo "NUT_VERSION_DEFAULT='${DESC50}'" > "${abs_top_builddir}/VERSION_DEFAULT.tmp" || exit if cmp "${abs_top_builddir}/VERSION_DEFAULT.tmp" "${abs_top_builddir}/VERSION_DEFAULT" >/dev/null 2>/dev/null ; then rm -f "${abs_top_builddir}/VERSION_DEFAULT.tmp" else @@ -212,7 +214,7 @@ report_output() { } DESC="" -if $PREFER_GIT ; then +if $NUT_VERSION_PREFER_GIT ; then if (command -v git && git rev-parse --show-toplevel) >/dev/null 2>/dev/null ; then getver_git || DESC="" fi From b43115ce9ceca16d9f09f51c8dfba071bfc5ecc6 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 27 Jul 2024 09:04:09 +0200 Subject: [PATCH 27/29] tools/gitlog2version.sh: update comment [#1949] Signed-off-by: Jim Klimov --- tools/gitlog2version.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/gitlog2version.sh b/tools/gitlog2version.sh index c9371c8cfa..32b61f17ec 100755 --- a/tools/gitlog2version.sh +++ b/tools/gitlog2version.sh @@ -63,9 +63,9 @@ fi # By legacy convention, 3-digit "semver" was for NUT releases, and # a nominal "semver.1" for any development snapshots afterwards. -# This file is absent in Git, but should be provided in tarballs. -# It may be re-generated by NUT autogen.sh script forcibly, but is -# otherwise preferred if present and NUT source dir is not a git +# The VERSION_DEFAULT files are absent in Git, but should be provided +# in tarballs. It may be re-generated by NUT autogen.sh script forcibly, +# but is otherwise preferred if present and NUT source dir is not a git # workspace itself (e.g. when we build from release tarballs in # a git-tracked repository of distro recipes, do not use that # distro's own versions for NUT). From aac869e8ce693aefb386ff4f6ce8b1d33d223053 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 27 Jul 2024 09:13:57 +0200 Subject: [PATCH 28/29] tools/gitlog2version.sh, ci_build.sh: allow VERSION_FORCED for some distros [#1949] Signed-off-by: Jim Klimov --- .gitignore | 1 + UPGRADING.adoc | 5 ++++- ci_build.sh | 2 +- tools/gitlog2version.sh | 10 ++++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index db5d9cf882..bebff04af3 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ Makefile.in /TODO /UPGRADING /VERSION_DEFAULT +/VERSION_FORCED /install-sh /libtool /ltmain.sh diff --git a/UPGRADING.adoc b/UPGRADING.adoc index 9af03874c7..fb1ec1c291 100644 --- a/UPGRADING.adoc +++ b/UPGRADING.adoc @@ -34,7 +34,10 @@ Changes from 2.8.2 to 2.8.3 have the standard "semver" exposed, but the development snapshots can now be more reasonably upgraded with automated tooling. A copy of the current version information would be embedded into "dist" archives as - a `VERSION_DEFAULT` file, so it can be used without git. [issue #1949] + a `VERSION_DEFAULT` file, so it can be used without git. Certain distros + can benefit from a `VERSION_FORCED` file or a `NUT_VERSION_FORCED` + environment variable exported from their build system, e.g. via + `echo NUT_VERSION_FORCED=1.1.1 > VERSION_FORCED`. [issue #1949] - `usbhid-ups` subdriver `PowerCOM HID` subdriver sent UPS `shutdown` and `stayoff` commands in wrong byte order, at least for devices currently diff --git a/ci_build.sh b/ci_build.sh index a92676cbe4..fc4b905d28 100755 --- a/ci_build.sh +++ b/ci_build.sh @@ -669,7 +669,7 @@ check_gitignore() { # reported by `git status -- '*'` and not hidden. [ -n "${FILE_GLOB-}" ] || FILE_GLOB="'*'" # Always filter these names away: - FILE_GLOB_EXCLUDE="':!.ci*.log*' ':!VERSION_DEFAULT'" + FILE_GLOB_EXCLUDE="':!.ci*.log*' ':!VERSION_DEFAULT' ':!VERSION_FORCED'" [ -n "${GIT_ARGS-}" ] || GIT_ARGS='' # e.g. GIT_ARGS="--ignored" # Display contents of the diff? # (Helps copy-paste from CI logs to source to amend quickly) diff --git a/tools/gitlog2version.sh b/tools/gitlog2version.sh index 32b61f17ec..0e15289e0d 100755 --- a/tools/gitlog2version.sh +++ b/tools/gitlog2version.sh @@ -69,6 +69,16 @@ fi # workspace itself (e.g. when we build from release tarballs in # a git-tracked repository of distro recipes, do not use that # distro's own versions for NUT). +# Embedded distros that hack a NUT version are not encouraged to, but +# can, use a VERSION_FORCED variable or file with higher priority. +if [ -s "${abs_top_srcdir}/VERSION_FORCED" ] ; then + . "${abs_top_srcdir}/VERSION_FORCED" || exit +fi +if [ -n "${NUT_VERSION_FORCED-}" ] ; then + NUT_VERSION_DEFAULT="${NUT_VERSION_FORCED-}" + NUT_VERSION_PREFER_GIT=false +fi + if [ -z "${NUT_VERSION_DEFAULT-}" -a -s "${abs_top_builddir}/VERSION_DEFAULT" ] ; then . "${abs_top_builddir}/VERSION_DEFAULT" || exit [ x"${NUT_VERSION_PREFER_GIT-}" = xtrue ] || { [ -e "${abs_top_srcdir}/.git" ] || NUT_VERSION_PREFER_GIT=false ; } From 88fdc820a04c0fcdae88beddf7d72a6f0af5be4b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 27 Jul 2024 09:46:37 +0200 Subject: [PATCH 29/29] tools/gitlog2version.sh: allow NUT_VERSION_FORCED_SEMVER for some distros [#1949] Test: :; ./clients/upsmon -DDV Network UPS Tools upsmon 2.8.2.404.365-769-g96f0c9cb3 0.000000 [D1] Network UPS Tools version 2.8.2.404.365-769-g96f0c9cb3 (development iteration after 1.1.1) built with clang version 16.0.6... Signed-off-by: Jim Klimov --- .gitignore | 1 + UPGRADING.adoc | 7 ++++++- ci_build.sh | 2 +- tools/gitlog2version.sh | 22 +++++++++++++++++++--- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index bebff04af3..c7292d334f 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,7 @@ Makefile.in /UPGRADING /VERSION_DEFAULT /VERSION_FORCED +/VERSION_FORCED_SEMVER /install-sh /libtool /ltmain.sh diff --git a/UPGRADING.adoc b/UPGRADING.adoc index fb1ec1c291..85cc1300fe 100644 --- a/UPGRADING.adoc +++ b/UPGRADING.adoc @@ -37,7 +37,12 @@ Changes from 2.8.2 to 2.8.3 a `VERSION_DEFAULT` file, so it can be used without git. Certain distros can benefit from a `VERSION_FORCED` file or a `NUT_VERSION_FORCED` environment variable exported from their build system, e.g. via - `echo NUT_VERSION_FORCED=1.1.1 > VERSION_FORCED`. [issue #1949] + `echo NUT_VERSION_FORCED=1.1.1 > VERSION_FORCED`. Unfortunately, some + appliances tag all software the same with their firmware version; + if this is required, a (NUT_)VERSION_FORCED_SEMVER envvar or file can + help identify the actual NUT release version triplet used on the box. + Please use it, it immensely helps with community troubleshooting! + [issue #1949] - `usbhid-ups` subdriver `PowerCOM HID` subdriver sent UPS `shutdown` and `stayoff` commands in wrong byte order, at least for devices currently diff --git a/ci_build.sh b/ci_build.sh index fc4b905d28..f9e330922a 100755 --- a/ci_build.sh +++ b/ci_build.sh @@ -669,7 +669,7 @@ check_gitignore() { # reported by `git status -- '*'` and not hidden. [ -n "${FILE_GLOB-}" ] || FILE_GLOB="'*'" # Always filter these names away: - FILE_GLOB_EXCLUDE="':!.ci*.log*' ':!VERSION_DEFAULT' ':!VERSION_FORCED'" + FILE_GLOB_EXCLUDE="':!.ci*.log*' ':!VERSION_DEFAULT' ':!VERSION_FORCED*'" [ -n "${GIT_ARGS-}" ] || GIT_ARGS='' # e.g. GIT_ARGS="--ignored" # Display contents of the diff? # (Helps copy-paste from CI logs to source to amend quickly) diff --git a/tools/gitlog2version.sh b/tools/gitlog2version.sh index 0e15289e0d..3e38102e60 100755 --- a/tools/gitlog2version.sh +++ b/tools/gitlog2version.sh @@ -70,10 +70,18 @@ fi # a git-tracked repository of distro recipes, do not use that # distro's own versions for NUT). # Embedded distros that hack a NUT version are not encouraged to, but -# can, use a VERSION_FORCED variable or file with higher priority. +# can, use a NUT_VERSION_FORCED variable or a VERSION_FORCED file with +# higher priority than auto-detection attempts. Unfortunately, some +# appliances tag all software the same with their firmware version; +# if this is required, a (NUT_)VERSION_FORCED_SEMVER envvar or file can +# help identify the actual NUT release version triplet used on the box. +# Please use it, it immensely helps with community troubleshooting! if [ -s "${abs_top_srcdir}/VERSION_FORCED" ] ; then . "${abs_top_srcdir}/VERSION_FORCED" || exit fi +if [ -s "${abs_top_srcdir}/VERSION_FORCED_SEMVER" ] ; then + . "${abs_top_srcdir}/VERSION_FORCED_SEMVER" || exit +fi if [ -n "${NUT_VERSION_FORCED-}" ] ; then NUT_VERSION_DEFAULT="${NUT_VERSION_FORCED-}" NUT_VERSION_PREFER_GIT=false @@ -141,7 +149,11 @@ getver_git() { DESC50="${VER50}${SUFFIX}" # Leave exactly 3 components - SEMVER="`echo "${VER5}" | sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)\..*$/\1/'`" + if [ -n "${NUT_VERSION_FORCED_SEMVER-}" ] ; then + SEMVER="${NUT_VERSION_FORCED_SEMVER-}" + else + SEMVER="`echo "${VER5}" | sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)\..*$/\1/'`" + fi # FIXME? Add ".0" up to 3 components? } @@ -174,7 +186,11 @@ getver_default() { VER50="${NUT_VERSION_DEFAULT}" SUFFIX="" BASE="" - SEMVER="${NUT_VERSION_DEFAULT3}" + if [ -n "${NUT_VERSION_FORCED_SEMVER-}" ] ; then + SEMVER="${NUT_VERSION_FORCED_SEMVER-}" + else + SEMVER="${NUT_VERSION_DEFAULT3}" + fi TAG="v${NUT_VERSION_DEFAULT3}" }