From 7c80bc891f83fe56410b238d8909092c191fa97a Mon Sep 17 00:00:00 2001 From: Michael Jennings Date: Mon, 31 May 2021 19:16:59 -0600 Subject: [PATCH 1/2] lbnl-nhc.spec.in: Fix rebuild release handling While the initial builds directly from the Git repository were working correctly, rebuilds of the resulting artifacts were not. These changes remove the erroneous outside-repo output so that out-of-tree RPM builds use the recorded metadata (i.e., `%{gitrelease}`) as intended. This should be the final tweak prior to the 1.4.3 release. (Hopefully I didn't just jinx myself by saying that.) --- lbnl-nhc.spec.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lbnl-nhc.spec.in b/lbnl-nhc.spec.in index 31fd0ed..f5f86c7 100644 --- a/lbnl-nhc.spec.in +++ b/lbnl-nhc.spec.in @@ -3,9 +3,9 @@ %global release %{rel}%{?dist} %global gitrelease @GITRELEASE@ -%{expand:%%global gd_rel_delta %(git describe --abbrev=4 --always --tags --long --match '[[:digit:]][[:alnum:].]*[[:alnum:]]' --dirty=.1 | cut -d- -f 2- | tr '-' '.')} -%{expand:%%global rel_pre_post %(git describe --tags HEAD | grep -Eq '^%{version}' >&/dev/null && echo 1. || echo 0.)} -%{expand:%%global spec_rel %{rel_pre_post}%{gd_rel_delta}} +%{expand:%%global gd_rel_delta %(GD1=`git describe --abbrev=4 --always --tags --long --match '[[:digit:]][[:alnum:].]*[[:alnum:]]' --dirty=.1 2>/dev/null` ; test -n "${GD1}" && echo "${GD1}" | cut -d- -f 2- | tr '-' '.')%%{nil}} +%{expand:%%global rel_pre_post %(GD2=`git describe --tags HEAD 2>/dev/null` ; if test -n "${GD2}" ; then echo "${GD2}" | grep -Eq '^%{version}' >&/dev/null && echo 1. || echo 0. ; fi)%%{nil}} +%{expand:%%global spec_rel %{?rel_pre_post}%{?gd_rel_delta}%%{nil}} %{!?rel:%{expand:%%global rel %(if test -z "%{spec_rel}" ; then echo "%{gitrelease}" ; else echo "%{spec_rel}" ; fi)}} %{!?sname:%global sname nhc} From c29cfb80f1434d3a362fb4418b036375763cf2c9 Mon Sep 17 00:00:00 2001 From: Michael Jennings Date: Thu, 3 Jun 2021 00:26:40 -0600 Subject: [PATCH 2/2] lbnl-nhc.spec.in: Special-case tagged release If the current version being built (as specified in `configure.ac` and assigned to `%{version}`) exactly matches the tag for that same version in the Git repository, swap out the normal Git-based `%{rel}` string for simply "1" if the working directory is clean or "1.1" if it's dirty. (The disttag is, of course, appended in all cases.) Additionally, since the Git-fu that generates all this stuff isn't exactly obvious, I added several detailed comments to describe what each macro is doing and why. --- lbnl-nhc.spec.in | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lbnl-nhc.spec.in b/lbnl-nhc.spec.in index f5f86c7..6efbded 100644 --- a/lbnl-nhc.spec.in +++ b/lbnl-nhc.spec.in @@ -2,11 +2,38 @@ %global version @VERSION@ %global release %{rel}%{?dist} +### Macros to populate RPM %{RELEASE} field with useful info +# {gitrelease} holds the ./configure-generated version of the same +# info that's calculated for {spec_rel} below. This allows us to +# build out-of-tree with the same Git info. %global gitrelease @GITRELEASE@ +# {gd_rel_delta} uses "git describe" to return a string in the form +# ".g[.1]?" to be used in {spec_rel} below. %{expand:%%global gd_rel_delta %(GD1=`git describe --abbrev=4 --always --tags --long --match '[[:digit:]][[:alnum:].]*[[:alnum:]]' --dirty=.1 2>/dev/null` ; test -n "${GD1}" && echo "${GD1}" | cut -d- -f 2- | tr '-' '.')%%{nil}} +# {rel_pre_post} gets set to either "1." or "0." based on whether the +# source was built from a commit before ("0.") or after ("1.") the +# tagged release specified by {version} above. %{expand:%%global rel_pre_post %(GD2=`git describe --tags HEAD 2>/dev/null` ; if test -n "${GD2}" ; then echo "${GD2}" | grep -Eq '^%{version}' >&/dev/null && echo 1. || echo 0. ; fi)%%{nil}} +# {spec_rel} combines the two values above into a single string for +# use in the "Release:" field. The resulting string, when used at the +# beginning of the "Release:" header value, not only guarantees +# correct RPM NEVR ordering (i.e., newer packages will always upgrade +# older ones) but also shows how many were made since the +# last tagged release, the Git commit from which the source +# tarball ("Source:" below) was built, and whether the tarball also +# contains some uncommitted changes from a "dirty" working tree (".1" +# on the end). %{expand:%%global spec_rel %{?rel_pre_post}%{?gd_rel_delta}%%{nil}} -%{!?rel:%{expand:%%global rel %(if test -z "%{spec_rel}" ; then echo "%{gitrelease}" ; else echo "%{spec_rel}" ; fi)}} +# {rel} ultimately determines what the release string will be; only +# the disttag gets appended to it. If the user specifies their own +# value (e.g., "rpmbuild --define 'rel 1'"), that value is used +# instead. If not, the string described above is pulled either from +# {spec_rel} (if building from Git repo) or {gitrelease} (if building +# from SRPM or source tarball). +# As a special case, if the commit being built exactly matches the Git +# tag for the specified version, {rel} is set to either "1" (clean +# working directory) or "1.1" (dirty working directory). +%{!?rel:%{expand:%%global rel %(REL="%{?spec_rel}%{!?spec_rel:%{gitrelease}}" ; if (echo "${REL:-nope}" | grep -Fq "1.0.g" 2>/dev/null) ; then if (echo "${REL:-nope}" | grep -q '\.1$' 2>/dev/null) ; then echo "1.1" ; else echo 1 ; fi ; elif test -z "%{spec_rel}" ; then echo "%{gitrelease}" ; else echo "%{spec_rel}" ; fi)%{nil}}} %{!?sname:%global sname nhc} %{!?nhc_script_dir:%global nhc_script_dir %{_sysconfdir}/%{sname}/scripts}